Search in sources :

Example 1 with VisitLabelIR

use of com.googlecode.aviator.code.interpreter.ir.VisitLabelIR 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 VisitLabelIR

use of com.googlecode.aviator.code.interpreter.ir.VisitLabelIR in project aviatorscript by killme2008.

the class InterpretCodeGenerator method visitLabel.

private void visitLabel(final Label label) {
    this.currLabel = label;
    emit(new VisitLabelIR(label));
}
Also used : VisitLabelIR(com.googlecode.aviator.code.interpreter.ir.VisitLabelIR)

Aggregations

VisitLabelIR (com.googlecode.aviator.code.interpreter.ir.VisitLabelIR)2 AssertTypeIR (com.googlecode.aviator.code.interpreter.ir.AssertTypeIR)1 BranchIfIR (com.googlecode.aviator.code.interpreter.ir.BranchIfIR)1 BranchUnlessIR (com.googlecode.aviator.code.interpreter.ir.BranchUnlessIR)1 ClearIR (com.googlecode.aviator.code.interpreter.ir.ClearIR)1 GotoIR (com.googlecode.aviator.code.interpreter.ir.GotoIR)1 JumpIR (com.googlecode.aviator.code.interpreter.ir.JumpIR)1 Label (com.googlecode.aviator.code.interpreter.ir.Label)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 IdentityHashMap (java.util.IdentityHashMap)1