1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Cache read values in local state, handle mutable variables properly

This commit is contained in:
Étienne Fildadut 2021-12-02 21:07:47 +01:00
parent 607313d5ce
commit 0f89307d5f
9 changed files with 258 additions and 7 deletions

View file

@ -195,6 +195,19 @@ else
local t, d = istate:step()
table.insert(result, { t, d })
until t == "return" or t == "error"
local postrun = vm:eval(namespace..".post run")
if postrun then
istate, e = vm:run(namespace.."."..postrun)
if not istate then
table.insert(result, { "error", e })
else
repeat
local t, d = istate:step()
table.insert(result, { t, d })
until t == "return" or t == "error"
end
end
end
else
table.insert(result, { "error", err })

View file

@ -0,0 +1,26 @@
:post run = "after error"
:l = [1,2]
1,2: {l}
~ l.insert(3)
1,2,3: {l}
§ a
~ l.insert(4)
1,2,3,4: {l}
§ b
~ l.insert(5)
1,2,3,4,5: {l}
~ error("cancel merge")
$ after error
1,2,3,4: {l}

View file

@ -0,0 +1,68 @@
local _={}
_[27]={}
_[26]={}
_[25]={}
_[24]={}
_[23]={}
_[22]={tags=_[27],text="[1, 2, 3, 4]"}
_[21]={tags=_[27],text="1,2,3,4: "}
_[20]={tags=_[26],text="[1, 2, 3, 4, 5]"}
_[19]={tags=_[26],text="1,2,3,4,5: "}
_[18]={tags=_[25],text="[1, 2, 3, 4]"}
_[17]={tags=_[25],text="1,2,3,4: "}
_[16]={tags=_[24],text="[1, 2, 3]"}
_[15]={tags=_[24],text="1,2,3: "}
_[14]={tags=_[23],text="[1, 2]"}
_[13]={tags=_[23],text="1,2: "}
_[12]={_[21],_[22]}
_[11]={_[19],_[20]}
_[10]={_[17],_[18]}
_[9]={_[15],_[16]}
_[8]={_[13],_[14]}
_[7]={"return"}
_[6]={"text",_[12]}
_[5]={"error","cancel merge; in Lua function \"error\"; at test/tests/checkpoint merging mutable value.ans:23"}
_[4]={"text",_[11]}
_[3]={"text",_[10]}
_[2]={"text",_[9]}
_[1]={"text",_[8]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7]}
--[[
{ "text", { {
tags = <1>{},
text = "1,2: "
}, {
tags = <table 1>,
text = "[1, 2]"
} } }
{ "text", { {
tags = <1>{},
text = "1,2,3: "
}, {
tags = <table 1>,
text = "[1, 2, 3]"
} } }
{ "text", { {
tags = <1>{},
text = "1,2,3,4: "
}, {
tags = <table 1>,
text = "[1, 2, 3, 4]"
} } }
{ "text", { {
tags = <1>{},
text = "1,2,3,4,5: "
}, {
tags = <table 1>,
text = "[1, 2, 3, 4, 5]"
} } }
{ "error", 'cancel merge; in Lua function "error"; at test/tests/checkpoint merging mutable value.ans:23' }
{ "text", { {
tags = <1>{},
text = "1,2,3,4: "
}, {
tags = <table 1>,
text = "[1, 2, 3, 4]"
} } }
{ "return" }
]]--

View file

@ -0,0 +1,26 @@
:post run = "after error"
:l = 1
1: {l}
~ l := 2
2: {l}
§ a
~ l := 3
3: {l}
§ b
~ l := 4
4: {l}
~ error("cancel merge")
$ after error
3: {l}

View file

@ -0,0 +1,68 @@
local _={}
_[27]={}
_[26]={}
_[25]={}
_[24]={}
_[23]={}
_[22]={tags=_[27],text="3"}
_[21]={tags=_[27],text="3: "}
_[20]={tags=_[26],text="4"}
_[19]={tags=_[26],text="4: "}
_[18]={tags=_[25],text="3"}
_[17]={tags=_[25],text="3: "}
_[16]={tags=_[24],text="2"}
_[15]={tags=_[24],text="2: "}
_[14]={tags=_[23],text="1"}
_[13]={tags=_[23],text="1: "}
_[12]={_[21],_[22]}
_[11]={_[19],_[20]}
_[10]={_[17],_[18]}
_[9]={_[15],_[16]}
_[8]={_[13],_[14]}
_[7]={"return"}
_[6]={"text",_[12]}
_[5]={"error","cancel merge; in Lua function \"error\"; at test/tests/checkpoint merging variable.ans:23"}
_[4]={"text",_[11]}
_[3]={"text",_[10]}
_[2]={"text",_[9]}
_[1]={"text",_[8]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7]}
--[[
{ "text", { {
tags = <1>{},
text = "1: "
}, {
tags = <table 1>,
text = "1"
} } }
{ "text", { {
tags = <1>{},
text = "2: "
}, {
tags = <table 1>,
text = "2"
} } }
{ "text", { {
tags = <1>{},
text = "3: "
}, {
tags = <table 1>,
text = "3"
} } }
{ "text", { {
tags = <1>{},
text = "4: "
}, {
tags = <table 1>,
text = "4"
} } }
{ "error", 'cancel merge; in Lua function "error"; at test/tests/checkpoint merging variable.ans:23' }
{ "text", { {
tags = <1>{},
text = "3: "
}, {
tags = <table 1>,
text = "3"
} } }
{ "return" }
]]--