mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
[internal] Clean resume_manager
This commit is contained in:
parent
b6473de4d2
commit
b32521cb60
2 changed files with 4 additions and 26 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue