1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 08:39:30 +00:00

[stdlib] merge branch! now perform a complete flush before merging by default

Otherwise, events written to the buffer before the merge may only be yielded after the merge is already done; if such an event would lead to the script being interrupted, we would likely want the state not to be merged in the first place, hence the change.
This commit is contained in:
Étienne Fildadut 2024-04-29 22:29:37 +02:00
parent 892cb2c623
commit b192206de0
8 changed files with 13 additions and 37 deletions

View file

@ -184,7 +184,7 @@ State = class {
assert(not self:active(), "a script is already active") assert(not self:active(), "a script is already active")
self._coroutine = coroutine.create(function() self._coroutine = coroutine.create(function()
local r = assert0(self:eval_local(code, source)) local r = assert0(self:eval_local(code, source))
event_manager:final_flush(self) event_manager:complete_flush(self)
if Return:is(r) then r = r.expression end if Return:is(r) then r = r.expression end
return "return", r return "return", r
end) end)
@ -228,7 +228,7 @@ State = class {
if code then if code then
self._coroutine = coroutine.create(function() self._coroutine = coroutine.create(function()
local r = assert0(self:eval_local(code, source)) local r = assert0(self:eval_local(code, source))
event_manager:final_flush(self) event_manager:complete_flush(self)
self.scope:reset() -- scope stack is probably messed up after the switch self.scope:reset() -- scope stack is probably messed up after the switch
if Return:is(r) then r = r.expression end if Return:is(r) then r = r.expression end
return "return", r return "return", r

View file

@ -75,7 +75,7 @@ return class {
end end
end, end,
-- keep flushing until nothing is left (a flush may re-fill the buffer during its execution) -- keep flushing until nothing is left (a flush may re-fill the buffer during its execution)
final_flush = function(self, state) complete_flush = function(self, state)
while state.scope:get(last_event_type_identifier):to_lua(state) do self:flush(state) end while state.scope:get(last_event_type_identifier):to_lua(state) do self:flush(state) end
end end
} }

View file

@ -2,6 +2,7 @@ local ast = require("anselme.ast")
local ArgumentTuple, Boolean, Nil = ast.ArgumentTuple, ast.Boolean, ast.Nil local ArgumentTuple, Boolean, Nil = ast.ArgumentTuple, ast.Boolean, ast.Nil
local resume_manager = require("anselme.state.resume_manager") local resume_manager = require("anselme.state.resume_manager")
local event_manager = require("anselme.state.event_manager")
local calling_environment_manager = require("anselme.state.calling_environment_manager") local calling_environment_manager = require("anselme.state.calling_environment_manager")
return { return {
@ -34,8 +35,11 @@ return {
end end
}, },
{ {
"merge branch", "()", "merge branch", "(complete flush=true)",
function(state) function(state, complete_flush)
if complete_flush:truthy() then
event_manager:complete_flush(state)
end
state:merge() state:merge()
return Nil:new() return Nil:new()
end end

View file

@ -1,17 +0,0 @@
--# run #--
--- text ---
| {}"Force run checkpoint:" |
| {}"a" |
| {}"b" |
--- text ---
| {}"From checkpoint:" |
| {}"a" |
| {}"b" |
--- text ---
| {}"Force no checkpoint:" |
| {}"x" |
| {}"b" |
--- return ---
()
--# saved #--
{"f.checkpoint":#p, "f.reached":*{#p:1}, "f.run":3}

View file

@ -10,6 +10,7 @@
--- text --- --- text ---
| {}"Force no checkpoint:" | | {}"Force no checkpoint:" |
| {}"x" | | {}"x" |
--- text ---
| {}"b" | | {}"b" |
--- return --- --- return ---
() ()

View file

@ -2,6 +2,7 @@
--- text --- --- text ---
| {}"No checkpoint:" | | {}"No checkpoint:" |
| {}"x" | | {}"x" |
--- text ---
| {}"b" | | {}"b" |
--- text --- --- text ---
| {}"From checkpoint:" | | {}"From checkpoint:" |
@ -10,6 +11,7 @@
--- text --- --- text ---
| {}"Force no checkpoint:" | | {}"Force no checkpoint:" |
| {}"x" | | {}"x" |
--- text ---
| {}"b" | | {}"b" |
--- return --- --- return ---
() ()

View file

@ -1,14 +0,0 @@
:f = "f"!script($_)
|x
#p!checkpoint($_)
|a
|b
|Force run checkpoint:
f!from(#p)
|From checkpoint:
f!
|Force no checkpoint:
f!from()

View file

@ -11,4 +11,4 @@ f!
f! f!
|Force no checkpoint: |Force no checkpoint:
f!from() f!from