References
Data
Automa.SizedMemory
— Type.SizedMemory(data)
Create a SizedMemory
object from data
.
data
must implement Automa.pointerstart
and Automa.pointerend
methods. These are used to get the range of the contiguous data memory of data
. These have default methods which uses Base.pointer
and Base.sizeof
methods. For example, String
and Vector{UInt8}
support these Base
methods.
Note that it is user's responsibility to keep the data
object alive during SizedMemory
's lifetime because it does not have a reference to the object.
Automa.pointerend
— Function.pointerend(data)::Ptr{UInt8}
Return the end position of data
.
The default implementation is Automa.pointerstart(data) + sizeof(data) - 1
.
Automa.pointerstart
— Function.pointerstart(data)::Ptr{UInt8}
Return the start position of data
.
The default implementation is convert(Ptr{UInt8}, pointer(data))
.
Code generator
Automa.Variables
— Type.Variable names used in generated code.
The following variable names may be used in the code.
p::Int
: current position of datap_end::Int
: end position of datap_eof::Int
: end position of file streamts::Int
: start position of token (tokenizer only)te::Int
: end position of token (tokenizer only)cs::Int
: current statedata::Any
: input datamem::SizedMemory
: input data memorybyte::UInt8
: current data byte
Automa.CodeGenContext
— Type.CodeGenContext(;
vars=Variables(:p, :p_end, :p_eof, :ts, :te, :cs, :data, gensym(), gensym()),
generator=:table,
checkbounds=true,
loopunroll=0,
getbyte=Base.getindex,
clean=false
)
Create a code generation context.
Arguments
vars
: variable names used in generated codegenerator
: code generator (:table
,:inline
or:goto
)checkbounds
: flag of bounds checkloopunroll
: loop unroll factor (≥ 0)getbyte
: function of byte access (i.e.getbyte(data, p)
)clean
: flag of code cleansing
Automa.generate_init_code
— Function.generate_init_code(machine)
Generate variable initialization code.
The generated code is equivalent to:
p::Int = 1
p_end::Int = 0
p_eof::Int = -1
cs::Int = <start state of machine>
generate_init_code(context::CodeGenContext, machine::Machine)::Expr
Generate variable initialization code.
Automa.generate_exec_code
— Function.generate_exec_code(ctx::CodeGenContext, machine::Machine, actions=nothing)::Expr
Generate machine execution code with actions.