Skip to content

Commit

Permalink
Compiler: fix toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo authored and OlivierNicole committed Sep 9, 2024
1 parent 6e90b4e commit 929eed2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions compiler/lib/link_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
| Some bi ->
Build_info.configure bi;
let primitives =
List.fold_left units ~init:[] ~f:(fun acc (u : Unit_info.t) ->
acc @ u.primitives)
List.fold_left units ~init:StringSet.empty ~f:(fun acc (u : Unit_info.t) ->
StringSet.union acc (StringSet.of_list u.primitives))
in
let code =
Parse_bytecode.link_info
Expand Down
4 changes: 4 additions & 0 deletions compiler/lib/parse_bytecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,10 @@ let link_info ~target ~symtable ~primitives ~crcs =
[]
|> Array.of_list
in
let primitives =
(* Add the externals translated by jsoo directly (in generate.ml) *)
StringSet.union (Primitive.get_external ()) primitives |> StringSet.elements
in
let body = [] in
let body =
(* Include linking information *)
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/parse_bytecode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ val predefined_exceptions : target:[ `JavaScript | `Wasm ] -> Code.program * Uni
val link_info :
target:[ `JavaScript | `Wasm ]
-> symtable:Ocaml_compiler.Symtable.GlobalMap.t
-> primitives:string list
-> primitives:StringSet.t
-> crcs:(string * Digest.t option) list
-> Code.program
21 changes: 19 additions & 2 deletions compiler/tests-toplevel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
(libraries js_of_ocaml-compiler.dynlink compiler-libs.toplevel)
(flags
(:standard -linkall))
(modes byte))
(js_of_ocaml
(flags :standard --toplevel))
(modes byte js))

(rule
(targets test_toplevel.js)
Expand All @@ -31,6 +33,19 @@
%{target}
(run node ./test_toplevel.js))))

(rule
(target test_toplevel.referencebcjs)
(deps test_toplevel.bc.js)
(enabled_if
(and
(<> %{profile} wasm)
(<> %{profile} wasm-effects)
(>= %{ocaml_version} 5.2)))
(action
(with-stdout-to
%{target}
(run node ./test_toplevel.bc.js))))

(rule
(alias runtest)
(enabled_if
Expand All @@ -40,4 +55,6 @@
(>= %{ocaml_version} 5.2)))
(deps test_toplevel.reference test_toplevel.referencejs)
(action
(diff test_toplevel.reference test_toplevel.referencejs)))
(progn
(diff test_toplevel.reference test_toplevel.referencebcjs)
(diff test_toplevel.reference test_toplevel.referencejs))))
8 changes: 6 additions & 2 deletions compiler/tests-toplevel/test_toplevel.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
let () =
let content = {|
let content =
{|
let () = print_endline "hello";;
1+1;;
1+;;
Missing_module.f;;
|} in
let y = float 1 /. float 3;;
|}
in
Topdirs.dir_directory "/static/cmis";
Toploop.initialize_toplevel_env ();
Toploop.input_name := "//toplevel//";
Expand Down
8 changes: 5 additions & 3 deletions compiler/tests-toplevel/test_toplevel.reference
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
hello
Line 3, characters 2-4:
- : int = 2
Line 4, characters 2-4:
Error: Syntax error
Line 4, characters 0-16:
Error: Unbound module Missing_module
Line 5, characters 0-16:
Error: Unbound module "Missing_module"
val y : float = 0.333333333333333315

0 comments on commit 929eed2

Please sign in to comment.