Skip to content

Instantly share code, notes, and snippets.

@Benabik
Created June 7, 2011 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Benabik/1013096 to your computer and use it in GitHub Desktop.
Save Benabik/1013096 to your computer and use it in GitHub Desktop.
nqp-rx fix for contextuals

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.

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment