GitHub

Original file line numberDiff line numberDiff line change

@@ -4498,9 +4498,12 @@ codegen_pattern(codegen_scope *s, node *pattern, int target, uint32_t *fail_pos,

44984498

* 1. Left pattern is not another NODE_PAT_ALT (avoid recursion issues)

44994499

* 2. Left pattern generated at least one JMPNOT

45004500

* 3. The last JMPNOT is immediately before current position

4501+

* 4. The instruction is actually OP_JMPNOT (not OP_JMP which has

4502+

* different format S vs BS - converting OP_JMP would corrupt bytecode)

45014503

* In this case, convert JMPNOT to JMPIF and skip generating JMP */

45024504

if (node_type(pat_alt->left) != NODE_PAT_ALT &&

4503-

left_fail != JMPLINK_START && left_fail + 2 == s->pc) {

4505+

left_fail != JMPLINK_START && left_fail + 2 == s->pc &&

4506+

s->iseq[left_fail - 2] == OP_JMPNOT) {

45044507

/* Extract the previous link from the JMPNOT chain.

45054508

* The chain uses relative offsets where the end is marked by

45064509

* an offset that points to address 0 (i.e., (pos+2)+offset == 0) */

Read the original on github.com ↗