aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:21 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:38 -0700
commit01aa199f7acfe9af57c5970793259b36e060fd11 (patch)
tree0af9fd009d820053f83dd60eed862886bfb3eb5c /core
parent28cd9ae0b7a09d8f2cd0cd929f1ebdce4b081502 (diff)
Adding support for coroutines, and cleaning up comment syntax.
Diffstat (limited to 'core')
-rw-r--r--core/control_flow.nom18
-rw-r--r--core/metaprogramming.nom4
2 files changed, 15 insertions, 7 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 2816dfb..c3b5b2b 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -74,11 +74,9 @@ immediately
compile [%tree has subtree %subtree where %condition] to
Lua value ".."
(function()
- for \(%subtree as lua expr) in coroutine.wrap(function() nomsu:walk_tree(\(%tree as lua expr)) end) do
- if Types.is_node(\(%subtree as lua expr)) then
- if \(%condition as lua expr) then
- return true;
- end
+ for \(%subtree as lua expr) in coroutine.wrap(function() \(%tree as lua expr):map(coroutine.yield) end) do
+ if \(%condition as lua expr) then
+ return true;
end
end
return false;
@@ -431,3 +429,13 @@ immediately
\(%body as lua statements)
end)()
+# Coroutines:
+immediately
+ compile [values %body, coroutine %body, generator %body] to
+ Lua value ".."
+ (function()
+ \(%body as lua statements)
+ end)
+ compile [->] to: Lua "coroutine.yield(true);"
+ compile [-> %] to: Lua "coroutine.yield(true, \(% as lua expr));"
+ compile [-> %k = %v] to: Lua "coroutine.yield(\(%k as lua expr), \(%v as lua expr));"
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 475cdeb..a2c3820 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -95,7 +95,7 @@ immediately
replacements = "{"..table.concat(replacements, ", ").."}";
lua:append([[)
local template = nomsu:parse(Nomsu(]]..repr(tree.source)..[[, ]]..template..[[));
- local replacement = nomsu:tree_with_replaced_vars(template, ]]..replacements..[[);
+ local replacement = nomsu:tree_with_replacements(template, ]]..replacements..[[);
return replacement:as_lua(nomsu);
end);]]);
return lua;
@@ -125,7 +125,7 @@ immediately
=lua "\%tree:as_lua(nomsu):as_statements()"
action [%tree with vars %vars]
- =lua "nomsu:tree_with_replaced_vars(\%tree, \%vars)"
+ =lua "nomsu:tree_with_replacements(\%tree, \%vars)"
compile [declare locals in %code] to
Lua value "\(%code as lua expr):declare_locals()"