Beispiel #1
0
        protected override void DoEmit(EmitContext ec)
        {
            ec.BeginBlock(InitBlock);
            foreach (var s in InitBlock.InitStatements)
            {
                s.Emit(ec);
            }
            foreach (var s in InitBlock.Statements)
            {
                s.Emit(ec);
            }

            var endLabel = ec.DefineLabel();

            var contLabel = ec.DefineLabel();

            ec.EmitLabel(contLabel);
            ContinueExpression.Emit(ec);
            ec.EmitCastToBoolean(ContinueExpression.GetEvaluatedCType(ec));
            ec.Emit(OpCode.BranchIfFalse, endLabel);

            LoopBody.Emit(ec);

            if (NextExpression != null)
            {
                NextExpression.Emit(ec);
                ec.Emit(OpCode.Pop);
            }
            ec.Emit(OpCode.Jump, contLabel);

            ec.EmitLabel(endLabel);

            ec.EndBlock();
        }
        protected override void DoEmit(EmitContext initialContext)
        {
            initialContext.BeginBlock(InitBlock);
            foreach (var s in InitBlock.InitStatements)
            {
                s.Emit(initialContext);
            }
            foreach (var s in InitBlock.Statements)
            {
                s.Emit(initialContext);
            }

            var nextLabel = initialContext.DefineLabel();
            var endLabel  = initialContext.DefineLabel();

            var ec = initialContext.PushLoop(breakLabel: endLabel, continueLabel: nextLabel);

            //
            // Test the condition:
            //   If succeeded then execute the loop body
            //   If failed, goto END
            //
            var conditionLabel = ec.DefineLabel();

            ec.EmitLabel(conditionLabel);
            ContinueExpression.Emit(ec);
            ec.EmitCastToBoolean(ContinueExpression.GetEvaluatedCType(ec));
            ec.Emit(OpCode.BranchIfFalse, endLabel);

            //
            // Fall through to the loop body
            //
            LoopBody.Emit(ec);

            //
            // Fall through to the NEXT label
            //   Run the incrementer
            //   Loop back to the condition
            //
            ec.EmitLabel(nextLabel);
            if (NextExpression != null)
            {
                NextExpression.Emit(ec);
                ec.Emit(OpCode.Pop);
            }
            ec.Emit(OpCode.Jump, conditionLabel);

            //
            // Arrive here when the condition fails
            //
            ec.EmitLabel(endLabel);

            ec.EndBlock();
        }
Beispiel #3
0
        protected override void DoEmit(EmitContext ec)
        {
            InitBlock.Emit(ec);

            var endLabel = ec.DefineLabel();

            var contLabel = ec.DefineLabel();

            ec.EmitLabel(contLabel);
            ContinueExpression.Emit(ec);
            ec.EmitCastToBoolean(ContinueExpression.GetEvaluatedCType(ec));
            ec.Emit(OpCode.BranchIfFalse, endLabel);

            LoopBody.Emit(ec);
            NextExpression.Emit(ec);
            ec.Emit(OpCode.Pop);
            ec.Emit(OpCode.Jump, contLabel);

            ec.EmitLabel(endLabel);
        }