daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

A new feature to reduce inter-module dependency #65

Closed daokoder closed 9 years ago

daokoder commented 9 years ago

Recent introduction of module stream has created several inter-module dependencies. More such dependencies can be expected when modules such as time and random get more used by other modules. So I tried to introduce a new feature to reduce such dependencies.

The idea is to create proxy APIs in the form of function pointers for commonly used modules. These APIs (function pointers) are defined in the aux module. These function pointers are set properly when the actual module is loaded. Other modules only need to have dependency on aux, in order to use the proxy APIs.

Now the aux module is built as a part of the Dao project, so all modules will automatically have dependency on aux as well, and users do not need to do anything about it for building. At running time, the aux module is loaded automatically when any dll module is loaded for the first time. This way the running time dependency is also resolved.

The only caveat is that all the proxy APIs are prefixed with _.

Please see stream, time and image for examples.

Night-walker commented 9 years ago

Doesn't work on Windows. I get overwhelmed by undefined references.

Night-walker commented 9 years ago

Sample output when building time:

gcc DaoMake.Objs/dao_time.c.D51B.o -ggdb -shared-libgcc -Wl,-rpath=../../../bin/
 -L../../bin/ -lwinmm -Wl,-rpath=/usr/local/lib -ldao -shared -shared-libgcc -Wl
,--out-implib,libdao_time.dll   -o ../../lib/dao/modules/dao_time.dll
DaoMake.Objs/dao_time.c.D51B.o: In function `DaoTime_OnLoad':
c:\Dao\modules\time/../auxlib/../time/dao_time.h:65: undefined reference to `_im
p___DaoMkTimeUtc'
c:\Dao\modules\time/../auxlib/../time/dao_time.h:66: undefined reference to `_im
p___DaoTime_GetParts'
c:\Dao\modules\time/../auxlib/../time/dao_time.h:67: undefined reference to `_im
p___DaoProcess_PutTime'
c:\Dao\modules\time/../auxlib/../time/dao_time.h:68: undefined reference to `_im
p___DaoProcess_NewTime'
collect2.exe: error: ld returned 1 exit status
daokoder commented 9 years ago

Fixed.

Night-walker commented 9 years ago

Now random also requires fixing.

gcc DaoMake.Objs/dao_random.c.17C8.o -ggdb -shared-libgcc -Wl,-rpath=../../../bi
n/ -L../../bin/ -lwinmm -Wl,-rpath=/usr/local/lib -ldao -shared -shared-libgcc -
Wl,--out-implib,libdao_random.dll   -o ../../lib/dao/modules/dao_random.dll
DaoMake.Objs/dao_random.c.17C8.o: In function `DaoRandom_OnLoad':
c:\Dao\modules\random/../auxlib/../random/dao_random.h:49: undefined reference t
o `_imp___DaoRandGenerator_New'
c:\Dao\modules\random/../auxlib/../random/dao_random.h:50: undefined reference t
o `_imp___DaoRandGenerator_Delete'
c:\Dao\modules\random/../auxlib/../random/dao_random.h:51: undefined reference t
o `_imp___DaoRandGenerator_Seed'
c:\Dao\modules\random/../auxlib/../random/dao_random.h:52: undefined reference t
o `_imp___DaoRandGenerator_GetUniform'
c:\Dao\modules\random/../auxlib/../random/dao_random.h:53: undefined reference t
o `_imp___DaoRandGenerator_GetNormal'
collect2.exe: error: ld returned 1 exit status
daokoder commented 9 years ago

Ok, random was modified on Mac, but it requires a minor change in its makefile.dao to support proxy api on Windows. Now done.

Night-walker commented 9 years ago

Now it's OK.

dumblob commented 9 years ago

How will be handled the (very) common case of compiling some external/downstream modules (i.e. not modules from standard library) depending on some module(s) in standard library without modifying and recompiling the aux module?

daokoder commented 9 years ago

How will be handled the (very) common case of compiling some external/downstream modules (i.e. not modules from standard library) depending on some module(s) in standard library without modifying and recompiling the aux module?

Should be handled in the same way, because the building dependency is only on the aux module and it is compiled with all the proxy APIs of all the supported standard modules.

Night-walker commented 9 years ago

I suppose the feature more or less stabilized, so the issue can be closed.