Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions extension/script/backend/worker/eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ generate("dump", function()
end
end)

generate("lineinfo", function()
local eval_lineinfo = assert(rdebug.load(readfile 'backend.worker.eval.lineinfo'))
return function(content)
return rdebug.eval(eval_lineinfo, content)
end
end)

generate("ffi_reflect", function ()
if not luaver.isjit then
return
Expand Down
28 changes: 28 additions & 0 deletions extension/script/backend/worker/eval/lineinfo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local jutil = require 'jit.util'

-- Describes a prototype as JSON, using the same field names as undump.
local function dump(fn)
local info = jutil.funcinfo(fn)
local lines = {}
-- pc 0 is the function header, which is not an active line.
for pc = 1, info.bytecodes - 1 do
lines[pc] = jutil.funcinfo(fn, pc).currentline
end
local protos = {}
for i = -1, -info.gcconsts, -1 do
local k = jutil.funck(fn, i)
if type(k) == "proto" then
protos[#protos + 1] = dump(k)
end
end
return string.format('{"linedefined":%d,"lastlinedefined":%d,"lineinfo":[%s],"sizep":%d,"p":[%s]}',
info.linedefined,
-- rdebug.getinfo reports 0 for the main chunk, see rdebug_visitor.cpp.
info.linedefined == 0 and 0 or info.lastlinedefined,
table.concat(lines, ","),
#protos,
table.concat(protos, ",")
)
end

return dump(assert(loadstring(...)))
19 changes: 18 additions & 1 deletion extension/script/backend/worker/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,28 @@ local function dumpTarget(content)
return nil, type(bin) == "string" and bin or "can not dump function."
end

-- undump can not read LuaJIT bytecode, so LuaJIT reports the line info itself.
local function dumpJit(content)
local eval = require 'backend.worker.eval'
local ok, res = eval.lineinfo(content)
if not ok then
local log = require 'common.log'
log.error("ERROR:"..tostring(res))
return
end
local json = require 'common.json'
return json.decode(res)
end

return function (content, syntaxCompatibility)
local luaver = require 'backend.worker.luaver'
local err
local bin
local cl, v
if syntaxCompatibility then
local proto = luaver.isjit and dumpJit(content)
if proto then
cl, v = { f = proto }, 0x51
elseif syntaxCompatibility then
bin, err = dumpTarget(content)
if not bin then
local log = require 'common.log'
Expand Down