3 Commits

View File

@@ -137,11 +137,19 @@ function splubp:wnx(...)
return self["write_"..self:op()](self, ...) return self["write_"..self:op()](self, ...)
end end
function splubp:emit_item(obj, filename) -- write an object of a known type.
debug_last_emit = obj -- global debug -- item must have a field named
filename = filename or obj._file -- _file, containing a filename
-- with a correct extension
-- to save the file under.
function splubp:emit_item(obj)
if DEBUG then
--[[global]] splubp_last_emit = obj
end
-- todo: should _addr skip the
-- filename, instead?
obj._addr = self.ptr obj._addr = self.ptr
self:write_s(filename) self:write_s(obj._file)
for row in all(self.fmts[split(filename, ".")[2]]) do for row in all(self.fmts[split(filename, ".")[2]]) do
local alt = self.wdirectives[row[1]] local alt = self.wdirectives[row[1]]
if alt then if alt then
@@ -195,6 +203,26 @@ function splubp:write_shr(n)
self:wnx(n) self:wnx(n)
end end
function splubp:write_a(tbl)
if (DEBUG) assert(#tbl <= 255, "'a' can't write array of length "..#tbl)
self:write_c(#tbl)
local rpt = self.cri
for item in all(tbl) do
self.cri = rpt
self:wnx(item)
end
end
function splubp:write_t(tbl)
if DEBUG then
local want_len = self.row[self.cri]
assert(#tbl == want_len, "'t' wants "..tostr(want_len).." items, but got "..#tbl..": "..tostr(tbl))
end
for i=1,self:op() do
self:wnx(tbl[i])
end
end
-->8 -->8
-- loader -- loader
@@ -217,3 +245,20 @@ function splubp:shr()
local amt = self:op() local amt = self:op()
return self:rnx() >>> amt return self:rnx() >>> amt
end end
function splubp:a()
local ret,rpt = {},self.cri
for i = 1,self:c() do
self.cri=rpt
add(ret, self:rnx())
end
return ret
end
function splubp:t()
local ret = {}
for i=1,self:op() do
add(ret, self:rnx())
end
return ret
end