Ejemplo n.º 1
0
        bool IBoundExprVisitor <bool> .Visit(BoundWhileExpr expr)
        {
            mJumpTable.PatchJumpBack("while");

            // evaluate the condition
            expr.Condition.Accept(this);
            mJumpTable.JumpIfFalse("end");

            // body
            expr.Body.Accept(this);

            // jump back to loop
            mJumpTable.JumpBack("while");

            // exit loop
            mJumpTable.PatchJump("end");

            return(true);
        }
Ejemplo n.º 2
0
        IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(WhileExpr expr)
        {
            var bound = new BoundWhileExpr(expr.Condition.Accept(this), expr.Body.Accept(this));

            if (bound.Condition.Type != Decl.Bool)
            {
                throw new CompileException(expr.Position, String.Format(
                    "Condition of while/do is returning type {0} but should be Bool.",
                    bound.Condition.Type));
            }

            if (bound.Body.Type != Decl.Unit)
            {
                throw new CompileException(expr.Position, String.Format(
                    "Body of while/do is returning type {0} but should be Unit.",
                    bound.Body.Type));
            }

            return bound;
        }