Skip to content

Commit

Permalink
fix running compiled code in sketcher, hackily for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrosen committed Jun 1, 2024
1 parent 3f3d323 commit b45653f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use core::arch::wasm32;
use core::ptr;
use core::mem;
use core::slice;

pub type ClockyFunc = extern "C" fn(*const Closure) -> *const ();
Expand Down Expand Up @@ -44,6 +45,13 @@ pub unsafe extern "C" fn sample(mut s: *const Stream, n: u32, out_ptr: *mut f32)
s
}

#[no_mangle]
pub unsafe extern "C" fn apply_clock(clos: *const Closure, clk: *const ()) -> *const () {
assert_eq!((*clos).arity, 1);
let func: extern "C" fn(*const Closure, *const ()) -> *const () = mem::transmute((*clos).func);
func(clos, clk)
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo<'_>) -> ! {
Expand Down
2 changes: 1 addition & 1 deletion sketching/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ClockyStreamProcessor extends AudioWorkletProcessor {
console.log("instantiated");
this.instance = instance;
this.first = true;
this.stream = instance.exports.main;
this.stream = instance.exports.apply_clock(instance.exports.main, 0);
this.samples_ptr = instance.exports.alloc(4 * 128);
});
};
Expand Down

0 comments on commit b45653f

Please sign in to comment.