Skip to content

Commit fa94a60

Browse files
committed
Add first pass at handling lexical returns; create a new :pasttype<lexotic>
that creates a continuation block and attaches it to a lexical name.
1 parent faf34e9 commit fa94a60

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/PAST/NQP.pir

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,53 @@ Select a single past child based on rtype.
6060
cpost = self.'as_post'(cpast, options :flat :named)
6161
.return (cpost)
6262
.end
63+
64+
65+
=item lexotic(PAST::Op node)
66+
67+
Establish a lexotic label (continuation) that can be invoked
68+
via a lexical lookup. The C<name> attribute gives the name of
69+
the lexical to be used to hold the continuation. The result
70+
of this node is any argument passed when invoking the continuation,
71+
or the result of the last child node if the continuation isn't
72+
invoked.
73+
74+
=cut
75+
76+
.sub 'lexotic' :method :multi(_, ['PAST';'Op'])
77+
.param pmc node
78+
.param pmc options :slurpy :named
79+
80+
.local pmc label1, label2
81+
$P0 = get_hll_global ['POST'], 'Label'
82+
label1 = $P0.'new'('name'=>'lexotic_')
83+
label2 = $P0.'new'('name'=>'lexotic_')
84+
85+
.local string lexname
86+
lexname = node.'name'()
87+
lexname = self.'escape'(lexname)
88+
89+
.local pmc ops, handler, cpost
90+
$P0 = get_hll_global ['POST'], 'Ops'
91+
ops = $P0.'new'('node'=>node)
92+
handler = self.'uniquereg'('P')
93+
ops.'push_pirop'('root_new', handler, "['parrot';'Continuation']")
94+
ops.'push_pirop'('set_label', handler, label1)
95+
ops.'push_pirop'('.lex', lexname, handler)
96+
.local pmc cpost
97+
cpost = self.'stmts'(node, 'rtype'=>'P')
98+
ops.'push'(cpost)
99+
ops.'result'(cpost)
100+
.local string result
101+
ops.'push_pirop'('goto', label2)
102+
ops.'push'(label1)
103+
result = ops.'result'()
104+
$S0 = concat '(', result
105+
$S0 = concat $S0, ')'
106+
ops.'push_pirop'('.get_results', $S0)
107+
ops.'push'(label2)
108+
.return (ops)
109+
.end
63110

64111

65112
=item map_add(mapid, [hash])
@@ -296,7 +343,7 @@ entry to produce the node to be returned.
296343
# object opcodes
297344
maphash['bindattr'] = 'setattribute__3PPsP'
298345
maphash['getattr'] = 'getattribute__PPPs'
299-
maphash['create'] = 'repr_instance_of'
346+
maphash['create'] = 'repr_instance_of__PP'
300347
maphash['clone'] = 'clone__PP'
301348
maphash['isconcrete'] = 'repr_defined__IP'
302349
maphash['iscont'] = 'is_container__IP'

0 commit comments

Comments
 (0)