On 05/10/2011 02:27 PM, Jim Laskey wrote:
Currently we get an "java.lang.IllegalArgumentException: Array is not
of length n" error if the array being passed in does not match the
array length supplied on the asSpreader call. But wouldn't a dynamic
language want some flexibility there.
ex.
Suppose a language implementation chose 8 as the maximum number of
args to be passed directly and any call over 8 arguments is passed as
an array. (All in the name of dispatch implementation simplicity.)
The main point of JSR 292 is that your implementation should not have to
do this kind of restriction.
This kind of trick can be done by the JSR 292 implementation,
from the language runtime point of view, you can pass 255 arguments or less.
def f(x, y) { ...}
f(1); // one short but can be padded with
null or undef.
You can use insertArguments here.
f(1, 2); // correct number of args.
f(1, 2, 3); // one too many, just truncate.
You can use dropArguments here.
f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // passed as an fixed size array,
need to spread over two args.
You can use asCollector() here.
f(1, 2 | x); // passed as a variable sized array,
need to spread over two args.
I ave no idea what '|' means.
In the last two cases we really don't know what size may be fired at
us based on call site info. All we really care about is the first two
value and then discard the rest.
a) Is the asSpread runtime check too restrictive?
OR
b) Is anyone aware of a clever little trick to spread and truncate on
the fly?
Again, why do you want to restrict your runtime to manage 8 parameters ?
Otherwise, if you want to collect array at runtime, there is a way:
f should be a method handle with asVarargsCollector() called on it and
the target of invokedynamic should be a generic invoker.
Basically, if you invoke a method handle using invokeGeneric on a method
handle
created with asVarargsCollector() the array will be created at runtime.
Cheers,
-- Jim
cheers,
Rémi
_______________________________________________
mlvm-dev mailing list
[email protected]
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev