use of com.googlecode.aviator.code.interpreter.ir.Label in project aviatorscript by killme2008.
the class InterpretCodeGenerator method resolveLabels.
private void resolveLabels(final List<IR> instruments) {
Map<Label, Integer> /* pc */
label2pc = new IdentityHashMap<Label, Integer>();
ListIterator<IR> it = instruments.listIterator();
int i = 0;
while (it.hasNext()) {
IR ir = it.next();
// Find all visit_label IR, replace them with pc.
if (ir instanceof VisitLabelIR) {
it.remove();
label2pc.put(((VisitLabelIR) ir).getLabel(), i);
} else {
i = i + 1;
}
}
// resolve label to pc
for (IR ir : instruments) {
if (ir instanceof JumpIR) {
((JumpIR) ir).setPc(label2pc.get(((JumpIR) ir).getLabel()));
}
}
}
use of com.googlecode.aviator.code.interpreter.ir.Label in project aviatorscript by killme2008.
the class InterpretCodeGenerator method onJoinLeft.
@Override
public void onJoinLeft(final Token<?> lookhead) {
if (!OperationRuntime.containsOpFunction(this.compileEnv, OperatorType.AND)) {
emit(new AssertTypeIR(AssertTypes.Bool));
Label label = makeLabel();
pushLabel0(label);
this.instruments.add(new BranchIfIR(label, new SourceInfo(this.sourceFile, lookhead.getLineNo())));
emit(PopIR.INSTANCE);
}
}
use of com.googlecode.aviator.code.interpreter.ir.Label in project aviatorscript by killme2008.
the class InterpretCodeGenerator method onJoinRight.
@Override
public void onJoinRight(final Token<?> lookhead) {
if (!OperationRuntime.containsOpFunction(this.compileEnv, OperatorType.AND)) {
emit(new AssertTypeIR(AssertTypes.Bool));
Label label = popLabel0();
visitLabel(label);
} else {
emit(OperatorIR.OR);
}
}
use of com.googlecode.aviator.code.interpreter.ir.Label in project aviatorscript by killme2008.
the class InterpretCodeGenerator method onAndRight.
@Override
public void onAndRight(final Token<?> lookhead) {
if (!OperationRuntime.containsOpFunction(this.compileEnv, OperatorType.AND)) {
emit(new AssertTypeIR(AssertTypes.Bool));
Label label = popLabel0();
visitLabel(label);
} else {
emit(OperatorIR.AND);
}
}
use of com.googlecode.aviator.code.interpreter.ir.Label in project aviatorscript by killme2008.
the class InterpretCodeGenerator method onTernaryLeft.
@Override
public void onTernaryLeft(final Token<?> lookhead) {
this.instruments.add(new GotoIR(peekLabel1(), new SourceInfo(this.sourceFile, lookhead.getLineNo())));
// emit(PopIR.INSTANCE);
Label label0 = popLabel0();
visitLabel(label0);
emit(PopIR.INSTANCE);
}
Aggregations