From c0333ca31532f14ec8ebd841a5f68b2f35e9cc80 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 11 Jan 2018 01:03:52 -0800 Subject: Overhaul of error reporting and removing nomsu:call(stub, line_no, ...) in favor of nomsu.defs[stub].fn(...) --- lib/metaprogramming.nom | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'lib/metaprogramming.nom') diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom index 4b3c615..d396ac3 100644 --- a/lib/metaprogramming.nom +++ b/lib/metaprogramming.nom @@ -19,7 +19,7 @@ immediately: immediately: lua> ".." - nomsu:defmacro("compile %macro_def to %body", function(nomsu, \%macro_def, \%body) + nomsu:defmacro("compile %macro_def to %body", \(__line_no__), function(nomsu, \%macro_def, \%body) nomsu:assert(\%macro_def.type == "List", "Invalid type for compile definition signature. Expected List, but got: "..tostring(\%macro_def.type)); nomsu:assert(\%body.type == "Block", @@ -33,13 +33,14 @@ immediately: %s end local function macro_wrapper(...) return {expr=macro(...)}; end - nomsu:defmacro(%s, macro_wrapper, %s); - end]]):format(args, body_lua, signature, nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src))); + nomsu:defmacro(%s, %s, macro_wrapper, %s); + end]]):format(args, body_lua, signature, nomsu:repr(\%macro_def:get_line_no()), + nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src))); return {statements=lua}; end, \(__src__ 1)); lua> ".." - nomsu:defmacro("compile %macro_def to code %body", function(nomsu, \%macro_def, \%body) + nomsu:defmacro("compile %macro_def to code %body", \(__line_no__), function(nomsu, \%macro_def, \%body) nomsu:assert(\%macro_def.type == "List", "Invalid type for compile definition signature. Expected List, but got: "..tostring(\%macro_def.type)); nomsu:assert(\%body.type == "Block", @@ -53,8 +54,9 @@ immediately: %s end local function macro_wrapper(...) return {statements=macro(...)}; end - nomsu:defmacro(%s, macro_wrapper, %s); - end]]):format(args, body_lua, signature, nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src))); + nomsu:defmacro(%s, %s, macro_wrapper, %s); + end]]):format(args, body_lua, signature, nomsu:repr(\%macro_def:get_line_no()), + nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src))); return {statements=lua}; end, \(__src__ 1)); @@ -71,7 +73,7 @@ immediately: body_lua = body_lua.statements or ("return "..body_lua.expr..";"); local src = nomsu:dedent(nomsu:source_code(0)); local def_lua = ([[ - nomsu:def(%s, function(%s) + nomsu:def(%s, \(__line_no__), function(%s) %s end, %s);]]):format(signature, args, body_lua, nomsu:repr(src)); return def_lua; @@ -79,7 +81,7 @@ immediately: # Rule to make nomsu macros: immediately: lua> ".." - nomsu:defmacro("parse %shorthand as %longhand", (function(nomsu, \%shorthand, \%longhand) + nomsu:defmacro("parse %shorthand as %longhand", \(__line_no__), (function(nomsu, \%shorthand, \%longhand) nomsu:assert(\%shorthand.type == "List", "Invalid type for parse definition signature. Expected List, but got: "..tostring(\%shorthand.type)); nomsu:assert(\%longhand.type == "Block", @@ -95,11 +97,12 @@ immediately: for i, a in ipairs(arg_names) do replacements[i] = "["..nomsu:repr(a).."]=_"..nomsu:var_to_lua_identifier(a); end replacements = "{"..table.concat(replacements, ", ").."}"; local lua_code = ([[ - nomsu:defmacro(%s, (function(%s) + nomsu:defmacro(%s, %s, (function(%s) local template = nomsu:parse(%s, %s); local replacement = nomsu:replaced_vars(template, %s); return nomsu:tree_to_lua(replacement); - end), %s)]]):format(signature, args, template, nomsu:repr(\%shorthand:get_line_no()), replacements, nomsu:repr(nomsu:source_code(0))); + end), %s)]]):format(signature, nomsu:repr(\%shorthand:get_line_no()), args, template, + nomsu:repr(\%shorthand:get_line_no()), replacements, nomsu:repr(nomsu:source_code(0))); return {statements=lua_code}; end), \(__src__ 1)); -- cgit v1.2.3