Bindings bindings = rule.getBindings();
Iterator<Binding> iterator = bindings.iterator();
while (iterator.hasNext()) {
Binding binding = iterator.next();
String name = binding.getName();
if (binding.isAlias()) {
// lookups and updates will use the aliased name
continue;
}
if (binding.isHelper()) {
// bindingMap.put(name, this);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitInsn(POP);
} else if (binding.isRecipient()) {
// bindingMap.put(name, recipient);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitInsn(POP);
// } else if (binding.isParam() || binding.isLocalVar() || binding.isReturn() ||
// binding.isThrowable() || binding.isParamCount() || binding.isParamArray()) {
} else if (!binding.isBindVar()) {
// bindingMap.put(name, args[binding.getCallArrayIndex()]);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, compiledHelperName, "bindingMap", "Ljava/util/HashMap;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 2);
mv.visitLdcInsn(binding.getCallArrayIndex());
mv.visitInsn(AALOAD);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitInsn(POP);
}
}
// execute0()
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, compiledHelperName, "execute0", "()V");
// now restore update bindings
iterator = bindings.iterator();
while (iterator.hasNext()) {
Binding binding = iterator.next();
if (binding.isAlias()) {
continue;
}
String name = binding.getName();
if (binding.isUpdated()) {
// if (binding.isParam() || binding.isLocalVar() || binding.isReturn()) {
if (!binding.isBindVar()) {
int idx = binding.getCallArrayIndex();
// Object value = bindingMap.get(name);
// args[idx] = value;
mv.visitVarInsn(ALOAD, 2); // args
mv.visitLdcInsn(idx);
mv.visitVarInsn(ALOAD, 0);