code / nomsu

Lines6.6K Lua5.1K PEG1.3K make117
2 others 83
Markdown60 Bourne Again Shell23
(65 lines)
1 #!/usr/bin/env nomsu -V7.0.0
2 ###
3 This file defines the code that creates and manipulates coroutines
5 use "core/metaprogramming"
6 use "core/operators"
7 use "core/control_flow"
9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 test:
12 $fn =
13 ->:
14 yield 4
15 yield 5
16 repeat 3 times:
17 yield 6
19 $nums = []
20 for $ in (coroutine from $fn): $nums, add $
21 assume ($nums == [4, 5, 6, 6, 6])
22 $d = {.x = 0}
23 $co =
24 coroutine:
25 $d.x += 1
26 yield 1
27 $d.x += 1
28 yield
29 $d.x += 1
31 repeat while ((coroutine status of $co) != "dead"): resume $co
32 assume $d.x == 3
33 $(co) = (coroutine: yield 5)
34 [$ok, $val] = (co)
35 assume ($ok == (yes))
36 assume ($val == 5)
37 $t = []
38 $i = 1
39 for $ in
40 coroutine:
41 yield 4
42 yield 5
43 yield
44 yield 6
45 ..:
46 $t.$i = $
47 $i += 1
48 assume ($t == [4, 5, nil, 6])
49 $t = []
50 for ($k = $) in
51 coroutine:
52 yield 4
53 yield 5
54 yield
55 yield 6
56 ..:
57 $t, add {.key = $k, .value = $}
59 assume $t == [
60 {.key = 1, .value = 4}, {.key = 2, .value = 5}, {.key = 3}, {.key = 4, .value = 6}
62 (coroutine $body) parses as (coroutine from ->$body)
63 external:
64 ($ is a dead coroutine) means
65 ((lua type of $) == "thread") and ((coroutine status of $) == "dead")