Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Heap-allocated Call Stack and Performance Improvements #606

Merged
merged 3 commits into from
Jun 24, 2024
Merged
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
33 changes: 22 additions & 11 deletions src/pallene/coder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ function Coder:pallene_entry_point_definition(f_id)
if self.flags.use_traceback then
table.insert(prologue, util.render([[
/**/
pt_cont_t *cont = pvalue(&K->uv[0].uv);
PALLENE_C_FRAMEENTER(cont, "$name");
PALLENE_C_FRAMEENTER(L, "$name");
/**/
]], {
name = func.name
Expand All @@ -472,7 +471,7 @@ function Coder:pallene_entry_point_definition(f_id)
setline = string.format("PALLENE_SETLINE(%d);", func.loc and func.loc.line or 0)

if #func.typ.ret_types == 0 then
void_frameexit = "PALLENE_FRAMEEXIT(cont);"
void_frameexit = "PALLENE_FRAMEEXIT();"
end
end

Expand Down Expand Up @@ -597,25 +596,31 @@ function Coder:lua_entry_point_definition(f_id)

local frameenter = ""
local frameexit = ""
local nargs = #arg_types
local cargs = nargs
if self.flags.use_traceback then
frameenter = util.render([[
/**/
pt_cont_t *cont = pvalue(&K->uv[0].uv);
PALLENE_LUA_FRAMEENTER(cont, $fun_name);
PALLENE_LUA_FRAMEENTER(L, $fun_name);
/**/
]], {
fun_name = self:lua_entry_point_name(f_id),
})
frameexit = "PALLENE_FRAMEEXIT(cont);"
-- It's as simple as popping the finalizer.
frameexit = "lua_pop(L, 1);"

-- We will be having our finalizer on top of our stack.
cargs = cargs + 1
end

local arity_check = util.render([[
int nargs = lua_gettop(L);
if (l_unlikely(nargs != $nargs)) {
if (l_unlikely(nargs != $cargs)) {
pallene_runtime_arity_error(L, $fname, $nargs, nargs);
}
]], {
nargs = C.integer(#arg_types),
cargs = C.integer(cargs),
nargs = C.integer(nargs),
fname = C.string(fname),
})

Expand Down Expand Up @@ -670,8 +675,8 @@ function Coder:lua_entry_point_definition(f_id)
/**/
${ret_decls}
${call_pallene}
${push_results}
${lua_fexit}
${push_results}
return $nresults;
}
]], {
Expand All @@ -698,14 +703,16 @@ end
define_union("Constant", {
Metatable = {"typ"},
String = {"str"},
DebugUserdata = {}
DebugUserdata = {},
DebugMetatable = {},
})

function Coder:init_upvalues()

-- If we are using tracebacks
if self.flags.use_traceback then
table.insert(self.constants, coder.Constant.DebugUserdata())
table.insert(self.constants, coder.Constant.DebugMetatable())
end

-- Metatables
Expand Down Expand Up @@ -1656,7 +1663,7 @@ end
gen_cmd["Return"] = function(self, cmd)
local frameexit = ""
if self.flags.use_traceback then
frameexit = "PALLENE_FRAMEEXIT(cont);"
frameexit = "PALLENE_FRAMEEXIT();"
end

if #cmd.srcs == 0 then
Expand Down Expand Up @@ -1879,6 +1886,10 @@ function Coder:generate_luaopen_function()
/* Initialize Pallene Tracer. */
lua_pushlightuserdata(L, (void *) pallene_tracer_init(L));
]]);
elseif tag == "coder.Constant.DebugMetatable" then
table.insert(init_constants, [[
/* `pallene_tracer_init` fn pushes the finalizer metatable into the stack. */
]])
else
tagged_union.error(tag)
end
Expand Down
2 changes: 1 addition & 1 deletion src/pallene/pallenec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ do
)

-- No Pallene tracebacks
p:flag("--use-traceback", "Use Pallene Tracer function traceback for debugging")
p:flag("--use-traceback", "Use function traceback for debugging")

p:option("-O", "Optimization level")
:args(1):convert(tonumber)
Expand Down
Loading
Loading