Enum synfx_dsp_jit::ASTNode
source · [−]pub enum ASTNode {
Lit(f64),
Var(String),
Assign(String, Box<ASTNode>),
BinOp(ASTBinOp, Box<ASTNode>, Box<ASTNode>),
If(Box<ASTNode>, Box<ASTNode>, Option<Box<ASTNode>>),
Call(String, u64, Vec<Box<ASTNode>>),
BufDeclare {
buf_idx: usize,
len: usize,
},
BufOp {
op: ASTBufOp,
idx: Box<ASTNode>,
val: Option<Box<ASTNode>>,
},
Len(ASTLenOp),
Stmts(Vec<Box<ASTNode>>),
}
Expand description
The abstract syntax tree that the crate::JIT can compile down to machine code (in form of a crate::DSPFunction) for you.
See also the crate::build module about creating these trees conveniently directly from Rust code.
Variants
Lit(f64)
Literal fixed f64 values.
Var(String)
Variable and parameter names. Variables that start with a “*” are stored persistently across multiple crate::DSPFunction invocations for you.
Assign(String, Box<ASTNode>)
Assigns a value to a variable.
BinOp(ASTBinOp, Box<ASTNode>, Box<ASTNode>)
A binary operator. See also ASTBinOp which operations are possible.
If(Box<ASTNode>, Box<ASTNode>, Option<Box<ASTNode>>)
A conditional statement.
You can specify a ASTBinOp with a comparison operation as first element
here (the condition), or any other kind of expression that returns a value.
In the latter case the value must be larger or equal to 0.5
to be true.
Call(String, u64, Vec<Box<ASTNode>>)
Calls a DSP node/function by it’s name. The second parameter here, the u64
is the unique ID for this ASTNode. It’s used to track state of this DSP node.
You have to make sure that the IDs don’t change and that you are not using
the same ID for multiple stateful DSP nodes here.
BufDeclare
Declare the length of a buffer. By default all buffers are only 16 samples long. If you change the length of a buffer, a new buffer will be allocated on the fly and sent to the backend. crate::DSPNodeContext and crate::DSPFunction take care of disposing the old buffer allocation and preserving the data as good as possible.
BufOp
Perform a buffer or table operation on the specified buffer/table at the given index with an optional value. Tables and buffers don’t share their index space, each have their own index space. The buffer or table index is passed as the [ASTBufOp] enumeration.
Len(ASTLenOp)
To retrieve the length of a buffer or table.
Stmts(Vec<Box<ASTNode>>)
A list of statements that must be executed in the here specified order.