From 1b7f3d120e5e0d620bc9554558e880c148e0b529 Mon Sep 17 00:00:00 2001 From: Garry Pettet Date: Tue, 17 Jul 2018 12:11:05 +0100 Subject: [PATCH] Added Interpreter.forceKill flag Setting the forceKill flag to True will stop the interpreter running. --- src/Roo/Interpreter.xojo_code | 15 ++++++++++++++- src/Roo/Parser.xojo_code | 13 ------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Roo/Interpreter.xojo_code b/src/Roo/Interpreter.xojo_code index 3609452..0ae758e 100644 --- a/src/Roo/Interpreter.xojo_code +++ b/src/Roo/Interpreter.xojo_code @@ -135,6 +135,7 @@ Implements ExprVisitor,StmtVisitor limit = statements.Ubound for i = 0 to limit Execute(statements(i)) + if forceKill then return next i End Sub @@ -198,6 +199,8 @@ Implements ExprVisitor,StmtVisitor Sub Reset() ' Reset the interpreter. + self.forceKill = False + self.globals = new Environment self.environment = globals @@ -1206,7 +1209,7 @@ Implements ExprVisitor,StmtVisitor Function VisitWhileStmt(stmt as WhileStmt) As Variant try - while IsTruthy(Evaluate(stmt.condition)) + while IsTruthy(Evaluate(stmt.condition)) and not forceKill Execute(stmt.body) wend @@ -1246,6 +1249,10 @@ Implements ExprVisitor,StmtVisitor Private environment As Environment #tag EndProperty + #tag Property, Flags = &h0 + forceKill As Boolean = False + #tag EndProperty + #tag Property, Flags = &h0 #tag Note Holds a fixed reference to the outermost global environment. @@ -1306,6 +1313,12 @@ Implements ExprVisitor,StmtVisitor InitialValue="0" Type="Integer" #tag EndViewProperty + #tag ViewProperty + Name="forceKill" + Group="Behavior" + InitialValue="False" + Type="Boolean" + #tag EndViewProperty #tag EndViewBehavior End Class #tag EndClass diff --git a/src/Roo/Parser.xojo_code b/src/Roo/Parser.xojo_code index 561b00b..1cef329 100644 --- a/src/Roo/Parser.xojo_code +++ b/src/Roo/Parser.xojo_code @@ -108,19 +108,6 @@ Protected Class Parser #tag Method, Flags = &h21 Private Function BreakStatement() As Stmt - ' ' BreakStmt → BREAK SEMICOLON - ' - ' ' Get a reference to the triggering `break` token in case we encounter an error and need - ' ' to inform the user of it's position in the source code. - ' dim keyword as Token = tokens(current - 1) - ' - ' call Consume(TokenType.SEMICOLON, "Expected a `;` after the break keyword.") - ' - ' return new BreakStmt(keyword) - - - - ' BreakStmt → BREAK SEMICOLON ' BreakStmt → BREAK (IF Expression)? SEMICOLON