From 01aa199f7acfe9af57c5970793259b36e060fd11 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 15 May 2018 16:36:21 -0700 Subject: Adding support for coroutines, and cleaning up comment syntax. --- core/control_flow.nom | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'core/control_flow.nom') 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));" -- cgit v1.2.3