예제 #1
0
 public void Accept(ForeachNode node)
 {
 }
예제 #2
0
        public void Accept(ForeachNode node)
        {
            var startLabel = nextLabel();
            var endLabel = nextLabel();
            method.ContinueLabels.Push(startLabel);
            method.BreakLabels.Push(endLabel);

            int tmp, variable;
            if (!table.ContainsSymbol((++labelIndex).ToString()))
                table.AddSymbol(labelIndex.ToString());
            tmp = table.GetSymbol(labelIndex.ToString());
            if (table.ContainsSymbol(node.Variable))
                variable = table.GetSymbol(node.Variable);
            else
                variable = table.AddSymbol(node.Variable);

            node.Target.Visit(this);
            method.Emit(node.SourceLocation, InstructionType.Iter);
            method.Emit(node.SourceLocation, InstructionType.StoreLocal, tmp);
            method.EmitLabel(node.SourceLocation, startLabel);
            method.Emit(node.SourceLocation, InstructionType.LoadLocal, tmp);
            method.Emit(node.SourceLocation, InstructionType.IterableFull);
            method.Emit(node.SourceLocation, InstructionType.JumpIfTrue, endLabel);
            method.Emit(node.SourceLocation, InstructionType.LoadLocal, tmp);
            method.Emit(node.SourceLocation, InstructionType.IterableNext);
            method.Emit(node.SourceLocation, InstructionType.StoreLocal, variable);
            node.Body.Visit(this);
            method.Emit(node.SourceLocation, InstructionType.Jump, startLabel);
            method.EmitLabel(node.SourceLocation, endLabel);
        }