diff --git a/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs b/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs index 3fd93fe..e2443d5 100644 --- a/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs +++ b/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs @@ -265,8 +265,8 @@ public Void VisitClsStatement(Cls statement) public Void VisitCompoundStatement(Compound statement) { - _machine.RunStatementList(statement.Statements[0], this, true); - + _machine.RunCompoundStatement(statement.Statements, this); + return null!; } @@ -282,7 +282,7 @@ public void RunProgram(IStatement statement, bool initialize) if (initialize) _machine.Initialize(); - _machine.RunStatementList(statement, this, false); + _machine.RunStatementList(statement, this); _trs80.WriteLine(); _trs80.WriteLine("READY"); } @@ -375,7 +375,7 @@ public Void VisitIfStatement(If statement) { if (!IsTruthy(Evaluate(statement.Condition))) return null!; - _machine.RunThenBranch(statement.ThenBranch, this); + _machine.RunCompoundStatement(statement.ThenBranch, this); return null!; } @@ -595,7 +595,7 @@ private void ExecuteGosub(IStatement jumpToStatement, IStatement resumeStatement { try { - _machine.RunStatementList(jumpToStatement, this, false); + _machine.RunStatementList(jumpToStatement, this); } catch (ReturnFromGosub) { diff --git a/Trs80.Level1Basic.VirtualMachine/Machine/IMachine.cs b/Trs80.Level1Basic.VirtualMachine/Machine/IMachine.cs index 7c698d5..6c7905c 100644 --- a/Trs80.Level1Basic.VirtualMachine/Machine/IMachine.cs +++ b/Trs80.Level1Basic.VirtualMachine/Machine/IMachine.cs @@ -25,8 +25,8 @@ public interface IMachine void SaveProgram(string path); void LoadProgram(string path); void NewProgram(); - void RunStatementList(IStatement statement, IInterpreter interpreter, bool breakOnLineChange); - void RunThenBranch(CompoundStatementList thenBranch, IInterpreter interpreter); + void RunStatementList(IStatement statement, IInterpreter interpreter); + void RunCompoundStatement(CompoundStatementList compound, IInterpreter interpreter); void SetNextStatement(IStatement statement); void HaltRun(); IStatement GetStatementByLineNumber(int lineNumber); diff --git a/Trs80.Level1Basic.VirtualMachine/Machine/Machine.cs b/Trs80.Level1Basic.VirtualMachine/Machine/Machine.cs index 804128e..c7e569b 100644 --- a/Trs80.Level1Basic.VirtualMachine/Machine/Machine.cs +++ b/Trs80.Level1Basic.VirtualMachine/Machine/Machine.cs @@ -124,32 +124,30 @@ public void NewProgram() Initialize(); } - public void RunStatementList(IStatement statement, IInterpreter interpreter, bool breakOnLineChange) + public void RunStatementList(IStatement statement, IInterpreter interpreter) { ExecutionHalted = false; if (statement == null) return; - int lineNumber = statement.LineNumber; while (statement != null && !ExecutionHalted) { _nextStatement = GetNextStatement(statement); interpreter.Execute(statement); statement = _nextStatement; - if (breakOnLineChange && statement?.LineNumber != lineNumber) break; } } - public void RunThenBranch(CompoundStatementList thenBranch, IInterpreter interpreter) + public void RunCompoundStatement(CompoundStatementList compound, IInterpreter interpreter) { IStatement nextStatement = _nextStatement; ExecutionHalted = false; - if (thenBranch == null) return; - IStatement statement = thenBranch[0]; + if (compound == null) return; + IStatement statement = compound[0]; while (statement != null && !ExecutionHalted) { - _nextStatement = GetNextStatement(statement); + _nextStatement = statement.Next; interpreter.Execute(statement); if (statement is IListStatementDecorator decorated && decorated.BaseType() == typeof(Goto)) return; statement = _nextStatement;