예제 #1
0
        public object VisitStatementLoopStatement(StatementLoopStatement statementLoopStatement, object o)
        {
            var loopStartAddress = nextAdr;

            Emit(Machine.JUMPop, 0, Machine.CBr, -1);
            var stopTheLoopAddress = nextAdr;

            Emit(Machine.JUMPop, 0, Machine.CBr, -1);
            Patch(loopStartAddress, nextAdr);

            var conditionEvaluationAddress = nextAdr;

            statementLoopStatement.Condition.Visit(this);
            var jumpIfAddress = nextAdr;

            Emit(Machine.JUMPIFop, 0, Machine.CBr, -1);

            statementLoopStatement.Statements.Visit(this, stopTheLoopAddress);

            Emit(Machine.JUMPop, 0, Machine.CBr, conditionEvaluationAddress);
            Patch(jumpIfAddress, nextAdr);
            Patch(stopTheLoopAddress, nextAdr);

            return(null);
        }
예제 #2
0
파일: Checker.cs 프로젝트: Laegas/CMC
        public object VisitStatementLoopStatement(StatementLoopStatement statementLoopStatement, object o)
        {
            idTable.EnterNestedScopeLevel(isLoopScope: true);

            var variableType = (VariableType.ValueTypeEnum)statementLoopStatement.Condition.Visit(this);

            if (variableType != VariableType.ValueTypeEnum.BOOLY)
            {
                throw new Exception("Loop statement condition must evaluate to a booly value");
            }

            statementLoopStatement.Statements.Visit(this);

            idTable.ExitNestedScopeLevel();

            return(null);
        }