diff --git a/interpreter/common.lua b/interpreter/common.lua index 4a44749..e166e19 100644 --- a/interpreter/common.lua +++ b/interpreter/common.lua @@ -191,12 +191,10 @@ common = { for k, v in pairs(common.to_lua(val)) do new[k] = v end -- add table.insert(state.interpreter.tags, new) - return self:len(state) end, --- same but do not merge with last stack item push_lua_no_merge = function(self, state, val) table.insert(state.interpreter.tags, val) - return self:len(state) end, -- pop tag table on top of the stack pop = function(self, state) @@ -211,8 +209,7 @@ common = { return #state.interpreter.tags end, --- pop item until we reached desired stack length - -- try to prefer this to pop if possible, so in case we mess up the stack somehow it will restore the stack to a good state - -- (we may allow tag push/pop from the user side at some point TODO) + -- so in case there's a possibility to mess up the stack somehow, it will restore the stack to a good state trim = function(self, state, len) while #state.interpreter.tags > len do self:pop(state) @@ -342,9 +339,9 @@ common = { -- execute in expected tag & event capture state local capture_state = state.interpreter.event_capture_stack state.interpreter.event_capture_stack = {} - local i = common.tags:push_lua_no_merge(state, choice.tags) + common.tags:push_lua_no_merge(state, choice.tags) local _, e = run_block(state, choice.block) - common.tags:trim(state, i-1) + common.tags:pop(state) state.interpreter.event_capture_stack = capture_state if e then return nil, e end -- we discard return value from choice block as the execution is delayed until an event flush diff --git a/interpreter/expression.lua b/interpreter/expression.lua index b8d17e9..1526d1d 100644 --- a/interpreter/expression.lua +++ b/interpreter/expression.lua @@ -138,9 +138,9 @@ local function eval(state, exp) elseif exp.type == "#" then local right, righte = eval(state, exp.right) if not right then return right, righte end - local i = tags:push(state, right) + tags:push(state, right) local left, lefte = eval(state, exp.left) - tags:trim(state, i-1) + tags:pop(state) if not left then return left, lefte end return left -- variable diff --git a/interpreter/interpreter.lua b/interpreter/interpreter.lua index 0c30a1d..a79d35f 100644 --- a/interpreter/interpreter.lua +++ b/interpreter/interpreter.lua @@ -47,9 +47,9 @@ run_line = function(state, line) elseif line.type == "tag" then local v, e = eval(state, line.expression) if not v then return v, ("%s; at %s"):format(e, line.source) end - local i = tags:push(state, v) + tags:push(state, v) v, e = run_block(state, line.child) - tags:trim(state, i-1) + tags:pop(state) if e then return v, e end if v then return v end elseif line.type == "return" then @@ -180,7 +180,7 @@ local function run(state, block, resume_from_there, i, j) local v, e = run_block(state, block, resume_from_there, i, j) -- return to previous tag state -- when resuming is done, tag stack pop when exiting the tag block - -- stray elements may be left on the stack if there is a return before we exit all the tag block, so we trim them + -- stray elements may be left on the stack if there is a return before we go up all the tag blocks, so we trim them if resume_from_there then tags:trim(state, tags_len) end