Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit f2311b5

Browse files
committed
fix op branch
1 parent 84113cb commit f2311b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

interp.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,28 +1329,30 @@ impl OpcodeExecutor for OpMinUntil {
13291329
#[derive(Default)]
13301330
struct OpBranch {
13311331
jump_id: usize,
1332-
current_branch_length: usize,
1332+
branch_offset: usize,
13331333
}
13341334
impl OpcodeExecutor for OpBranch {
1335+
// alternation
1336+
// <BRANCH> <0=skip> code <JUMP> ... <NULL>
13351337
fn next(&mut self, drive: &mut StackDrive) -> Option<()> {
13361338
match self.jump_id {
13371339
0 => {
13381340
drive.state.marks_push();
13391341
// jump out the head
1340-
self.current_branch_length = 1;
1342+
self.branch_offset = 1;
13411343
self.jump_id = 1;
13421344
self.next(drive)
13431345
}
13441346
1 => {
1345-
drive.skip_code(self.current_branch_length);
1346-
self.current_branch_length = drive.peek_code(0) as usize;
1347-
if self.current_branch_length == 0 {
1347+
let next_branch_length = drive.peek_code(self.branch_offset) as usize;
1348+
if next_branch_length == 0 {
13481349
drive.state.marks_pop_discard();
13491350
drive.ctx_mut().has_matched = Some(false);
13501351
return None;
13511352
}
13521353
drive.state.string_position = drive.ctx().string_position;
1353-
drive.push_new_context(1);
1354+
drive.push_new_context(self.branch_offset + 1);
1355+
self.branch_offset += next_branch_length;
13541356
self.jump_id = 2;
13551357
Some(())
13561358
}

0 commit comments

Comments
 (0)