Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Dec 12, 2024
1 parent ac21078 commit 3f476bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 3 additions & 2 deletions runtime/js/effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions runtime/js/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions runtime/wasm/effect.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))))

Expand Down

0 comments on commit 3f476bc

Please sign in to comment.