예제 #1
0
        public override void Accept(ForeachStatement foreachStmt)
        {
            IodineLabel foreachLabel = methodBuilder.CreateLabel();
            IodineLabel breakLabel   = methodBuilder.CreateLabel();

            breakLabels.Push(breakLabel);
            continueLabels.Push(foreachLabel);
            foreachStmt.Iterator.Visit(this);
            int tmp = methodBuilder.CreateTemporary();

            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.Dup);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.StoreLocal, tmp);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.IterReset);
            methodBuilder.MarkLabelPosition(foreachLabel);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.LoadLocal, tmp);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.IterMoveNext);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.JumpIfFalse,
                                          breakLabel);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.LoadLocal, tmp);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.IterGetNext);
            methodBuilder.EmitInstruction(foreachStmt.Iterator.Location, Opcode.StoreLocal,
                                          symbolTable.GetSymbol
                                              (foreachStmt.Item).Index);
            foreachStmt.Body.Visit(this);
            methodBuilder.EmitInstruction(foreachStmt.Body.Location, Opcode.Jump, foreachLabel);
            methodBuilder.MarkLabelPosition(breakLabel);
            breakLabels.Pop();
            continueLabels.Pop();
        }
예제 #2
0
        public override void Accept(TupleExpression tuple)
        {
            IodineLabel startLabel = methodBuilder.CreateLabel();
            IodineLabel endLabel   = methodBuilder.CreateLabel();
            int         item       = methodBuilder.CreateTemporary();

            PatternCompiler compiler = new PatternCompiler(symbolTable, methodBuilder,
                                                           item,
                                                           parentVisitor);

            for (int i = 0; i < tuple.Children.Count; i++)
            {
                if (tuple.Children [i] is NameExpression &&
                    ((NameExpression)tuple.Children [i]).Value == "_")
                {
                    continue;
                }
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadLocal, temporary);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadConst,
                                              methodBuilder.Module.DefineConstant(new IodineInteger(i)));
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadIndex);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.StoreLocal, item);
                tuple.Children [i].Visit(compiler);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.JumpIfFalse, endLabel);
            }
            methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadTrue);
            methodBuilder.EmitInstruction(tuple.Location, Opcode.Jump, startLabel);

            methodBuilder.MarkLabelPosition(endLabel);
            methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadFalse);

            methodBuilder.MarkLabelPosition(startLabel);
        }