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