Skip to content

Support ocaml 5.2 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/example.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Js_of_ocaml
open Js_top_worker_rpc
module W = Js_top_worker_client.W

let log s = Firebug.console##log (Js.string s)
let log s = Console.console##log (Js.string s)

let initialise s callback =
let ( let* ) = Lwt_result.bind in
Expand Down
6 changes: 3 additions & 3 deletions lib/uTop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ let parse_default parse str eos_is_error =
| Syntaxerr.Ill_formed_ast (loc, s) ->
Error ([mkloc loc],
Printf.sprintf "Error: broken invariant in parsetree: %s" s)
| Syntaxerr.Invalid_package_type (loc, s) ->
| Syntaxerr.Invalid_package_type (loc, _s) ->
Error ([mkloc loc],
Printf.sprintf "Invalid package type: %s" s)
Printf.sprintf "Invalid package type")
#if OCAML_VERSION >= (5, 0, 0)
| Syntaxerr.Removed_string_set loc ->
Error ([mkloc loc],
Expand Down Expand Up @@ -354,4 +354,4 @@ let set_load_path path =
Load_path.init path ~auto_include:Load_path.no_auto_include
#else
let set_load_path path = Load_path.init path
#endif
#endif
25 changes: 19 additions & 6 deletions lib/uTop_complete.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ let visible_modules () =
(Sys.readdir (if dir = "" then Filename.current_dir_name else dir))
with Sys_error _ ->
acc)
#if OCAML_VERSION >= (4, 08, 0)
#if OCAML_VERSION >= (5, 2, 0)
String_set.empty @@ Load_path.get_path_list ()
#elif OCAML_VERSION >= (4, 08, 0)
String_set.empty @@ Load_path.get_paths ()
#else
String_set.empty !Config.load_path
Expand All @@ -399,8 +401,11 @@ let add_fields_of_type decl acc =
acc
| Type_record (fields, _) ->
List.fold_left (fun acc field -> add (field_name field) acc) acc fields
| Type_abstract ->
acc
#if OCAML_VERSION >= (5, 2, 0)
| Type_abstract _ -> acc
#else
| Type_abstract -> acc
#endif
| Type_open ->
acc

Expand All @@ -414,7 +419,11 @@ let add_names_of_type decl acc =
List.fold_left (fun acc cstr -> add (constructor_name cstr) acc) acc constructors
| Type_record (fields, _) ->
List.fold_left (fun acc field -> add (field_name field) acc) acc fields
| Type_abstract ->
#if OCAML_VERSION >= (5, 2, 0)
| Type_abstract _ ->
#else
| Type_abstract ->
#endif
acc
| Type_open ->
acc
Expand Down Expand Up @@ -950,7 +959,9 @@ let complete ~phrase_terminator ~input =
(fun acc d -> add_files filter acc (Filename.concat d dir))
String_map.empty
(Filename.current_dir_name ::
#if OCAML_VERSION >= (4, 08, 0)
#if OCAML_VERSION >= (5, 2, 0)
(Load_path.get_path_list ())
#elif OCAML_VERSION >= (4, 08, 0)
(Load_path.get_paths ())
#else
!Config.load_path
Expand Down Expand Up @@ -985,7 +996,9 @@ let complete ~phrase_terminator ~input =
(fun acc d -> add_files filter acc (Filename.concat d dir))
String_map.empty
(Filename.current_dir_name ::
#if OCAML_VERSION >= (4, 08, 0)
#if OCAML_VERSION >= (5, 2, 0)
(Load_path.get_path_list ())
#elif OCAML_VERSION >= (4, 08, 0)
(Load_path.get_paths ())
#else
!Config.load_path
Expand Down
23 changes: 17 additions & 6 deletions lib/worker.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let optbind : 'a option -> ('a -> 'b option) -> 'b option = fun x fn -> match x

let log fmt =
Format.kasprintf
(fun s -> Js_of_ocaml.(Firebug.console##log (Js.string s)))
(fun s -> Js_of_ocaml.(Console.console##log (Js.string s)))
fmt

(* OCamlorg toplevel in a web worker
Expand Down Expand Up @@ -136,7 +136,7 @@ let sync_get url =
Js.Opt.case
(File.CoerceTo.arrayBuffer x##.response)
(fun () ->
Firebug.console##log (Js.string "Failed to receive file");
Console.console##log (Js.string "Failed to receive file");
None)
(fun b -> Some (Typed_array.String.of_arrayBuffer b))
| _ -> None
Expand Down Expand Up @@ -198,7 +198,11 @@ let init (init_libs : Toplevel_api_gen.init_libs) =
#endif
let old_loader = !load in
(load :=
#if OCAML_VERSION >= (5,2,0)
fun ~allow_hidden ~unit_name ->
#else
fun ~unit_name ->
#endif
let result =
optbind
(try Some (List.assoc (String.uncapitalize_ascii unit_name) cmi_files) with _ -> None)
Expand All @@ -211,15 +215,22 @@ let init (init_libs : Toplevel_api_gen.init_libs) =
filename =
Sys.executable_name;
cmi = read_cmi unit_name (Bytes.of_string x);
#if OCAML_VERSION >= (5,2,0)
visibility = Visible
#endif
}
#if OCAML_VERSION >= (5,2,0)
| _ -> old_loader ~allow_hidden ~unit_name);
#else
| _ -> old_loader ~unit_name);
#endif
Js_of_ocaml.Worker.import_scripts
(List.map (fun cma -> cma.Toplevel_api_gen.url) init_libs.cmas);
functions :=
Some
(List.map
(fun func_name ->
Firebug.console##log (Js.string ("Function: " ^ func_name));
Console.console##log (Js.string ("Function: " ^ func_name));
let func = Js.Unsafe.js_expr func_name in
fun () ->
Js.Unsafe.fun_call func [| Js.Unsafe.inject Dom_html.window |])
Expand Down Expand Up @@ -376,14 +387,14 @@ let run () =
let open Js_of_ocaml in
try
(Js_top_worker_rpc.Idl.logfn :=
fun s -> Js_of_ocaml.(Firebug.console##log s));
fun s -> Js_of_ocaml.(Console.console##log s));
Server.complete complete;
Server.exec execute;
Server.setup setup;
Server.init init;
Server.typecheck typecheck_phrase;
let rpc_fn = IdlM.server Server.implementation in
Js_of_ocaml.Worker.set_onmessage (server rpc_fn);
Firebug.console##log (Js.string "All finished")
Console.console##log (Js.string "All finished")
with e ->
Firebug.console##log (Js.string ("Exception: " ^ Printexc.to_string e))
Console.console##log (Js.string ("Exception: " ^ Printexc.to_string e))