Skip to content

Commit

Permalink
Trap succeed in blocks that signature-bind $_
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Feb 6, 2011
1 parent 64beb12 commit 7742322
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/NAMOutput.pm6
Expand Up @@ -16,7 +16,11 @@ method run($*unit) {
}
sub nam_sub($s) {
@*subsnam[$s.xref[1]] = $s.code.cgop($s);
my $code = $s.code;
if $s.topicalizer {
$code = ::Op::TopicalHook.new(inner => $code);
}
@*subsnam[$s.xref[1]] = $code.cgop($s);
if $s.parametric_role_hack {
for @( $*unit.deref($s.parametric_role_hack).methods ) -> $me {
if $me.name ~~ ::GLOBAL::Op {
Expand Down
4 changes: 4 additions & 0 deletions src/NieczaPassBeta.pm6
Expand Up @@ -106,5 +106,9 @@ sub beta_optimize($body, $op, $inv, $cbody) {
$nop = ::Op::Let.new(var => $a.[1], to => $a.[0], in => $nop);
}

if $cbody.topicalizer {
$nop = ::Op::TopicalHook.new(inner => $nop);
}

$nop;
}
22 changes: 22 additions & 0 deletions src/niecza
Expand Up @@ -18,6 +18,7 @@ use MONKEY_TYPING;

use NieczaActions;
use Operator;
use CgOp;
sub node($M) { { line => $M.cursor.lineof($M.to) } }

sub mklet($value, $body) {
Expand All @@ -38,6 +39,27 @@ augment class NieczaActions {
method infix:sym<~~> ($/) { make ::Operator::SmartMatch.new }
}

augment class Metamodel::StaticSub { #OK exist
method topicalizer() {
$.signature && ?( grep { .slot && .slot eq '$_' }, @( $.signature.params ) )
}
}

augment class Op {
class TopicalHook is Op {
has $.inner;
method zyg() { $.inner }

method code($body) {
my $id = ::GLOBAL::NieczaActions.genid;

CgOp.prog(
CgOp.ehspan(6, '', 0, "start$id", "end$id", "end$id"),
CgOp.span("start$id", "end$id", 0, $.inner.cgop($body)));
}
}
}

augment class Operator {
class SmartMatch is Operator {
method as_function($/) { mklex($/, '&infix:<~~>') }
Expand Down

0 comments on commit 7742322

Please sign in to comment.