def emit

bend-kit-regex@0.8.0.0 · regex.bend:642

import bend-kit-regex@0.8.0.0/regex.bend as Regex
import Base

642# The instructions of n, placed at pc, in front of rest. ISplit tries x first.
643def emit(n: Node, +pc: U32, rest: List<&2, Inst>) -> List<&2, Inst>:
644  match n:
645    case NEmpty{}:
646      rest
647    case NSet{neg, items}:
648      ISet{neg, items} <> rest
649    case NAssert{k}:
650      IAssert{k} <> rest
651    case NCat{+a, b}:
652      emit(a, pc, emit(b, (pc + size(a) : U32), rest))
653    case NAlt{+a, +b}:
654      +j = (pc + 1 + size(a) : U32)
655      ISplit{(pc + 1 : U32), (j + 1 : U32)} <> emit(a, (pc + 1 : U32), IJmp{(j + 1 + size(b) : U32)} <> emit(b, (j + 1 : U32), rest))
656    case NPlus{+g, +a}:
657      +out = (pc + 1 + size(a) : U32)
658      emit(a, pc, ISplit{Bool.pick(U32, g, pc, out), Bool.pick(U32, g, out, pc)} <> rest)
659    case NQuest{+g, +a}:
660      +out = (pc + 1 + size(a) : U32)
661      ISplit{Bool.pick(U32, g, (pc + 1 : U32), out), Bool.pick(U32, g, out, (pc + 1 : U32))} <> emit(a, (pc + 1 : U32), rest)
662    case NGroup{+i, a}:
663      ISave{(2 * i : U32)} <> emit(a, (pc + 1 : U32), ISave{(2 * i + 1 : U32)} <> rest)

Uses (8)

Used by (2)