Esempio n. 1
0
        void EmitIfConstant(EmitContext ec)
        {
            IntegralExpression ce = null;

            if (Expression is IntegralExpression)
            {
                ce = (IntegralExpression)Expression;
            }

            bool val = ce.Value != 0;

            if (!val) // emit else
            {
                FalseStatement.Emit(ec);
            }
            else
            {
                TrueStatement.Emit(ec);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Emit code
 /// </summary>
 /// <returns>Success or fail</returns>
 public override bool Emit(EmitContext ec)
 {
     if (Expression is IntegralExpression)
     {
         EmitIfConstant(ec);
     }
     else
     {
         // emit expression branchable
         ec.EmitComment("if-expression evaluation");
         Expression.EmitBranchable(ec, Else, false);
         ec.EmitComment("(" + Expression.CommentString() + ") is true");
         TrueStatement.Emit(ec);
         ec.EmitInstruction(new Jump()
         {
             DestinationLabel = ExitIf.Name
         });
         ec.MarkLabel(Else);
         ec.EmitComment("Else ");
         FalseStatement.Emit(ec);
         ec.MarkLabel(ExitIf);
     }
     return(true);
 }
Esempio n. 3
0
        protected override void DoEmit(EmitContext ec)
        {
            var endLabel = ec.DefineLabel();

            Condition.Emit(ec);
            ec.EmitCastToBoolean(Condition.GetEvaluatedCType(ec));

            if (FalseStatement == null)
            {
                ec.Emit(OpCode.BranchIfFalse, endLabel);
                TrueStatement.Emit(ec);
            }
            else
            {
                var falseLabel = ec.DefineLabel();
                ec.Emit(OpCode.BranchIfFalse, falseLabel);
                TrueStatement.Emit(ec);
                ec.Emit(OpCode.Jump, endLabel);
                ec.EmitLabel(falseLabel);
                FalseStatement.Emit(ec);
            }

            ec.EmitLabel(endLabel);
        }