mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-23 23:04:50 -08:00
Refactor emit API
This commit is contained in:
parent
5b5f4fd176
commit
cc69c607ba
|
@ -95,7 +95,7 @@ public class AnnotationDependencyListener implements DependencyListener {
|
||||||
|
|
||||||
MethodHolder accessor = new MethodHolder(methodDecl.getDescriptor());
|
MethodHolder accessor = new MethodHolder(methodDecl.getDescriptor());
|
||||||
ProgramEmitter pe = ProgramEmitter.create(accessor);
|
ProgramEmitter pe = ProgramEmitter.create(accessor);
|
||||||
ValueEmitter thisVal = pe.wrapNew();
|
ValueEmitter thisVal = pe.newVar();
|
||||||
ValueEmitter result = thisVal.getField(field.getReference(), field.getType());
|
ValueEmitter result = thisVal.getField(field.getReference(), field.getType());
|
||||||
if (field.getType() instanceof ValueType.Array) {
|
if (field.getType() instanceof ValueType.Array) {
|
||||||
result = result.cloneArray();
|
result = result.cloneArray();
|
||||||
|
@ -109,13 +109,13 @@ public class AnnotationDependencyListener implements DependencyListener {
|
||||||
|
|
||||||
MethodHolder ctor = new MethodHolder("<init>", ctorSignature.toArray(new ValueType[ctorSignature.size()]));
|
MethodHolder ctor = new MethodHolder("<init>", ctorSignature.toArray(new ValueType[ctorSignature.size()]));
|
||||||
ProgramEmitter pe = ProgramEmitter.create(ctor);
|
ProgramEmitter pe = ProgramEmitter.create(ctor);
|
||||||
ValueEmitter thisVal = pe.wrapNew();
|
ValueEmitter thisVal = pe.newVar();
|
||||||
thisVal.invokeSpecial(new MethodReference(Object.class, "<init>", void.class));
|
thisVal.invokeSpecial(new MethodReference(Object.class, "<init>", void.class));
|
||||||
for (MethodReader methodDecl : annotation.getMethods()) {
|
for (MethodReader methodDecl : annotation.getMethods()) {
|
||||||
if (methodDecl.hasModifier(ElementModifier.STATIC)) {
|
if (methodDecl.hasModifier(ElementModifier.STATIC)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ValueEmitter param = pe.wrapNew();
|
ValueEmitter param = pe.newVar();
|
||||||
FieldReference field = new FieldReference(implementorName, "$" + methodDecl.getName());
|
FieldReference field = new FieldReference(implementorName, "$" + methodDecl.getName());
|
||||||
thisVal.setField(field, methodDecl.getResultType(), param);
|
thisVal.setField(field, methodDecl.getResultType(), param);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class AnnotationDependencyListener implements DependencyListener {
|
||||||
|
|
||||||
MethodHolder annotTypeMethod = new MethodHolder("annotationType", ValueType.parse(Class.class));
|
MethodHolder annotTypeMethod = new MethodHolder("annotationType", ValueType.parse(Class.class));
|
||||||
pe = ProgramEmitter.create(annotTypeMethod);
|
pe = ProgramEmitter.create(annotTypeMethod);
|
||||||
pe.wrapNew();
|
pe.newVar();
|
||||||
pe.constant(ValueType.object(annotationType)).returnValue();
|
pe.constant(ValueType.object(annotationType)).returnValue();
|
||||||
implementor.addMethod(annotTypeMethod);
|
implementor.addMethod(annotTypeMethod);
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constant(String value) {
|
public ValueEmitter constant(String value) {
|
||||||
|
@ -84,7 +84,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constant(int value) {
|
public ValueEmitter constant(int value) {
|
||||||
|
@ -93,7 +93,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constant(long value) {
|
public ValueEmitter constant(long value) {
|
||||||
|
@ -102,7 +102,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constant(float value) {
|
public ValueEmitter constant(float value) {
|
||||||
|
@ -111,7 +111,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constant(double value) {
|
public ValueEmitter constant(double value) {
|
||||||
|
@ -120,7 +120,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setConstant(value);
|
insn.setConstant(value);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constantNull() {
|
public ValueEmitter constantNull() {
|
||||||
|
@ -128,7 +128,7 @@ public final class ProgramEmitter {
|
||||||
NullConstantInstruction insn = new NullConstantInstruction();
|
NullConstantInstruction insn = new NullConstantInstruction();
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter getField(FieldReference field, ValueType type) {
|
public ValueEmitter getField(FieldReference field, ValueType type) {
|
||||||
|
@ -138,7 +138,7 @@ public final class ProgramEmitter {
|
||||||
insn.setFieldType(type);
|
insn.setFieldType(type);
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgramEmitter setField(FieldReference field, ValueType type, ValueEmitter value) {
|
public ProgramEmitter setField(FieldReference field, ValueType type, ValueEmitter value) {
|
||||||
|
@ -163,7 +163,7 @@ public final class ProgramEmitter {
|
||||||
insn.getArguments().add(arg.variable);
|
insn.getArguments().add(arg.variable);
|
||||||
}
|
}
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return result != null ? wrap(result) : null;
|
return result != null ? var(result) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgramEmitter invokeAndIgnore(MethodReference method, ValueEmitter... arguments) {
|
public ProgramEmitter invokeAndIgnore(MethodReference method, ValueEmitter... arguments) {
|
||||||
|
@ -177,7 +177,7 @@ public final class ProgramEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setType(method.getClassName());
|
insn.setType(method.getClassName());
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
ValueEmitter instance = wrap(var);
|
ValueEmitter instance = var(var);
|
||||||
instance.invokeSpecial(method, arguments);
|
instance.invokeSpecial(method, arguments);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ public final class ProgramEmitter {
|
||||||
insn.setSize(size.getVariable());
|
insn.setSize(size.getVariable());
|
||||||
insn.setItemType(type);
|
insn.setItemType(type);
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
return wrap(var);
|
return var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter constructArray(ValueType type, int size) {
|
public ValueEmitter constructArray(ValueType type, int size) {
|
||||||
|
@ -223,12 +223,12 @@ public final class ProgramEmitter {
|
||||||
addInstruction(insn);
|
addInstruction(insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter wrap(Variable var) {
|
public ValueEmitter var(Variable var) {
|
||||||
return new ValueEmitter(this, block, var);
|
return new ValueEmitter(this, block, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter wrapNew() {
|
public ValueEmitter newVar() {
|
||||||
return wrap(program.createVariable());
|
return var(program.createVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InstructionLocation getCurrentLocation() {
|
public InstructionLocation getCurrentLocation() {
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class ValueEmitter {
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setInstance(variable);
|
insn.setInstance(variable);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(var);
|
return pe.var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setField(FieldReference field, ValueType type, ValueEmitter value) {
|
public void setField(FieldReference field, ValueType type, ValueEmitter value) {
|
||||||
|
@ -102,7 +102,7 @@ public class ValueEmitter {
|
||||||
insn.setSecondOperand(other.variable);
|
insn.setSecondOperand(other.variable);
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(var);
|
return pe.var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter add(NumericOperandType type, ValueEmitter other) {
|
public ValueEmitter add(NumericOperandType type, ValueEmitter other) {
|
||||||
|
@ -134,7 +134,7 @@ public class ValueEmitter {
|
||||||
NegateInstruction insn = new NegateInstruction(type);
|
NegateInstruction insn = new NegateInstruction(type);
|
||||||
insn.setOperand(variable);
|
insn.setOperand(variable);
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
return pe.wrap(var);
|
return pe.var(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter ineg() {
|
public ValueEmitter ineg() {
|
||||||
|
@ -155,7 +155,7 @@ public class ValueEmitter {
|
||||||
insn.getArguments().add(arg.variable);
|
insn.getArguments().add(arg.variable);
|
||||||
}
|
}
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return result != null ? pe.wrap(result) : null;
|
return result != null ? pe.var(result) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter invokeSpecial(MethodReference method, ValueEmitter... arguments) {
|
public ValueEmitter invokeSpecial(MethodReference method, ValueEmitter... arguments) {
|
||||||
|
@ -224,7 +224,7 @@ public class ValueEmitter {
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
insn.setTargetType(type);
|
insn.setTargetType(type);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter cast(NumericOperandType from, NumericOperandType to) {
|
public ValueEmitter cast(NumericOperandType from, NumericOperandType to) {
|
||||||
|
@ -233,7 +233,7 @@ public class ValueEmitter {
|
||||||
insn.setValue(variable);
|
insn.setValue(variable);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter cast(IntegerSubtype subtype, CastIntegerDirection dir) {
|
public ValueEmitter cast(IntegerSubtype subtype, CastIntegerDirection dir) {
|
||||||
|
@ -242,7 +242,7 @@ public class ValueEmitter {
|
||||||
insn.setValue(variable);
|
insn.setValue(variable);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter toInteger(IntegerSubtype from) {
|
public ValueEmitter toInteger(IntegerSubtype from) {
|
||||||
|
@ -260,7 +260,7 @@ public class ValueEmitter {
|
||||||
insn.setIndex(index.variable);
|
insn.setIndex(index.variable);
|
||||||
insn.setReceiver(variable);
|
insn.setReceiver(variable);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter getElement(int index) {
|
public ValueEmitter getElement(int index) {
|
||||||
|
@ -285,7 +285,7 @@ public class ValueEmitter {
|
||||||
insn.setArray(variable);
|
insn.setArray(variable);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter arrayLength() {
|
public ValueEmitter arrayLength() {
|
||||||
|
@ -294,7 +294,7 @@ public class ValueEmitter {
|
||||||
insn.setArray(variable);
|
insn.setArray(variable);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter instanceOf(ValueType type) {
|
public ValueEmitter instanceOf(ValueType type) {
|
||||||
|
@ -304,7 +304,7 @@ public class ValueEmitter {
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
insn.setType(type);
|
insn.setType(type);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEmitter cloneArray() {
|
public ValueEmitter cloneArray() {
|
||||||
|
@ -313,6 +313,6 @@ public class ValueEmitter {
|
||||||
insn.setArray(variable);
|
insn.setArray(variable);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
pe.addInstruction(insn);
|
pe.addInstruction(insn);
|
||||||
return pe.wrap(result);
|
return pe.var(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user