Internals

Complete docstring documentation of the JLPeg internal API.

JLpeg.InstructionType
Instruction

Abstract type of JLPeg VM instructions.

The possible struct fields have consistent meanings:

FieldTypeMeaning
op@enum UInt8The Opcode
l`Int3216`
nUInt32A subject index or offset
cCharA character to match
bUInt8A test byte
tagUInt16Key in a capture/throw Dict
checkUInt16Which check to perform
vecBitVector (kinda)A set's test BitVector

There are also fields moe, larry, and curly, which are struct padding, so that the op field (for the instructions which have it) are in a consistent location. These consist of all 1s and do not play a role in the semantics of the VM.

source
JLpeg.VMStateType
VMState(patt::Pattern, subject::AbstractString)

Contains the state of a match on subject by program.

Fields

Other than the subject, program, and patt, we have:

  • top: the byte length of subject
  • i: Instruction counter
  • s: Subject pointer
  • ti, ts, tc, tm, tp: Stack top registers
  • t_on: flag for nonempty stack
  • running: Bool which is true when the VM is executing
  • matched: true if we matched the program on the subject
  • inpred: Bool is true inside predicates (PAnd, PNot)
  • sfar: furthest subject pointer we've failed at, for error reporting
  • failtag: tag for a labeled failure
  • stack: Contains stack frames for calls and backtracks
  • cap: A stack for captures
  • mark: A stack for marks

Implementation

Classic dispatch-driven VM with a program counter, opcodes, stack frames. I borrowed a page from Forth and made the top of the stack a register, allowing stack frames to be immutable while still permitting the PartialCommit optimization.

source