mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-08-25 02:20:33 +00:00
More path collapse for metaprogram.
This commit is contained in:
@@ -2390,131 +2390,6 @@ local DECL_PARSERS = {
|
||||
-- Only the bare `atom_dbg_skip` marker reaches `parse_dbg_skip_marker`.
|
||||
-- Unknown identifiers follow the same unrelated-token path as every other unsupported source token.
|
||||
|
||||
local function tape_skip_ident(ident)
|
||||
return ident and (DECL_FORMS[ident] or ident == "Struct_" or ident == "Enum_")
|
||||
end
|
||||
|
||||
local function collect_addrs_assigns_REMOVED(text)
|
||||
local addrs = {}
|
||||
local pos = 1
|
||||
local n = #text
|
||||
while pos <= n do
|
||||
pos = duffle.skip_ws_and_cmt(text, pos)
|
||||
if pos > n then break end
|
||||
local ident, ident_end = duffle.read_ident(text, pos)
|
||||
if ident == "addrs" then
|
||||
local after = duffle.skip_ws_and_cmt(text, ident_end)
|
||||
if text:sub(after, after) == "[" then
|
||||
local inner, after_br = duffle.read_brackets(text, after)
|
||||
local idx = inner and tonumber(duffle.trim(inner))
|
||||
after_br = duffle.skip_ws_and_cmt(text, after_br or after)
|
||||
if idx and text:sub(after_br, after_br) == "=" then
|
||||
local rhs = duffle.skip_ws_and_cmt(text, after_br + 1)
|
||||
local rhs_ident = duffle.read_ident(text, rhs)
|
||||
if rhs_ident then addrs[idx] = rhs_ident end
|
||||
pos = rhs
|
||||
else
|
||||
pos = after_br or (after + 1)
|
||||
end
|
||||
else
|
||||
pos = ident_end
|
||||
end
|
||||
elseif ident then
|
||||
pos = ident_end
|
||||
else
|
||||
pos = pos + 1
|
||||
end
|
||||
end
|
||||
return addrs
|
||||
end
|
||||
|
||||
local function collect_tb_emits(body, addrs)
|
||||
local names = {}
|
||||
local pos = 1
|
||||
local n = #body
|
||||
while pos <= n do
|
||||
pos = duffle.skip_ws_and_cmt(body, pos)
|
||||
if pos > n then break end
|
||||
local ident, ident_end = duffle.read_ident(body, pos)
|
||||
if ident == "tb_emit_" or ident == "tb_emit" then
|
||||
local after = duffle.skip_ws_and_cmt(body, ident_end)
|
||||
if body:sub(after, after) == "(" then
|
||||
local inner, after_p = duffle.read_parens(body, after)
|
||||
local name
|
||||
if ident == "tb_emit_" then
|
||||
name = duffle.trim(inner or ""):match("^([%w_]+)")
|
||||
else
|
||||
local args = duffle.split_top_level_commas(inner or "")
|
||||
local last = duffle.trim(args[#args] or "")
|
||||
local idx = last:match("^addrs%s*%[%s*(%d+)%s*%]$")
|
||||
if idx then
|
||||
name = addrs[tonumber(idx)]
|
||||
else
|
||||
name = last:match("([%w_]+)$")
|
||||
end
|
||||
end
|
||||
if name then names[#names + 1] = name end
|
||||
pos = after_p or (after + 1)
|
||||
else
|
||||
pos = ident_end
|
||||
end
|
||||
elseif ident then
|
||||
pos = ident_end
|
||||
else
|
||||
pos = pos + 1
|
||||
end
|
||||
end
|
||||
return names
|
||||
end
|
||||
|
||||
-- Linear appearance order of tb_emit / tb_emit_ in each C function body.
|
||||
-- Commented-out emits are skipped by skip_ws_and_cmt. No C if/loop CFG.
|
||||
local function scan_tape_chains(source)
|
||||
local addrs = collect_addrs_assigns(source)
|
||||
local chains = {}
|
||||
local pos = 1
|
||||
local n = #source
|
||||
while pos <= n do
|
||||
pos = duffle.skip_ws_and_cmt(source, pos)
|
||||
if pos > n then break end
|
||||
local ident, ident_end = duffle.read_ident(source, pos)
|
||||
if tape_skip_ident(ident) then
|
||||
local after = duffle.skip_ws_and_cmt(source, ident_end)
|
||||
if source:sub(after, after) == "(" then
|
||||
local _, after_p = duffle.read_parens(source, after)
|
||||
after = duffle.skip_ws_and_cmt(source, after_p or after)
|
||||
end
|
||||
if source:sub(after, after) == "{" then
|
||||
local _, after_b = duffle.read_braces(source, after)
|
||||
pos = after_b or (after + 1)
|
||||
else
|
||||
pos = after
|
||||
end
|
||||
elseif ident then
|
||||
local after = duffle.skip_ws_and_cmt(source, ident_end)
|
||||
if source:sub(after, after) == "(" then
|
||||
local _, after_p = duffle.read_parens(source, after)
|
||||
after = duffle.skip_ws_and_cmt(source, after_p or after)
|
||||
if source:sub(after, after) == "{" then
|
||||
local body, after_b = duffle.read_braces(source, after)
|
||||
local names = collect_tb_emits(body or "", addrs)
|
||||
if #names > 0 then
|
||||
chains[#chains + 1] = names
|
||||
end
|
||||
pos = after_b or (after + 1)
|
||||
else
|
||||
pos = after
|
||||
end
|
||||
else
|
||||
pos = ident_end
|
||||
end
|
||||
else
|
||||
pos = pos + 1
|
||||
end
|
||||
end
|
||||
return chains
|
||||
end
|
||||
|
||||
-- ════════════════════════════════════════════════════════════════════════════
|
||||
-- The single source walker
|
||||
-- ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user