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§

source§

impl JIT

source

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();
source

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§

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