aboutsummaryrefslogtreecommitdiff
path: root/core/coroutines.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-17 14:38:05 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-17 14:39:08 -0800
commit7f47d4204039258cec78c767f489b7809b4257ff (patch)
treec8533068b75ab453accfe1f688705e9e94c9e279 /core/coroutines.nom
parent34a3dd22a4e132bd4e0fe3ce89831c3fe761d3d9 (diff)
In-progress (but working) overhaul of some elements including: function
calls, lib/thing.nom API, multi-assignments, varargs, etc.
Diffstat (limited to 'core/coroutines.nom')
-rw-r--r--core/coroutines.nom33
1 files changed, 22 insertions, 11 deletions
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 7d17d63..0a625c2 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -3,29 +3,40 @@
This file defines the code that creates and manipulates coroutines
use "core/metaprogramming.nom"
+use "core/operators.nom"
+use "core/control_flow.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test:
- %nums = []
%co = (..)
- coroutine:
- -> 4
- -> 5
- repeat 3 times: -> 6
+ ->:
+ yield 4
+ yield 5
+ repeat 3 times: yield 6
+ %nums = []
for % in coroutine %co:
%nums::add %
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
-[coroutine %body, generator %body] all compile to "\
- ..(function()
- \(%body as lua)
- end)"
-(-> %) compiles to "coroutine.yield(true, \((% as lua expr) if % else "nil"))"
+ %d = {x:0}
+ %co2 = (..)
+ coroutine:
+ %d.x += 1
+ yield 1
+ %d.x += 1
+ yield
+ %d.x += 1
+ repeat while ((coroutine status of %co2) != "dead"):
+ resume %co2
+ assume %d.x == 3
+
+(coroutine %body) parses as (coroutine from (-> %body))
+
(for % in coroutine %co %body) compiles to "\
- ..for _junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
+ ..for \(% as lua expr) in coroutine_wrap(\(%co as lua expr)) do
\(%body as lua)
end"