use of java.lang.invoke.MethodHandle in project es6draft by anba.
the class Properties method toCanonical.
private static MethodHandle toCanonical(MethodHandle handle, int fixedArguments, boolean varargs, Method method) {
assert !handle.isVarargsCollector();
MethodType type = handle.type();
int actual = type.parameterCount() - fixedArguments - (varargs ? 1 : 0);
Object[] defaults = method != null ? methodDefaults(method, fixedArguments, actual) : null;
MethodHandle filter = Parameters.filter(actual, varargs, defaults);
MethodHandle spreader = MethodHandles.spreadInvoker(type, fixedArguments);
spreader = MethodHandles.insertArguments(spreader, 0, handle);
spreader = MethodHandles.filterArguments(spreader, fixedArguments, filter);
return spreader;
}
use of java.lang.invoke.MethodHandle in project es6draft by anba.
the class Bootstrap method addSetup.
@SuppressWarnings("unused")
private static MethodHandle addSetup(MutableCallSite callsite, Object arg1, Object arg2, ExecutionContext cx) {
Type type = getType(arg1, arg2);
MethodHandle target;
if (type == Type.String) {
target = addStringMH;
} else if (type == Type.Number) {
target = addNumberMH;
} else {
target = null;
}
return setCallSiteTarget(callsite, target, getTestFor(type), addGenericMH);
}
use of java.lang.invoke.MethodHandle in project es6draft by anba.
the class Bootstrap method bootstrapDynamic.
/**
* The invokedynamic bootstrapping method.
*
* @param caller
* the caller lookup
* @param name
* the instruction name
* @param type
* the expected method type
* @return the invokedynamic call-site object
*/
public static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) {
// System.out.printf("type: %s\n", type);
try {
MutableCallSite callsite = new MutableCallSite(type);
MethodHandle setup;
switch(name) {
case CallNames.CALL:
setup = MethodHandles.insertArguments(callSetupMH, 0, callsite);
break;
case CallNames.CONSTRUCT:
setup = MethodHandles.insertArguments(constructSetupMH, 0, callsite);
break;
case CallNames.SUPER:
setup = MethodHandles.insertArguments(superSetupMH, 0, callsite);
break;
case CallNames.ADD:
setup = MethodHandles.insertArguments(addSetupMH, 0, callsite);
break;
case CallNames.EQ:
setup = MethodHandles.insertArguments(eqCmpSetupMH, 0, callsite);
break;
case CallNames.SHEQ:
setup = MethodHandles.insertArguments(strictEqCmpSetupMH, 0, callsite);
break;
case CallNames.LT:
setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.LessThan);
break;
case CallNames.GT:
setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.GreaterThan);
break;
case CallNames.LE:
setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.LessThanEquals);
break;
case CallNames.GE:
setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.GreaterThanEquals);
break;
case CallNames.CONCAT:
concatSetup(callsite, type);
return callsite;
default:
throw new IllegalArgumentException(name);
}
callsite.setTarget(setupCallSiteTarget(type, setup));
return callsite;
} catch (StackOverflowError e) {
switch(name) {
case CallNames.CALL:
return stackOverFlow_Call;
case CallNames.CONSTRUCT:
return stackOverFlow_Construct;
case CallNames.SUPER:
return stackOverFlow_Super;
case CallNames.CONCAT:
return new ConstantCallSite(MethodHandles.dropArguments(stackOverFlow_Concat, 0, type.parameterArray()));
case CallNames.ADD:
return stackOverFlow_Add;
case CallNames.EQ:
return stackOverFlow_Eq;
case CallNames.SHEQ:
return stackOverFlow_StrictEq;
case CallNames.LT:
case CallNames.GT:
case CallNames.LE:
case CallNames.GE:
return stackOverFlow_Cmp;
default:
throw new IllegalArgumentException(name);
}
}
}
use of java.lang.invoke.MethodHandle in project es6draft by anba.
the class Bootstrap method callSetup.
@SuppressWarnings("unused")
private static MethodHandle callSetup(MutableCallSite callsite, Object function, ExecutionContext cx, Object thisValue, Object[] arguments) {
MethodHandle target, test;
if (function instanceof FunctionObject) {
FunctionObject fn = (FunctionObject) function;
test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
target = fn.getCallMethod();
} else if (function instanceof BuiltinFunction) {
BuiltinFunction fn = (BuiltinFunction) function;
test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
target = fn.getCallMethod();
} else {
target = test = null;
}
return setCallSiteTarget(callsite, target, test, callGenericMH);
}
use of java.lang.invoke.MethodHandle in project es6draft by anba.
the class Bootstrap method strictEqCmpSetup.
@SuppressWarnings("unused")
private static MethodHandle strictEqCmpSetup(MutableCallSite callsite, Object arg1, Object arg2) {
Type type = getType(arg1, arg2);
MethodHandle target;
if (type == Type.String) {
target = strictEqCmpStringMH;
} else if (type == Type.Number) {
target = strictEqCmpNumberMH;
} else if (type == Type.Boolean) {
target = strictEqCmpBooleanMH;
} else {
target = null;
}
return setCallSiteTarget(callsite, target, getTestFor(type), strictEqCmpGenericMH);
}
Aggregations