1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +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")
self._coroutine = coroutine.create(function()
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
return "return", r
end)
@ -228,7 +228,7 @@ State = class {
if code then
self._coroutine = coroutine.create(function()
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
if Return:is(r) then r = r.expression end
return "return", r

View file

@ -75,7 +75,7 @@ return class {
end
end,
-- 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
end
}

View file

@ -2,6 +2,7 @@ local ast = require("anselme.ast")
local ArgumentTuple, Boolean, Nil = ast.ArgumentTuple, ast.Boolean, ast.Nil
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")
return {
@ -34,8 +35,11 @@ return {
end
},
{
"merge branch", "()",
function(state)
"merge branch", "(complete flush=true)",
function(state, complete_flush)
if complete_flush:truthy() then
event_manager:complete_flush(state)
end
state:merge()
return Nil:new()
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 ---
| {}"Force no checkpoint:" |
| {}"x" |
--- text ---
| {}"b" |
--- return ---
()

View file

@ -2,6 +2,7 @@
--- text ---
| {}"No checkpoint:" |
| {}"x" |
--- text ---
| {}"b" |
--- text ---
| {}"From checkpoint:" |
@ -10,6 +11,7 @@
--- text ---
| {}"Force no checkpoint:" |
| {}"x" |
--- text ---
| {}"b" |
--- 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!
|Force no checkpoint:
f!from()
f!from