diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68a404e678..461bb5691c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,11 +17,6 @@ jobs: os: - ubuntu-latest ocaml-compiler: - - "4.08" - - "4.09" - - "4.10" - - "4.11" - - "4.12" - "4.13" - "5.0" - "5.1" diff --git a/CHANGES.md b/CHANGES.md index 755cfcfa3d..92af6ef0bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ # dev ## Features/Changes +* Misc: drop support for OCaml 4.12 and bellow * Compiler: use a Wasm text files preprocessor (#1822) * Compiler: support for OCaml 4.14.3+trunk (#1844) * Runtime: use es6 class (#1840) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 971cc9f30b..59afb8fbe3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,8 +28,4 @@ opam install odoc lwt_log yojson ocp-indent graphics higlo ### Running the tests -Tests are maintained for a single version of the OCaml compiler (currently 4.13). - -Make sure to use the correct opam switch (e.g. `opam switch 4.13.1`). - Run `make tests`. diff --git a/compiler/bin-js_of_ocaml/check_runtime.ml b/compiler/bin-js_of_ocaml/check_runtime.ml index e5d6fa4447..0f688963ce 100644 --- a/compiler/bin-js_of_ocaml/check_runtime.ml +++ b/compiler/bin-js_of_ocaml/check_runtime.ml @@ -22,7 +22,7 @@ open Js_of_ocaml_compiler let group_by_snd l = l - |> List.sort_uniq ~compare:(fun (n1, l1) (n2, l2) -> + |> List.sort_uniq ~cmp:(fun (n1, l1) (n2, l2) -> match Poly.compare l1 l2 with | 0 -> String.compare n1 n2 | c -> c) @@ -49,8 +49,8 @@ let f (runtime_files, bytecode, target_env) = let runtime_files, builtin = List.partition_map runtime_files ~f:(fun name -> match Builtins.find name with - | Some t -> `Snd t - | None -> `Fst name) + | Some t -> Right t + | None -> Left name) in let builtin = if false then builtin else Js_of_ocaml_compiler_runtime_files.runtime @ builtin diff --git a/compiler/bin-js_of_ocaml/compile.ml b/compiler/bin-js_of_ocaml/compile.ml index 6c19facb9b..53e82f7a97 100644 --- a/compiler/bin-js_of_ocaml/compile.ml +++ b/compiler/bin-js_of_ocaml/compile.ml @@ -102,7 +102,8 @@ let sourcemap_section_of_info | Some _ -> Filename.concat "/builtin" filename) in let ignore_list = - List.filter sources ~f:(fun filename -> String.is_prefix ~prefix:"/builtin/" filename) + List.filter sources ~f:(fun filename -> + String.starts_with ~prefix:"/builtin/" filename) in let offset, mappings = Source_map.Mappings.encode_with_offset mappings in let map = @@ -207,8 +208,8 @@ let run let runtime_files, builtin = List.partition_map runtime_files ~f:(fun name -> match Builtins.find name with - | Some t -> `Snd t - | None -> `Fst name) + | Some t -> Right t + | None -> Left name) in let t1 = Timer.make () in let builtin = diff --git a/compiler/bin-wasm_of_ocaml/compile.ml b/compiler/bin-wasm_of_ocaml/compile.ml index cd91ca450a..c86546a4b8 100644 --- a/compiler/bin-wasm_of_ocaml/compile.ml +++ b/compiler/bin-wasm_of_ocaml/compile.ml @@ -313,8 +313,8 @@ let run let runtime_js_files, builtin = List.partition_map runtime_js_files ~f:(fun name -> match Builtins.find name with - | Some t -> `Snd t - | None -> `Fst name) + | Some t -> Right t + | None -> Left name) in let t1 = Timer.make () in let builtin = Js_of_ocaml_compiler_runtime_files.runtime @ builtin in diff --git a/compiler/lib-runtime-files/gen/gen.ml b/compiler/lib-runtime-files/gen/gen.ml index 147f2453e6..a13ad8d38f 100644 --- a/compiler/lib-runtime-files/gen/gen.ml +++ b/compiler/lib-runtime-files/gen/gen.ml @@ -58,7 +58,7 @@ let () = match Array.to_list Sys.argv with | [] -> assert false | _ :: rest -> - let rest = List.sort_uniq ~compare:String.compare rest in + let rest = List.sort_uniq ~cmp:String.compare rest in let fragments = List.map rest ~f:(fun f -> f, Js_of_ocaml_compiler.Linker.Fragment.parse_file f) in diff --git a/compiler/lib-runtime-files/js_of_ocaml_compiler_runtime_files.ml b/compiler/lib-runtime-files/js_of_ocaml_compiler_runtime_files.ml index 22ebd08bbf..41466846a2 100644 --- a/compiler/lib-runtime-files/js_of_ocaml_compiler_runtime_files.ml +++ b/compiler/lib-runtime-files/js_of_ocaml_compiler_runtime_files.ml @@ -34,7 +34,6 @@ let runtime = ; hash ; ieee_754 ; int64 - ; internalMod ; ints ; io ; jslib diff --git a/compiler/lib-runtime-files/tests/all.ml b/compiler/lib-runtime-files/tests/all.ml index bd76636f7d..0896252226 100644 --- a/compiler/lib-runtime-files/tests/all.ml +++ b/compiler/lib-runtime-files/tests/all.ml @@ -30,7 +30,6 @@ let%expect_test _ = +hash.js +ieee_754.js +int64.js - +internalMod.js +ints.js +io.js +jslib.js @@ -51,7 +50,8 @@ let%expect_test _ = +toplevel.js +unix.js +weak.js - +zstd.js |}]; + +zstd.js + |}]; printl runtime; [%expect {| @@ -73,7 +73,6 @@ let%expect_test _ = +hash.js +ieee_754.js +int64.js - +internalMod.js +ints.js +io.js +jslib.js @@ -93,7 +92,8 @@ let%expect_test _ = +sys.js +unix.js +weak.js - +zstd.js |}]; + +zstd.js + |}]; printl extra; [%expect {| +dynlink.js diff --git a/compiler/lib/build_path_prefix_map.ml b/compiler/lib/build_path_prefix_map.ml index 75af3b2000..7fb9a469f4 100644 --- a/compiler/lib/build_path_prefix_map.ml +++ b/compiler/lib/build_path_prefix_map.ml @@ -100,7 +100,7 @@ let decode_map str = | Ok str -> Some str | Error err -> raise (Shortcut err)) in - let pairs = String.split_char ~sep:':' str in + let pairs = String.split_on_char ~sep:':' str in match List.map ~f:decode_or_empty pairs with | exception Shortcut err -> Error err | map -> Ok map @@ -108,7 +108,7 @@ let decode_map str = let rewrite_opt prefix_map path = let is_prefix = function | None -> false - | Some { target = _; source } -> String.is_prefix path ~prefix:source + | Some { target = _; source } -> String.starts_with path ~prefix:source in match List.find diff --git a/compiler/lib/generate.ml b/compiler/lib/generate.ml index 0ebfe8d891..85bf9137d5 100644 --- a/compiler/lib/generate.ml +++ b/compiler/lib/generate.ml @@ -1464,7 +1464,7 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t match internal_prim name with | Some f -> f l ctx loc | None -> - if String.is_prefix name ~prefix:"%" + if String.starts_with name ~prefix:"%" then failwith (Printf.sprintf "Unresolved internal primitive: %s" name); let prim = Share.get_prim (runtime_fun ctx) name ctx.Ctx.share in let* () = info ~need_loc:true (kind (Primitive.kind name)) in @@ -1522,7 +1522,7 @@ and translate_instr ctx expr_queue loc instr = (* "switcher" is emitted by the OCaml compiler when compiling pattern matching, it does not help much to keep it in the generated js, let's drop it *) - (not (generated_name s)) && not (String.is_prefix s ~prefix:"jsoo_") + (not (generated_name s)) && not (String.starts_with s ~prefix:"jsoo_") in match ctx.Ctx.live.(Var.idx x), e with | 0, _ -> diff --git a/compiler/lib/javascript.ml b/compiler/lib/javascript.ml index 998341bf72..88d52dca25 100644 --- a/compiler/lib/javascript.ml +++ b/compiler/lib/javascript.ml @@ -56,7 +56,7 @@ end = struct let to_targetint s = if - String.is_prefix s ~prefix:"0" + String.starts_with s ~prefix:"0" && String.length s > 1 && String.for_all s ~f:(function | '0' .. '7' -> true diff --git a/compiler/lib/js_output.ml b/compiler/lib/js_output.ml index f2cf8c79ed..f547dc62d2 100644 --- a/compiler/lib/js_output.ml +++ b/compiler/lib/js_output.ml @@ -542,7 +542,8 @@ struct for i = 0 to l - 1 do let c = s.[i] in match c with - | '\000' when i = l - 1 || not (Char.is_num s.[i + 1]) -> Buffer.add_string b "\\0" + | '\000' when i = l - 1 || not (Char.is_digit s.[i + 1]) -> + Buffer.add_string b "\\0" | '\b' (* 008 *) -> Buffer.add_string b "\\b" | '\t' (* 009 *) -> Buffer.add_string b "\\t" | '\n' (* 010 *) -> Buffer.add_string b "\\n" diff --git a/compiler/lib/link_js.ml b/compiler/lib/link_js.ml index 71bd724a50..a95c83136f 100644 --- a/compiler/lib/link_js.ml +++ b/compiler/lib/link_js.ml @@ -130,10 +130,10 @@ type action = | Source_map of Source_map.t let prefix_kind line = - match String.is_prefix ~prefix:info_prefix line with + match String.starts_with ~prefix:info_prefix line with | false -> `Other | true -> ( - match String.is_prefix ~prefix:sourceMappingURL line with + match String.starts_with ~prefix:sourceMappingURL line with | false -> ( match Build_info.parse line with | Some bi -> `Build_info bi @@ -142,7 +142,7 @@ let prefix_kind line = | Some _ -> `Unit | None -> `Other)) | true -> ( - match String.is_prefix ~prefix:sourceMappingURL_base64 line with + match String.starts_with ~prefix:sourceMappingURL_base64 line with | true -> `Json_base64 (String.length sourceMappingURL_base64) | false -> `Url (String.length sourceMappingURL))) diff --git a/compiler/lib/linker.ml b/compiler/lib/linker.ml index f3ce13b689..a94b29e969 100644 --- a/compiler/lib/linker.ml +++ b/compiler/lib/linker.ml @@ -101,7 +101,7 @@ module Check = struct (fun x acc -> match x with | S { name = Utf8_string.Utf8 s; _ } -> - if String.is_prefix s ~prefix:"_" || String.equal s name + if String.starts_with s ~prefix:"_" || String.equal s name then acc else s :: acc | V _ -> acc) diff --git a/compiler/lib/magic_number.ml b/compiler/lib/magic_number.ml index e476410004..a5e11d1f76 100644 --- a/compiler/lib/magic_number.ml +++ b/compiler/lib/magic_number.ml @@ -67,11 +67,6 @@ let equal a b = compare a b = 0 let v = let current = Ocaml_version.current in match current with - | 4 :: 08 :: _ -> 25 - | 4 :: 09 :: _ -> 26 - | 4 :: 10 :: _ -> 27 - | 4 :: 11 :: _ -> 28 - | 4 :: 12 :: _ -> 29 | 4 :: 13 :: _ -> 30 | 4 :: 14 :: _ -> 31 | 5 :: 00 :: _ -> 32 @@ -79,8 +74,8 @@ let v = | 5 :: 02 :: _ -> 34 | 5 :: 03 :: _ -> 35 | _ -> - if Ocaml_version.compare current [ 4; 8 ] < 0 - then failwith "OCaml version unsupported. Upgrade to OCaml 4.08 or newer." + if Ocaml_version.compare current [ 4; 13 ] < 0 + then failwith "OCaml version unsupported. Upgrade to OCaml 4.13 or newer." else ( assert (Ocaml_version.compare current [ 5; 4 ] >= 0); failwith "OCaml version unsupported. Upgrade js_of_ocaml.") diff --git a/compiler/lib/ocaml_compiler.ml b/compiler/lib/ocaml_compiler.ml index f8cd33453e..135bef8fd1 100644 --- a/compiler/lib/ocaml_compiler.ml +++ b/compiler/lib/ocaml_compiler.ml @@ -24,8 +24,7 @@ let rec constant_of_const c : Code.constant = match c with | Const_base (Const_int i) -> Int (Targetint.of_int_warning_on_overflow i) | Const_base (Const_char c) -> Int (Targetint.of_int_exn (Char.code c)) - | ((Const_base (Const_string (s, _))) [@if ocaml_version < (4, 11, 0)]) - | ((Const_base (Const_string (s, _, _))) [@if ocaml_version >= (4, 11, 0)]) -> String s + | Const_base (Const_string (s, _, _)) -> String s | Const_base (Const_float s) -> Float (float_of_string s) | Const_base (Const_int32 i) -> ( match Config.target () with @@ -40,8 +39,6 @@ let rec constant_of_const c : Code.constant = | Const_float_array sl -> let l = List.map ~f:(fun f -> float_of_string f) sl in Float_array (Array.of_list l) - | ((Const_pointer i) [@if ocaml_version < (4, 12, 0)]) -> - Int (Targetint.of_int_warning_on_overflow i) | Const_block (tag, l) -> let l = Array.of_list (List.map l ~f:constant_of_const) in Tuple (tag, l, Unknown) diff --git a/compiler/lib/parse_bytecode.ml b/compiler/lib/parse_bytecode.ml index edb9cd7cc1..ce62238525 100644 --- a/compiler/lib/parse_bytecode.ml +++ b/compiler/lib/parse_bytecode.ml @@ -33,8 +33,6 @@ type bytecode = string let predefined_exceptions = Runtimedef.builtin_exceptions |> Array.to_list |> List.mapi ~f:(fun i name -> i, name) -let new_closure_repr = Ocaml_version.compare Ocaml_version.current [ 4; 12 ] >= 0 - (* Read and manipulate debug section *) module Debug : sig type t @@ -249,10 +247,7 @@ end = struct let { event; _ } = Int_table.find events_by_pc pc in let env = event.ev_compenv in let names = - Ident.fold_name - (fun ident i acc -> ((if new_closure_repr then i / 3 else i / 2), ident) :: acc) - env.ce_rec - [] + Ident.fold_name (fun ident i acc -> (i / 3, ident) :: acc) env.ce_rec [] in List.sort names ~cmp:(fun (i, _) (j, _) -> compare i j) with Not_found -> [] @@ -498,7 +493,6 @@ type globals = ; mutable is_const : bool array ; mutable is_exported : bool array ; mutable named_value : string option array - ; mutable override : (Var.t -> Code.instr list -> Var.t * Code.instr list) option array ; constants : Code.constant array ; primitives : string array } @@ -508,7 +502,6 @@ let make_globals size constants primitives = ; is_const = Array.make size false ; is_exported = Array.make size false ; named_value = Array.make size None - ; override = Array.make size None ; constants ; primitives } @@ -522,8 +515,7 @@ let resize_globals g size = g.vars <- resize_array g.vars size None; g.is_const <- resize_array g.is_const size false; g.is_exported <- resize_array g.is_exported size true; - g.named_value <- resize_array g.named_value size None; - g.override <- resize_array g.override size None + g.named_value <- resize_array g.named_value size None (* State of the VM *) module State = struct @@ -788,7 +780,7 @@ let compiled_blocks : (_ * instr list * last) Addr.Map.t ref = ref Addr.Map.empt let method_cache_id = ref 1 -let clo_offset_3 = if new_closure_repr then 3 else 2 +let clo_offset_3 = 3 type compile_info = { blocks : Blocks.t @@ -1194,7 +1186,7 @@ and compile infos pc state (instrs : instr list) = let env = let code = State.Dummy "closure(code)" in let closure_info = State.Dummy "closure(info)" in - if new_closure_repr then code :: closure_info :: env else code :: env + code :: closure_info :: env in let env = Array.of_list env in if debug_parser () then Format.printf "fun %a (" Var.print x; @@ -1241,9 +1233,7 @@ and compile infos pc state (instrs : instr list) = List.iter !vars ~f:(fun (i, x) -> let code = State.Var x in let closure_info = State.Dummy "closurerec(info)" in - if new_closure_repr - then env := code :: closure_info :: !env - else env := code :: !env; + env := code :: closure_info :: !env; if i > 0 then let infix_tag = State.Dummy "closurerec(infix_tag)" in @@ -1325,16 +1315,7 @@ and compile infos pc state (instrs : instr list) = assert (Option.is_none g.vars.(i)); if debug_parser () then Format.printf "(global %d) = %a@." i Var.print y; - let instrs = - match g.override.(i) with - | Some f -> - let v, instrs = f y instrs in - g.vars.(i) <- Some v; - instrs - | None -> - g.vars.(i) <- Some y; - instrs - in + g.vars.(i) <- Some y; let x, state = State.fresh_var state in if debug_parser () then Format.printf "%a = 0@." Var.print x; let instrs = register_global g i instrs in @@ -2477,26 +2458,6 @@ let parse_bytecode code globals debug_data = tagged_blocks := Addr.Map.empty; p -(* HACK - override module *) - -let override_global = - match Ocaml_version.compare Ocaml_version.current [ 4; 13 ] >= 0 with - | true -> [] - | false -> - [ ( "CamlinternalMod" - , fun _orig instrs -> - let x = Var.fresh_n "internalMod" in - let init_mod = Var.fresh_n "init_mod" in - let update_mod = Var.fresh_n "update_mod" in - ( x - , Let (x, Block (0, [| init_mod; update_mod |], NotArray, Immutable)) - :: Let (init_mod, Special (Alias_prim "caml_CamlinternalMod_init_mod")) - :: Let (update_mod, Special (Alias_prim "caml_CamlinternalMod_update_mod")) - :: instrs ) ) - ] - -(* HACK END *) - module Toc : sig type t @@ -2569,7 +2530,7 @@ end let read_primitives toc ic = let prim = Toc.read_prim toc ic in assert (Char.equal (String.get prim (String.length prim - 1)) '\000'); - String.split_char ~sep:'\000' (String.sub prim ~pos:0 ~len:(String.length prim - 1)) + String.split_on_char ~sep:'\000' (String.sub prim ~pos:0 ~len:(String.length prim - 1)) type bytesections = { symb : Ocaml_compiler.Symtable.GlobalMap.t @@ -2634,14 +2595,6 @@ let from_exe if times () then Format.eprintf " read debug events: %a@." Timer.print t; let globals = make_globals (Array.length init_data) init_data primitive_table in - (* Initialize module override mechanism *) - List.iter override_global ~f:(fun (name, v) -> - try - let nn = Ocaml_compiler.Symtable.Global.Glob_compunit name in - let i = Ocaml_compiler.Symtable.GlobalMap.find nn orig_symbols in - globals.override.(i) <- Some v; - if debug_parser () then Format.eprintf "overriding global %s@." name - with Not_found -> ()); if linkall then (* export globals *) @@ -2900,13 +2853,6 @@ module Reloc = struct let globals = make_globals (Array.length constants) constants primitives in resize_globals globals t.pos; Hashtbl.iter (fun name i -> globals.named_value.(i) <- Some name) t.names; - (* Initialize module override mechanism *) - List.iter override_global ~f:(fun (name, v) -> - try - let i = Hashtbl.find t.names name in - globals.override.(i) <- Some v; - if debug_parser () then Format.eprintf "overriding global %s@." name - with Not_found -> ()); globals end diff --git a/compiler/lib/pseudo_fs.ml b/compiler/lib/pseudo_fs.ml index b5e4a453e3..f45b0e68d4 100644 --- a/compiler/lib/pseudo_fs.ml +++ b/compiler/lib/pseudo_fs.ml @@ -61,7 +61,7 @@ let list_files name paths = in let name, exts (* extensions filter *) = match String.lsplit2 name ~on:'=' with - | Some (name, exts) -> name, String.split_char ~sep:',' exts + | Some (name, exts) -> name, String.split_on_char ~sep:',' exts | None -> name, [] in let file = diff --git a/compiler/lib/stdlib.ml b/compiler/lib/stdlib.ml index e528cc8e3f..2906321bd2 100644 --- a/compiler/lib/stdlib.ml +++ b/compiler/lib/stdlib.ml @@ -30,6 +30,8 @@ end = struct let open_out = open_out end +include Deprecated + module Poly = struct external ( < ) : 'a -> 'a -> bool = "%lessthan" @@ -99,31 +101,9 @@ let failwith_ fmt = let raise_ exn = if !fail then raise exn else Format.eprintf "%s@." (Printexc.to_string exn) -let int_num_bits = Sys.int_size - module List = struct include ListLabels - let rec equal ~eq a b = - match a, b with - | [], [] -> true - | x :: xs, y :: ys -> eq x y && equal ~eq xs ys - | [], _ :: _ | _ :: _, [] -> false - - let rec find_map ~f = function - | [] -> None - | x :: l -> ( - match f x with - | Some _ as result -> result - | None -> find_map ~f l) - - let rec find_map_value ~f ~default = function - | [] -> default - | x :: l -> ( - match f x with - | Some result -> result - | None -> find_map_value ~f ~default l) - let rec rev_append_map ~f l acc = match l with | [] -> acc @@ -196,34 +176,12 @@ module List = struct | [ x ] -> Some x | _ :: xs -> last xs - let sort_uniq ~compare l = - let l = List.sort compare l in - match l with - | ([] | [ _ ]) as l -> l - | x :: xs -> - let rec loop prev = function - | [] -> [ prev ] - | x :: rest when compare x prev = 0 -> loop prev rest - | x :: rest -> prev :: loop x rest - in - loop x xs - let is_empty = function | [] -> true | _ -> false + [@@if ocaml_version < (5, 1, 0)] - let partition_map t ~f = - let rec loop t fst snd = - match t with - | [] -> rev fst, rev snd - | x :: t -> ( - match f x with - | `Fst y -> loop t (y :: fst) snd - | `Snd y -> loop t fst (y :: snd)) - in - loop t [] [] - - let tail_append l1 l2 = rev_append (rev l1) l2 + let tail_append l1 l2 = rev_append (rev l1) l2 [@@if ocaml_version < (5, 1, 0)] let rec count_append l1 l2 count = match l2 with @@ -245,8 +203,9 @@ module List = struct (if count > max_non_tailcall then tail_append tl l2 else count_append tl l2 (count + 1))) + [@@if ocaml_version < (5, 1, 0)] - let append l1 l2 = count_append l1 l2 0 + let append l1 l2 = count_append l1 l2 0 [@@if ocaml_version < (5, 1, 0)] let group l ~f = let rec loop (l : 'a list) (this_group : 'a list) (acc : 'a list list) : 'a list list @@ -263,15 +222,6 @@ module List = struct | [] -> [] | x :: xs -> loop xs [ x ] [] - let concat_map ~f l = - let rec aux f acc = function - | [] -> rev acc - | x :: l -> - let xs = f x in - aux f (rev_append xs acc) l - in - aux f [] l - let split_last xs = let rec aux acc = function | [] -> None @@ -303,12 +253,6 @@ end let ( @ ) = List.append -module Nativeint = struct - include Nativeint - - external equal : nativeint -> nativeint -> bool = "%equal" -end - module Int32 = struct include Int32 @@ -324,10 +268,6 @@ module Int32 = struct external ( >= ) : int32 -> int32 -> bool = "%greaterequal" - external compare : int32 -> int32 -> int = "%compare" - - external equal : int32 -> int32 -> bool = "%equal" - let warn_overflow name ~to_dec ~to_hex i i32 = warn "Warning: integer overflow: %s 0x%s (%s) truncated to 0x%lx (%ld); the generated \ @@ -356,15 +296,13 @@ module Int32 = struct end module Option = struct + include Option + let map ~f x = match x with | None -> None | Some v -> Some (f v) - let to_list = function - | None -> [] - | Some x -> [ x ] - let bind ~f x = match x with | None -> None @@ -380,40 +318,13 @@ module Option = struct | None -> None | Some v -> if f v then Some v else None - let compare compare_elt a b = - match a, b with - | None, None -> 0 - | None, Some _ -> -1 - | Some _, None -> 1 - | Some a, Some b -> compare_elt a b - - let equal equal_elt a b = - match a, b with - | None, None -> true - | Some a, Some b -> equal_elt a b - | Some _, None | None, Some _ -> false - - let is_none = function - | None -> true - | Some _ -> false - - let is_some = function - | None -> false - | Some _ -> true - let value ~default = function | None -> default | Some s -> s end -module Int64 = struct - include Int64 - - let equal (a : int64) (b : int64) = Poly.(a = b) -end - module Float = struct - type t = float + include Float let equal (_ : float) (_ : float) = `Use_ieee_equal_or_bitwise_equal @@ -422,9 +333,6 @@ module Float = struct let bitwise_equal (a : float) (b : float) = Int64.equal (Int64.bits_of_float a) (Int64.bits_of_float b) - (* Re-defined here to stay compatible with OCaml 4.02 *) - external classify_float : float -> fpclass = "caml_classify_float" - external ( < ) : t -> t -> bool = "%lessthan" external ( <= ) : t -> t -> bool = "%lessequal" @@ -439,13 +347,13 @@ module Float = struct end module Bool = struct + include Bool + external ( <> ) : bool -> bool -> bool = "%notequal" external ( = ) : bool -> bool -> bool = "%equal" external ( > ) : bool -> bool -> bool = "%greaterthan" - - external equal : bool -> bool -> bool = "%equal" end module Char = struct @@ -463,27 +371,13 @@ module Char = struct external ( >= ) : char -> char -> bool = "%greaterequal" - external compare : char -> char -> int = "%compare" - - external equal : char -> char -> bool = "%equal" - - let is_alpha = function + let is_letter = function | 'a' .. 'z' | 'A' .. 'Z' -> true | _ -> false - let is_num = function + let is_digit = function | '0' .. '9' -> true | _ -> false - - let lowercase_ascii c = - match c with - | 'A' .. 'Z' as c -> Char.unsafe_chr (Char.code c + 32) - | _ -> c - - let uppercase_ascii c = - match c with - | 'a' .. 'z' as c -> Char.unsafe_chr (Char.code c - 32) - | _ -> c end module Uchar = struct @@ -585,73 +479,17 @@ module Buffer = struct Buffer.add_char b (Array.unsafe_get array_conv (c land 0xf)) end -module Bytes = struct - include BytesLabels - - let sub_string b ~pos:ofs ~len = unsafe_to_string (Bytes.sub b ofs len) - - let fold_left ~f ~init b = - let r = ref init in - for i = 0 to length b - 1 do - r := f !r (unsafe_get b i) - done; - !r - - let fold_right ~f b ~init = - let r = ref init in - for i = length b - 1 downto 0 do - r := f (unsafe_get b i) !r - done; - !r -end +module Bytes = BytesLabels module String = struct include StringLabels - let equal (a : string) (b : string) = Poly.(a = b) - let hash (a : string) = Hashtbl.hash a let is_empty = function | "" -> true | _ -> false - let is_prefix ~prefix s = - let len_a = length prefix in - let len_s = length s in - if len_a > len_s - then false - else - let max_idx_a = len_a - 1 in - let rec loop i = - if i > max_idx_a - then true - else if not (Char.equal (unsafe_get prefix i) (unsafe_get s i)) - then false - else loop (i + 1) - in - loop 0 - - let is_suffix ~suffix s = - let len_a = length suffix in - let len_s = length s in - if len_a > len_s - then false - else - let max_idx_a = len_a - 1 in - let rec loop i = - if i > max_idx_a - then true - else if - not - (Char.equal - (unsafe_get suffix (len_a - 1 - i)) - (unsafe_get s (len_s - 1 - i))) - then false - else loop (i + 1) - in - loop 0 - let drop_prefix ~prefix s = let plen = String.length prefix in if plen > String.length s @@ -664,16 +502,6 @@ module String = struct Some (String.sub s plen (String.length s - plen)) with Exit -> None - let for_all = - let rec loop s ~f ~last i = - if i > last - then true - else if f (String.unsafe_get s i) - then loop s ~f ~last (i + 1) - else false - in - fun s ~f -> loop s ~f ~last:(String.length s - 1) 0 - let is_ascii s = let res = ref true in for i = 0 to String.length s - 1 do @@ -690,69 +518,6 @@ module String = struct done; !res - let split_char ~sep p = String.split_on_char sep p - - (* copied from https://github.com/ocaml/ocaml/pull/10 *) - let split ~sep s = - let sep_len = String.length sep in - if sep_len = 1 - then split_char ~sep:sep.[0] s - else - let sep_max = sep_len - 1 in - if sep_max < 0 - then invalid_arg "String.split: empty separator" - else - let s_max = String.length s - 1 in - if s_max < 0 - then [ "" ] - else - let acc = ref [] in - let sub_start = ref 0 in - let k = ref 0 in - let i = ref 0 in - (* We build the substrings by running from the start of [s] to the - end with [i] trying to match the first character of [sep] in - [s]. If this matches, we verify that the whole [sep] is matched - using [k]. If this matches we extract a substring from the start - of the current substring [sub_start] to [!i - 1] (the position - before the [sep] we found). We then continue to try to match - with [i] by starting after the [sep] we just found, this is also - becomes the start position of the next substring. If [i] is such - that no separator can be found we exit the loop and make a - substring from [sub_start] until the end of the string. *) - while !i + sep_max <= s_max do - if not (Char.equal (String.unsafe_get s !i) (String.unsafe_get sep 0)) - then incr i - else ( - (* Check remaining [sep] chars match, access to unsafe s (!i + !k) is - guaranteed by loop invariant. *) - k := 1; - while - !k <= sep_max - && Char.equal (String.unsafe_get s (!i + !k)) (String.unsafe_get sep !k) - do - incr k - done; - if !k <= sep_max - then (* no match *) incr i - else - let new_sub_start = !i + sep_max + 1 in - let sub_end = !i - 1 in - let sub_len = sub_end - !sub_start + 1 in - acc := String.sub s !sub_start sub_len :: !acc; - sub_start := new_sub_start; - i := new_sub_start) - done; - List.rev (String.sub s !sub_start (s_max - !sub_start + 1) :: !acc) - - let apply1 f (s : string) : string = - let b = Bytes.of_string s in - if Bytes.length b = 0 - then s - else ( - Bytes.unsafe_set b 0 (f (Bytes.unsafe_get b 0)); - Bytes.to_string b) - let lsplit2 line ~on:delim = try let pos = index line delim in @@ -765,10 +530,6 @@ module String = struct Some (sub line ~pos:0 ~len:pos, sub line ~pos:(pos + 1) ~len:(length line - pos - 1)) with Not_found -> None - let capitalize_ascii s = apply1 Char.uppercase_ascii s - - let uncapitalize_ascii s = apply1 Char.lowercase_ascii s - let[@inline] not_in_x80_to_xBF b = b lsr 6 <> 0b10 let[@inline] not_in_xA0_to_xBF b = b lsr 5 <> 0b101 @@ -1025,20 +786,6 @@ module String = struct | _ -> false in loop (length b - 1) b 0 - - let fold_left ~f ~init s = - let r = ref init in - for i = 0 to length s - 1 do - r := f !r (unsafe_get s i) - done; - !r - - let fold_right ~f s ~init = - let r = ref init in - for i = length s - 1 downto 0 do - r := f (unsafe_get s i) !r - done; - !r end module Utf8_string : sig @@ -1063,11 +810,7 @@ end = struct end module Int = struct - type t = int - - let compare (x : int) y = compare x y - - let equal (x : t) y = x = y + include Int let hash (x : t) = Hashtbl.hash x end @@ -1106,14 +849,14 @@ end = struct let create () = { arr = Array.make 1 0 } - let create' n = { arr = Array.make ((n / int_num_bits) + 1) 0 } + let create' n = { arr = Array.make ((n / Sys.int_size) + 1) 0 } - let size t = Array.length t.arr * int_num_bits + let size t = Array.length t.arr * Sys.int_size let mem t i = let arr = t.arr in - let idx = i / int_num_bits in - let off = i mod int_num_bits in + let idx = i / Sys.int_size in + let off = i mod Sys.int_size in idx < Array.length arr && let x = Array.unsafe_get arr idx in @@ -1130,15 +873,15 @@ end = struct t.arr <- a let set t i = - let idx = i / int_num_bits in - let off = i mod int_num_bits in + let idx = i / Sys.int_size in + let off = i mod Sys.int_size in let size = Array.length t.arr in if idx >= size then resize t idx; Array.unsafe_set t.arr idx (Array.unsafe_get t.arr idx lor (1 lsl off)) let unset t i = - let idx = i / int_num_bits in - let off = i mod int_num_bits in + let idx = i / Sys.int_size in + let off = i mod Sys.int_size in let size = Array.length t.arr in if idx >= size then () @@ -1172,17 +915,6 @@ end module Array = struct include ArrayLabels - let find_opt ~f:p a = - let n = length a in - let rec loop i = - if i = n - then None - else - let x = unsafe_get a i in - if p x then Some x else loop (succ i) - in - loop 0 - let fold_right_i a ~f ~init:x = let r = ref x in for i = Array.length a - 1 downto 0 do @@ -1405,4 +1137,4 @@ let file_lines_text file = let generated_name = function | "param" | "match" | "switcher" -> true - | s -> String.is_prefix ~prefix:"cst_" s + | s -> String.starts_with ~prefix:"cst_" s diff --git a/compiler/lib/var_printer.ml b/compiler/lib/var_printer.ml index 7cca64e730..b075803e37 100644 --- a/compiler/lib/var_printer.ml +++ b/compiler/lib/var_printer.ml @@ -93,7 +93,7 @@ let name t v nm_orig = then ( let buf = Buffer.create (String.length nm_orig) in let idx = ref 0 in - while !idx < len && not (Char.is_alpha nm_orig.[!idx]) do + while !idx < len && not (Char.is_letter nm_orig.[!idx]) do incr idx done; let pending = ref false in @@ -102,7 +102,7 @@ let name t v nm_orig = pending := true; idx := 0); for i = !idx to len - 1 do - if Char.is_alpha nm_orig.[i] || Char.is_num nm_orig.[i] + if Char.is_letter nm_orig.[i] || Char.is_digit nm_orig.[i] then ( if !pending then Buffer.add_char buf '_'; Buffer.add_char buf nm_orig.[i]; diff --git a/compiler/tests-check-prim/gen_dune.ml b/compiler/tests-check-prim/gen_dune.ml index 64c2868ac9..401df00106 100644 --- a/compiler/tests-check-prim/gen_dune.ml +++ b/compiler/tests-check-prim/gen_dune.ml @@ -1,12 +1,7 @@ (** *) type version = - [ `V4_08 - | `V4_09 - | `V4_10 - | `V4_11 - | `V4_12 - | `V4_13 + [ `V4_13 | `V4_14 | `V5_0 | `V5_1 @@ -16,11 +11,6 @@ type version = ] let string_of_version : version -> string = function - | `V4_08 -> "4.08" - | `V4_09 -> "4.09" - | `V4_10 -> "4.10" - | `V4_11 -> "4.11" - | `V4_12 -> "4.12" | `V4_13 -> "4.13" | `V4_14 -> "4.14" | `V5_0 -> "5.0" @@ -30,11 +20,6 @@ let string_of_version : version -> string = function | `V5_4 -> "5.4" let next_version : version -> version option = function - | `V4_08 -> Some `V4_09 - | `V4_09 -> Some `V4_10 - | `V4_10 -> Some `V4_11 - | `V4_11 -> Some `V4_12 - | `V4_12 -> Some `V4_13 | `V4_13 -> Some `V4_14 | `V4_14 -> Some `V5_0 | `V5_0 -> Some `V5_1 diff --git a/compiler/tests-compiler/util/util.ml b/compiler/tests-compiler/util/util.ml index 8b53796ecb..1e49e43d4d 100644 --- a/compiler/tests-compiler/util/util.ml +++ b/compiler/tests-compiler/util/util.ml @@ -183,7 +183,7 @@ let exec_to_string_exn ?input ~fail ~cmd () = let prev, env = Unix.environment () |> Array.to_list - |> List.partition ~f:(String.is_prefix ~prefix:build_path_prefix_map) + |> List.partition ~f:(String.starts_with ~prefix:build_path_prefix_map) in let prev = List.filter_map ~f:(String.drop_prefix ~prefix:build_path_prefix_map) prev diff --git a/compiler/tests-js-parser/run.ml b/compiler/tests-js-parser/run.ml index 2acda654b8..37f07d4252 100644 --- a/compiler/tests-js-parser/run.ml +++ b/compiler/tests-js-parser/run.ml @@ -66,7 +66,7 @@ let normalize_string s = for i = 0 to l - 1 do let c = s.[i] in match c with - | '\000' when i = l - 1 || not (Char.is_num s.[i + 1]) -> Buffer.add_string b "\\0" + | '\000' when i = l - 1 || not (Char.is_digit s.[i + 1]) -> Buffer.add_string b "\\0" | '\b' -> Buffer.add_string b "\\b" | '\t' -> Buffer.add_string b "\\t" | '\n' -> Buffer.add_string b "\\n" diff --git a/compiler/tests-jsoo/test_rec_mod.ml b/compiler/tests-jsoo/test_rec_mod.ml index 950b98d91d..f68253d623 100644 --- a/compiler/tests-jsoo/test_rec_mod.ml +++ b/compiler/tests-jsoo/test_rec_mod.ml @@ -38,7 +38,7 @@ let%expect_test _ = ignore (IdSet.mem { id = 1 } basic_set : bool) (* diverge here *) with e -> - if String.is_suffix ~suffix:"Undefined recursive module" (Printexc.to_string e) + if String.ends_with ~suffix:"Undefined recursive module" (Printexc.to_string e) then () else raise e diff --git a/compiler/tests-ocaml/lib-sys/dune b/compiler/tests-ocaml/lib-sys/dune index 9c8fdcd68b..a71af2d55c 100644 --- a/compiler/tests-ocaml/lib-sys/dune +++ b/compiler/tests-ocaml/lib-sys/dune @@ -5,7 +5,5 @@ (tests (names immediate64) - (build_if - (>= %{ocaml_version} 4.10)) (libraries ocaml_testing) (modes js wasm)) diff --git a/dune-project b/dune-project index b694b130a9..dcb969ad65 100644 --- a/dune-project +++ b/dune-project @@ -18,7 +18,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (and (>= 4.08) (< 5.4))) + (ocaml (and (>= 4.13) (< 5.4))) (num :with-test) (ppx_expect (and (>= v0.16.1) :with-test)) (ppxlib (>= 0.15)) @@ -43,7 +43,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml (= :version)) (js_of_ocaml-ppx (= :version)) (lwt (>= 2.4.4)) @@ -62,7 +62,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml (= :version)) (ppxlib (>= 0.15)) (num :with-test) @@ -76,7 +76,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml (= :version)) (ppxlib (>= 0.15)) (ppxlib (and (< 0.36) :with-test)) @@ -91,7 +91,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml-compiler (= :version)) (ocamlfind (>= 1.5.1)) ;;(cohttp-lwt-unix (and (>= 6.0.0) :with-test)) @@ -108,7 +108,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml (= :version)) (js_of_ocaml-ppx (= :version)) (react (>= 1.2.2)) @@ -126,7 +126,7 @@ (description "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends - (ocaml (>= 4.08)) + (ocaml (>= 4.13)) (js_of_ocaml-compiler (= :version)) (ppxlib (>= 0.15)) (num :with-test) diff --git a/dune-workspace.dev b/dune-workspace.dev index 5b5373a125..08c5d13913 100644 --- a/dune-workspace.dev +++ b/dune-workspace.dev @@ -7,26 +7,6 @@ ;; ;; This will build js_of_ocaml against all these version of OCaml -(context - (opam - (switch 4.08.1))) - -(context - (opam - (switch 4.09.1))) - -(context - (opam - (switch 4.10.2))) - -(context - (opam - (switch 4.11.2))) - -(context - (opam - (switch 4.12.1))) - (context (opam (switch 4.13.1))) diff --git a/js_of_ocaml-compiler.opam b/js_of_ocaml-compiler.opam index 2ad2f90347..e7f30cd610 100644 --- a/js_of_ocaml-compiler.opam +++ b/js_of_ocaml-compiler.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08" & < "5.4"} + "ocaml" {>= "4.13" & < "5.4"} "num" {with-test} "ppx_expect" {>= "v0.16.1" & with-test} "ppxlib" {>= "0.15"} diff --git a/js_of_ocaml-lwt.opam b/js_of_ocaml-lwt.opam index eb96726b78..b8f1f4fe92 100644 --- a/js_of_ocaml-lwt.opam +++ b/js_of_ocaml-lwt.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml" {= version} "js_of_ocaml-ppx" {= version} "lwt" {>= "2.4.4"} diff --git a/js_of_ocaml-ppx.opam b/js_of_ocaml-ppx.opam index f5f059c6f2..df83005beb 100644 --- a/js_of_ocaml-ppx.opam +++ b/js_of_ocaml-ppx.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml" {= version} "ppxlib" {>= "0.15"} "ppxlib" {< "0.36" & with-test} diff --git a/js_of_ocaml-ppx_deriving_json.opam b/js_of_ocaml-ppx_deriving_json.opam index 731bb76b45..c0c5ade8f7 100644 --- a/js_of_ocaml-ppx_deriving_json.opam +++ b/js_of_ocaml-ppx_deriving_json.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml" {= version} "ppxlib" {>= "0.15"} "num" {with-test} diff --git a/js_of_ocaml-toplevel.opam b/js_of_ocaml-toplevel.opam index 08bfdc652f..931dab70f5 100644 --- a/js_of_ocaml-toplevel.opam +++ b/js_of_ocaml-toplevel.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml-compiler" {= version} "ocamlfind" {>= "1.5.1"} "graphics" {with-test} diff --git a/js_of_ocaml-tyxml.opam b/js_of_ocaml-tyxml.opam index adc5995ffc..01c5a7fcdb 100644 --- a/js_of_ocaml-tyxml.opam +++ b/js_of_ocaml-tyxml.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml" {= version} "js_of_ocaml-ppx" {= version} "react" {>= "1.2.2"} diff --git a/js_of_ocaml.opam b/js_of_ocaml.opam index 6de6024413..5326aa555d 100644 --- a/js_of_ocaml.opam +++ b/js_of_ocaml.opam @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview" bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} - "ocaml" {>= "4.08"} + "ocaml" {>= "4.13"} "js_of_ocaml-compiler" {= version} "ppxlib" {>= "0.15"} "num" {with-test} diff --git a/runtime/js/bigarray.js b/runtime/js/bigarray.js index f60f07ec68..adf904d8b1 100644 --- a/runtime/js/bigarray.js +++ b/runtime/js/bigarray.js @@ -247,11 +247,6 @@ function caml_ba_create_buffer(kind, size) { } //Provides: caml_ba_custom_name -//Version: < 4.11 -var caml_ba_custom_name = "_bigarray"; - -//Provides: caml_ba_custom_name -//Version: >= 4.11 var caml_ba_custom_name = "_bigarr02"; //Provides: Ml_Bigarray diff --git a/runtime/js/dune b/runtime/js/dune index f31ffd1b6a..17b7db4117 100644 --- a/runtime/js/dune +++ b/runtime/js/dune @@ -12,7 +12,6 @@ graphics.js ieee_754.js int64.js - internalMod.js io.js jslib.js jslib_js_of_ocaml.js diff --git a/runtime/js/dynlink.js b/runtime/js/dynlink.js index 8ffa521996..70f9473317 100644 --- a/runtime/js/dynlink.js +++ b/runtime/js/dynlink.js @@ -71,21 +71,3 @@ function caml_dynlink_get_current_libs() { for (var i = 0; i < len; i++) a[i] = i; return a; } - -//Provides: caml_register_code_fragment -//Version: < 4.10 -function caml_register_code_fragment(code, codesize, digest) { - return 0; -} - -//Provides: caml_add_debug_info -//Version: < 4.13 -function caml_add_debug_info(code, size, events) { - return 0; -} - -//Provides: caml_remove_debug_info -//Version: < 4.13 -function caml_remove_debug_info(code) { - return 0; -} diff --git a/runtime/js/gc.js b/runtime/js/gc.js index 3692f89970..a3883508c5 100644 --- a/runtime/js/gc.js +++ b/runtime/js/gc.js @@ -25,16 +25,10 @@ function caml_gc_counters() { return [254, 0, 0, 0]; } //Provides: caml_gc_quick_stat -//Version: >= 4.12 function caml_gc_quick_stat() { return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } -//Provides: caml_gc_quick_stat -//Version: < 4.12 -function caml_gc_quick_stat() { - return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -} //Provides: caml_gc_stat //Requires: caml_gc_quick_stat function caml_gc_stat() { @@ -51,12 +45,6 @@ function caml_gc_get() { return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } -//Provides: caml_memprof_set -//Version: = 4.10 -function caml_memprof_set(_control) { - return 0; -} - //Provides: caml_final_register const function caml_final_register() { return 0; diff --git a/runtime/js/hash.js b/runtime/js/hash.js index a1f499adf8..dcd9f9825f 100644 --- a/runtime/js/hash.js +++ b/runtime/js/hash.js @@ -17,75 +17,6 @@ ///////////// Hashtbl -//Provides: caml_hash_univ_param mutable -//Requires: caml_is_ml_string, caml_is_ml_bytes -//Requires: caml_ml_bytes_content -//Requires: caml_int64_to_bytes, caml_int64_bits_of_float, caml_custom_ops -//Requires: caml_ml_bytes_length, caml_jsbytes_of_string -//Version: < 4.12 -function caml_hash_univ_param(count, limit, obj) { - var hash_accu = 0; - function hash_aux(obj) { - limit--; - if (count < 0 || limit < 0) return; - if (Array.isArray(obj) && obj[0] === (obj[0] | 0)) { - switch (obj[0]) { - case 248: - // Object - count--; - hash_accu = (hash_accu * 65599 + obj[2]) | 0; - break; - case 250: - // Forward - limit++; - hash_aux(obj); - break; - default: - count--; - hash_accu = (hash_accu * 19 + obj[0]) | 0; - for (var i = obj.length - 1; i > 0; i--) hash_aux(obj[i]); - } - } else if (caml_is_ml_bytes(obj)) { - count--; - var content = caml_ml_bytes_content(obj); - if (typeof content === "string") { - for (var b = content, l = b.length, i = 0; i < l; i++) - hash_accu = (hash_accu * 19 + b.charCodeAt(i)) | 0; - } else { - /* ARRAY */ - for (var a = content, l = a.length, i = 0; i < l; i++) - hash_accu = (hash_accu * 19 + a[i]) | 0; - } - } else if (caml_is_ml_string(obj)) { - var jsbytes = caml_jsbytes_of_string(obj); - for (var b = jsbytes, l = jsbytes.length, i = 0; i < l; i++) - hash_accu = (hash_accu * 19 + b.charCodeAt(i)) | 0; - } else if (typeof obj === "string") { - for (var b = obj, l = obj.length, i = 0; i < l; i++) - hash_accu = (hash_accu * 19 + b.charCodeAt(i)) | 0; - } else if (obj === (obj | 0)) { - // Integer - count--; - hash_accu = (hash_accu * 65599 + obj) | 0; - } else if (obj === +obj) { - // Float - count--; - var p = caml_int64_to_bytes(caml_int64_bits_of_float(obj)); - for (var i = 7; i >= 0; i--) hash_accu = (hash_accu * 19 + p[i]) | 0; - } else if (obj?.caml_custom) { - if ( - caml_custom_ops[obj.caml_custom] && - caml_custom_ops[obj.caml_custom].hash - ) { - var h = caml_custom_ops[obj.caml_custom].hash(obj) | 0; - hash_accu = (hash_accu * 65599 + h) | 0; - } - } - } - hash_aux(obj); - return hash_accu & 0x3fffffff; -} - //function ROTL32(x,n) { return ((x << n) | (x >>> (32-n))); } //Provides: caml_hash_mix_int //Requires: caml_mul diff --git a/runtime/js/internalMod.js b/runtime/js/internalMod.js deleted file mode 100644 index bf09932850..0000000000 --- a/runtime/js/internalMod.js +++ /dev/null @@ -1,139 +0,0 @@ -// Js_of_ocaml runtime support -// http://www.ocsigen.org/js_of_ocaml/ -// Copyright (C) 2014 Jérôme Vouillon, Hugo Heuzard -// Laboratoire PPS - CNRS Université Paris Diderot -// -// 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. - -//Provides: caml_CamlinternalMod_init_mod -//Requires: caml_raise_with_arg, caml_global_data, caml_alloc_dummy_infix -//If: !effects -//Version: < 4.13 -function caml_CamlinternalMod_init_mod(loc, shape) { - function undef_module(_x) { - caml_raise_with_arg(caml_global_data.Undefined_recursive_module, loc); - } - function loop(shape, struct, idx) { - if (typeof shape === "number") - switch (shape) { - case 0: //function - var dummy = caml_alloc_dummy_infix(); - dummy.fun = undef_module; - struct[idx] = dummy; - break; - case 1: //lazy - struct[idx] = [246, undef_module]; - break; - default: //case 2://class - struct[idx] = []; - } - else - switch (shape[0]) { - case 0: //module - struct[idx] = [0]; - for (var i = 1; i < shape[1].length; i++) - loop(shape[1][i], struct[idx], i); - break; - default: //case 1://Value - struct[idx] = shape[1]; - } - } - var res = []; - loop(shape, res, 0); - return res[0]; -} -//Provides: caml_CamlinternalMod_update_mod -//Requires: caml_update_dummy -//If: !effects -//Version: < 4.13 -function caml_CamlinternalMod_update_mod(shape, real, x) { - if (typeof shape === "number") - //function - //lazy - //class - caml_update_dummy(real, x); - else - switch (shape[0]) { - case 0: //module - for (var i = 1; i < shape[1].length; i++) - caml_CamlinternalMod_update_mod(shape[1][i], real[i], x[i]); - break; - //case 1://Value - default: - } - return 0; -} - -//Provides: caml_CamlinternalMod_init_mod -//Requires: caml_raise_with_arg, caml_global_data, caml_alloc_dummy_infix -//If: effects -//Version: < 4.13 -function caml_CamlinternalMod_init_mod(loc, shape, cont) { - function undef_module(_x, _cont) { - caml_raise_with_arg(caml_global_data.Undefined_recursive_module, loc); - } - function loop(shape, struct, idx) { - if (typeof shape === "number") - switch (shape) { - case 0: //function - var dummy = caml_alloc_dummy_infix(); - dummy.fun = undef_module; - struct[idx] = dummy; - break; - case 1: //lazy - struct[idx] = [246, undef_module]; - break; - default: //case 2://class - struct[idx] = []; - } - else - switch (shape[0]) { - case 0: //module - struct[idx] = [0]; - for (var i = 1; i < shape[1].length; i++) - loop(shape[1][i], struct[idx], i); - break; - default: //case 1://Value - struct[idx] = shape[1]; - } - } - var res = []; - loop(shape, res, 0); - return cont(res[0]); -} -//Provides: caml_CamlinternalMod_update_mod -//Requires: caml_update_dummy -//If: effects -//Version: < 4.13 -function caml_CamlinternalMod_update_mod(shape, real, x, cont) { - function loop(shape, real, x) { - if (typeof shape === "number") - //function - //lazy - //class - caml_update_dummy(real, x); - else - switch (shape[0]) { - case 0: //module - for (var i = 1; i < shape[1].length; i++) - loop(shape[1][i], real[i], x[i]); - break; - //case 1://Value - default: - } - } - loop(shape, real, x); - return cont(0); -} diff --git a/runtime/js/marshal.js b/runtime/js/marshal.js index 39f2da30eb..208dff8275 100644 --- a/runtime/js/marshal.js +++ b/runtime/js/marshal.js @@ -182,21 +182,6 @@ function caml_float_of_bytes(a) { return caml_int64_float_of_bits(caml_int64_of_bytes(a)); } -//Provides: caml_input_value_from_string mutable -//Requires: JsStringReader, UInt8ArrayReader -//Requires: caml_input_value_from_reader -//Requires: caml_ml_bytes_content -//Version: < 4.12 -function caml_input_value_from_string(s, ofs) { - var c = typeof s === "string" ? s : caml_ml_bytes_content(s); - var ofs = typeof ofs === "number" ? ofs : ofs[0]; - var reader = - c instanceof Uint8Array - ? new UInt8ArrayReader(c, ofs) - : new JsStringReader(c, ofs); - return caml_input_value_from_reader(reader); -} - //Provides: caml_input_value_from_bytes mutable //Requires: JsStringReader, UInt8ArrayReader //Requires: caml_input_value_from_reader diff --git a/runtime/js/obj.js b/runtime/js/obj.js index d0df309b40..2d2ab48b0d 100644 --- a/runtime/js/obj.js +++ b/runtime/js/obj.js @@ -38,12 +38,6 @@ function caml_alloc_dummy_infix() { }; } -//Provides: caml_obj_is_block const (const) -//Version: < 4.12 -function caml_obj_is_block(x) { - return +Array.isArray(x); -} - //Provides: caml_obj_tag //Requires: caml_is_ml_bytes, caml_is_ml_string function caml_obj_tag(x) { diff --git a/runtime/js/sys.js b/runtime/js/sys.js index 0217e902ee..16ecee6ad6 100644 --- a/runtime/js/sys.js +++ b/runtime/js/sys.js @@ -332,30 +332,11 @@ function caml_ml_runtime_warnings_enabled(_unit) { return caml_runtime_warnings; } -//Provides: caml_spacetime_enabled const (const) -//Version: < 4.12 -function caml_spacetime_enabled(_unit) { - return 0; -} - //Provides: caml_sys_const_naked_pointers_checked const (const) function caml_sys_const_naked_pointers_checked(_unit) { return 0; } -//Provides: caml_register_channel_for_spacetime const (const) -//Version: < 4.12 -function caml_register_channel_for_spacetime(_channel) { - return 0; -} - -//Provides: caml_spacetime_only_works_for_native_code -//Requires: caml_failwith -//Version: < 4.12 -function caml_spacetime_only_works_for_native_code() { - caml_failwith("Spacetime profiling only works for native code"); -} - //Provides: caml_xdg_defaults //Version: >= 5.2 function caml_xdg_defaults(_unit) { diff --git a/runtime/js/toplevel.js b/runtime/js/toplevel.js index 2e4547ee4e..0a74139b97 100644 --- a/runtime/js/toplevel.js +++ b/runtime/js/toplevel.js @@ -133,19 +133,6 @@ function caml_static_release_bytecode() { return 0; } -//Provides: caml_static_alloc -//Requires: caml_create_bytes -//Version: < 4.12 -function caml_static_alloc(len) { - return caml_create_bytes(len); -} - -//Provides: caml_static_free -//Version: < 4.12 -function caml_static_free() { - return 0; -} - //Provides: caml_realloc_global //Requires: caml_global_data function caml_realloc_global(len) { diff --git a/tools/toplevel_expect/gen.ml b/tools/toplevel_expect/gen.ml index 04661fc990..a905d5e575 100644 --- a/tools/toplevel_expect/gen.ml +++ b/tools/toplevel_expect/gen.ml @@ -49,7 +49,6 @@ let () = | _ -> assert false in match maj, min with - | 4, 8 | 4, 9 | 4, 10 -> dump_file "toplevel_expect_test.ml-4.08" | 4, min -> assert (min >= 11); dump_file "toplevel_expect_test.ml-4.11" diff --git a/tools/toplevel_expect/toplevel_expect_test.ml-4.08 b/tools/toplevel_expect/toplevel_expect_test.ml-4.08 deleted file mode 100644 index 0741a007fb..0000000000 --- a/tools/toplevel_expect/toplevel_expect_test.ml-4.08 +++ /dev/null @@ -1,382 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Jeremie Dimino, Jane Street Europe *) -(* *) -(* Copyright 2016 Jane Street Group LLC *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Execute a list of phrases from a .ml file and compare the result to the - expected output, written inside [%%expect ...] nodes. At the end, create - a .corrected file containing the corrected expectations. The test is - successful if there is no differences between the two files. - - An [%%expect] node always contains both the expected outcome with and - without -principal. When the two differ the expectation is written as - follows: - - {[ - [%%expect {| - output without -principal - |}, Principal{| - output with -principal - |}] - ]} -*) - -[@@@ocaml.warning "-40"] - -open StdLabels - -(* representation of: {tag|str|tag} *) -type string_constant = - { str : string - ; tag : string - } - -type expectation = - { extid_loc : Location.t (* Location of "expect" in "[%%expect ...]" *) - ; payload_loc : Location.t (* Location of the whole payload *) - ; normal : string_constant (* expectation without -principal *) - ; principal : string_constant (* expectation with -principal *) - } - -(* A list of phrases with the expected toplevel output *) -type chunk = - { phrases : Parsetree.toplevel_phrase list - ; expectation : expectation - } - -type correction = - { corrected_expectations : expectation list - ; trailing_output : string - } - -let match_expect_extension (ext : Parsetree.extension) = - match ext with - | ({Asttypes.txt="expect"|"ocaml.expect"; loc = extid_loc}, payload) -> - let invalid_payload () = - Location.raise_errorf ~loc:extid_loc - "invalid [%%%%expect payload]" - in - let string_constant (e : Parsetree.expression) = - match e.pexp_desc with - | Pexp_constant (Pconst_string (str, Some tag)) -> - { str; tag } - | _ -> invalid_payload () - in - let expectation = - match payload with - | PStr [{ pstr_desc = Pstr_eval (e, []); _ }] -> - let normal, principal = - match e.pexp_desc with - | Pexp_tuple - [ a - ; { pexp_desc = Pexp_construct - ({ txt = Lident "Principal"; _ }, Some b); _ } - ] -> - (string_constant a, string_constant b) - | _ -> let s = string_constant e in (s, s) - in - { extid_loc - ; payload_loc = e.pexp_loc - ; normal - ; principal - } - | PStr [] -> - let s = { tag = ""; str = "" } in - { extid_loc - ; payload_loc = { extid_loc with loc_start = extid_loc.loc_end } - ; normal = s - ; principal = s - } - | _ -> invalid_payload () - in - Some expectation - | _ -> - None - -(* Split a list of phrases from a .ml file *) -let split_chunks phrases = - let rec loop (phrases : Parsetree.toplevel_phrase list) code_acc acc = - match phrases with - | [] -> - if code_acc = [] then - (List.rev acc, None) - else - (List.rev acc, Some (List.rev code_acc)) - | phrase :: phrases -> - match phrase with - | Ptop_def [] -> loop phrases code_acc acc - | Ptop_def [{pstr_desc = Pstr_extension(ext, []); _}] -> begin - match match_expect_extension ext with - | None -> loop phrases (phrase :: code_acc) acc - | Some expectation -> - let chunk = - { phrases = List.rev code_acc - ; expectation - } - in - loop phrases [] (chunk :: acc) - end - | _ -> loop phrases (phrase :: code_acc) acc - in - loop phrases [] [] - -module Compiler_messages = struct - let print_loc ppf (loc : Location.t) = - let startchar = loc.loc_start.pos_cnum - loc.loc_start.pos_bol in - let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in - Format.fprintf ppf "Line _"; - if startchar >= 0 then - Format.fprintf ppf ", characters %d-%d" startchar endchar; - Format.fprintf ppf ":@." - - let () = - let default = !Location.report_printer () in - Location.report_printer := (fun _ -> - { default with - Location.pp_main_loc = (fun _ _ fmt loc -> print_loc fmt loc); - Location.pp_submsg_loc = (fun _ _ fmt loc -> print_loc fmt loc); - }) - - let capture ppf ~f = - Misc.protect_refs - [ R (Location.formatter_for_warnings , ppf ) - ] - f -end - -let collect_formatters buf pps ~f = - List.iter ~f:(fun pp -> Format.pp_print_flush pp ()) pps; - let save = - List.map ~f:(fun pp -> Format.pp_get_formatter_out_functions pp ()) pps - in - let restore () = - List.iter2 - ~f:(fun pp out_functions -> - Format.pp_print_flush pp (); - Format.pp_set_formatter_out_functions pp out_functions) - pps save - in - let out_string str ofs len = Buffer.add_substring buf str ofs len - and out_flush = ignore - and out_newline () = Buffer.add_char buf '\n' - and out_spaces n = for _i = 1 to n do Buffer.add_char buf ' ' done - and out_indent n = for _i = 1 to n do Buffer.add_char buf ' ' done in - let out_functions = - { Format.out_string; out_flush; out_newline; out_spaces; out_indent } - in - List.iter - ~f:(fun pp -> Format.pp_set_formatter_out_functions pp out_functions) - pps; - match f () with - | x -> restore (); x - | exception exn -> restore (); raise exn - -(* Invariant: ppf = Format.formatter_of_buffer buf *) -let capture_everything buf ppf ~f = - collect_formatters buf [Format.std_formatter; Format.err_formatter] - ~f:(fun () -> Compiler_messages.capture ppf ~f) - -let exec_phrase ppf phrase = - if !Clflags.dump_parsetree then Printast. top_phrase ppf phrase; - if !Clflags.dump_source then Pprintast.top_phrase ppf phrase; - Toploop.execute_phrase true ppf phrase - -let parse_contents ~fname contents = - let lexbuf = Lexing.from_string contents in - Location.init lexbuf fname; - Location.input_name := fname; - Parse.use_file lexbuf - -let eval_expectation expectation ~output = - let s = - if !Clflags.principal then - expectation.principal - else - expectation.normal - in - if s.str = output then - None - else - let s = { s with str = output } in - Some ( - if !Clflags.principal then - { expectation with principal = s } - else - { expectation with normal = s } - ) - -let preprocess_structure mappers str = - let open Ast_mapper in - List.fold_right - ~f:(fun ppx_rewriter str -> - let mapper : Ast_mapper.mapper = ppx_rewriter [] in - mapper.structure mapper str) - mappers - ~init:str - -let preprocess_phrase mappers phrase = - let open Parsetree in - match phrase with - | Ptop_def str -> Ptop_def (preprocess_structure mappers str) - | Ptop_dir _ as x -> x - - -let shift_lines delta = - let position (pos : Lexing.position) = - { pos with pos_lnum = pos.pos_lnum + delta } - in - let location _this (loc : Location.t) = - { loc with - loc_start = position loc.loc_start - ; loc_end = position loc.loc_end - } - in - fun _ -> { Ast_mapper.default_mapper with location } - -let rec min_line_number : Parsetree.toplevel_phrase list -> int option = -function - | [] -> None - | (Ptop_dir _ | Ptop_def []) :: l -> min_line_number l - | Ptop_def (st :: _) :: _ -> Some st.pstr_loc.loc_start.pos_lnum - -let eval_expect_file mapper fname ~file_contents = - Warnings.reset_fatal (); - let chunks, trailing_code = - parse_contents ~fname:fname file_contents |> split_chunks - in - let buf = Buffer.create 1024 in - let ppf = Format.formatter_of_buffer buf in - let out_fun = Format.pp_get_formatter_out_functions ppf () in - Format.pp_set_formatter_out_functions Format.std_formatter out_fun; - - let exec_phrases phrases = - - let mappers = - match min_line_number phrases with - | None -> [] - | Some lnum -> [shift_lines (1 - lnum)] - in - let mappers = mapper :: mappers in - let phrases = List.map ~f:(preprocess_phrase mappers) phrases in - - (* For formatting purposes *) - Buffer.add_char buf '\n'; - let _ : bool = - List.fold_left phrases ~init:true ~f:(fun acc phrase -> - acc && - try - exec_phrase ppf phrase - with exn -> - Location.report_exception ppf exn; - false) - in - Format.pp_print_flush ppf (); - let len = Buffer.length buf in - if len > 0 && Buffer.nth buf (len - 1) <> '\n' then - (* For formatting purposes *) - Buffer.add_char buf '\n'; - let s = Buffer.contents buf in - Buffer.clear buf; - Misc.delete_eol_spaces s - in - let corrected_expectations = - capture_everything buf ppf ~f:(fun () -> - List.fold_left chunks ~init:[] ~f:(fun acc chunk -> - let output = exec_phrases chunk.phrases in - match eval_expectation chunk.expectation ~output with - | None -> acc - | Some correction -> correction :: acc) - |> List.rev) - in - let trailing_output = - match trailing_code with - | None -> "" - | Some phrases -> - capture_everything buf ppf ~f:(fun () -> exec_phrases phrases) - in - { corrected_expectations; trailing_output } - -let output_slice oc s a b = - output_string oc (String.sub s ~pos:a ~len:(b - a)) - -let output_corrected oc ~file_contents correction = - let output_body oc { str; tag } = - Printf.fprintf oc "{%s|%s|%s}" tag str tag - in - let ofs = - List.fold_left correction.corrected_expectations ~init:0 - ~f:(fun ofs c -> - output_slice oc file_contents ofs c.payload_loc.loc_start.pos_cnum; - output_body oc c.normal; - if !Clflags.principal && c.normal.str <> c.principal.str then begin - output_string oc ", Principal"; - output_body oc c.principal - end; - c.payload_loc.loc_end.pos_cnum) - in - output_slice oc file_contents ofs (String.length file_contents); - match correction.trailing_output with - | "" -> () - | s -> Printf.fprintf oc "\n[%%%%expect{|%s|}]\n" s - -let write_corrected ~file ~file_contents correction = - let oc = open_out file in - output_corrected oc ~file_contents correction; - close_out oc - -let process_expect_file mapper fname = - let corrected_fname = fname ^ ".corrected" in - let file_contents = - let ic = open_in_bin fname in - match really_input_string ic (in_channel_length ic) with - | s -> close_in ic; Misc.normalise_eol s - | exception e -> close_in ic; raise e - in - let correction = eval_expect_file mapper fname ~file_contents in - write_corrected ~file:corrected_fname ~file_contents correction - -let repo_root = ref "" - -let main mapper fname = - Toploop.override_sys_argv - (Array.sub Sys.argv ~pos:!Arg.current - ~len:(Array.length Sys.argv - !Arg.current)); - (* Ignore OCAMLRUNPARAM=b to be reproducible *) - Printexc.record_backtrace false; - List.iter [ "stdlib" ] ~f:(fun s -> - Topdirs.dir_directory (Filename.concat !repo_root s)); - Toploop.initialize_toplevel_env (); - Sys.interactive := false; - process_expect_file mapper fname; - exit 0 - -let args = - Arg.align - [ "-repo-root", Set_string repo_root, - " root of the OCaml repository" - ; "-principal", Set Clflags.principal, - " Evaluate the file with -principal set" - ] - -let usage = "Usage: expect_test [script-file [arguments]]\n\ - options are:" - -let run mapper = - Toploop.set_paths (); - Clflags.error_style := Some Misc.Error_style.Short; - try - Arg.parse args (main mapper) usage; - Printf.eprintf "expect_test: no input file\n"; - exit 2 - with exn -> - Location.report_exception Format.err_formatter exn; - exit 2 diff --git a/toplevel/bin/jsoo_common.ml b/toplevel/bin/jsoo_common.ml index 9e79ac7521..b202a9e308 100644 --- a/toplevel/bin/jsoo_common.ml +++ b/toplevel/bin/jsoo_common.ml @@ -75,7 +75,7 @@ let cmis_of_package pkg : string list = try Findlib.package_property [ "byte" ] pkg "archive" with exc -> if String.equal pkg "stdlib" then "stdlib.cma" else raise exc in - let l = String.split_char ~sep:' ' archive in + let l = String.split_on_char ~sep:' ' archive in List.iter l ~f:(function | "" -> () | x -> @@ -107,7 +107,7 @@ let cmis files = match kind file with | `Pkg pkg -> cmis_of_package pkg @ fs | `Cmi s -> ( - match String.split_char ~sep:':' s with + match String.split_on_char ~sep:':' s with | [ s ] -> read_cmi ~dir:"." s :: fs | [ pkg; s ] -> let dir = Findlib.package_directory pkg in diff --git a/toplevel/bin/jsoo_mkcmis.ml b/toplevel/bin/jsoo_mkcmis.ml index c1ab4d04e9..3dda46ee04 100644 --- a/toplevel/bin/jsoo_mkcmis.ml +++ b/toplevel/bin/jsoo_mkcmis.ml @@ -68,8 +68,8 @@ let () = let runtime_files, builtin = List.partition_map runtime_files ~f:(fun name -> match Js_of_ocaml_compiler.Builtins.find name with - | Some t -> `Snd t - | None -> `Fst name) + | Some t -> Right t + | None -> Left name) in let builtin = if !runtime then Js_of_ocaml_compiler_runtime_files.runtime @ builtin else builtin