diff --git a/compiler/lib/link_js.ml b/compiler/lib/link_js.ml index 63e8639d5..cdd4d610c 100644 --- a/compiler/lib/link_js.ml +++ b/compiler/lib/link_js.ml @@ -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 diff --git a/compiler/lib/parse_bytecode.ml b/compiler/lib/parse_bytecode.ml index 9ed5bf484..1caac8caf 100644 --- a/compiler/lib/parse_bytecode.ml +++ b/compiler/lib/parse_bytecode.ml @@ -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 *) diff --git a/compiler/lib/parse_bytecode.mli b/compiler/lib/parse_bytecode.mli index 5500e4f4a..244472cd4 100644 --- a/compiler/lib/parse_bytecode.mli +++ b/compiler/lib/parse_bytecode.mli @@ -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 diff --git a/compiler/tests-toplevel/dune b/compiler/tests-toplevel/dune index ba0474819..2e541eec6 100644 --- a/compiler/tests-toplevel/dune +++ b/compiler/tests-toplevel/dune @@ -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) @@ -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 @@ -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)))) diff --git a/compiler/tests-toplevel/test_toplevel.ml b/compiler/tests-toplevel/test_toplevel.ml index fde3c4579..e35a3ea90 100644 --- a/compiler/tests-toplevel/test_toplevel.ml +++ b/compiler/tests-toplevel/test_toplevel.ml @@ -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//"; diff --git a/compiler/tests-toplevel/test_toplevel.reference b/compiler/tests-toplevel/test_toplevel.reference index 3ab394a97..81e85b344 100644 --- a/compiler/tests-toplevel/test_toplevel.reference +++ b/compiler/tests-toplevel/test_toplevel.reference @@ -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