Skip to content

Commit

Permalink
Added proper LOP_BREAK and debuginsn
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatSageEqualToHeaven committed Jul 19, 2024
1 parent e4a706b commit 287488c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ local function luau_newsettings()
allowProxyErrors = false,
useImportConstants = false,
staticEnvironment = {},
decodeOp = function(op) return op end
}
end

Expand All @@ -177,6 +178,7 @@ local function luau_validatesettings(luau_settings)
assert(type(luau_settings.allowProxyErrors) == "boolean", "luau_settings.allowProxyErrors should be a boolean")
assert(type(luau_settings.staticEnvironment) == "table", "luau_settings.staticEnvironment should be a table")
assert(type(luau_settings.useImportConstants) == "boolean", "luau_settings.useImportConstants should be a boolean")
assert(type(luau_settings.decodeOp) == "function", "luau_settings.function should be a function")
end

local function resolveImportConstant(static, count, k0, k1, k2)
Expand Down Expand Up @@ -271,7 +273,7 @@ local function luau_deserialize(bytecode, luau_settings)
end

local function readInstruction(codeList)
local value = readWord()
local value = luau_settings.decodeOp(readWord())
local opcode = bit32_band(value, 0xFF)

local opinfo = opList[opcode + 1]
Expand Down Expand Up @@ -388,6 +390,11 @@ local function luau_deserialize(bytecode, luau_settings)

skipnext = readInstruction(codelist)
end

local debugcodelist = table_create(sizecode)
for i = 1, sizecode do
debugcodelist[i] = codelist[i].opcode
end

local sizek = readVarInt()
local klist = table_create(sizek)
Expand Down Expand Up @@ -508,6 +515,7 @@ local function luau_deserialize(bytecode, luau_settings)

sizecode = sizecode;
code = codelist;
debugcode = debugcodelist;

sizek = sizek;
k = klist;
Expand Down Expand Up @@ -615,6 +623,7 @@ local function luau_load(module, env, luau_settings)

local top, pc, open_upvalues, generalized_iterators = -1, 1, setmetatable({}, {__mode = "vs"}), setmetatable({}, {__mode = "ks"})
local constants = proto.k
local debugopcodes = proto.debugcode
local extensions = luau_settings.extensions

while alive do
Expand All @@ -635,10 +644,15 @@ local function luau_load(module, env, luau_settings)
--// Do nothing
elseif op == 1 then --[[ BREAK ]]
if breakHook then
breakHook(stack, debugging, proto, module, upvals)
else
error("Breakpoint encountered without a break hook")
local results = table.pack(breakHook(stack, debugging, proto, module, upvals))

if results[1] then
return table_unpack(results, 2, #results)
end
end

pc -= 1
op = debugopcodes[pc]
elseif op == 2 then --[[ LOADNIL ]]
stack[inst.A] = nil
elseif op == 3 then --[[ LOADB ]]
Expand Down

0 comments on commit 287488c

Please sign in to comment.