DSL for handle binding

Charles Oliver Nutter headius at headius.com
Mon Mar 21 18:13:54 PDT 2011


On Mon, Mar 21, 2011 at 5:42 PM, John Rose <john.r.rose at oracle.com> wrote:
> The small integers are a little hard to decode since they shift from step to step.  In the above case, I think you don't need the explicit drop:
>
>       MethodHandle handle = Binder
>               .from(String.class, Integer.class, Float.class, String.class)
>               .reorder(3, 3)
>               .invoke(target);

Yes, I was showing some test code that introduced a drop to make sure
I'm still lining arguments up correctly. A drop plus a reorder would
not be necessary normally.

> Also, some users (including Ola, I think) have requested a combined transform which (a) drops, (b) permutes, and (c) introduces bound values.  With Binder it would look like one of these:
>
>       MethodHandle handle = Binder
>               .from(String.class, Integer.class, Float.class, String.class)
>               .reorder(Binder.arg(3), new File("foo"), Binder.arg(3))
>               .invoke(target);
>
> which ends with type signature (String, File, String)String.  Or even:
>
>       MethodHandle handle = Binder
>               .from(String.class, Integer.class, Float.class, String.class)
>               .invoke(target, Binder.arg(3), new File("foo"), Binder.arg(3));

Ahh, interesting ideas! Yes, the positional nature is probably the
trickiest (especially when binding backward...I never get it right!)
because of arguments moving around. I should probably see if there are
other good language representations for list manipulation that make it
clearer what's happening (and aren't as subject to elements moving).

Another option might be a name/value representation of the incoming arguments?

Binder
    .from(returns(String.class), arg("a", Integer.class), arg("b",
Float.class), arg("c", String.class)
    .reorder("c", "c")

Internally it would be juggling around pairs of name+type, so it would
use the same identifier even if arguments shift around. The "a", "b",
"c" could also be defaults, so that if you used the simple form:

    .from(String.class, Integer.class, Float.class, String.class)

You could still use "c" to represent the String argument.

- Charlie


More information about the mlvm-dev mailing list