From 4c693d74746f35008808b1faa4c3f98efdf77931 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 5 Mar 2018 18:44:26 -0800 Subject: Updated for optional metadata support. --- core/metaprogramming.nom | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'core/metaprogramming.nom') diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index fa589bd..373846b 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -32,7 +32,8 @@ immediately: end local lua_fn_args = table.concat(args, ", "); local def_metadata = nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]]; - local code_location = ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop); + local code_location = (metadata and ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop) + or ""); return {statements=([[ nomsu:define_compile_action(]]..repr(stubs)..[[, ]]..repr(code_location)..[[, function(]]..lua_fn_args..[[) ]]..body_code.."\\n"..[[ @@ -67,8 +68,8 @@ immediately: end local lua_fn_args = table.concat(args, ", "); local def_metadata = nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]]; - assert(def_metadata, "No metadata found for: "..tostring(nomsu.compilestack[#nomsu.compilestack])); - local code_location = ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop); + local code_location = (metadata and ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop) + or ""); return {statements=[[ nomsu:define_action(]]..repr(stubs)..[[, ]]..repr(code_location)..[[, function(]]..lua_fn_args..[[) ]]..body_code.."\\n"..[[ @@ -100,7 +101,8 @@ immediately: for i, a in ipairs(args) do replacements[i] = a.."="..a; end replacements = "{"..table.concat(replacements, ", ").."}"; local def_metadata = nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]]; - local code_location = ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop); + local code_location = (metadata and ("%s:%s,%s"):format(def_metadata.filename, def_metadata.start, def_metadata.stop) + or ""); return {statements=[[ nomsu:define_compile_action(]]..repr(stubs)..[[, ]]..repr(code_location)..[[, function(]]..lua_fn_args..[[) local template = nomsu:parse(]]..template..[[, ]]..repr(def_metadata.filename)..[[); @@ -175,7 +177,7 @@ immediately: compile [run %code] to {..} expr: ".." nomsu:run(\(%code as lua expr), '\ - =lua "nomsu.tree_metadata[nomsu.compilestack[#nomsu.compilestack]].filename" + =lua "nomsu:get_line_number(nomsu.compilestack[#nomsu.compilestack])" ..') parse [enable debugging] as: lua> "nomsu.debug = true;" parse [disable debugging] as: lua> "nomsu.debug = false;" -- cgit v1.2.3