public
Last active

nqp-rx fix for contextuals

  • Download Gist
gistfile1.md
Markdown

In NQP, all variables get declared at the beginning of the block. This makes the following code fail:

my $old  := $*VAR;
my $*VAR := $new;

Instead of the old (outer) value of the contextual $*VAR, $old contains Undef. The following one line fix to nqp-rx seems to solve this problem by making NQP declare variables at the same point in the generated PIR as they are in the NQP code.

gistfile2.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13
diff --git i/src/NQP/Actions.pm w/src/NQP/Actions.pm
index d7c7602..2aba92a 100644
--- i/src/NQP/Actions.pm
+++ w/src/NQP/Actions.pm
@@ -438,7 +438,7 @@ method variable_declarator($/) {
:lvalue(1), :viviself( vivitype($sigil) ),
:node($/) );
$BLOCK.symbol($name, :scope($scope) );
- $BLOCK[0].push($decl);
+ $BLOCK.push($decl);
}
make $past;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.