Guest User

Untitled

a guest
Jan 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. diff --git a/src/Perl6/Metamodel/BOOTSTRAP.nqp b/src/Perl6/Metamodel/BOOTSTRAP.nqp
  2. index 5176e0c..e80b938 100644
  3. --- a/src/Perl6/Metamodel/BOOTSTRAP.nqp
  4. +++ b/src/Perl6/Metamodel/BOOTSTRAP.nqp
  5. @@ -3236,23 +3236,17 @@ nqp::sethllconfig('perl6', nqp::hash(
  6. $result
  7. },
  8. 'exit_handler', -> $coderef, $resultish {
  9. - my %phasers :=
  10. - nqp::getattr(nqp::getcodeobj($coderef),Block,'$!phasers');
  11. - unless nqp::isnull(%phasers) || nqp::p6inpre() {
  12. - my @leaves := nqp::atkey(%phasers, '!LEAVE-ORDER');
  13. - my @posts := nqp::atkey(%phasers, 'POST');
  14. - my @exceptions;
  15. - unless nqp::isnull(@leaves) {
  16. - my @keeps := nqp::atkey(%phasers, 'KEEP');
  17. - my @undos := nqp::atkey(%phasers, 'UNDO');
  18. - my int $n := nqp::elems(@leaves);
  19. -
  20. - # only have a single LEAVEish phaser, so no frills needed
  21. - if nqp::isnull(@keeps)
  22. - && nqp::isnull(@undos)
  23. - && nqp::isnull(@posts)
  24. - && $n == 1
  25. - {
  26. + unless nqp::p6inpre() {
  27. + my %phasers :=
  28. + nqp::getattr(nqp::getcodeobj($coderef),Block,'$!phasers');
  29. + my @leaves := nqp::atkey(%phasers,'!LEAVE-ORDER');
  30. +
  31. + # fast path: only the one LEAVE phaser
  32. + if nqp::elems(%phasers) == 1
  33. + && nqp::not_i(nqp::isnull(@leaves))
  34. + && nqp::elems(@leaves) == 1 {
  35. + unless nqp::isnull(@leaves) { # dummy if for extra scope
  36. + unless nqp::isnull(@leaves) { # dummy if for extra scope
  37. #?if jvm
  38. nqp::decont(nqp::atpos(@leaves,0))();
  39. #?endif
  40. @@ -3262,71 +3256,78 @@ nqp::sethllconfig('perl6', nqp::hash(
  41. #?endif
  42. # don't bother to CATCH, there can only be one exception
  43. }
  44. + }
  45. + }
  46.  
  47. - # slow path here
  48. - else {
  49. - my int $i := -1;
  50. - my int $run;
  51. - my $phaser;
  52. - while ++$i < $n {
  53. - $phaser := nqp::decont(nqp::atpos(@leaves, $i));
  54. - $run := 1;
  55. - unless nqp::isnull(@keeps) {
  56. - for @keeps {
  57. - if nqp::eqaddr(nqp::decont($_),$phaser) {
  58. - $run := !nqp::isnull($resultish) &&
  59. - nqp::isconcrete($resultish) &&
  60. - $resultish.defined;
  61. - last;
  62. - }
  63. + # slow path if we have any leaves
  64. + elsif nqp::not_i(nqp::isnull(@leaves)) {
  65. + my @exceptions;
  66. + my @keeps := nqp::atkey(%phasers, 'KEEP');
  67. + my @undos := nqp::atkey(%phasers, 'UNDO');
  68. + my int $n := nqp::elems(@leaves);
  69. +
  70. + my int $i := -1;
  71. + my int $run;
  72. + my $phaser;
  73. + while ++$i < $n {
  74. + $phaser := nqp::decont(nqp::atpos(@leaves, $i));
  75. + $run := 1;
  76. + unless nqp::isnull(@keeps) {
  77. + for @keeps {
  78. + if nqp::decont($_) =:= $phaser {
  79. + $run := !nqp::isnull($resultish) &&
  80. + nqp::isconcrete($resultish) &&
  81. + $resultish.defined;
  82. + last;
  83. }
  84. }
  85. - unless nqp::isnull(@undos) {
  86. - for @undos {
  87. - if nqp::eqaddr(nqp::decont($_),$phaser) {
  88. - $run := nqp::isnull($resultish) ||
  89. - !nqp::isconcrete($resultish) ||
  90. - !$resultish.defined;
  91. - last;
  92. - }
  93. + }
  94. + unless nqp::isnull(@undos) {
  95. + for @undos {
  96. + if nqp::decont($_) =:= $phaser {
  97. + $run := nqp::isnull($resultish) ||
  98. + !nqp::isconcrete($resultish) ||
  99. + !$resultish.defined;
  100. + last;
  101. }
  102. }
  103. - if $run {
  104. + }
  105. + if $run {
  106. #?if jvm
  107. - $phaser();
  108. + $phaser();
  109. #?endif
  110. #?if moar
  111. - nqp::p6capturelexwhere($phaser.clone())();
  112. + nqp::p6capturelexwhere($phaser.clone())();
  113. #?endif
  114. - CATCH { nqp::push(@exceptions, $_) }
  115. - }
  116. + CATCH { nqp::push(@exceptions, $_) }
  117. }
  118. }
  119. - }
  120.  
  121. - unless nqp::isnull(@posts) {
  122. - my $value := nqp::ifnull($resultish,Mu);
  123. - my int $n := nqp::elems(@posts);
  124. - my int $i := -1;
  125. - while ++$i < $n {
  126. + my @posts := nqp::atkey(%phasers, 'POST');
  127. + unless nqp::isnull(@posts) {
  128. + my $value := nqp::ifnull($resultish,Mu);
  129. + my int $n := nqp::elems(@posts);
  130. + my int $i := -1;
  131. + while ++$i < $n {
  132. #?if jvm
  133. - nqp::atpos(@posts, $i)($value));
  134. + nqp::atpos(@posts, $i)($value));
  135. #?endif
  136. #?if moar
  137. - nqp::p6capturelexwhere(nqp::atpos(@posts,$i).clone)($value);
  138. + nqp::p6capturelexwhere(nqp::atpos(@posts,$i).clone)($value);
  139. #?endif
  140. - CATCH { nqp::push(@exceptions, $_); last; }
  141. + CATCH { nqp::push(@exceptions, $_); last; }
  142. + }
  143. }
  144. - }
  145.  
  146. - if @exceptions {
  147. - if nqp::elems(@exceptions) > 1 {
  148. - my %ex := nqp::gethllsym('perl6', 'P6EX');
  149. - if !nqp::isnull(%ex) && nqp::existskey(%ex, 'X::PhaserExceptions') {
  150. - nqp::atkey(%ex, 'X::PhaserExceptions')(@exceptions);
  151. + if @exceptions {
  152. + if nqp::elems(@exceptions) > 1 {
  153. + my %ex := nqp::gethllsym('perl6', 'P6EX');
  154. + if !nqp::isnull(%ex) && nqp::existskey(%ex, 'X::PhaserExceptions') {
  155. + nqp::atkey(%ex, 'X::PhaserExceptions')(@exceptions);
  156. + }
  157. }
  158. + nqp::rethrow(@exceptions[0]);
  159. }
  160. - nqp::rethrow(@exceptions[0]);
  161. }
  162. }
  163. },
Add Comment
Please, Sign In to add comment