After exploring the JSR-292 API, looks like dataflow-style keeps the code free from hardcoded signatures that expose datatypes (int, float, etc). It would be great to hear from projects testing this approach. For example, adding three operands (either ints or floats) in a datatype-agnostic manner becomes:
@ForceInlining public final MethodHandle add3(MethodHandle rand1, MethodHandle rand2, MethodHandle rand3) { return add2(add2(rand1, rand2), rand3);}@ForceInlining public finalMethodHandle add2(MethodHandle a, MethodHandle b) { // assert: both operands have the same datatype (int or float) if(a.type().returnType() == INT) { int result = ( (int) a.invokeExact() // this triggers all side-effects of evaluating the first operand + (int) b.invokeExact() ) return constantMH(result); } else { ... // ditto for float}The compilation scheme above does without reifying everything into MHs, e.g. loops, try-catch-finally, and all of switch, ternary operation, if-then stmt; can appear in their plain formulation. On the other hand, accesses to datatype-dependent fields and local vars has to be mediated via MHs.
I really hope the above can be made to run at native speed (after inlining and tracing).
P.S.: It would be great to have an API for the above besides the current one ;)
Miguel
http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/