More cleanup

This commit is contained in:
Uwe Schindler 2016-06-11 21:20:39 +02:00
parent 65352face2
commit c08b45a277
2 changed files with 12 additions and 9 deletions

View File

@ -166,4 +166,8 @@ public class SFunction extends AStatement {
}
}
}
String getHandleStaticFieldName() {
return "handle$" + name + "$" + parameters.size();
}
}

View File

@ -154,42 +154,41 @@ public final class SSource extends AStatement {
execute.endMethod();
// Write all functions:
for (SFunction function : functions) {
function.write(writer, expressions);
}
// Write a static field with Handle (function reference) for every function:
if (!functions.isEmpty()) {
// write a reference to each function
for (SFunction function : functions) {
writer.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
"handle$" + function.name + "$" + function.parameters.size(),
function.getHandleStaticFieldName(),
Type.getDescriptor(MethodHandle.class),
null,
null).visitEnd();
}
MethodWriter clinit = new MethodWriter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
final MethodWriter clinit = new MethodWriter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
WriterConstants.CLINIT, writer, expressions);
for (SFunction function : functions) {
Handle handle = new Handle(Opcodes.H_INVOKESTATIC,
final Handle handle = new Handle(Opcodes.H_INVOKESTATIC,
CLASS_TYPE.getInternalName(),
function.name,
function.method.method.getDescriptor(),
false);
clinit.push(handle);
clinit.putStatic(CLASS_TYPE,
"handle$" + function.name + "$" + function.parameters.size(),
function.getHandleStaticFieldName(),
Type.getType(MethodHandle.class));
}
clinit.returnValue();
clinit.endMethod();
}
// End writing the class and store the generated bytes.
// End writing the class and store the generated bytes:
writer.visitEnd();
bytes = writer.toByteArray();
}
@Override
void write(MethodWriter writer) {
if (reserved.usesScore()) {