pub struct JIT { /* private fields */ }
Expand description

The Just In Time compiler, that translates a crate::ASTNode tree into machine code in form of a DSPFunction structure you can use to execute it.

See also JIT::compile for an example.

Implementations

Create a new JIT compiler instance.

Because every newly compile function gets it’s own fresh module, you need to recreate a JIT instance for every time you compile a function.

 use synfx_dsp_jit::*;
 let lib = get_standard_library();
 let ctx = DSPNodeContext::new_ref();

 let jit = JIT::new(lib.clone(), ctx.clone());
 // ...
 ctx.borrow_mut().free();

Compiles a crate::ASTFun / crate::ASTNode tree into a DSPFunction.

There are some checks done by the compiler, see the possible errors in JITCompileError. Otherwise the usage is pretty straight forward, here is another example:

 use synfx_dsp_jit::*;
 let lib = get_standard_library();
 let ctx = DSPNodeContext::new_ref();

 let jit = JIT::new(lib.clone(), ctx.clone());
 let mut fun = jit.compile(ASTFun::new(Box::new(ASTNode::Lit(0.424242))))
     .expect("Compiles fine");

 // ...
 fun.init(44100.0, None);
 // ...
 let (mut sig1, mut sig2) = (0.0, 0.0);
 let ret = fun.exec(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &mut sig1, &mut sig2);
 // ...

 // Compile a different function now...
 let jit = JIT::new(lib.clone(), ctx.clone());
 let mut new_fun = jit.compile(ASTFun::new(Box::new(ASTNode::Lit(0.33333))))
     .expect("Compiles fine");

 // Make sure to preserve any (possible) state...
 new_fun.init(44100.0, Some(&fun));
 // ...
 let (mut sig1, mut sig2) = (0.0, 0.0);
 let ret = new_fun.exec(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &mut sig1, &mut sig2);
 // ...

 ctx.borrow_mut().free();

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 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.