Internals
Complete docstring
documentation of the JLPeg internal API.
JLpeg.Instruction
— TypeInstruction
Abstract type of JLPeg VM instructions.
The possible struct fields have consistent meanings:
Field | Type | Meaning |
---|---|---|
op | @enum UInt8 | The Opcode |
l | `Int32 | 16` |
n | UInt32 | A subject index or offset |
c | Char | A character to match |
b | UInt8 | A test byte |
tag | UInt16 | Key in a capture/throw Dict |
check | UInt16 | Which check to perform |
vec | BitVector (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.
JLpeg.VMState
— TypeVMState(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 ofsubject
i
: Instruction counters
: Subject pointerti
,ts
,tc
,tm
,tp
: Stack top registerst_on
: flag for nonempty stackrunning
:Bool
which istrue
when the VM is executingmatched
: true if we matched the program on the subjectinpred
:Bool
istrue
inside predicates (PAnd
,PNot
)sfar
: furthest subject pointer we've failed at, for error reportingfailtag
: tag for a labeled failurestack
: Contains stack frames for calls and backtrackscap
: A stack for capturesmark
: 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.