From 3f476bcb21bedf7dedc60d3cb146a2a8a8a94463 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 10 Dec 2024 16:04:38 +0100 Subject: [PATCH] fix --- dune | 6 ++++++ runtime/js/effect.js | 5 +++-- runtime/js/jslib.js | 4 ++-- runtime/wasm/effect.wat | 5 +++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dune b/dune index 72e1b1d00f..c68dad2d65 100644 --- a/dune +++ b/dune @@ -12,6 +12,12 @@ (:standard --enable effects)) (build_runtime_flags (:standard --enable effects))) + (wasm_of_ocaml + (compilation_mode separate) + (flags + (:standard --enable effects)) + (build_runtime_flags + (:standard --enable effects))) (binaries (tools/node_wrapper.exe as node) (tools/node_wrapper.exe as node.exe))) diff --git a/runtime/js/effect.js b/runtime/js/effect.js index 2cb1668050..5c3da510ff 100644 --- a/runtime/js/effect.js +++ b/runtime/js/effect.js @@ -122,9 +122,10 @@ function caml_perform_effect(eff, cont, last, k0) { // Move to parent fiber and execute the effect handler there // The handler is defined in Stdlib.Effect, so we know that the arity matches var k1 = caml_pop_fiber(); + var last_fiber = "last_fiber" // FIXME return caml_stack_check_depth() - ? handler(eff, cont, last, k1) - : caml_trampoline_return(handler, [eff, cont, last, k1]); + ? handler(eff, cont, last_fiber, k1) + : caml_trampoline_return(handler, [eff, cont, last_fiber, k1]); } //Provides: caml_alloc_stack diff --git a/runtime/js/jslib.js b/runtime/js/jslib.js index 43290e00b0..8943b05a88 100644 --- a/runtime/js/jslib.js +++ b/runtime/js/jslib.js @@ -86,9 +86,9 @@ var caml_callback = caml_call_gen; //Requires:caml_stack_depth, caml_call_gen, caml_exn_stack, caml_fiber_stack, caml_wrap_exception, caml_resume_stack, caml_fresh_oo_id, caml_named_value, caml_raise_with_arg, caml_string_of_jsbytes //Requires: caml_raise_constant function caml_callback(f, args) { - function uncaught_effect_handler(eff, k, ms) { + function uncaught_effect_handler(eff, k, last, ms) { // Resumes the continuation k by raising exception Unhandled. - caml_resume_stack(k[1], 0, ms); + caml_resume_stack(k[1], last, ms); var exn = caml_named_value("Effect.Unhandled"); if (exn) caml_raise_with_arg(exn, eff); else { diff --git a/runtime/wasm/effect.wat b/runtime/wasm/effect.wat index c2b35c2882..6c32c16c37 100644 --- a/runtime/wasm/effect.wat +++ b/runtime/wasm/effect.wat @@ -615,7 +615,7 @@ (struct.get $cps_fiber $cont (local.get $top))) (func $caml_resume_stack (export "caml_resume_stack") - (param $vstack (ref eq)) (param $k (ref eq)) (result (ref eq)) + (param $vstack (ref eq)) (param $last (ref eq)) (param $k (ref eq)) (result (ref eq)) (local $stack (ref $cps_fiber)) (drop (block $already_resumed (result (ref eq)) (local.set $stack @@ -645,7 +645,7 @@ (ref.i31 (i32.const 0))) (func (export "caml_perform_effect") - (param $eff (ref eq)) (param $vcont (ref eq)) (param $k0 (ref eq)) + (param $eff (ref eq)) (param $vcont (ref eq)) (param $last (ref eq)) (param $k0 (ref eq)) (result (ref eq)) (local $handlers (ref $handlers)) (local $handler (ref eq)) (local $k1 (ref eq)) @@ -728,6 +728,7 @@ (call $caml_resume_stack (array.get $block (ref.cast (ref $block) (local.get $k)) (i32.const 1)) + (ref.i31 (i32.const 0)) (local.get $ms))) (call $raise_unhandled (local.get $eff) (ref.i31 (i32.const 0))))