diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2b0f54b..ffaa9ef 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,9 +1,5 @@ -#![no_std] - -use core::arch::wasm32; -use core::ptr; -use core::mem; -use core::slice; +use std::mem; +use std::slice; pub type ClockyFunc = extern "C" fn(*const Closure) -> *const (); @@ -83,12 +79,6 @@ pub unsafe extern "C" fn since_last_tick_stream(clock: *const Clock) -> *const S since_last_tick_closure(clos) } -#[cfg(not(test))] -#[panic_handler] -fn panic(_: &core::panic::PanicInfo<'_>) -> ! { - core::arch::wasm32::unreachable() -} - #[no_mangle] pub extern "C" fn sin(x: f32) -> f32 { libm::sinf(x) @@ -99,31 +89,9 @@ pub extern "C" fn cos(x: f32) -> f32 { libm::cosf(x) } -static mut HEAP_PTR: *mut () = ptr::null_mut(); -static mut HEAP_END: *mut () = ptr::null_mut(); - -// ?? -const ALLOC_SIZE_PAGES: usize = 4; - #[no_mangle] pub unsafe extern "C" fn alloc(n: u32) -> *mut () { - let old_heap_ptr = HEAP_PTR; - if let Some(new_heap_ptr) = (HEAP_PTR as usize).checked_add(n as usize) { - if new_heap_ptr < HEAP_END as usize { - HEAP_PTR = new_heap_ptr as *mut (); - old_heap_ptr - } else { - let old_size = wasm32::memory_grow(0, ALLOC_SIZE_PAGES); - if old_size < usize::MAX { - let allocation = (old_size * 65536) as *mut (); - HEAP_PTR = (old_size * 65536 + n as usize) as *mut (); - HEAP_END = ((old_size + ALLOC_SIZE_PAGES) * 65536) as *mut (); - allocation - } else { - panic!() - } - } - } else { - panic!() - } + // TODO: obviously so much. but right now i'm thinking about the + // alignment + std::alloc::alloc(std::alloc::Layout::from_size_align(n as usize, 4).unwrap()) as *mut () }