Skip to content

Commit 227f261

Browse files
committed
CR: Create Js_of_ocaml.Effect_js
1 parent 7161b7e commit 227f261

File tree

7 files changed

+56
-5
lines changed

7 files changed

+56
-5
lines changed

compiler/tests-ocaml/lib-effects/assume_no_perform.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ let () =
136136

137137
(* The code below should be called in direct style despite the installed
138138
effect handler *)
139-
Jsoo_runtime.Effect.assume_no_perform (fun () ->
139+
Js_of_ocaml.Effect_js.assume_no_perform (fun () ->
140140
let m, sd = benchmark iter_fun 5 in
141141
let () = printf "Iter: mean = %f, sd = %f\n%!" m sd in
142142

compiler/tests-ocaml/lib-effects/assume_no_perform_nested_handler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t
77
let () =
88
try_with
99
(fun () ->
10-
Jsoo_runtime.Effect.assume_no_perform (fun () ->
10+
Js_of_ocaml.Effect_js.assume_no_perform (fun () ->
1111
try_with
1212
(fun () -> ())
1313
()

compiler/tests-ocaml/lib-effects/assume_no_perform_unhandled.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t
77
let must_raise () =
88
try_with
99
(fun () ->
10-
Jsoo_runtime.Effect.assume_no_perform (fun () ->
10+
Js_of_ocaml.Effect_js.assume_no_perform (fun () ->
1111
(* Should raise [Effect.Unhandled] despite the installed handler *)
1212
perform Dummy
1313
)

lib/js_of_ocaml/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
(library
22
(name js_of_ocaml)
33
(public_name js_of_ocaml)
4-
(libraries
5-
(re_export js_of_ocaml-compiler.runtime))
4+
(libraries js_of_ocaml-compiler.runtime)
65
(foreign_stubs
76
(language c)
87
(names js_of_ocaml_stubs))

lib/js_of_ocaml/effect_js.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(* Js_of_ocaml library
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2024 Olivier Nicole
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
external assume_no_perform : (unit -> 'a) -> 'a = "caml_assume_no_perform"

lib/js_of_ocaml/effect_js.mli

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(* Js_of_ocaml library
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2024 Olivier Nicole
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
(** Javascript-specific effect functions. *)
21+
22+
external assume_no_perform : (unit -> 'a) -> 'a = "caml_assume_no_perform"
23+
(** Passing a function [f] as argument of `assume_no_perform` guarantees that,
24+
when compiling with `--effects=double-translation`, the direct-style
25+
version of [f] is called, which is faster than the CPS version. As a
26+
consequence, performing an effect in a transitive callee of [f] will raise
27+
`Effect.Unhandled`, regardless of any effect handlers installed before the
28+
call to `assume_no_perform`, unless a new effect handler was installed in
29+
the meantime.
30+
31+
This behaviour is the same when double translation is disabled. *)

lib/js_of_ocaml/js_of_ocaml.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Dom = Dom
2222
module Dom_events = Dom_events
2323
module Dom_html = Dom_html
2424
module Dom_svg = Dom_svg
25+
module Effect_js = Effect_js
2526
module EventSource = EventSource
2627
module File = File
2728
module Firebug = Firebug

0 commit comments

Comments
 (0)