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

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

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§

source§

impl ASTNode

source

pub fn to_string(&self) -> String

source

pub fn typ_str(&self) -> &str

source

pub fn dump(&self, indent: usize) -> String

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

Trait Implementations§

source§

impl Clone for ASTNode

source§

fn clone(&self) -> ASTNode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ASTNode

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.