On Wednesday, 19 September 2012 at 20:56:17 UTC, Simen Kjaeraas wrote:
On Wed, 19 Sep 2012 22:25:46 +0200, Øivind <oivind....@gmail.com> wrote:

I am struggeling to get around the cycle detection kicking in when I have static init in modules that depend on eachother.

I have seen some threads on 'fixes' for this, e.g. adding a @standalone property to the module or similar. Has there been any progress on this?

If not would it be possible in e.g. main() to get a list of all compiled-in modules, and then iterate over them and call an init function where it exists? As long as there is a way to list the name of the modules at compile-time, this should be pretty easy..?

There's no way to get that list at compile-time, because object files may be added at link-time. However, D has a ModuleInfo object, which contains
information on all modules in the program:

import std.stdio;
void main( ) {
    foreach( m; ModuleInfo ) {
        writeln( m.name );
    }
}

For details on how this object works, have a look-see at
src/druntime/src/object_.d in your DMD installation folder.

I'm not sure what you're asking for is possible even given this object,
but it's probably the closest you'll (easily) get.

If I define a function:

void getMembers() {

}

in one of my modules, all modules including this get the xgetMembers property of the ModuleInfo struct set. It seems like I should be able to do something with this, but i then get the following assertion failure:

./dboss(_d_assertm+0x26) [0x8aa1da]
./dboss() [0x7c8555]
./dboss(boss.core.proc.ProcBase!(boss.core.boss.Boss, "boss").ProcBase boss.core.proc.ProcBase!(boss.core.boss.Boss, "boss").ProcBase.__ctor()+0x31) [0x797805] ./dboss(boss.core.boss.Boss boss.core.boss.Boss.__ctor(immutable(char)[][])+0x21) [0x791099]
./dboss(_Dmain+0x33) [0x7488fb]
./dboss(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x1c) [0x8aaa70] ./dboss(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x2a) [0x8aa3ea] ./dboss(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3b) [0x8aaab7] ./dboss(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x2a) [0x8aa3ea]
./dboss(main+0xd1) [0x8aa375]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f1d0edcc76d]

Removing the function from the module makes the assertion failure go away.. What is the cause of this? And what is the getMembers function used for?


Another way of approaching this would be if I could feed a list of modules into DMD during compile time. In C++, i would be able to do this by passing a define to g++ on the command line when invoking it. Is it possible to do something similar with DMD? E.g. create a list of modules before invoking DMD, pass it to DMD, and use this at compile time to import and call my init function?





Reply via email to