void EmitConstantLoop(EmitContext ec)
        {
            IntegralExpression ce = null;

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


            bool val = ce.Value != 0;

            if (val)
            { // if true
                infinite = true;

                ec.MarkLabel(EnterLoop);

                Statement.Emit(ec);
                ec.EmitInstruction(new Jump()
                {
                    DestinationLabel = EnterLoop.Name
                });
                ec.MarkLabel(ExitLoop);
            }
        }
Exemple #2
0
 void facteur(ref Expression ex)
 {
     if (la.kind == 1)
     {
         Get();
         if (StartOf(8))
         {
             ex = new VariableExpression {
                 Name = t.val, Location = new Location(t.line, t.col, t.charPos)
             };
         }
         else if (la.kind == 22)
         {
             ex = new MethodInvocationExpression {
                 Name = t.val, Location = new Location(t.line, t.col, t.charPos)
             }; List <Expression> el = null;
             Get();
             expr_list(ref el);
             (ex as MethodInvocationExpression).Arguments = el;
             Expect(23);
         }
         else
         {
             SynErr(61);
         }
     }
     else if (la.kind == 2)
     {
         Get();
         ex = new IntegralExpression {
             Value = int.Parse(t.val), Location = new Location(t.line, t.col, t.charPos)
         };
     }
     else if (la.kind == 22)
     {
         Expression target = null;
         Get();
         ex = new ParenthesisExpression {
             Location = new Location(t.line, t.col, t.charPos)
         };
         expr(ref target);
         (ex as ParenthesisExpression).Target = target;
         Expect(23);
     }
     else if (la.kind == 17)
     {
         Expression e = null;
         Get();
         ex = new UnaryOperationExpression {
             Location = new Location(t.line, t.col, t.charPos), Operator = Operators.LogicalNot
         };
         facteur(ref e);
         (ex as UnaryOperationExpression).Expression = e;
     }
     else
     {
         SynErr(62);
     }
 }
        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);
            }
        }
Exemple #4
0
        int GetValue(Expression rexp, Expression lexp)
        {
            IntegralExpression lce = ((IntegralExpression)lexp);
            IntegralExpression rce = ((IntegralExpression)rexp);


            if (_op == Operators.Add)
            {
                return(lce.Value + rce.Value);
            }
            else if (_op == Operators.Sub)
            {
                return(lce.Value - rce.Value);
            }
            else if (_op == Operators.Mul)
            {
                return(lce.Value * rce.Value);
            }
            else if (_op == Operators.Div)
            {
                return(lce.Value / rce.Value);
            }
            else if (_op == Operators.Mod)
            {
                return(lce.Value % rce.Value);
            }
            else if (_op == Operators.And)
            {
                return(lce.Value & rce.Value);
            }
            else if (_op == Operators.Or)
            {
                return(lce.Value | rce.Value);
            }
            else
            {
                return(EvalueComparison(lce.Value, rce.Value) ? 1 : 0);
            }
        }