Skip to content

Commit 28d7029

Browse files
committed
OxCaml: Sys.with_async_exns
Add primitive caml_with_async_exns.
1 parent 1d6a06c commit 28d7029

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

compiler/bin-js_of_ocaml/js_of_ocaml.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ let () =
4343
| _ -> argv
4444
in
4545
try
46+
with_async_exns
47+
@@ fun () ->
4648
match
4749
Cmdliner.Cmd.eval_value
4850
~catch:false

compiler/bin-jsoo_minify/jsoo_minify.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ let main =
9292
Cmdliner.Cmd.v Cmd_arg.info t
9393

9494
let (_ : int) =
95-
try Cmdliner.Cmd.eval ~catch:false ~argv:Sys.argv main with
95+
try with_async_exns @@ fun () -> Cmdliner.Cmd.eval ~catch:false ~argv:Sys.argv main with
9696
| (Match_failure _ | Assert_failure _ | Not_found) as exc ->
9797
let backtrace = Printexc.get_backtrace () in
9898
Format.eprintf

compiler/bin-wasm_of_ocaml/wasm_of_ocaml.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ let () =
4141
| _ -> argv
4242
in
4343
try
44+
with_async_exns
45+
@@ fun () ->
4446
match
4547
Cmdliner.Cmd.eval_value
4648
~catch:false

compiler/lib/stdlib.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,7 @@ module Lexing = struct
12041204
Printf.sprintf "File \"%s\", line %d, characters %d-%d:\n" file line char1 char2
12051205
(* use [char1 + 1] and [char2 + 1] if *not* using Caml mode *)
12061206
end
1207+
1208+
let with_async_exns = Sys.with_async_exns [@@if oxcaml]
1209+
1210+
let with_async_exns f = f () [@@if not oxcaml]

runtime/js/stdlib.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,11 @@ function caml_is_printable(c) {
300300
function caml_maybe_print_stats(_unit) {
301301
return 0;
302302
}
303+
304+
//Provides: caml_with_async_exns
305+
//Requires: caml_callback
306+
//Version: >= 5.2, < 5.3
307+
//OxCaml
308+
function caml_with_async_exns(body_callback) {
309+
return caml_callback(body_callback, [0]);
310+
}

runtime/wasm/stdlib.wat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,7 @@
234234
(call $unwrap
235235
(call $caml_jsstring_of_string (local.get $msg)))))
236236
(call $exit (i32.const 2)))))
237+
238+
(func (export "caml_with_async_exns") (param $f (ref eq)) (result (ref eq))
239+
(return_call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0))))
237240
)

0 commit comments

Comments
 (0)