Skip to content

Commit

Permalink
Generate control exception data for return
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 15, 2010
1 parent 2d649c9 commit 59fa498
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
6 changes: 6 additions & 0 deletions src/Body.pm
Expand Up @@ -18,6 +18,7 @@ use CgOp ();
builder => 'is_mainline');
# '' for incorrectly contextualized {p,x,}block, blast
has type => (isa => 'Str', is => 'rw');
has returnable=> (isa => 'Bool', is => 'rw');

# Any => [ 'Variable', 'SAFE.F12_34' ] # a global
# $x => [ 'Variable', undef, 5 ] # slot 5 in pad
Expand Down Expand Up @@ -155,6 +156,11 @@ use CgOp ();
CgOp::sink($self->do->cgop($self)),
CgOp::rawsccall('Kernel.Take',
CgOp::scopedlex('EMPTY'))));
} elsif ($self->returnable) {
$self->cgoptree(CgOp::prog(@enter,
CgOp::return(CgOp::span("rstart", "rend",
$self->do->cgop($self))),
CgOp::ehspan(4, undef, 0, "rstart", "rend", "rend")));
} else {
$self->cgoptree(CgOp::prog(@enter,
CgOp::return($self->do->cgop($self))));
Expand Down
2 changes: 1 addition & 1 deletion src/CgOp.pm
Expand Up @@ -281,7 +281,7 @@ use warnings;
$_->var_cg($cg);
}
my ($c, @o) = @{ $self->op };
if ($cg->unreach && $c ne 'labelhere') {
if ($cg->unreach && $c ne 'labelhere' && $c ne 'ehspan') {
return;
}
$cg->$c(@o);
Expand Down
1 change: 1 addition & 0 deletions src/Niecza/Actions.pm
Expand Up @@ -2237,6 +2237,7 @@ sub sl_to_block { my ($cl, $type, $ast, %args) = @_;
$cl->blockcheck;
Body->new(
name => $subname,
returnable=> ($type eq 'sub'),
($type eq 'mainline' ? (
file => $::FILE->{name},
text => $::ORIG) : ()),
Expand Down
49 changes: 48 additions & 1 deletion test.pl
Expand Up @@ -2,7 +2,7 @@

use Test;

plan 454;
plan 518;

ok 1, "one is true";
ok 2, "two is also true";
Expand Down Expand Up @@ -1029,3 +1029,50 @@
is +$me<tok>[4]<sign>, 0, "fifth no sign";
is $me<tok>[2], '-34', "3rd token '-34'";
}
{
rxtest / . << . /, ".<<.", (" x",), ("x "," ","xx");
rxtest / . << /, ".<<", Nil, ("x", " ");
rxtest / << . /, "<<.", ("x",), (" ",);
rxtest / << /, "<<", Nil, ("",);
rxtest / . >> . /, ".>>.", ("x ",), (" x"," ","xx");
rxtest / . >> /, ".>>", ("x",), (" ",);
rxtest / >> . /, ">>.", Nil, ("x"," ");
rxtest / >> /, ">>", Nil, ("",);
rxtest / . « . /, ".«.", (" x",), ("x "," ","xx");
rxtest / . « /, ".«", Nil, ("x", " ");
rxtest / « . /, "«.", ("x",), (" ",);
rxtest / « /, "«", Nil, ("",);
rxtest / . » . /, ".».", ("x ",), (" x"," ","xx");
rxtest / . » /, ".»", ("x",), (" ",);
rxtest / » . /, "».", Nil, ("x"," ");
rxtest / » /, "»", Nil, ("",);
rxtest / . ^ . /, ".^.", Nil, ("x",);
rxtest / . ^ /, ".^", Nil, ("x",);
rxtest / ^ . /, "^.", ("x",), Nil;
rxtest / ^ /, "^", ("",), Nil;
rxtest / . $ . /, '.$.', Nil, ("x",);
rxtest / . $ /, '.$', ("x",), Nil;
rxtest / $ . /, '$.', Nil, ("x",);
rxtest / $ /, '$', ("",), Nil;
rxtest / . ^^ . /, '.^^.', ("\nx","\n\n"), ("x\n","xx");
rxtest / . ^^ /, '.^^', Nil, ("x","\n");
rxtest / ^^ . /, '^^.', ("x","\n"), Nil;
rxtest / ^^ /, '^^', ("",), Nil;
rxtest / . $$ . /, '.$$.', ("x\n", "\n\n"), ("\nx","xx");
rxtest / . $$ /, '.$$', ("x",), ("\n",);
rxtest / $$ . /, '$$.', ("\n",), ("x",);
rxtest / $$ /, '$$', ("",), Nil;
}
{
ok "foo" ~~ / :my $gothere = 1; foo /, "can embed :my in regexes";
ok $gothere, ":my code is run";
}
47 changes: 0 additions & 47 deletions test2.pl
@@ -1,51 +1,4 @@
# vim: ft=perl6
use Test;

{
rxtest / . << . /, ".<<.", (" x",), ("x "," ","xx");
rxtest / . << /, ".<<", Nil, ("x", " ");
rxtest / << . /, "<<.", ("x",), (" ",);
rxtest / << /, "<<", Nil, ("",);

rxtest / . >> . /, ".>>.", ("x ",), (" x"," ","xx");
rxtest / . >> /, ".>>", ("x",), (" ",);
rxtest / >> . /, ">>.", Nil, ("x"," ");
rxtest / >> /, ">>", Nil, ("",);

rxtest / . « . /, ".«.", (" x",), ("x "," ","xx");
rxtest / . « /, "", Nil, ("x", " ");
rxtest / « . /, "«.", ("x",), (" ",);
rxtest / « /, "«", Nil, ("",);

rxtest / . » . /, ".».", ("x ",), (" x"," ","xx");
rxtest / . » /, "", ("x",), (" ",);
rxtest / » . /, "».", Nil, ("x"," ");
rxtest / » /, "»", Nil, ("",);

rxtest / . ^ . /, ".^.", Nil, ("x",);
rxtest / . ^ /, ".^", Nil, ("x",);
rxtest / ^ . /, "^.", ("x",), Nil;
rxtest / ^ /, "^", ("",), Nil;

rxtest / . $ . /, '.$.', Nil, ("x",);
rxtest / . $ /, '.$', ("x",), Nil;
rxtest / $ . /, '$.', Nil, ("x",);
rxtest / $ /, '$', ("",), Nil;

rxtest / . ^^ . /, '.^^.', ("\nx","\n\n"), ("x\n","xx");
rxtest / . ^^ /, '.^^', Nil, ("x","\n");
rxtest / ^^ . /, '^^.', ("x","\n"), Nil;
rxtest / ^^ /, '^^', ("",), Nil;

rxtest / . $$ . /, '.$$.', ("x\n", "\n\n"), ("\nx","xx");
rxtest / . $$ /, '.$$', ("x",), ("\n",);
rxtest / $$ . /, '$$.', ("\n",), ("x",);
rxtest / $$ /, '$$', ("",), Nil;
}

{
ok "foo" ~~ / :my $gothere = 1; foo /, "can embed :my in regexes";
ok $gothere, ":my code is run";
}

done-testing;

0 comments on commit 59fa498

Please sign in to comment.