mirror of
https://github.com/Reuh/anselme.git
synced 2025-12-14 12:19:09 +00:00
Clean implementation of 👁️ and no longer increment 🏁 on checkpoint execution (redundant with 👁️)
This commit is contained in:
parent
f79e2f5716
commit
2ff494d108
12 changed files with 115 additions and 77 deletions
|
|
@ -41,7 +41,7 @@ common = {
|
|||
end
|
||||
end
|
||||
-- scoping: since merging means we will re-copy every variable from global state again, we need to simulate this
|
||||
-- behavious for scoped variables (to have consistent references for mutables values in particular), including
|
||||
-- behaviour for scoped variables (to have consistent references for mutables values in particular), including
|
||||
-- scopes that aren't currently active
|
||||
fix_not_modified_references(mt.scoped, copy_cache, modified_tables) -- replace not modified values in scope with original before re-copying to keep consistent references
|
||||
for _, scopes in pairs(mt.scoped) do
|
||||
|
|
|
|||
|
|
@ -397,8 +397,15 @@ local function eval(state, exp)
|
|||
local fn = selected_variant.variant
|
||||
if fn.type ~= "function" then
|
||||
return nil, ("unknown function type %q"):format(fn.type)
|
||||
-- checkpoint: no args and resume execution
|
||||
-- checkpoint: no args and can resume execution
|
||||
elseif fn.subtype == "checkpoint" then
|
||||
-- set current checkpoint
|
||||
local s, e = set_variable(state, fn.parent_resumable.namespace.."🔖", {
|
||||
type = "function reference",
|
||||
value = { fn.name }
|
||||
})
|
||||
if not s then return nil, e end
|
||||
-- run checkpoint content, eventually resuming
|
||||
local r, e = run(state, fn.child, not paren_call)
|
||||
if not r then return nil, e end
|
||||
return r
|
||||
|
|
@ -423,8 +430,6 @@ local function eval(state, exp)
|
|||
checkpoint, checkpointe = get_variable(state, fn.namespace.."🔖")
|
||||
if not checkpoint then return nil, checkpointe end
|
||||
end
|
||||
local seen, seene = get_variable(state, fn.namespace.."👁️")
|
||||
if not seen then return nil, seene end
|
||||
-- execute lua functions
|
||||
-- I guess we could technically skip getting & updating the seen and checkpoints vars since they can't be used from Anselme
|
||||
-- but it's also kinda fun to known how many time a function was ran
|
||||
|
|
@ -501,12 +506,6 @@ local function eval(state, exp)
|
|||
end
|
||||
if not ret then return nil, e end
|
||||
end
|
||||
-- update function vars
|
||||
local s, e = set_variable(state, fn.namespace.."👁️", {
|
||||
type = "number",
|
||||
value = seen.value + 1
|
||||
})
|
||||
if not s then return nil, e end
|
||||
-- for classes: build resulting object
|
||||
if fn.subtype == "class" and ret and ret.type == "nil" then
|
||||
ret = {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ run_line = function(state, line)
|
|||
if not iv then return nil, ("%s; at %s"):format(ie, line.source) end
|
||||
end
|
||||
end
|
||||
elseif line.type == "flush_events" then
|
||||
elseif line.type == "flush events" then
|
||||
local v, e = events:flush(state)
|
||||
if not v then return nil, ("%s; in event flush at %s"):format(e, line.source) end
|
||||
elseif line.type == "function" and line.subtype == "checkpoint" then
|
||||
|
|
@ -151,36 +151,8 @@ run_block = function(state, block, resume_from_there, i, j)
|
|||
end
|
||||
i = i + 1
|
||||
end
|
||||
-- if we are exiting a checkpoint block, mark it as ran and update checkpoint
|
||||
-- (when resuming from a checkpoint, execution is resumed from inside the checkpoint, the line.subtype=="checkpoint" check in run_line is never called)
|
||||
-- (and we want this to be done after executing the checkpoint block anyway)
|
||||
-- if we reach the end of a checkpoint block (we are resuming execution from a checkpoint), merge state
|
||||
if block.parent_line and block.parent_line.type == "function" and block.parent_line.subtype == "checkpoint" then
|
||||
local parent_line = block.parent_line
|
||||
local reached, reachede = get_variable(state, parent_line.namespace.."🏁")
|
||||
if not reached then return nil, reachede end
|
||||
local seen, seene = get_variable(state, parent_line.namespace.."👁️")
|
||||
if not seen then return nil, seene end
|
||||
local checkpoint, checkpointe = get_variable(state, parent_line.parent_resumable.namespace.."🔖")
|
||||
if not checkpoint then return nil, checkpointe end
|
||||
local s, e = set_variable(state, parent_line.namespace.."👁️", {
|
||||
type = "number",
|
||||
value = seen.value + 1
|
||||
})
|
||||
if not s then return nil, e end
|
||||
s, e = set_variable(state, parent_line.namespace.."🏁", {
|
||||
type = "number",
|
||||
value = reached.value + 1
|
||||
})
|
||||
if not s then return nil, e end
|
||||
-- don't update checkpoint if an already more precise checkpoint is set
|
||||
-- (since we will go up the whole checkpoint hierarchy when resuming from a nested checkpoint)
|
||||
if checkpoint.type == "nil" or not checkpoint.value[1]:match("^"..escape(parent_line.name)) then
|
||||
s, e = set_variable(state, parent_line.parent_resumable.namespace.."🔖", {
|
||||
type = "function reference",
|
||||
value = { parent_line.name }
|
||||
})
|
||||
if not s then return nil, e end
|
||||
end
|
||||
merge_state(state)
|
||||
end
|
||||
-- go up hierarchy if asked to resume
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue