From 6bcccd60eb53636e068a766c70fdddbc971677b2 Mon Sep 17 00:00:00 2001 From: jnthn Date: Thu, 9 Apr 2009 15:28:52 +0200 Subject: [PATCH] Implement callwith for the wrapped sub case. --- src/builtins/control.pir | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/builtins/control.pir b/src/builtins/control.pir index 656f69da24d..2cc542f5839 100644 --- a/src/builtins/control.pir +++ b/src/builtins/control.pir @@ -114,7 +114,7 @@ the moment -- we'll do more complex handling a bit later.) continuation() .end -=item next +=item last =cut @@ -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' @@ -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' @@ -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' @@ -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 @@ -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