Browse files

LEAVE/KEEP/UNDO support for on JVM.

Passes almost all of the tests for these features that Parrot does.
This also makes let/temp work and their tests pass on JVM.
  • Loading branch information...
1 parent 60cb3e3 commit 45fb1bad71dcb9b9371473fb7f763b840b7f6e6e @jnthn jnthn committed Jul 16, 2013
Showing with 46 additions and 2 deletions.
  1. +44 −1 src/Perl6/Metamodel/BOOTSTRAP.nqp
  2. +1 −0 src/Perl6/World.nqp
  3. +1 −1 tools/build/NQP_REVISION
View
45 src/Perl6/Metamodel/BOOTSTRAP.nqp
@@ -1872,7 +1872,7 @@ Perl6::Metamodel::GrammarHOW.set_default_parent_type(Grammar);
# Put PROCESS in place.
nqp::bindhllsym('perl6', 'PROCESS', PROCESS);
-# HLL interop configuration.
+# HLL configuration: interop, boxing and exit handling.
nqp::sethllconfig('perl6', nqp::hash(
'int_box', Int,
'num_box', Num,
@@ -1893,5 +1893,48 @@ nqp::sethllconfig('perl6', nqp::hash(
my $result := nqp::create(ForeignCode);
nqp::bindattr($result, ForeignCode, '$!do', $code);
$result
+ },
+ 'exit_handler', -> $coderef, $resultish {
+ my $code := nqp::getcodeobj($coderef);
+ my %phasers := nqp::getattr($code, Block, '$!phasers');
+ unless nqp::isnull(%phasers) {
+ my @leaves := nqp::atkey(%phasers, '!LEAVE-ORDER');
+ my @keeps := nqp::atkey(%phasers, 'KEEP');
+ my @undos := nqp::atkey(%phasers, 'UNDO');
+ unless nqp::isnull(@leaves) {
+ my int $n := nqp::elems(@leaves);
+ my int $i := 0;
+ my int $run;
+ my $phaser;
+ while $i < $n {
+ $phaser := nqp::decont(nqp::atpos(@leaves, $i));
+ $run := 1;
+ unless nqp::isnull(@keeps) {
+ for @keeps {
+ if nqp::decont($_) =:= $phaser {
+ $run := !nqp::isnull($resultish) &&
+ nqp::isconcrete($resultish) &&
+ $resultish.defined;
+ last;
+ }
+ }
+ }
+ unless nqp::isnull(@undos) {
+ for @undos {
+ if nqp::decont($_) =:= $phaser {
+ $run := nqp::isnull($resultish) ||
+ !nqp::isconcrete($resultish) ||
+ !$resultish.defined;
+ last;
+ }
+ }
+ }
+ if $run {
+ $phaser();
+ }
+ $i++;
+ }
+ }
+ }
}
));
View
1 src/Perl6/World.nqp
@@ -1124,6 +1124,7 @@ class Perl6::World is HLL::World {
$code_past[+@($code_past) - 1] := QAST::Op.new(
:op('p6return'),
$code_past[+@($code_past) - 1]);
+ $code_past.has_exit_handler(1);
}
}
}
View
2 tools/build/NQP_REVISION
@@ -1 +1 @@
-2013.06-156-g0d19655
+2013.06-170-g04a1331

0 comments on commit 45fb1ba

Please sign in to comment.