Skip to content

Commit

Permalink
Implement callwith for the wrapped sub case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 9, 2009
1 parent a36c3b2 commit 6bcccd6
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/builtins/control.pir
Expand Up @@ -114,7 +114,7 @@ the moment -- we'll do more complex handling a bit later.)
continuation()
.end
=item next
=item last
=cut
Expand All @@ -126,6 +126,10 @@ the moment -- we'll do more complex handling a bit later.)
throw e
.end
=item next
=cut
.sub 'next'
.local pmc e
e = new 'Exception'
Expand All @@ -134,6 +138,10 @@ the moment -- we'll do more complex handling a bit later.)
throw e
.end
=item redo
=cut
.sub 'redo'
.local pmc e
e = new 'Exception'
Expand All @@ -142,6 +150,10 @@ the moment -- we'll do more complex handling a bit later.)
throw e
.end
=item continue
=cut
.sub 'continue'
.local pmc e
e = new 'Exception'
Expand All @@ -150,6 +162,10 @@ the moment -- we'll do more complex handling a bit later.)
throw e
.end
=item break
=cut
.sub 'break'
.param pmc arg :optional
.param int has_arg :opt_flag
Expand Down Expand Up @@ -410,6 +426,36 @@ on error.
.end


=item callwith

=cut

.sub 'callwith'
.param pmc pos_args :slurpy
.param pmc named_args :slurpy :named

# Is our caller a wrapping? If so, call inner.
.local pmc caller, inner
$P0 = new 'ParrotInterpreter'
caller = $P0['sub'; 1]
search_loop:
inner = getprop '$!wrap_inner', caller
if null inner goto try_outer
.tailcall inner(pos_args :flat, named_args :flat :named)
try_outer:
$I0 = isa caller, 'Routine' # Should not search out of current routine.
if $I0 goto not_wrapped
caller = caller.'get_outer'()
if null caller goto not_wrapped
$P0 = getprop '$!real_self', caller
if null $P0 goto search_loop
caller = $P0
goto search_loop

not_wrapped:
'die'('Use of callwith in non-wrapped case not yet implemented.')
.end

=back

=head1 TODO: Functions
Expand Down

0 comments on commit 6bcccd6

Please sign in to comment.