Пример #1
0
    // TODO: Add vardecl to while loop?
    //  It's pretty dumb but C++ allows it =/

    protected void ExecuteWhileStmt(AstWhileStmt stmt)
    {
        if (HadErrorOrReturn())
        {
            return;
        }

        while (!m_runtimeError)
        {
            m_blockexitk = BLOCKEXITK.Normal;

            object conditionVal = EvaluateExpr(stmt.m_condition);

            if (!IsTruthy(conditionVal))
            {
                break;
            }

            ExecuteStmt(stmt.m_body);

            if (m_blockexitk == BLOCKEXITK.Break)
            {
                break;
            }
        }
    }
Пример #2
0
 public SymbolStatusTable(SymbolStatusTable?parent, AstWhileStmt loop)
 {
     this.Parent        = parent;
     this.mSymbolStatus = new Dictionary <ISymbol, SymbolStatus>();
     this.Breakable     = loop;
     this.Continuable   = loop;
 }
Пример #3
0
        public override NodeFinderResult VisitWhileStmt(AstWhileStmt ws, int i = 0)
        {
            if (GetRelativeLocation(ws.Body.Location, i) == RelativeLocation.Same)
            {
                return(ws.Body.Accept(this, i));
            }

            return(new NodeFinderResult(ws.Scope, stmt: ws));
        }
Пример #4
0
        private AstWhileStmt AnalyseWhileStatement(AstWhileStmt whl)
        {
            whl.SubScope = new Scope("loop", whl.Scope);
            whl.SubScope.DefineLoop(whl);
            whl.Body.AttachTo(whl, whl.SubScope);
            InferType(whl.Body, null);

            return(whl);
        }
Пример #5
0
        public override string VisitWhileStmt(AstWhileStmt wh, int indentLevel = 0)
        {
            var str = "loop ";

            if (wh.Label != null)
            {
                str += " #label " + wh.Label.Name;
            }
            str += wh.Body.Accept(this);
            return(str);
        }
Пример #6
0
        private void GenerateWhile(AstWhileStmt whl)
        {
            var bbBody = LLVM.AppendBasicBlock(currentLLVMFunction, "_loop_body");
            var bbEnd  = LLVM.AppendBasicBlock(currentLLVMFunction, "_loop_end");

            loopBodyMap[whl]    = bbBody;
            breakTargetMap[whl] = bbEnd;

            builder.CreateBr(bbBody);
            builder.PositionBuilderAtEnd(bbBody);
            GenerateExpression(whl.Body, false);

            if (!whl.Body.GetFlag(ExprFlags.Returns) && !whl.Body.GetFlag(ExprFlags.Breaks))
            {
                builder.CreateBr(bbBody);
            }
            builder.PositionBuilderAtEnd(bbEnd);
        }
Пример #7
0
 public virtual ReturnType VisitWhileStmt(AstWhileStmt stmt, DataType data   = default) => default;
Пример #8
0
 protected void ResolveWhileStmt(AstWhileStmt stmt)
 {
     ResolveExpr(stmt.m_condition);
     ResolveStmt(stmt.m_body);
 }