From 86a3219e7fc3244331595819f742b365172f96ad Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 21 Jun 2018 19:12:59 -0700 Subject: 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. --- core/metaprogramming.nom | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core/metaprogramming.nom') 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));" -- cgit v1.2.3