Skip to content

Commit c8ff2a6

Browse files
committed
Toplevel: fix example
1 parent d669a18 commit c8ff2a6

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

compiler/js_of_ocaml.ml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let f
104104
Filename.concat (Findlib.find_pkg_dir pkg) d'
105105
| None -> d)
106106
in
107-
let expunge =
107+
let exported_unit =
108108
match export_file with
109109
| None -> None
110110
| Some file ->
@@ -119,12 +119,7 @@ let f
119119
assert false
120120
with End_of_file -> ());
121121
close_in ic;
122-
Some
123-
(fun s ->
124-
try
125-
Hashtbl.find t s;
126-
`Keep
127-
with Not_found -> `Skip)
122+
Some (Hashtbl.fold (fun cmi () acc -> cmi :: acc) t [])
128123
in
129124
Linker.load_files runtime_files;
130125
let paths =
@@ -247,7 +242,7 @@ let f
247242
Parse_bytecode.from_exe
248243
~includes:paths
249244
~toplevel
250-
?expunge
245+
?exported_unit
251246
~dynlink
252247
~debug:need_debug
253248
ic

compiler/lib/parse_bytecode.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ let read_toc ic =
20392039
let from_exe
20402040
?(includes = [])
20412041
?(toplevel = false)
2042-
?(expunge = fun _ -> `Keep)
2042+
?exported_unit
20432043
?(dynlink = false)
20442044
?(debug = `No)
20452045
ic =
@@ -2068,9 +2068,9 @@ let from_exe
20682068
Hashtbl.find keeps s;
20692069
true
20702070
with Not_found -> (
2071-
match expunge s with
2072-
| `Keep -> true
2073-
| `Skip -> false)
2071+
match exported_unit with
2072+
| Some l -> List.mem s ~set:l
2073+
| None -> false)
20742074
in
20752075
let crcs = List.filter ~f:(fun (unit, _crc) -> keep unit) orig_crcs in
20762076
let symbols =
@@ -2193,6 +2193,14 @@ let from_exe
21932193
StringSet.empty
21942194
else StringSet.empty
21952195
in
2196+
let cmis =
2197+
match exported_unit with
2198+
| None -> cmis
2199+
| Some l ->
2200+
if toplevel && Config.Flag.include_cmis ()
2201+
then List.fold_left l ~init:cmis ~f:(fun acc s -> StringSet.add s acc)
2202+
else cmis
2203+
in
21962204
let code = prepend p body in
21972205
Code.invariant code;
21982206
{code; cmis; debug = debug_data}

compiler/lib/parse_bytecode.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type one =
4040
val from_exe :
4141
?includes:string list
4242
-> ?toplevel:bool
43-
-> ?expunge:(string -> [`Keep | `Skip])
43+
-> ?exported_unit:string list
4444
-> ?dynlink:bool
4545
-> ?debug:[`Full | `Names | `No]
4646
-> in_channel

toplevel/bin/jsoo_common.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,11 @@ let cmis files =
105105
List.fold_left files ~init:[] ~f:(fun fs file ->
106106
match kind file with
107107
| `Pkg pkg -> cmis_of_package pkg @ fs
108-
| `Cmi s -> read_cmi ~dir:"." s :: fs
108+
| `Cmi s -> (
109+
match String.split_char ~sep:':' s with
110+
| [s] -> read_cmi ~dir:"." s :: fs
111+
| [pkg; s] ->
112+
let dir = Findlib.package_directory pkg in
113+
read_cmi ~dir s :: fs
114+
| [] | _ :: _ :: _ :: _ -> assert false)
109115
| `Cma s -> cmis_of_cma ~dir:"." s @ fs)

toplevel/examples/lwt_toplevel/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@
5959
js_of_ocaml.deriving
6060
lwt bigarray
6161
tyxml.functor
62+
tyxml.functor:html_types.cmi
6263
react reactiveData
6364
js_of_ocaml js_of_ocaml-lwt
6465
js_of_ocaml-tyxml
6566
js_of_ocaml-toplevel
6667
dynlink
67-
;; FIX: html_types is missing
68-
;; html_types.cmi
6968
)))
7069

7170
(rule

toplevel/examples/lwt_toplevel/examples.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(** Overview *)
2+
23
let x = 10 + 10
34

45
let y = x * 3
@@ -14,6 +15,7 @@ let _ = Printf.printf "fact 20 = %f\n" (fact 20)
1415
let _ = "abc" < "def"
1516

1617
(** Mutually recursive function *)
18+
1719
let rec even n =
1820
match n with
1921
| 0 -> true
@@ -25,6 +27,7 @@ and odd n =
2527
| x -> even (x - 1)
2628

2729
(** Mutually recursive module *)
30+
2831
module rec Odd : sig
2932
val odd : int -> bool
3033
end = struct
@@ -91,22 +94,24 @@ let div_elt =
9194

9295
let _ = display div_elt
9396

94-
open Graphics_js
9597
(** Graphics: Draw *)
9698

99+
open Graphics_js
100+
97101
let () = loop [Mouse_motion] (function {mouse_x = x; mouse_y = y} -> fill_circle x y 5)
98102

99-
open Graphics_js
100103
(** Graphics: Draw chars*)
101104

105+
open Graphics_js
106+
102107
let () =
103108
loop [Mouse_motion; Key_pressed] (function {mouse_x = x; mouse_y = y; key} ->
104109
moveto x y;
105110
draw_char key)
106111

107-
open Js_of_ocaml_lwt
108112
(** Graphics: PingPong *)
109113

114+
open Js_of_ocaml_lwt
110115
open Graphics_js
111116

112117
let c = 3

0 commit comments

Comments
 (0)