Skip to content

Commit

Permalink
CR: Create Js_of_ocaml.Effect_js
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Dec 29, 2024
1 parent 7161b7e commit 227f261
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/tests-ocaml/lib-effects/assume_no_perform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let () =

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t
let () =
try_with
(fun () ->
Jsoo_runtime.Effect.assume_no_perform (fun () ->
Js_of_ocaml.Effect_js.assume_no_perform (fun () ->
try_with
(fun () -> ())
()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t
let must_raise () =
try_with
(fun () ->
Jsoo_runtime.Effect.assume_no_perform (fun () ->
Js_of_ocaml.Effect_js.assume_no_perform (fun () ->
(* Should raise [Effect.Unhandled] despite the installed handler *)
perform Dummy
)
Expand Down
3 changes: 1 addition & 2 deletions lib/js_of_ocaml/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(library
(name js_of_ocaml)
(public_name js_of_ocaml)
(libraries
(re_export js_of_ocaml-compiler.runtime))
(libraries js_of_ocaml-compiler.runtime)
(foreign_stubs
(language c)
(names js_of_ocaml_stubs))
Expand Down
20 changes: 20 additions & 0 deletions lib/js_of_ocaml/effect_js.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2024 Olivier Nicole
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

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

(** Javascript-specific effect functions. *)

external assume_no_perform : (unit -> 'a) -> 'a = "caml_assume_no_perform"
(** Passing a function [f] as argument of `assume_no_perform` guarantees that,
when compiling with `--effects=double-translation`, the direct-style
version of [f] is called, which is faster than the CPS version. As a
consequence, performing an effect in a transitive callee of [f] will raise
`Effect.Unhandled`, regardless of any effect handlers installed before the
call to `assume_no_perform`, unless a new effect handler was installed in
the meantime.
This behaviour is the same when double translation is disabled. *)
1 change: 1 addition & 0 deletions lib/js_of_ocaml/js_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Dom = Dom
module Dom_events = Dom_events
module Dom_html = Dom_html
module Dom_svg = Dom_svg
module Effect_js = Effect_js
module EventSource = EventSource
module File = File
module Firebug = Firebug
Expand Down

0 comments on commit 227f261

Please sign in to comment.