Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement labeled for loops on parrot
  • Loading branch information
FROGGS committed May 16, 2014
1 parent ee0c5ed commit 876bb54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/core/MapIter.pm
Expand Up @@ -51,6 +51,7 @@ my class MapIter is Iterator {
my int $NEXT = nqp::can($block, 'fire_phasers')
&& +$block.phasers('NEXT');
my int $is_sink = $sink ?? 1 !! 0;
my Mu $label := $!label;

#?if parrot
Q:PIR {
Expand All @@ -71,7 +72,16 @@ my class MapIter is Iterator {
is_sink = find_lex '$is_sink'
set_addr handler, catch
handler.'handle_types'(.CONTROL_LOOP_LAST, .CONTROL_LOOP_NEXT, .CONTROL_LOOP_REDO)
};
if $!label {
Q:PIR { handler.'handle_types'(.CONTROL_LOOP_LAST, .CONTROL_LOOP_NEXT, .CONTROL_LOOP_REDO, 512, 513, 514) };
1
}
else {
Q:PIR { handler.'handle_types'(.CONTROL_LOOP_LAST, .CONTROL_LOOP_NEXT, .CONTROL_LOOP_REDO) };
1
}
Q:PIR {
push_eh handler

iter_loop:
Expand Down Expand Up @@ -111,6 +121,24 @@ my class MapIter is Iterator {
type = getattribute exception, 'type'
if type == .CONTROL_LOOP_REDO goto redo
if type == .CONTROL_LOOP_LAST goto last
};
if $!label {
Q:PIR {
.local int id1_reg, id2_reg
.local pmc label
label = find_lex '$label'
id1_reg = get_id result
id2_reg = label
if id1_reg != id2_reg goto rethrow
if type == 512 goto next
if type == 513 goto redo
if type == 514 goto last
rethrow:
rethrow exception # XXX Should that be perl6_based_rethrow?
};
1
}
Q:PIR {
next:
unless NEXT goto iter_loop
block.'fire_phasers'('NEXT')
Expand All @@ -127,7 +155,6 @@ my class MapIter is Iterator {
my int $state = 1;
my int $itmp;
my Mu $items := $!items;
my Mu $label := $!label;
my Mu $args := nqp::list();
my Mu $arg;

Expand Down
1 change: 1 addition & 0 deletions src/core/PseudoStash.pm
Expand Up @@ -36,6 +36,7 @@ my class Label {

"Label<$!name>(at $file:$line, '$green$left$yellow$eject$red$!name: $green$right$clear')"
}
method Int() { nqp::where(nqp::decont(self)) }
method next() {
my Mu $ex := nqp::newexception();
nqp::setpayload($ex, nqp::decont(self));
Expand Down

0 comments on commit 876bb54

Please sign in to comment.