DSL for handle binding

Charles Oliver Nutter headius at headius.com
Mon Mar 21 15:24:22 PDT 2011


Yeah, binding backward makes sense for the standard API because the
only real "anchor" in the process is the eventual target handle. You
have to eventually end up *somewhere*, so that somewhere is what you
start with. I'm mostly making this API because of my own frailties...I
have endless problems picturing MH adaptation going backward,
especially since so many of the adaptations are explicitly going
*forward* like permute taking an expected input and permuting onto the
given handle).

I did get reorder in, and it's far easier for me to follow when
explicitly going forward:

        MethodHandle handle = Binder
                .from(String.class, Integer.class, Float.class, String.class)
                .drop(0, 2)
                .reorder(0, 0)
                .invoke(target);

...with the end target having a signature of (String, String)String.
My brain is happy.

- Charlie

On Mon, Mar 21, 2011 at 5:05 PM, John Rose <john.r.rose at oracle.com> wrote:
> The standard MH factory methods construct method handles functionally, from the target backward.  This simplifies "pure functional" implementations, but (as you found) is kind of hard to read.  Constructing them from the caller forward is often easier to read, since it is a narrative of what happens when the composite MH gets called.
>
> That's a long way of saying, yes, this is very interesting.  Bravo!
>
> -- John
>
> On Mar 20, 2011, at 11:21 PM, Charles Oliver Nutter wrote:
>
>> I'm working on a DSL for binding method handles *forward* rather than
>> backward. It's not much logic, really, but for me it's much easier to
>> reason about incoming arguments being transformed toward an eventual
>> target, rather than a target being transformed backward toward
>> incoming arguments. The API lets you bind like this:
>>
>> MethodHandle mh = Binder
>>    .from(String.class, String.class, String.class) // (String, String)String
>>    .drop(1, String.class) // (String)String
>>    .insert(0, 'hello') // (String, String)String
>>    .cast(String.class, CharSequence.class, Object.class) //
>> (CharSequence, Object)String
>>    .invoke(someTargetHandle);
>>
>> Is this interesting to others on the list? I will push my work to
>> github sooner rather than later if so. I plan to use this in JRuby to
>> make the MH binding code easier to read.
>>
>> - Charlie
>> _______________________________________________
>> mlvm-dev mailing list
>> mlvm-dev at openjdk.java.net
>> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>


More information about the mlvm-dev mailing list