I have now modified the dynamic loader by adding a regopen function which is used instead of dlopen. I use this at the moment:
typedef module_dictionary_t = StrDict::strdict[address]; typedef registry_t = StrDict::strdict[module_dictionary_t]; fun get_module_registry: 1 -> module_dictionary_t = "PTF gcp->collector->module_registry"; which provides a map: string -> string -> address proc regopen (registry:registry_t) (lib:flx_library, name:string) tries to find a module (DLL basename) in the dictionary. If its in there it gets back another dictionary mapping strings to addresses. Otherwise it revert to dlopen and dlsym to get the core symbols. Now, Felix stuff requires two core symbols: module_name_create_thread_frame module_name_flx_start The first of these is a wrapper around the C++ constructor of the thread frame object (the thing that holds global variables). The second is equivalent to the "body" of a C++ constructor. Now, when you write a Felix program like: println$ "Hello World"; that code is actually the "body" of the constructor. Actually you did NOT write a program. Felix doesn't know what a program is. We just use side effects of the library initialisation as a program! Now, you can possibly add a "flx_main()" equivalent to C main(). This is called AFTER initialisation. however plugins add instead module_name_setup : string -> int as well as an arbitrary set of entry points. Ok, so the next problem is that we have to stop using dlopen, and instead a routine that looks up in the registry if the module is statically linked, or uses C dlopen if its a DLL. That's pretty easy :) So there now remains one problem: if we statically link a plugin, how do we populate the registry?? Unfortunately there is only one way to do this. We have to write a procedure that adds the entries to the registry, and call it. So: with static linkage we have to "mention" the symbol name anyhow to yank the routine out of a static archive. We can actually tell "flx" to generate the routine, in a similar way to how static link thunks work now. [in fact .. its the same thing we're doing and there should really only be "one way" to do it, but the top level "program" is a bit special] So given you may have to say: flx --static --preload=fdoc2html webserver for example, it remains to figure out how "webserver" can call the preloader. One way to do this is to just always call it, even if you're using all dynamic linkage. However there's a problem! Each library module is equivalent to all others. Remember "webserver" is NOT a program its actually "just another library". I think this can be made harmless (i.e. adding entries to the registry twice won't matter). -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language