incomplete work towards general ser and deser

This commit is contained in:
2025-11-07 13:55:57 -08:00
parent 03b4d86e47
commit acd18103b8

View File

@@ -84,8 +84,8 @@ end
--[[preserve-keys]] splubp = mknew{ --[[preserve-keys]] splubp = mknew{
ptr = 0x8000, ptr = 0x8000,
init = function(self) init = function(self)
self.fmts,self.defers,self.files = {},{},{}
-- fill from ffile or saved file -- fill from ffile or saved file
self.fmts = {}
if (not self.ffile) self.ffile, self.ptr = self:e() if (not self.ffile) self.ffile, self.ptr = self:e()
for f in all(split(self.ffile, "===", false)) do for f in all(split(self.ffile, "===", false)) do
local tok = shatter(f) local tok = shatter(f)
@@ -146,18 +146,19 @@ function splubp:emit_item(obj)
if DEBUG then if DEBUG then
--[[global]] splubp_last_emit = obj --[[global]] splubp_last_emit = obj
end end
-- todo: should _addr skip the
-- filename, instead?
obj._addr = self.ptr obj._addr = self.ptr
self:write_s(obj._file) self:write_s(obj._file)
for row in all(self.fmts[split(filename, ".")[2]]) do local srow, scri = self.row, self.cri
for row in all(self.fmts[split(obj._file, ".")[2]]) do
self.row, self.cri = row, 1
local alt = self.wdirectives[row[1]] local alt = self.wdirectives[row[1]]
if alt then if alt then
alt(self, obj, row) alt(self, obj) -- they should check row
else else
self:write_fmt(obj[row[1]], row, 2) self:wnx(obj[row[1]])
end end
end end
self.row, self.cri = srow, scri
end end
-- TODO: splubp.wdirectives -- a -- TODO: splubp.wdirectives -- a
@@ -165,7 +166,21 @@ end
-- special values to -- special values to
-- functions to write them -- functions to write them
-- TODO: write_fmt: recursive -- TODO: write_fmt: recursive
-- writing thing -- writing thing. args:
-- item
-- fmt row (parsed)
-- next column
-- NOTE: args row and col might actually be self.row, self.cri.
-- we probably need to push old values into locals and pop
-- on return, in the emit_content_of_type helper, to support
-- obj and potentially other nested parse scenarios
-- NOTE: not actually recursive.
-- right, this is literally just wnx isn't it? because the read version is rnx.
-- now I have it based off wnx, setting row and cri appropriately.
-- TODO: split emit_item up
-- because write-without-name
-- needs to be a thing, and
-- write-with-name uses it
-- Write each argument as one -- Write each argument as one
-- byte at self.ptr, then -- byte at self.ptr, then
@@ -262,3 +277,22 @@ function splubp:t()
end end
return ret return ret
end end
-- read data of type (filetype)
-- into table dest, without
-- filename; do not set
-- _file or _addr
-- restores self.row and self.cr on return
function splubp:rtp(dest, tp)
local srow, scri = self.row, self.cri
for row in all(self.fmts[tp]) do
self.row, self.cri=row, 1
local alt = self.rz[row[1]] -- rz: counterpart to wdirectives
if alt then
alt(self, dest)
else
dest[row[1]] = self:rnx()
end
end
self.row, self.cri = srow, scri
end