It occurs to me that, with my Harmonium project, using the standard C ABI directly isn’t necessarily a win. The C linking model is, shall we say, outdated. To make other languages work with it, I have to use some sort of external definition file to specify a function’s semantics. I can’t just say “function pointer”, I have to say “Function-that-takes-these-type-arguments-and-returns-this pointer.” And any OO is right out.
Because I have to add semantics anyway, it makes sense to go to a higher level; support a simple object model as well, perhaps? Closures? Typing information?
Since once the Harmonium interface has been laid down, it’s pretty much laid down for good, this is something that deserves some more thought.
On the other hand, recall that C is the lowest common denominator. Anything I do, I have to be able to use in C. I think JIT-compiled closures might be the cleanest solution; we can do lots of fun things with that. Let’s make up some pseudo-C:
harm_module_t *fooMod = harm_load_module(”foo”);
harm_module_t *(*newFoo)(int bar) = harm_get_symbol(fooMod, “new”);
harm_module_t *foo = newFoo(5);
int (*foo_getBar)(void) = harm_get_symbol(foo, “getBar”);
int bar = foo_getBar(); // returns 5
You’ll notice I needed to loosen up the idea of what exactly makes a “module”, since a function in a module can generate them at a whim. I probably shouldn’t call them modules. The “foo” module isn’t exactly a class, though; it’s not like you can subclass it. Trying to make different object models intermingle is a terribly, terribly bad idea.
See, you still get all this glue code, but it’s standard glue code. Although for languages with enough introspection ability to not need XML files for their language module to be aware of all of its semantics, it’s not really automatable.
Well, I suppose one could use Harmonium itself to generate C glue code. In fact, now that I think of it, that’s a tremendously interesting and promising idea; one that really shows off why Harmonium is useful as a platform. I don’t have to write a new tool to bind every language to every other language supported by Harmonium; once the initial (relatively light) porting work is done for that language, that’s it. You don’t have to know what language you’re dealing with to bind code to it.
JIT is a huge win. This project is not usefully possible without it. With just a touch of runtime-generated code, however, we can get a world of great results.