1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 00:59: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

@ -32,11 +32,23 @@ local common
common = {
--- merge interpreter state with global state
merge_state = function(state)
-- merge alias state
local global = state.interpreter.global_state
for alias, fqm in pairs(state.aliases) do
global.aliases[alias] = fqm
state.aliases[alias] = nil
end
-- variable state
-- move values modifed in-place from read cache to variables
local cache = getmetatable(state.variables).cache
for var, value in pairs(cache) do
if value.modified then
value.modified = nil
state.variables[var] = value
end
cache[var] = nil
end
-- merge modified variables
for var, value in pairs(state.variables) do
global.variables[var] = value
state.variables[var] = nil