Dump tables in bytecode
This commit is contained in:
parent
5fef11675d
commit
e3a993669e
38
bc.lua
38
bc.lua
@ -522,6 +522,26 @@ local function lj_value_tostring(proto, line, value)
|
||||
return vs
|
||||
end
|
||||
|
||||
local function lj_kgcatom_tostring(val, top)
|
||||
local tp = type(val)
|
||||
if tp == "string" then
|
||||
return ([["%s"]]):format(escape_string(val))
|
||||
elseif tp == "number" then
|
||||
if top then
|
||||
return ("[BYTECODE %d]"):format(val)
|
||||
else
|
||||
return tostring(val)
|
||||
end
|
||||
elseif tp == "table" then
|
||||
if next(val) == nil then
|
||||
return "{}"
|
||||
end
|
||||
return "[TABLE]"
|
||||
else
|
||||
return "[???]"
|
||||
end
|
||||
end
|
||||
|
||||
local function lj_proto_tostring(index, proto)
|
||||
local st = {("-- BYTECODE -- %d"):format(index-1)}
|
||||
local jmp_target = {}
|
||||
@ -536,16 +556,18 @@ local function lj_proto_tostring(index, proto)
|
||||
end
|
||||
for id = 0, kgc_count do
|
||||
local val = proto.kgc[id]
|
||||
if type(val) == "string" then
|
||||
val = ([["%s"]]):format(escape_string(val))
|
||||
elseif type(val) == "number" then
|
||||
val = ("BYTECODE %d"):format(val)
|
||||
elseif type(val) == "table" then
|
||||
val = "[table]"
|
||||
if type(val) == "table" and next(val) ~= nil then
|
||||
table.insert(st, ("%-7s %6d {"):format("KGC", id))
|
||||
local prepend = ("%-7s %6s"):format("KGC", ".")
|
||||
-- LJ bytecode does not have nested tables
|
||||
for k, v in pairs(val) do
|
||||
table.insert(st, ("%s [%s] = %s,"):format(prepend,
|
||||
lj_kgcatom_tostring(k), lj_kgcatom_tostring(v)))
|
||||
end
|
||||
table.insert(st, ("%s }"):format(prepend))
|
||||
else
|
||||
val = "???"
|
||||
table.insert(st, ("%-7s %6d %s"):format("KGC", id, lj_kgcatom_tostring(val, true)))
|
||||
end
|
||||
table.insert(st, ("%-7s %6d %s"):format("KGC", id, val))
|
||||
end
|
||||
local kn_count = #proto.kn
|
||||
if proto.kn[0] == nil then
|
||||
|
Loading…
x
Reference in New Issue
Block a user