aboutsummaryrefslogtreecommitdiff
path: root/core/metaprogramming.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-21 19:12:59 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-21 19:13:47 -0700
commit86a3219e7fc3244331595819f742b365172f96ad (patch)
tree948a3f308bd9c45b85efa2e130af8432bb1a97e2 /core/metaprogramming.nom
parent7761f715f7497e8b325a4f1134869f332848fd16 (diff)
Cleanup of some metaprogramming stuff, as well as adding support for
"package.nomsupath" to search for files in different locations, and prioritizing use of "luafilesystem" over system calls.
Diffstat (limited to 'core/metaprogramming.nom')
-rw-r--r--core/metaprogramming.nom20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 1e167d0..068513a 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -52,6 +52,20 @@ lua> ".."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+compile [using %defs compile %body] to
+ lua> ".."
+ local lua = LuaCode(tree.source)
+ lua:append(
+ "local old_nomsu = nomsu\n",
+ "local nomsu = table.fork(old_nomsu, {COMPILE_ACTIONS=table.fork(old_nomsu.COMPILE_ACTIONS)})")
+ lua:append(nomsu:compile(\%defs))
+ lua:append("\n")
+ lua:append("local ret = nomsu:compile(tree)\n")
+ lua:append("return ret")
+ nomsu = table.fork(nomsu, {tree=\%body})
+ local output = nomsu:run_lua(lua)
+ return output
+
compile [local action %actions %body] to
lua> ".."
local fn_name = "A"..string.as_lua_id(\%actions[1].stub)
@@ -84,6 +98,9 @@ compile [action %actions %body] to
lua:remove_free_vars(table.map(\%actions, function(a) return "A"..string.as_lua_id(a.stub) end))
return lua
+compile [action %action] to
+ Lua value "A\(%action.stub as lua id)"
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile [parse %actions as %body] to
@@ -160,6 +177,9 @@ compile [declare locals in %code] to
compile [declare locals %locals in %code] to
Lua value "\(%code as lua expr):declare_locals(\(%locals as lua expr))"
+compile [add free vars %vars to %code] to
+ Lua "\(%code as lua expr):add_free_vars(\(%vars as lua expr));"
+
compile [remove free vars %vars from %code] to
Lua "\(%code as lua expr):remove_free_vars(\(%vars as lua expr));"