From 2d1f49f78d260b4a34720d07b3e3a1a24cab8d69 Mon Sep 17 00:00:00 2001 From: liquidev Date: Sat, 24 Aug 2024 18:04:18 +0200 Subject: [PATCH] move apply_defs to just before the VM evaluates code --- crates/haku-wasm/src/lib.rs | 7 +++++-- crates/rkgk/src/haku.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/haku-wasm/src/lib.rs b/crates/haku-wasm/src/lib.rs index a8336ea..7697a2e 100644 --- a/crates/haku-wasm/src/lib.rs +++ b/crates/haku-wasm/src/lib.rs @@ -174,6 +174,7 @@ unsafe extern "C" fn haku_instance_destroy(instance: *mut Instance) { #[no_mangle] unsafe extern "C" fn haku_reset(instance: *mut Instance) { + debug!("resetting instance: {instance:?}"); let instance = &mut *instance; instance.system.restore_image(&instance.system_image); instance.defs.restore_image(&instance.defs_image); @@ -181,6 +182,7 @@ unsafe extern "C" fn haku_reset(instance: *mut Instance) { #[no_mangle] unsafe extern "C" fn haku_reset_vm(instance: *mut Instance) { + debug!("resetting instance VM: {instance:?}"); let instance = &mut *instance; instance.vm.restore_image(&instance.vm_image); } @@ -348,8 +350,6 @@ unsafe extern "C" fn haku_compile_brush( }; brush.state = BrushState::Ready(chunk_id); - instance.vm.apply_defs(&instance.defs); - info!("brush compiled into {chunk_id:?}"); StatusCode::Ok @@ -395,6 +395,9 @@ unsafe extern "C" fn haku_eval_brush(instance: *mut Instance, brush: *const Brus panic!("brush is not compiled and ready to be used"); }; + debug!("applying defs"); + instance.vm.apply_defs(&instance.defs); + let Ok(closure_id) = instance.vm.create_ref(Ref::Closure(Closure { start: BytecodeLoc { chunk_id, diff --git a/crates/rkgk/src/haku.rs b/crates/rkgk/src/haku.rs index 6f4aa19..81b88a9 100644 --- a/crates/rkgk/src/haku.rs +++ b/crates/rkgk/src/haku.rs @@ -114,8 +114,6 @@ impl Haku { let chunk_id = self.system.add_chunk(chunk).context("too many chunks")?; self.brush = Some(chunk_id); - self.vm.apply_defs(&self.defs); - Ok(()) } @@ -124,6 +122,8 @@ impl Haku { .brush .ok_or_eyre("brush is not compiled and ready to be used")?; + self.vm.apply_defs(&self.defs); + let closure_id = self .vm .create_ref(Ref::Closure(Closure {