pub enum ASTNode {
    Lit(f64),
    Var(String),
    Assign(StringBox<ASTNode>),
    BinOp(ASTBinOpBox<ASTNode>, Box<ASTNode>),
    If(Box<ASTNode>, Box<ASTNode>, Option<Box<ASTNode>>),
    Call(Stringu64Vec<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(StringBox<ASTNode>)

Assigns a value to a variable.

BinOp(ASTBinOpBox<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(Stringu64Vec<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

Fields

buf_idx: usize
len: usize

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

Fields

op: ASTBufOp
idx: Box<ASTNode>

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.

Implementations

Tree dump of the AST. Returns a neatly indented tree. Pass 0 as first indent.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.