import static org.mvel2.asm.Opcodes.IASTORE;
public class ASMConditionEvaluatorJitter {
public static ConditionEvaluator jitEvaluator(String expression, Condition condition, Declaration[] declarations, ClassLoader classLoader, LeftTuple leftTuple) {
ClassGenerator generator = new ClassGenerator(getUniqueClassName(), classLoader)
.setInterfaces(ConditionEvaluator.class)
.addStaticField(ACC_PRIVATE | ACC_FINAL, "EXPRESSION", String.class, expression)
.addField(ACC_PRIVATE | ACC_FINAL, "declarations", Declaration[].class)
.addDefaultConstructor(new ClassGenerator.MethodBody() {
public void body(MethodVisitor mv) {
putFieldInThisFromRegistry("declarations", Declaration[].class, 1);
mv.visitInsn(RETURN);
}
}, Declaration[].class);
generator.addMethod(ACC_PUBLIC,
"evaluate",
generator.methodDescr(boolean.class, Object.class, InternalWorkingMemory.class, LeftTuple.class),
new EvaluateMethodGenerator(condition, declarations, leftTuple));
return generator.newInstance(Declaration[].class, declarations);
}