push_frame should take frame, remove adjust_frame

This commit is contained in:
Christopher Monsanto 2020-05-06 03:48:39 -04:00
parent c1d3a87133
commit 7da531e214
2 changed files with 10 additions and 16 deletions

View File

@ -64,23 +64,14 @@ end
local FRAMES = {}
function push_frame()
local frame = {}
function push_frame(frame)
table.insert(FRAMES, frame)
return frame
end
function pop_frame()
table.remove(FRAMES)
end
function adjust_frame(t)
local last_frame = FRAMES[#FRAMES]
for k, v in pairs(t) do
last_frame[k] = v
end
end
function print_frame()
local last_frame = FRAMES[#FRAMES]
for k, v in pairs(last_frame) do
@ -107,15 +98,15 @@ function expand(str)
end
function with_rep(vars, f)
push_frame()
adjust_frame(vars)
push_frame(vars)
local ret = f()
pop_frame()
return ret
end
function iter_rep(varspec, f)
local frame = push_frame()
local frame = {}
push_frame(frame)
local keys = table_keys(varspec)
local function loop(i)
if #keys + 1 == i then

View File

@ -43,7 +43,8 @@ function glob(pat, opts)
local key = opts and opts.key
local seen = {}
for pat in iter(globpat_normalize(pat)) do
local frame = push_frame()
local frame = {}
push_frame(frame)
for file in iter(tup.glob(pat)) do
-- Workaround a weird issue pre reported
file = file:gsub("//", "/")
@ -112,7 +113,8 @@ local function do_rule_frame(opts, foreach)
if foreach then
local input = glob(opts.input, opts)
for i in iter(input) do
local frame = push_frame()
local frame = {}
push_frame(frame)
frame.input = i
local output = {}
for v in iter(astable(opts.output)) do
@ -123,7 +125,8 @@ local function do_rule_frame(opts, foreach)
pop_frame()
end
else
local frame = push_frame()
local frame = {}
push_frame(frame)
local input = glob(opts.input)
frame.input = tostring(input)
local output = {}