Custom calling conventions

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Feb 21 09:02:18 PST 2012


On Tue, Feb 21, 2012 at 01:03:09PM +0200, Manu wrote:
> So I was thinking about this extern(language) thing, the obvious ones are
> supported, but it would be really nice to be able to implement custom
> conventions for other languages/scripting languages.
> 
> For instance, I'm thinking about Android, I have JNI binding code
> everywhere, it's really ugly.
> I'd love to be able to declare:
>   extern(Java) int someJavaFunc(int x, float y)

I wonder if there's a way to "outsource" (har har) extern declarations
somehow so that instead of requiring the compiler to implement
everything, it can forward most of the stuff to a library, e.g.,
something that interfaces with JNI. The compiler would provide hooks to
such a library so that it doesn't have to know how JNI works, but just
forward calls to someJavaFunc(x,y) to a wrapper in the external library
that can then do type translation, JNI mapping, etc..

This way, we don't have to bottleneck at the compiler when we need to
support a new language binding, and we don't have to bloat the compiler
with C, C++, JNI, PerlAPI (buahaha), what-have-you. Somebody can just
write a library with the necessary hooks, and you can compile away at
your leisure.


T

-- 
Why waste time learning, when ignorance is instantaneous? -- Hobbes, from Calvin & Hobbes


More information about the Digitalmars-d mailing list