From b32521cb60cfd46b7e2bb15b478b5d293a8f5e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Thu, 11 Jan 2024 13:50:04 +0100 Subject: [PATCH] [internal] Clean resume_manager --- anselme/ast/Block.lua | 3 +-- anselme/state/resume_manager.lua | 27 +++------------------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/anselme/ast/Block.lua b/anselme/ast/Block.lua index e996120..aa7db0a 100644 --- a/anselme/ast/Block.lua +++ b/anselme/ast/Block.lua @@ -38,7 +38,6 @@ local Block = ast.abstract.Node { state.scope:push() if self:contains_current_resume_target(state) then local target = resume_manager:get(state) - local no_continue = resume_manager:no_continue(state) local resumed = false for _, e in ipairs(self.expressions) do if e:contains_resume_target(target) then resumed = true end @@ -47,7 +46,7 @@ local Block = ast.abstract.Node { if AutoCall:issub(r) then r = r:call(state, ArgumentTuple:new()) end - if Return:is(r) or no_continue then + if Return:is(r) then break -- pass on to parent block until we reach a function boundary end end diff --git a/anselme/state/resume_manager.lua b/anselme/state/resume_manager.lua index 5637a95..1dc7831 100644 --- a/anselme/state/resume_manager.lua +++ b/anselme/state/resume_manager.lua @@ -1,11 +1,10 @@ local class = require("anselme.lib.class") local ast = require("anselme.ast") -local Nil, Identifier, ResumeTarget, Boolean +local Nil, Identifier, ResumeTarget -- stack of resumable contexts local resume_target_identifier, resume_target_symbol -local resume_no_continue_identifier, resume_no_continue_symbol local resume_environment_identifier, resume_environment_symbol local resume_manager = class { @@ -14,20 +13,8 @@ local resume_manager = class { -- push a new resume context: all run code between this and the next push will try to resume to target push = function(self, state, target) assert(ResumeTarget:issub(target), "can only resume to a resume target") - state.scope:push_partial(resume_target_identifier, resume_no_continue_identifier, resume_environment_identifier) + state.scope:push_partial(resume_target_identifier, resume_environment_identifier) state.scope:define(resume_target_symbol, target) - state.scope:define(resume_no_continue_symbol, Boolean:new(false)) - state.scope:define(resume_environment_symbol, state.scope:capture()) - end, - -- same as :push, but the resume will stop immediately after reaching the target or a node containing the target - -- (we will stop even if the node is not directly reached - this is used to run a specific line containing a node, - -- notably for Definition of exported variables) - -- TODO unused? - push_no_continue = function(self, state, target) - assert(ResumeTarget:issub(target), "can only resume to a resume target") - state.scope:push_partial(resume_target_identifier, resume_no_continue_identifier, resume_environment_identifier) - state.scope:define(resume_target_symbol, target) - state.scope:define(resume_no_continue_symbol, Boolean:new(true)) state.scope:define(resume_environment_symbol, state.scope:capture()) end, -- pop the current resume context @@ -49,11 +36,6 @@ local resume_manager = class { set_reached = function(self, state) state.scope:set(resume_target_identifier, Nil:new()) end, - -- indicate if the evaluation should stop after reaching a node containing the target - -- (assumes that we are currently :resuming) - no_continue = function(self, state) - return state.scope:get(resume_no_continue_identifier):to_lua(state) - end, -- returns the environment that was on top of the stack when the resume started -- (assumes that we are currently :resuming) resuming_environment = function(self, state) @@ -63,7 +45,7 @@ local resume_manager = class { package.loaded[...] = resume_manager -Nil, Identifier, ResumeTarget, Boolean = ast.Nil, ast.Identifier, ast.abstract.ResumeTarget, ast.Boolean +Nil, Identifier, ResumeTarget = ast.Nil, ast.Identifier, ast.abstract.ResumeTarget resume_target_identifier = Identifier:new("_resume_target") resume_target_symbol = resume_target_identifier:to_symbol() @@ -71,7 +53,4 @@ resume_target_symbol = resume_target_identifier:to_symbol() resume_environment_identifier = Identifier:new("_resume_environment") resume_environment_symbol = resume_environment_identifier:to_symbol() -resume_no_continue_identifier = Identifier:new("_resume_no_continue") -resume_no_continue_symbol = resume_no_continue_identifier:to_symbol() - return resume_manager