Skip to content

Commit bb0350f

Browse files
committed
Don't leave leftovers on the bstack after an alternation.
1 parent ddf6d6b commit bb0350f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/QAST/Compiler.nqp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,19 @@ class QAST::Compiler is HLL::Compiler {
108108

109109
# Calculate all the branches to try, which populates the bstack
110110
# with the options. Then immediately fail to start iterating it.
111+
my $prefix := self.unique('alt') ~ '_';
112+
my $endlabel := self.post_new('Label', :result($prefix ~ 'end'));
111113
my $label_list_ops := self.post_new('Ops', :result<$P11>);
112114
$label_list_ops.push_pirop('new', '$P11', '"ResizableIntegerArray"');
113115
my $ops := self.post_new('Ops', :result(%*REG<cur>));
114116
$ops.push($label_list_ops);
117+
self.regex_mark($ops, $endlabel, -1, 0);
115118
$ops.push_pirop('callmethod', '"!alt"', %*REG<cur>, %*REG<pos>,
116119
self.escape($node.name), $label_list_ops.result);
117120
$ops.push_pirop('goto', %*REG<fail>);
118121

119122
# Emit all the possible alternations.
120-
my $prefix := self.unique('alt') ~ '_';
121123
my $altcount := 0;
122-
my $endlabel := self.post_new('Label', :result($prefix ~ 'end'));
123124
my $iter := nqp::iterator($node.list);
124125
while $iter {
125126
my $altlabel := self.post_new('Label', :result($prefix ~ $altcount));
@@ -131,6 +132,7 @@ class QAST::Compiler is HLL::Compiler {
131132
$altcount++;
132133
}
133134
$ops.push($endlabel);
135+
self.regex_commit($ops, $endlabel) if $node.backtrack eq 'r';
134136
$ops;
135137
}
136138

0 commit comments

Comments
 (0)