Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix register lifetime for min/max in quants.
Since we backtrack in/out of the quant code, the min/max must not be
kept in registers with a lifetime of just that region of code, or they
may get scribbled over. Fixes the remaining t/qregex failure and one
of the t/p5regex failures.
  • Loading branch information
jnthn committed Oct 10, 2013
1 parent ee57fd9 commit 84ff46d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/vm/moar/QAST/QASTRegexCompilerMAST.nqp
Expand Up @@ -540,11 +540,7 @@ class QAST::MASTRegexCompiler {
my $needmark := $needrep || $backtrack eq 'r';
my $rep := %*REG<rep>;
my $pos := %*REG<pos>;
my $minreg := fresh_i();
my $maxreg := fresh_i();
nqp::push(@ins, op('const_i64', $minreg, ival($min))) if $min > 1;
nqp::push(@ins, op('const_i64', $maxreg, ival($max))) if $max > 1;
my $ireg := fresh_i();
my $ireg := fresh_i();

if $backtrack eq 'f' {
my $seplabel := label($prefix ~ '_sep');
Expand All @@ -564,12 +560,18 @@ class QAST::MASTRegexCompiler {
nqp::push(@ins, op('set', $rep, $ireg));
nqp::push(@ins, op('inc_i', $rep));
if $min > 1 {
my $minreg := fresh_i();
nqp::push(@ins, op('const_i64', $minreg, ival($min)));
nqp::push(@ins, op('lt_i', $ireg, $rep, $minreg));
nqp::push(@ins, op('if_i', $ireg, $looplabel));
release($minreg, $MVM_reg_int64);
}
if $max > 1 {
my $maxreg := fresh_i();
nqp::push(@ins, op('const_i64', $maxreg, ival($max))) if $max > 1;
nqp::push(@ins, op('ge_i', $ireg, $rep, $maxreg));
nqp::push(@ins, op('if_i', $ireg, $donelabel));
release($maxreg, $MVM_reg_int64);
}
self.regex_mark(@ins, $looplabel_index, $pos, $rep) if $max != 1;
nqp::push(@ins, $donelabel);
Expand All @@ -584,8 +586,11 @@ class QAST::MASTRegexCompiler {
self.regex_commit(@ins, $donelabel_index) if $backtrack eq 'r';
nqp::push(@ins, op('inc_i', $rep));
if $max > 1 {
my $maxreg := fresh_i();
nqp::push(@ins, op('const_i64', $maxreg, ival($max))) if $max > 1;
nqp::push(@ins, op('ge_i', $ireg, $rep, $maxreg));
nqp::push(@ins, op('if_i', $ireg, $donelabel));
release($maxreg, $MVM_reg_int64);
}
}
unless $max == 1 {
Expand All @@ -595,13 +600,14 @@ class QAST::MASTRegexCompiler {
}
nqp::push(@ins, $donelabel);
if $min > 1 {
my $minreg := fresh_i();
nqp::push(@ins, op('const_i64', $minreg, ival($min)));
nqp::push(@ins, op('lt_i', $ireg, $rep, $minreg));
nqp::push(@ins, op('if_i', $ireg, %*REG<fail>));
release($minreg, $MVM_reg_int64);
}
}
release($ireg, $MVM_reg_int64);
release($minreg, $MVM_reg_int64);
release($maxreg, $MVM_reg_int64);
@ins
}

Expand Down

0 comments on commit 84ff46d

Please sign in to comment.