Struct synfx_dsp_jit::JIT
source · [−]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
sourceimpl JIT
impl JIT
sourcepub fn new(
dsp_lib: Rc<RefCell<DSPNodeTypeLibrary>>,
dsp_ctx: Rc<RefCell<DSPNodeContext>>
) -> Self
pub fn new(
dsp_lib: Rc<RefCell<DSPNodeTypeLibrary>>,
dsp_ctx: Rc<RefCell<DSPNodeContext>>
) -> Self
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();
sourcepub fn compile(self, prog: ASTFun) -> Result<Box<DSPFunction>, JITCompileError>
pub fn compile(self, prog: ASTFun) -> Result<Box<DSPFunction>, JITCompileError>
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
impl !RefUnwindSafe for JIT
impl !Send for JIT
impl !Sync for JIT
impl Unpin for JIT
impl !UnwindSafe for JIT
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more