-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
GatherIter.pir
103 lines (83 loc) · 2.13 KB
/
GatherIter.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
=head1 TITLE
GatherIter - Perl 6 gather iterator
=head1 DESCRIPTION
GatherIter is used to handle gather/take.
=head2 Methods
=over 4
=cut
.namespace ['GatherIter']
.sub 'onload' :anon :init :load
.local pmc p6meta, proto
p6meta = get_hll_global ['Mu'], '$!P6META'
proto = p6meta.'new_class'('GatherIter', 'parent'=>'Iterator', 'attr'=>'@!reify &!coro')
.end
=item reify()
Returns the next component of the iteration.
=cut
.namespace ['GatherIter']
.sub 'reify' :method
x_enter_sublog
.local pmc reify
reify = getattribute self, '@!reify'
unless null reify goto iter_reified
.local pmc coro
coro = getattribute self, '&!coro'
reify = coro()
setattribute self, '@!reify', reify
iter_reified:
.return (reify)
.end
.namespace []
.sub '!GATHER'
.param pmc block
x_enter_sublog
.local pmc gatheriter, coro, list
gatheriter = new ['GatherIter']
.const 'Sub' coro_sub = '!gather_coroutine'
.local pmc coro
coro = clone coro_sub
# Initial coroutine call to set the Coroutine's block and coro values
coro(block, coro)
setattribute gatheriter, '&!coro', coro
list = gatheriter.'list'()
.return (list)
.end
.include 'except_types.pasm'
.sub '' :subid('!gather_coroutine')
.param pmc block
.param pmc coro
x_enter_sublog
# Initial yield back to !GATHER
.yield ()
.local pmc handler
handler = root_new ['parrot';'ExceptionHandler']
handler.'handle_types'(.CONTROL_TAKE)
set_addr handler, take
push_eh handler
block()
pop_eh
gather_done:
.local pmc reify
reify = root_new ['parrot';'ResizablePMCArray']
.yield (reify)
goto gather_done
take:
.local pmc exception, value, resume, nextiter
.get_results (exception)
value = exception['payload']
resume = exception['resume']
reify = root_new ['parrot';'ResizablePMCArray']
push reify, value
nextiter = new ['GatherIter']
setattribute nextiter, '&!coro', coro
push reify, nextiter
.yield (reify)
resume()
.end
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: