aboutsummaryrefslogtreecommitdiff
path: root/core/metaprogramming.nom
diff options
context:
space:
mode:
Diffstat (limited to 'core/metaprogramming.nom')
-rw-r--r--core/metaprogramming.nom49
1 files changed, 23 insertions, 26 deletions
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