aboutsummaryrefslogtreecommitdiff
path: root/core
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
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')
-rw-r--r--core/control_flow.nom15
-rw-r--r--core/metaprogramming.nom20
-rw-r--r--core/operators.nom10
-rw-r--r--core/scopes.nom8
4 files changed, 39 insertions, 14 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 9aae937..0cc8f4e 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -383,3 +383,18 @@ compile [do %action then always %final_action] to
# Inline thunk:
compile [result of %body] to
Lua value "(\(compile as: [] -> %body))()"
+
+# Recurion control flow
+using
+ compile [%var's stack] to: Lua value "stack\(%var as lua id)"
+..compile
+ parse [for %var in recursive %structure %body] as
+ with local {(%var's stack): [%structure], action: recurse % on %}
+ action [recurse %v on %x]
+ add %x to (%v's stack)
+ repeat while: (length of (%var's stack)) > 0
+ %var <- (remove 1 from (%var's stack))
+ %body
+ === next %var ==
+ === stop %var ===
+
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));"
diff --git a/core/operators.nom b/core/operators.nom
index c81760d..0756751 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -130,16 +130,6 @@ compile [with %assignments %body] to
\%lua
end -- 'with' block
-compile [local %var_or_vars] to
- %lua <- (Lua "")
- lua> ".."
- if \%var_or_vars.type == "List" then
- \%lua:add_free_vars(table.map(\%var_or_vars, function(v) return tostring(nomsu:compile(v)) end))
- else
- \%lua:add_free_vars({tostring(nomsu:compile(\%var_or_vars))})
- end
- return %lua
-
# Math Operators
compile [%x wrapped around %y, %x mod %y] to: Lua value "(\(%x as lua expr) % \(%y as lua expr))"
diff --git a/core/scopes.nom b/core/scopes.nom
index b5fdded..3af59c5 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -9,18 +9,18 @@ compile [with local %locals %body, with local %locals do %body] to
* "Dict"
%body_lua <-
Lua ".."
- \(=lua "A_assign_1(\%locals, \%locals)")
+ \(compile as: <- %locals)
\%body_lua
declare locals
- (%.1 as lua id) for % in %locals
+ "\(%.1 as lua)" for % in %locals
.. in %body_lua
* "List"
declare locals
- (% as lua id) for % in %locals
+ "\(% as lua)" for % in %locals
.. in %body_lua
* "Var"
* "Action"
- declare locals [%locals as lua id] in %body_lua
+ declare locals ["\(%locals as lua)"] in %body_lua
* else
barf "Unexpected local: \(%locals as nomsu)"
return