diff --git a/compiler/lib-wasm/binaryen.ml b/compiler/lib-wasm/binaryen.ml index 8276444458..c5a7a5d355 100644 --- a/compiler/lib-wasm/binaryen.ml +++ b/compiler/lib-wasm/binaryen.ml @@ -131,6 +131,7 @@ let optimize in command ("wasm-opt" + :: "--emit-exnref" :: (common_options () @ Option.value ~default:optimization_options.(level - 1) options @ [ Filename.quote input_file; "-o"; Filename.quote output_file ]) diff --git a/compiler/lib-wasm/wasm_output.ml b/compiler/lib-wasm/wasm_output.ml index febd2c650e..2c85e5b6aa 100644 --- a/compiler/lib-wasm/wasm_output.ml +++ b/compiler/lib-wasm/wasm_output.ml @@ -648,15 +648,16 @@ end = struct output_byte ch 0x0B | Try (typ, l, catches) -> Feature.require exception_handling; - output_byte ch 0x06; + output_byte ch 0x1f; output_blocktype st.type_names ch typ; - List.iter ~f:(fun i' -> output_instruction st ch i') l; + output_uint ch (List.length catches); List.iter - ~f:(fun (tag, l, ty) -> - output_byte ch 0x07; + ~f:(fun (tag, l, _) -> + output_byte ch 0x00; output_uint ch (Hashtbl.find st.tag_names tag); - output_instruction st ch (Br (l + 1, Some (Pop ty)))) + output_uint ch l) catches; + List.iter ~f:(fun i' -> output_instruction st ch i') l; output_byte ch 0X0B and output_instruction st ch i = diff --git a/compiler/lib-wasm/wat_output.ml b/compiler/lib-wasm/wat_output.ml index 27c2307801..a3b02f11ae 100644 --- a/compiler/lib-wasm/wat_output.ml +++ b/compiler/lib-wasm/wat_output.ml @@ -445,17 +445,13 @@ let expression_or_instructions ctx st in_function = ] | Try (ty, body, catches) -> [ List - (Atom "try" + (Atom "try_table" :: (block_type st ty - @ List (Atom "do" :: instructions body) - :: List.map - ~f:(fun (tag, i, ty) -> - List - (Atom "catch" - :: index st.tag_names tag - :: (instruction (Wasm_ast.Event Code_generation.hidden_location) - @ instruction (Wasm_ast.Br (i + 1, Some (Pop ty)))))) - catches)) + @ List.map + ~f:(fun (tag, i, _ty) -> + List [ Atom "catch"; index st.tag_names tag; Atom (string_of_int i) ]) + catches + @ instructions body)) ] and instruction i = match i with diff --git a/runtime/wasm/fail.wat b/runtime/wasm/fail.wat index 04a6092a0e..f0de7224fd 100644 --- a/runtime/wasm/fail.wat +++ b/runtime/wasm/fail.wat @@ -74,7 +74,7 @@ (@string $index_out_of_bounds "index out of bounds") (func (export "caml_bound_error") - (return_call $caml_invalid_argument (global.get $index_out_of_bounds))) + (call $caml_invalid_argument (global.get $index_out_of_bounds))) (global $END_OF_FILE_EXN i32 (i32.const 4)) diff --git a/tools/node_wrapper.ml b/tools/node_wrapper.ml index 9d58203591..6fbc9cd904 100644 --- a/tools/node_wrapper.ml +++ b/tools/node_wrapper.ml @@ -1,6 +1,7 @@ let extra_args_for_wasoo = [ "--experimental-wasm-imported-strings" ; "--experimental-wasm-stack-switching" + ; "--experimental-wasm-exnref" ; "--stack-size=10000" ]