30 lines
833 B
Plaintext
30 lines
833 B
Plaintext
#!/usr/bin/env nomsu -V3.8.7.6
|
|
#
|
|
This file defines the code that creates and manipulates coroutines
|
|
|
|
use "core/metaprogramming.nom"
|
|
|
|
test:
|
|
%nums = []
|
|
%co = (..)
|
|
coroutine:
|
|
-> 4
|
|
-> 5
|
|
repeat 3 times: -> 6
|
|
|
|
for % in coroutine %co: %nums::add %
|
|
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
|
|
compile [coroutine %body, generator %body] to (..)
|
|
Lua value ".."
|
|
(function()
|
|
\(%body as lua statements)
|
|
end)
|
|
|
|
compile [->] to (Lua value "coroutine.yield(true)")
|
|
compile [-> %] to (Lua value "coroutine.yield(true, \(% as lua expr))")
|
|
compile [for % in coroutine %co %body] to (..)
|
|
Lua ".."
|
|
for junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
|
|
\(%body as lua statements)
|
|
end
|