From d42d20c50ae0443e2ac5ffa6492ad57745e27830 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 9 Apr 2018 18:58:05 -0700 Subject: Re-added callstack callsite info. It's a bit hacky, but better than nothing. --- core/metaprogramming.nom | 5 ++++- core/text.nom | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 97f4ac1..7488ff8 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -5,7 +5,7 @@ # Compile-time action to make compile-time actions: immediately: lua> ".." - nomsu:define_compile_action("compile %actions to %lua", \(!! code location !!), function(\%actions, \%lua) + nomsu:define_compile_action("compile %actions to %lua", \(!! code location !!), function(__callsite, \%actions, \%lua) local stubs = {}; for i, action in ipairs(\%actions.value) do stubs[i] = nomsu:tree_to_named_stub(action); @@ -30,6 +30,7 @@ immediately: if #undeclared_locals > 0 then body_code = "local "..table.concat(undeclared_locals, ", ")..";\\n"..body_code; end + table.insert(args, 1, "__callsite"); local lua_fn_args = table.concat(args, ", "); local def_metadata = nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]]; local code_location = (def_metadata and ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop) @@ -66,6 +67,7 @@ immediately: if #undeclared_locals > 0 then body_code = "local "..table.concat(undeclared_locals, ", ")..";\\n"..body_code; end + table.insert(args, 1, "__callsite"); local lua_fn_args = table.concat(args, ", "); local def_metadata = nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]]; local code_location = (def_metadata and ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop) @@ -88,6 +90,7 @@ immediately: for i,tok in ipairs(\%shorthand.value[1].value) do if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end end + table.insert(args, 1, "__callsite"); local lua_fn_args = table.concat(args, ", "); local template; if \%longhand.type == "Block" then diff --git a/core/text.nom b/core/text.nom index 8213988..b3a2b6a 100644 --- a/core/text.nom +++ b/core/text.nom @@ -32,7 +32,7 @@ lua> ".." }; for name, e in pairs(escapes) do local lua = "'"..e.."'"; - nomsu:define_compile_action(name, \(!! code location !!), function() return {expr=lua}; end); + nomsu:define_compile_action(name, \(!! code location !!), function(__callsite) return {expr=lua}; end); end local colors = { ["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m", @@ -47,8 +47,8 @@ lua> ".." for name, c in pairs(colors) do local color = "'"..c.."'"; local reset = "'"..colors["reset color"].."'"; - nomsu:define_compile_action(name, \(!! code location !!), function() return {expr=color}; end); - nomsu:define_compile_action(name.." %", \(!! code location !!), function(\%) + nomsu:define_compile_action(name, \(!! code location !!), function(__callsite) return {expr=color}; end); + nomsu:define_compile_action(name.." %", \(!! code location !!), function(__callsite, \%) return {expr=color..".."..nomsu:tree_to_lua(\%).expr..".."..reset}; end); end -- cgit v1.2.3