Search in sources :

Example 1 with Label

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()));
        }
    }
}
Also used : VisitLabelIR(com.googlecode.aviator.code.interpreter.ir.VisitLabelIR) IdentityHashMap(java.util.IdentityHashMap) Label(com.googlecode.aviator.code.interpreter.ir.Label) AssertTypeIR(com.googlecode.aviator.code.interpreter.ir.AssertTypeIR) NewLambdaIR(com.googlecode.aviator.code.interpreter.ir.NewLambdaIR) BranchUnlessIR(com.googlecode.aviator.code.interpreter.ir.BranchUnlessIR) LoadIR(com.googlecode.aviator.code.interpreter.ir.LoadIR) GotoIR(com.googlecode.aviator.code.interpreter.ir.GotoIR) OperatorIR(com.googlecode.aviator.code.interpreter.ir.OperatorIR) VisitLabelIR(com.googlecode.aviator.code.interpreter.ir.VisitLabelIR) ClearIR(com.googlecode.aviator.code.interpreter.ir.ClearIR) JumpIR(com.googlecode.aviator.code.interpreter.ir.JumpIR) PopIR(com.googlecode.aviator.code.interpreter.ir.PopIR) BranchIfIR(com.googlecode.aviator.code.interpreter.ir.BranchIfIR) SendIR(com.googlecode.aviator.code.interpreter.ir.SendIR) JumpIR(com.googlecode.aviator.code.interpreter.ir.JumpIR)

Example 2 with Label

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);
    }
}
Also used : SourceInfo(com.googlecode.aviator.code.interpreter.ir.SourceInfo) Label(com.googlecode.aviator.code.interpreter.ir.Label) AssertTypeIR(com.googlecode.aviator.code.interpreter.ir.AssertTypeIR) BranchIfIR(com.googlecode.aviator.code.interpreter.ir.BranchIfIR)

Example 3 with Label

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);
    }
}
Also used : Label(com.googlecode.aviator.code.interpreter.ir.Label) AssertTypeIR(com.googlecode.aviator.code.interpreter.ir.AssertTypeIR)

Example 4 with Label

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);
    }
}
Also used : Label(com.googlecode.aviator.code.interpreter.ir.Label) AssertTypeIR(com.googlecode.aviator.code.interpreter.ir.AssertTypeIR)

Example 5 with Label

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);
}
Also used : SourceInfo(com.googlecode.aviator.code.interpreter.ir.SourceInfo) GotoIR(com.googlecode.aviator.code.interpreter.ir.GotoIR) Label(com.googlecode.aviator.code.interpreter.ir.Label)

Aggregations

Label (com.googlecode.aviator.code.interpreter.ir.Label)8 AssertTypeIR (com.googlecode.aviator.code.interpreter.ir.AssertTypeIR)5 SourceInfo (com.googlecode.aviator.code.interpreter.ir.SourceInfo)4 BranchUnlessIR (com.googlecode.aviator.code.interpreter.ir.BranchUnlessIR)3 BranchIfIR (com.googlecode.aviator.code.interpreter.ir.BranchIfIR)2 GotoIR (com.googlecode.aviator.code.interpreter.ir.GotoIR)2 ClearIR (com.googlecode.aviator.code.interpreter.ir.ClearIR)1 JumpIR (com.googlecode.aviator.code.interpreter.ir.JumpIR)1 LoadIR (com.googlecode.aviator.code.interpreter.ir.LoadIR)1 NewLambdaIR (com.googlecode.aviator.code.interpreter.ir.NewLambdaIR)1 OperatorIR (com.googlecode.aviator.code.interpreter.ir.OperatorIR)1 PopIR (com.googlecode.aviator.code.interpreter.ir.PopIR)1 SendIR (com.googlecode.aviator.code.interpreter.ir.SendIR)1 VisitLabelIR (com.googlecode.aviator.code.interpreter.ir.VisitLabelIR)1 IdentityHashMap (java.util.IdentityHashMap)1