Skip to content

Commit 0e60187

Browse files
committed
Refactor handling of $¢ in subs, make sure that match objects can
be created in closures.
1 parent e0f623d commit 0e60187

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/NQPQ/Actions.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,12 @@ class NQP::Actions is HLL::Actions {
10401040
}
10411041
}
10421042
else {
1043-
my $regex :=
1044-
QRegex::P6Regex::Actions::buildsub($<p6regex>.ast, @BLOCK.shift);
1043+
my $block := @BLOCK.shift;
1044+
$block[0].push(PAST::Var.new(:name<>, :scope<lexical>, :isdecl(1)));
1045+
$block[0].push(PAST::Var.new(:name<$/>, :scope<lexical>, :isdecl(1)));
1046+
$block.symbol('', :scope<lexical>);
1047+
$block.symbol('$/', :scope<lexical>);
1048+
my $regex := QRegex::P6Regex::Actions::buildsub($<p6regex>.ast, $block);
10451049
$regex.name($name);
10461050
my $prefix_meth;
10471051

src/QAST/Compiler.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class QAST::Compiler is HLL::Compiler {
3636

3737
# common prologue
3838
my $startreg := '(' ~ nqp::join(', ', [%*REG<cur>, %*REG<tgt>, %*REG<pos>, %*REG<curclass>, %*REG<bstack>]) ~ ')';
39+
$ops.push_pirop('store_lex', 'unicode:"$\x{a2}"', %*REG<cur>);
3940
$ops.push_pirop('callmethod', '"!cursor_start"', 'self', :result($startreg));
4041
$ops.push_pirop('length', %*REG<eos>, %*REG<tgt>);
4142
$ops.push(self.regex_post($node));

src/QRegex/Cursor.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ role NQPCursorRole {
5252
my $new := self.CREATE();
5353
nqp::bindattr($new, $?CLASS, '$!orig', $!orig);
5454
nqp::bindattr_i($new, $?CLASS, '$!pos', -3);
55+
nqp::bindattr($new, $?CLASS, '$!regexsub', Q:PIR {
56+
$P0 = getinterp
57+
%r = $P0['sub';1]
58+
});
5559
pir::return__vPsiPP(
5660
$new,
5761
nqp::bindattr_s($new, $?CLASS, '$!target', $!target),

src/QRegex/P6Regex/Actions.nqp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
392392
$ast;
393393
}
394394

395-
our sub buildsub($qast, $block = PAST::Block.new()) {
395+
our sub buildsub($qast, $block = PAST::Block.new(:blocktype<method>)) {
396396
my $hashpast := PAST::Op.new( :pasttype<hash> );
397397
for capnames($qast, 0) {
398398
if $_.key gt '' {
@@ -404,12 +404,16 @@ class QRegex::P6Regex::Actions is HLL::Actions {
404404
my $capblock := PAST::Block.new( :hll<nqp>, :namespace(['Sub']), :lexical(0),
405405
:name($block.subid ~ '_caps'), $hashpast );
406406
$block.push($capblock);
407+
408+
unless $block.symbol('') {
409+
$block.push(PAST::Var.new(:name<>, :scope<lexical>, :isdecl(1)));
410+
$block.symbol('', :scope<lexical>);
411+
}
407412
$qast := QAST::Regex.new( :rxtype<concat>,
408413
QAST::Regex.new( :rxtype<scan> ),
409414
$qast,
410415
QAST::Regex.new( :rxtype<pass> ));
411416
$block.push(PAST::QAST.new($qast));
412-
$block.blocktype('method');
413417
$block;
414418
}
415419

0 commit comments

Comments
 (0)