From b53516c47c0dd1f9325f9f721f561487510cca98 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 30 May 2018 17:20:22 -0700 Subject: Simplified and correctified lib/object (though the codegen still need streamlining), added a .stub member to Action trees, and switched Source's repr to be @filename[start:stop] instead of "filename[start:stop]" --- core/metaprogramming.nom | 49 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'core/metaprogramming.nom') diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 36f7d34..c343ae9 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -7,15 +7,15 @@ immediately lua> ".." nomsu:define_compile_action("compile %actions to %lua", function(tree, \%actions, \%lua) local lua = Lua(tree.source, "nomsu:define_compile_action(") - local stubs = {} + local specs = {} for i, action in ipairs(\%actions.value) do - stubs[i] = action:get_stub(true) + specs[i] = action:get_spec() end - stubs = repr(stubs) - if #stubs > 80 then - lua:append("\n ",stubs,",\n ") + specs = repr(specs) + if #specs > 80 then + lua:append("\n ",specs,",\n ") else - lua:append(stubs,", ") + lua:append(specs,", ") end lua:append("function(tree") local args = {} @@ -37,15 +37,15 @@ immediately compile [action %actions %body] to lua> ".." local lua = Lua(tree.source, "nomsu:define_action(") - local stubs = {} + local specs = {} for i, action in ipairs(\%actions.value) do - stubs[i] = action:get_stub(true) + specs[i] = action:get_spec() end - stubs = repr(stubs) - if #stubs > 80 then - lua:append("\n ",stubs,",\n ") + specs = repr(specs) + if #specs > 80 then + lua:append("\n ",specs,",\n ") else - lua:append(stubs,", ") + lua:append(specs,", ") end lua:append("function(") local args = {} @@ -67,15 +67,15 @@ immediately compile [parse %shorthand as %longhand] to lua> ".." local lua = Lua(tree.source, "nomsu:define_compile_action(") - local stubs = {} + local specs = {} for i, action in ipairs(\%shorthand.value) do - stubs[i] = action:get_stub(true) + specs[i] = action:get_spec() end - stubs = repr(stubs) - if #stubs > 80 then - lua:append("\n ",stubs,",\n ") + specs = repr(specs) + if #specs > 80 then + lua:append("\n ",specs,",\n ") else - lua:append(stubs,", ") + lua:append(specs,", ") end lua:append("function(tree") local replacements = {} @@ -93,15 +93,15 @@ immediately elseif t.type == 'Var' and replacements[t.value] then return replacements[t.value] elseif t.type == 'Var' then - return t.type.."("..repr(t.value.."#"..tostring(MANGLE_INDEX))..", "..repr(t.source)..")" + return t.type.."("..repr(t.value.."#"..tostring(MANGLE_INDEX))..", "..repr(tostring(t.source))..")" elseif t.is_multi then local bits = {} for i, entry in ipairs(t.value) do bits[i] = make_tree(entry) end - return t.type.."(Tuple("..table.concat(bits, ", ").."), "..repr(t.source)..")" + return t.type.."(Tuple("..table.concat(bits, ", ").."), "..repr(tostring(t.source))..")" else - return t.type.."("..repr(t.value)..", "..repr(t.source)..")" + return t.type.."("..repr(t.value)..", "..repr(tostring(t.source))..")" end end lua:append(")\n local tree = ", make_tree(\%longhand), "\n return nomsu:tree_to_lua(tree)\nend);") @@ -110,7 +110,7 @@ immediately compile [remove action %action] to Lua ".." do - local fn = ACTIONS[\(=lua "repr(\%action:get_stub())")] + local fn = ACTIONS[\(=lua "repr(\%action.stub)")] local stubs = ARG_ORDERS[fn] for stub in pairs(stubs) do ACTIONS[stub] = nil @@ -159,9 +159,6 @@ immediately local lua = Lua(\%tree.source, "return ",nomsu:tree_to_lua(\%tree)) return nomsu:run_lua(lua) - action [%tree's stub] - =lua "\%tree:get_stub()" - immediately parse [%var <-write %code] as: lua> "\%var:append(\%code);" parse [to %var write %code] as: lua> "\%var:append(\%code);" @@ -178,7 +175,7 @@ immediately # Compiler tools immediately compile [run %code] to - Lua "nomsu:run(Nomsu(\(%code.source as text), \(%code as lua expr)))" + Lua "nomsu:run(Nomsu(\"\(%code.source as text)\", \(%code as lua expr)))" immediately compile [show lua %block] to -- cgit v1.2.3