[Java] Function binding

John Moeller <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
I promise that there will be some questions in here, but I wanted to 
offer a bit of background first.

If I understand it correctly, the means of determining conversions of 
function arguments from xxx functions to C++ functions is done through 
the registry, probably in one of two scenarios:

1.  If a C++ argument type is known in advance (through a bound invoker, 
for example), this argument type is a key in the registry to find the 
correct conversion for the xxx type.
2.  If a C++ argument type is not known in advance (because of a need 
for overload resolution), each overload should be attempted on-the-fly, 
and as soon as an overload is found whose conversions all succeed, then 
those converted values are used for the invoke() method of the invoker.

I have no problems with the above method; I'd surmise that it's 
extremely useful (and possibly necessary) to use with a 
dynamically-typed language.  However, for a statically-typed and 
statically-declared language like Java, it doesn't really work.

The problem is that there needs to be a function for the Java class to 
link to.  Since there isn't a way to generate a function dynamically 
(other than to have a forwarding function with every possible argument 
combination defined ahead of time; while possible up to a max arity, it 
isn't feasible), that means that there needs to be a static (i.e., 
compile-time) way of creating a forwarding function that the Java class 
may link to.  (By the way: varargs won't work; I investigated this 
possibility, and it turns out that on Windows implementations of the Sun 
JVM (and by extension, other JVM's), JNICALL is defined to be __stdcall. 
  That means no varargs.)

The obvious way that I thought of to handle something like this was to 
use fusion and/or mpl to create a (compile-time) transformed argument 
list from a set of user-defined type associations.  Much like the user 
defines a set of dynamic conversion functions for use with the invoker 
class, a user could define a set of metafunctions that would define 
legal conversions at compile time.  This would enable the transformed 
argument list to be used to generate an instantiation of a function that 
could be linked to a Java class.  This lazy list could then be used to 
perform the actual conversions at runtime.

Another method I thought about was possibly something involving proto, 
though I haven't really worked out a strategy there.

So here are my questions:

1.  Am I way off base, or did I miss something crucial in my assessment 
of the situation?

2.  Being far more experienced metaprogrammers than myself, do you think 
that a fusion/mpl (or possibly a proto) solution might work?  That is, 
do you see any glaringly obvious problems with such a solution?

3.  Given that such a solution would essentially be a *replacement* of 
the invocation architecture currently in place, which of the following 
approaches would work best for Boost?

   a.  Make the solution generic enough to work with any binding, thus 
having an alternative invocation architecture
   b.  Design a Java binding that would work independently of langbinding
   c.  Something else entirely

I'll also do more research into the design of what's already in place; 
when I read through the posts in this group the first time, I didn't 
understand what was going on as much as I do now.

Thanks for your time in reading this post.  I understand that there's a 
lot going on right now.

-- 

John Moeller
[email protected]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.