Esempio n. 1
0
        public override Unit VisitWhileExpression(WhileExpressionAST whileExpression)
        {
            ILGenerator il = code.Method.GetILGenerator();

            //declaracion de las etiquetas de salto
            Label evaluarCond = il.DefineLabel();
            Label bodyInstr   = il.DefineLabel();

            //--->
            Label loopAboveEnd = code.EndCurrentLoop;

            code.EndCurrentLoop = il.DefineLabel();
            //salto a la comparacion
            il.Emit(OpCodes.Br, evaluarCond);
            //body
            il.MarkLabel(bodyInstr);
            code.PushOnStack = false;
            whileExpression.BodyExpressions.Accept(this);
            //condicion
            il.MarkLabel(evaluarCond);
            code.PushOnStack = true;
            whileExpression.ExpressionConditional.Accept(this);
            il.Emit(OpCodes.Brtrue, bodyInstr);
            //lo que viene detras del while.
            il.MarkLabel(code.EndCurrentLoop);

            //<--- reponiendo la marca del posible ciclo sobre mi.
            code.EndCurrentLoop = loopAboveEnd;

            return(Unit.Create());
        }
Esempio n. 2
0
        public override bool VisitWhileExpression(WhileExpressionAST whileExpression)
        {
            var other = _other as WhileExpressionAST;

            if (other == null)
            {
                return(false);
            }

            return(IsEqualNodes(other.ExpressionConditional, whileExpression.ExpressionConditional) &&
                   IsEqualNodes(other.BodyExpressions, whileExpression.BodyExpressions));
        }
Esempio n. 3
0
 public override bool VisitWhileExpression(WhileExpressionAST whileExpression)
 {
     whileExpression.ExpressionConditional.Accept(this);
     whileExpression.ReturnType = TigerType.GetType <ErrorType>();
     if (whileExpression.ExpressionConditional.ReturnType != TigerType.GetType <IntType>())
     {
         _errorListener.Add(new AnalysisError(AnalysisError.LoadMessage("IfCond"), whileExpression.Line, whileExpression.Columns));
     }
     else
     {
         //guardo, si hay, el ciclo previo
         LoopAST prevLoop = _scope.ContainerLoop;
         _scope.ContainerLoop = whileExpression;
         if (whileExpression.BodyExpressions.Accept(this))
         {
             //repongo el ciclo q habia
             _scope.ContainerLoop       = prevLoop;
             whileExpression.ReturnType = TigerType.GetType <NoType>();
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
 public abstract T VisitWhileExpression(WhileExpressionAST whileExpression);