diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d4917a71..580e6e264 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -122,7 +122,7 @@ jobs: - run: opam install . --best-effort if: ${{ matrix.skip-test }} - - run: cat VERSION | xargs opam pin wasm_of_ocaml-compiler . -n --with-version + - run: cat VERSION | xargs opam pin . -n --with-version if: ${{ !matrix.skip-test }} shell: bash @@ -164,44 +164,4 @@ jobs: branch: wikidoc folder: doc-dev clean: true - target-folder: doc/dev/ - - lint-opam: - runs-on: ubuntu-latest - steps: - - name: Checkout tree - uses: actions/checkout@v4 - - name: Set-up OCaml - uses: ocaml/setup-ocaml@v3 - with: - ocaml-compiler: "5.2" - dune-cache: true - - name: Pin dune - run: | - opam pin add -n dune.3.17 https://github.com/ocaml/dune.git - - uses: ocaml/setup-ocaml/lint-opam@v3 - - lint-fmt: - runs-on: ubuntu-latest - steps: - - name: Checkout tree - uses: actions/checkout@v4 - - name: Set-up OCaml - uses: ocaml/setup-ocaml@v3 - with: - ocaml-compiler: "5.2" - dune-cache: true - - name: Pin dune - run: | - opam pin add -n dune.3.17 https://github.com/ocaml/dune.git - - uses: ocaml/setup-ocaml/lint-fmt@v3 - - lint-runtime: - runs-on: ubuntu-latest - steps: - - name: Checkout tree - uses: actions/checkout@v4 - - name: Set-up Biome - uses: biomejs/setup-biome@v2 - - name: Run biome - run: biome ci + target-folder: doc/dev/ \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..36f9a8c5e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,48 @@ +name: lint + +on: + pull_request: + push: + branches: + - master + +jobs: + lint-opam: + runs-on: ubuntu-latest + steps: + - name: Checkout tree + uses: actions/checkout@v4 + - name: Set-up OCaml + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: "5.2" + dune-cache: true + - name: Pin dune + run: | + opam pin add -n dune.3.17 https://github.com/ocaml/dune.git + - uses: ocaml/setup-ocaml/lint-opam@v3 + + lint-fmt: + runs-on: ubuntu-latest + steps: + - name: Checkout tree + uses: actions/checkout@v4 + - name: Set-up OCaml + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: "5.2" + dune-cache: true + - name: Pin dune + run: | + opam pin add -n dune.3.17 https://github.com/ocaml/dune.git + - uses: ocaml/setup-ocaml/lint-fmt@v3 + + lint-runtime: + runs-on: ubuntu-latest + steps: + - name: Checkout tree + uses: actions/checkout@v4 + - name: Set-up Biome + uses: biomejs/setup-biome@v2 + - name: Run biome + run: biome ci diff --git a/CHANGES.md b/CHANGES.md index cb0a41545..e0d314ad2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,16 +1,15 @@ -# dev +# 5.9.0 (2024-11-22) - Lille ## Features/Changes * Misc: update testsuite to OCaml 5.2 * Misc: CI uses opam.2.2 and no longer use sunset repo * Misc: yojson is no longer optional * Misc: reduce the diff with the wasm_of_ocaml fork +* Misc: finalize support for OCaml 5.3 * Compiler: speedup global_flow/global_deadcode pass on large bytecode * Compiler: improved global dead code elimination (#2206) * Compiler: speedup json parsing, relying on Yojson.Raw (#1640) * Compiler: Decode sourcemap mappings only when necessary (#1664) -* Compiler: make indirect call using sequence instead of using the call method - [f.call(null, args)] becomes [(0,f)(args)] * Compiler: mark [TextEncoder] as reserved * Compiler: add support for the Wasm backend in parts of the pipeline, in prevision for the merge of wasm_of_ocaml @@ -21,12 +20,15 @@ * Compiler: Emit index source_map to avoid changing mappings (#1714, #1715) * Compiler: improved source map generation (#1716) * Runtime: change Sys.os_type on windows (Cygwin -> Win32) -* Runtime: backtraces are really expensive, they need to be be explicitly +* Runtime: backtraces are really expensive, they need to be explicitly requested at compile time (--enable with-js-error) or at startup (OCAMLRUNPARAM=b=1) * Runtime: allow dynlink of precompiled js with separate compilation (#1676) * Runtime: reimplement the runtime of weak and ephemeron (#1707) * Lib: Modify Typed_array API for compatibility with WebAssembly +* Lib: add details element and toggle event (#1728) * Toplevel: no longer set globals for toplevel initialization +* Runtime: precompute constants used in `caml_lxm_next` (#1730) +* Runtime: cleanup runtime ## Bug fixes * Runtime: fix parsing of unsigned integers (0u2147483648) (#1633, #1666) diff --git a/VERSION b/VERSION index 5e21ca5a8..b3d91f9cf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.8.2 +5.9.0 diff --git a/biome.json b/biome.json index 5de4567ff..9a0658559 100644 --- a/biome.json +++ b/biome.json @@ -2,7 +2,7 @@ "$schema": "https://biomejs.dev/schemas/1.9.1/schema.json", "files": { "include": ["runtime"], - "ignore": ["runtime/zstd.ts"] + "ignore": ["runtime/js/zstd.ts"] }, "formatter": { "enabled": true, diff --git a/compiler/bin-js_of_ocaml/cmd_arg.ml b/compiler/bin-js_of_ocaml/cmd_arg.ml index 58cf49053..c294be23a 100644 --- a/compiler/bin-js_of_ocaml/cmd_arg.ml +++ b/compiler/bin-js_of_ocaml/cmd_arg.ml @@ -130,7 +130,7 @@ let options = in let no_sourcemap = let doc = - "Don't generate source map. All other source map related flags will be be ignored." + "Don't generate source map. All other source map related flags will be ignored." in Arg.(value & flag & info [ "no-sourcemap"; "no-source-map" ] ~doc) in @@ -395,7 +395,7 @@ let options_runtime_only = in let no_sourcemap = let doc = - "Don't generate source map. All other source map related flags will be be ignored." + "Don't generate source map. All other source map related flags will be ignored." in Arg.(value & flag & info [ "no-sourcemap"; "no-source-map" ] ~doc) in diff --git a/compiler/bin-js_of_ocaml/link.ml b/compiler/bin-js_of_ocaml/link.ml index 521ab6f70..f48c333fe 100644 --- a/compiler/bin-js_of_ocaml/link.ml +++ b/compiler/bin-js_of_ocaml/link.ml @@ -39,7 +39,7 @@ let options = in let no_sourcemap = let doc = - "Don't generate source map. All other source map related flags will be be ignored." + "Don't generate source map. All other source map related flags will be ignored." in Arg.(value & flag & info [ "no-sourcemap"; "no-source-map" ] ~doc) in diff --git a/compiler/lib-runtime-files/dune b/compiler/lib-runtime-files/dune index e9e77ae73..5742162d2 100644 --- a/compiler/lib-runtime-files/dune +++ b/compiler/lib-runtime-files/dune @@ -7,7 +7,7 @@ (target files.ml) (deps gen/gen.exe - (glob_files ../../runtime/*.js)) + (glob_files ../../runtime/js/*.js)) (action (with-stdout-to %{target} diff --git a/compiler/lib/flow_lexer.ml b/compiler/lib/flow_lexer.ml index 526b71096..a3449fa32 100644 --- a/compiler/lib/flow_lexer.ml +++ b/compiler/lib/flow_lexer.ml @@ -832,9 +832,9 @@ let backquote env lexbuf = let wrap f = let f env = - let start, _ = Sedlexing.lexing_positions env.Lex_env.lex_lb in + let start = Sedlexing.lexing_position_start env.Lex_env.lex_lb in let t = f env env.Lex_env.lex_lb in - let _, stop = Sedlexing.lexing_positions env.Lex_env.lex_lb in + let stop = Sedlexing.lexing_position_curr env.Lex_env.lex_lb in t, Loc.create ~last_line:(Loc.line_end' !(env.lex_last_loc)) start stop in let rec helper comments env = diff --git a/compiler/lib/generate.ml b/compiler/lib/generate.ml index dbf057750..7784206d6 100644 --- a/compiler/lib/generate.ml +++ b/compiler/lib/generate.ml @@ -898,7 +898,8 @@ let apply_fun_raw ctx f params exact trampolined loc = (* Make sure we are performing a regular call, not a (slower) method call *) match f with - | J.EAccess _ | J.EDot _ -> J.call (J.ESeq (int 0, f)) params loc + | J.EAccess _ | J.EDot _ -> + J.call (J.dot f (Utf8_string.of_string_exn "call")) (s_var "null" :: params) loc | _ -> J.call f params loc in let apply = diff --git a/compiler/lib/parse_bytecode.ml b/compiler/lib/parse_bytecode.ml index b3fbc6c1b..667f62c5c 100644 --- a/compiler/lib/parse_bytecode.ml +++ b/compiler/lib/parse_bytecode.ml @@ -88,8 +88,6 @@ module Debug : sig val create : include_cmis:bool -> bool -> t - val fold : t -> (Code.Addr.t -> Instruct.debug_event -> 'a -> 'a) -> 'a -> 'a - val paths : t -> units:StringSet.t -> StringSet.t end = struct open Instruct @@ -315,9 +313,6 @@ end = struct | [], [] -> () | _ -> assert false - let fold t f acc = - Int_table.fold (fun k { event; _ } acc -> f k event acc) t.events_by_pc acc - let paths t ~units = let paths = Hashtbl.fold @@ -333,46 +328,38 @@ end module Blocks : sig type t - val analyse : Debug.t -> bytecode -> t - - val add : t -> int -> t - - type u - - val finish_analysis : t -> u + val analyse : bytecode -> t - val next : u -> int -> int + val next : t -> int -> int - val is_empty : u -> bool + val is_empty : t -> bool end = struct - type t = Addr.Set.t - - type u = int array + type t = int array let add blocks pc = Addr.Set.add pc blocks - let rec scan debug blocks code pc len = + let rec scan blocks code pc len = if pc < len then match (get_instr_exn code pc).kind with - | KNullary -> scan debug blocks code (pc + 1) len - | KUnary -> scan debug blocks code (pc + 2) len - | KBinary -> scan debug blocks code (pc + 3) len - | KNullaryCall -> scan debug blocks code (pc + 1) len - | KUnaryCall -> scan debug blocks code (pc + 2) len - | KBinaryCall -> scan debug blocks code (pc + 3) len + | KNullary -> scan blocks code (pc + 1) len + | KUnary -> scan blocks code (pc + 2) len + | KBinary -> scan blocks code (pc + 3) len + | KNullaryCall -> scan blocks code (pc + 1) len + | KUnaryCall -> scan blocks code (pc + 2) len + | KBinaryCall -> scan blocks code (pc + 3) len | KJump -> let offset = gets code (pc + 1) in let blocks = Addr.Set.add (pc + offset + 1) blocks in - scan debug blocks code (pc + 2) len + scan blocks code (pc + 2) len | KCond_jump -> let offset = gets code (pc + 1) in let blocks = Addr.Set.add (pc + offset + 1) blocks in - scan debug blocks code (pc + 2) len + scan blocks code (pc + 2) len | KCmp_jump -> let offset = gets code (pc + 2) in let blocks = Addr.Set.add (pc + offset + 2) blocks in - scan debug blocks code (pc + 3) len + scan blocks code (pc + 3) len | KSwitch -> let sz = getu code (pc + 1) in let blocks = ref blocks in @@ -380,19 +367,17 @@ end = struct let offset = gets code (pc + 2 + i) in blocks := Addr.Set.add (pc + offset + 2) !blocks done; - scan debug !blocks code (pc + 2 + (sz land 0xffff) + (sz lsr 16)) len + scan !blocks code (pc + 2 + (sz land 0xffff) + (sz lsr 16)) len | KClosurerec -> let nfuncs = getu code (pc + 1) in - scan debug blocks code (pc + nfuncs + 3) len - | KClosure -> scan debug blocks code (pc + 3) len - | KStop n -> scan debug blocks code (pc + n + 1) len + scan blocks code (pc + nfuncs + 3) len + | KClosure -> scan blocks code (pc + 3) len + | KStop n -> scan blocks code (pc + n + 1) len | K_will_not_happen -> assert false else ( assert (pc = len); blocks) - let finish_analysis blocks = Array.of_list (Addr.Set.elements blocks) - (* invariant: a.(i) <= x < a.(j) *) let rec find a i j x = assert (i < j); @@ -406,17 +391,13 @@ end = struct let is_empty x = Array.length x <= 1 - let analyse debug_data code = - let debug_data = - if Debug.enabled debug_data - then debug_data - else Debug.create ~include_cmis:false false - in + let analyse code = let blocks = Addr.Set.empty in let len = String.length code / 4 in let blocks = add blocks 0 in let blocks = add blocks len in - scan debug_data blocks code 0 len + let blocks = scan blocks code 0 len in + Array.of_list (Addr.Set.elements blocks) end (* Parse constants *) @@ -806,7 +787,7 @@ let method_cache_id = ref 1 let clo_offset_3 = if new_closure_repr then 3 else 2 type compile_info = - { blocks : Blocks.u + { blocks : Blocks.t ; code : string ; limit : int ; debug : Debug.t @@ -1865,7 +1846,7 @@ and compile infos pc state (instrs : instr list) = if debug_parser () then ( - Format.printf "%a = ccal \"%s\" (" Var.print x prim; + Format.printf "%a = ccall \"%s\" (" Var.print x prim; for i = 0 to nargs - 1 do if i > 0 then Format.printf ", "; Format.printf "%a" Var.print (List.nth args i) @@ -1885,7 +1866,7 @@ and compile infos pc state (instrs : instr list) = if debug_parser () then ( - Format.printf "%a = ccal \"%s\" (" Var.print x prim; + Format.printf "%a = ccall \"%s\" (" Var.print x prim; for i = 0 to nargs - 1 do if i > 0 then Format.printf ", "; Format.printf "%a" Var.print (List.nth args i) @@ -1905,7 +1886,7 @@ and compile infos pc state (instrs : instr list) = if debug_parser () then ( - Format.printf "%a = ccal \"%s\" (" Var.print x prim; + Format.printf "%a = ccall \"%s\" (" Var.print x prim; for i = 0 to nargs - 1 do if i > 0 then Format.printf ", "; Format.printf "%a" Var.print (List.nth args i) @@ -2465,14 +2446,7 @@ type one = let parse_bytecode code globals debug_data = let state = State.initial globals in Code.Var.reset (); - let blocks = Blocks.analyse debug_data code in - let blocks = - (* Disabled. [pc] might not be an appropriate place to split blocks *) - if false && Debug.enabled debug_data - then Debug.fold debug_data (fun pc _ blocks -> Blocks.add blocks pc) blocks - else blocks - in - let blocks' = Blocks.finish_analysis blocks in + let blocks' = Blocks.analyse code in let p = if not (Blocks.is_empty blocks') then ( diff --git a/compiler/lib/parse_js.ml b/compiler/lib/parse_js.ml index e8a4e5353..13c9c4aca 100644 --- a/compiler/lib/parse_js.ml +++ b/compiler/lib/parse_js.ml @@ -85,7 +85,7 @@ end = struct Option.iter filename ~f:(Sedlexing.set_filename l); create ?report_error l - let curr_pos lexbuf = snd (Sedlexing.lexing_positions lexbuf.l) + let curr_pos lexbuf = Sedlexing.lexing_position_curr lexbuf.l let report_errors t res = match Flow_lexer.Lex_result.errors res with diff --git a/compiler/tests-check-prim/dune b/compiler/tests-check-prim/dune index 88cf01f81..4b786374d 100644 --- a/compiler/tests-check-prim/dune +++ b/compiler/tests-check-prim/dune @@ -1,6 +1,6 @@ (executables (names main) - (libraries js_of_ocaml num) + (libraries js_of_ocaml num str) (link_flags (:standard -linkall)) (modules main) @@ -8,7 +8,7 @@ (executables (names unix) - (libraries js_of_ocaml num unix) + (libraries js_of_ocaml num str unix) (link_flags (:standard -linkall)) (modules unix) @@ -23,7 +23,8 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:main.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:main.bc})))) (rule (targets unix-unix.output) @@ -36,7 +37,8 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:unix.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:unix.bc})))) (rule (targets unix-win32.output) @@ -49,7 +51,8 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:unix.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:unix.bc})))) (rule (targets main.output5) @@ -60,7 +63,8 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:main.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:main.bc})))) (rule (targets unix-unix.output5) @@ -73,7 +77,8 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:unix.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:unix.bc})))) (rule (targets unix-win32.output5) @@ -86,4 +91,5 @@ (action (with-stdout-to %{targets} - (run %{bin:js_of_ocaml} check-runtime +toplevel.js %{dep:unix.bc})))) + (run %{bin:js_of_ocaml} check-runtime +dynlink.js +toplevel.js + %{dep:unix.bc})))) diff --git a/compiler/tests-check-prim/main.output b/compiler/tests-check-prim/main.output index b5d4c4d6b..3051f6b6e 100644 --- a/compiler/tests-check-prim/main.output +++ b/compiler/tests-check-prim/main.output @@ -3,11 +3,6 @@ Missing From main.bc: caml_alloc_dummy_function -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int64_add_native caml_int64_and_native caml_int64_div_native @@ -19,9 +14,7 @@ caml_int64_sub_native caml_int64_xor_native caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit debugger -is_digit_normalized Unused ------- @@ -41,32 +34,7 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_atomic_cas -caml_atomic_exchange -caml_atomic_fetch_add -caml_atomic_load -caml_atomic_make_contended -caml_domain_dls -caml_domain_dls_get -caml_domain_dls_set -caml_domain_id -caml_domain_spawn -caml_ml_domain_cpu_relax -caml_ml_domain_id -caml_ml_domain_set_name -caml_ml_domain_unique_token -caml_recommended_domain_count - From +effect.js: -caml_alloc_stack -caml_continuation_use_and_update_handler_noexc -caml_continuation_use_noexc -caml_get_continuation_callstack -caml_ml_condition_broadcast -caml_ml_condition_new -caml_ml_condition_signal -caml_ml_condition_wait jsoo_effect_not_supported From +fs.js: @@ -76,10 +44,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_memprof_discard -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -129,18 +93,10 @@ caml_gr_text_size caml_gr_wait_event caml_gr_window_id -From +hash.js: -caml_string_hash - From +ints.js: caml_div caml_mod -From +io.js: -caml_input_value_to_outside_heap -caml_ml_input_bigarray -caml_ml_output_bigarray - From +jslib.js: caml_is_js caml_trampoline @@ -149,49 +105,15 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring -caml_new_string caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_lazy_read_result -caml_lazy_reset_to_lazy -caml_lazy_update_to_forcing -caml_lazy_update_to_forward -caml_obj_compare_and_swap -caml_obj_is_block -caml_obj_is_shared -caml_obj_update_tag - -From +prng.js: -caml_lxm_next - -From +runtime_events.js: -caml_custom_event_index -caml_ml_runtime_events_pause -caml_ml_runtime_events_resume -caml_ml_runtime_events_start -caml_runtime_events_create_cursor -caml_runtime_events_free_cursor -caml_runtime_events_read_poll -caml_runtime_events_user_register -caml_runtime_events_user_resolve -caml_runtime_events_user_write - From +stdlib.js: caml_build_symbols caml_is_printable @@ -199,15 +121,6 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sync.js: MlMutex caml_ml_mutex_lock @@ -219,20 +132,10 @@ From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code -caml_sys_is_regular_file From +toplevel.js: caml_dynlink_get_bytecode_sections -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-check-prim/main.output5 b/compiler/tests-check-prim/main.output5 index 470dc712b..f685d9f19 100644 --- a/compiler/tests-check-prim/main.output5 +++ b/compiler/tests-check-prim/main.output5 @@ -5,16 +5,9 @@ From main.bc: caml_alloc_dummy_function caml_continuation_use caml_drop_continuation -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit debugger -is_digit_normalized Unused ------- @@ -34,9 +27,6 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_ml_domain_set_name - From +effect.js: jsoo_effect_not_supported @@ -47,14 +37,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_eventlog_pause -caml_eventlog_resume -caml_gc_huge_fallback_count -caml_get_major_bucket -caml_get_major_credit -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -116,7 +98,6 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: @@ -124,21 +105,8 @@ caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_obj_is_block -caml_obj_make_forward -caml_obj_set_tag -caml_obj_truncate - From +runtime_events.js: caml_runtime_events_create_cursor caml_runtime_events_free_cursor @@ -152,33 +120,15 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code caml_sys_const_naked_pointers_checked From +toplevel.js: caml_get_section_table -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-check-prim/unix-unix.output b/compiler/tests-check-prim/unix-unix.output index 3d6399954..a5b4b7b99 100644 --- a/compiler/tests-check-prim/unix-unix.output +++ b/compiler/tests-check-prim/unix-unix.output @@ -3,11 +3,6 @@ Missing From unix.bc: caml_alloc_dummy_function -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int64_add_native caml_int64_and_native caml_int64_div_native @@ -19,10 +14,8 @@ caml_int64_sub_native caml_int64_xor_native caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit caml_unix_map_file_bytecode debugger -is_digit_normalized unix_accept unix_access unix_alarm @@ -150,32 +143,7 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_atomic_cas -caml_atomic_exchange -caml_atomic_fetch_add -caml_atomic_load -caml_atomic_make_contended -caml_domain_dls -caml_domain_dls_get -caml_domain_dls_set -caml_domain_id -caml_domain_spawn -caml_ml_domain_cpu_relax -caml_ml_domain_id -caml_ml_domain_set_name -caml_ml_domain_unique_token -caml_recommended_domain_count - From +effect.js: -caml_alloc_stack -caml_continuation_use_and_update_handler_noexc -caml_continuation_use_noexc -caml_get_continuation_callstack -caml_ml_condition_broadcast -caml_ml_condition_new -caml_ml_condition_signal -caml_ml_condition_wait jsoo_effect_not_supported From +fs.js: @@ -185,10 +153,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_memprof_discard -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -238,18 +202,10 @@ caml_gr_text_size caml_gr_wait_event caml_gr_window_id -From +hash.js: -caml_string_hash - From +ints.js: caml_div caml_mod -From +io.js: -caml_input_value_to_outside_heap -caml_ml_input_bigarray -caml_ml_output_bigarray - From +jslib.js: caml_is_js caml_trampoline @@ -258,49 +214,15 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring -caml_new_string caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_lazy_read_result -caml_lazy_reset_to_lazy -caml_lazy_update_to_forcing -caml_lazy_update_to_forward -caml_obj_compare_and_swap -caml_obj_is_block -caml_obj_is_shared -caml_obj_update_tag - -From +prng.js: -caml_lxm_next - -From +runtime_events.js: -caml_custom_event_index -caml_ml_runtime_events_pause -caml_ml_runtime_events_resume -caml_ml_runtime_events_start -caml_runtime_events_create_cursor -caml_runtime_events_free_cursor -caml_runtime_events_read_poll -caml_runtime_events_user_register -caml_runtime_events_user_resolve -caml_runtime_events_user_write - From +stdlib.js: caml_build_symbols caml_is_printable @@ -308,15 +230,6 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sync.js: MlMutex caml_ml_mutex_lock @@ -328,20 +241,10 @@ From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code -caml_sys_is_regular_file From +toplevel.js: caml_dynlink_get_bytecode_sections -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-check-prim/unix-unix.output5 b/compiler/tests-check-prim/unix-unix.output5 index 3ac8083bb..7902a823d 100644 --- a/compiler/tests-check-prim/unix-unix.output5 +++ b/compiler/tests-check-prim/unix-unix.output5 @@ -5,14 +5,8 @@ From unix.bc: caml_alloc_dummy_function caml_continuation_use caml_drop_continuation -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit caml_unix_accept caml_unix_access caml_unix_alarm @@ -125,7 +119,6 @@ caml_unix_waitpid caml_unix_write caml_unix_write_bigarray debugger -is_digit_normalized Unused ------- @@ -145,9 +138,6 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_ml_domain_set_name - From +effect.js: jsoo_effect_not_supported @@ -158,14 +148,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_eventlog_pause -caml_eventlog_resume -caml_gc_huge_fallback_count -caml_get_major_bucket -caml_get_major_credit -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -227,7 +209,6 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: @@ -235,21 +216,8 @@ caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_obj_is_block -caml_obj_make_forward -caml_obj_set_tag -caml_obj_truncate - From +runtime_events.js: caml_runtime_events_create_cursor caml_runtime_events_free_cursor @@ -263,33 +231,15 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code caml_sys_const_naked_pointers_checked From +toplevel.js: caml_get_section_table -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-check-prim/unix-win32.output b/compiler/tests-check-prim/unix-win32.output index 9df6df3c0..284f7eb51 100644 --- a/compiler/tests-check-prim/unix-win32.output +++ b/compiler/tests-check-prim/unix-win32.output @@ -3,11 +3,6 @@ Missing From unix.bc: caml_alloc_dummy_function -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int64_add_native caml_int64_and_native caml_int64_div_native @@ -19,10 +14,8 @@ caml_int64_sub_native caml_int64_xor_native caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit caml_unix_map_file_bytecode debugger -is_digit_normalized unix_accept unix_access unix_bind @@ -115,32 +108,7 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_atomic_cas -caml_atomic_exchange -caml_atomic_fetch_add -caml_atomic_load -caml_atomic_make_contended -caml_domain_dls -caml_domain_dls_get -caml_domain_dls_set -caml_domain_id -caml_domain_spawn -caml_ml_domain_cpu_relax -caml_ml_domain_id -caml_ml_domain_set_name -caml_ml_domain_unique_token -caml_recommended_domain_count - From +effect.js: -caml_alloc_stack -caml_continuation_use_and_update_handler_noexc -caml_continuation_use_noexc -caml_get_continuation_callstack -caml_ml_condition_broadcast -caml_ml_condition_new -caml_ml_condition_signal -caml_ml_condition_wait jsoo_effect_not_supported From +fs.js: @@ -150,10 +118,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_memprof_discard -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -203,18 +167,10 @@ caml_gr_text_size caml_gr_wait_event caml_gr_window_id -From +hash.js: -caml_string_hash - From +ints.js: caml_div caml_mod -From +io.js: -caml_input_value_to_outside_heap -caml_ml_input_bigarray -caml_ml_output_bigarray - From +jslib.js: caml_is_js caml_trampoline @@ -223,49 +179,15 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring -caml_new_string caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_lazy_read_result -caml_lazy_reset_to_lazy -caml_lazy_update_to_forcing -caml_lazy_update_to_forward -caml_obj_compare_and_swap -caml_obj_is_block -caml_obj_is_shared -caml_obj_update_tag - -From +prng.js: -caml_lxm_next - -From +runtime_events.js: -caml_custom_event_index -caml_ml_runtime_events_pause -caml_ml_runtime_events_resume -caml_ml_runtime_events_start -caml_runtime_events_create_cursor -caml_runtime_events_free_cursor -caml_runtime_events_read_poll -caml_runtime_events_user_register -caml_runtime_events_user_resolve -caml_runtime_events_user_write - From +stdlib.js: caml_build_symbols caml_is_printable @@ -273,15 +195,6 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sync.js: MlMutex caml_ml_mutex_lock @@ -293,20 +206,10 @@ From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code -caml_sys_is_regular_file From +toplevel.js: caml_dynlink_get_bytecode_sections -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-check-prim/unix-win32.output5 b/compiler/tests-check-prim/unix-win32.output5 index 7db584011..b45443271 100644 --- a/compiler/tests-check-prim/unix-win32.output5 +++ b/compiler/tests-check-prim/unix-win32.output5 @@ -5,14 +5,8 @@ From unix.bc: caml_alloc_dummy_function caml_continuation_use caml_drop_continuation -caml_dynlink_add_primitive -caml_dynlink_close_lib -caml_dynlink_get_current_libs -caml_dynlink_lookup_symbol -caml_dynlink_open_lib caml_int_as_pointer caml_reset_afl_instrumentation -caml_signbit caml_unix_accept caml_unix_access caml_unix_bind @@ -91,7 +85,6 @@ caml_unix_waitpid caml_unix_write caml_unix_write_bigarray debugger -is_digit_normalized Unused ------- @@ -111,9 +104,6 @@ caml_bigstring_blit_string_to_ba caml_bigstring_memcmp caml_hash_mix_bigstring -From +domain.js: -caml_ml_domain_set_name - From +effect.js: jsoo_effect_not_supported @@ -124,14 +114,6 @@ caml_fs_init jsoo_create_file jsoo_create_file_extern -From +gc.js: -caml_eventlog_pause -caml_eventlog_resume -caml_gc_huge_fallback_count -caml_get_major_bucket -caml_get_major_credit -caml_memprof_set - From +graphics.js: caml_gr_arc_aux caml_gr_blit_image @@ -193,7 +175,6 @@ caml_wrap_exception From +marshal.js: BigStringReader -caml_input_value_from_string caml_marshal_constants From +mlBytes.js: @@ -201,21 +182,8 @@ caml_array_of_bytes caml_array_of_string caml_bytes_of_utf16_jsstring caml_string_concat -caml_string_set16 -caml_string_set32 -caml_string_set64 -caml_string_unsafe_set caml_to_js_string -From +nat.js: -compare_nat_real - -From +obj.js: -caml_obj_is_block -caml_obj_make_forward -caml_obj_set_tag -caml_obj_truncate - From +runtime_events.js: caml_runtime_events_create_cursor caml_runtime_events_free_cursor @@ -229,33 +197,15 @@ caml_maybe_print_stats caml_register_global jsoo_toplevel_reloc -From +str.js: -caml_str_initialize -re_match -re_partial_match -re_replacement_text -re_search_backward -re_search_forward -re_string_match - From +sys.js: caml_fatal_uncaught_exception caml_format_exception caml_is_special_exception -caml_register_channel_for_spacetime caml_set_static_env -caml_spacetime_enabled -caml_spacetime_only_works_for_native_code caml_sys_const_naked_pointers_checked From +toplevel.js: caml_get_section_table -caml_static_alloc -caml_static_free -caml_terminfo_backup -caml_terminfo_resume -caml_terminfo_setup -caml_terminfo_standout jsoo_toplevel_init_compile jsoo_toplevel_init_reloc diff --git a/compiler/tests-compiler/direct_calls.ml b/compiler/tests-compiler/direct_calls.ml index eac493b74..e458e8391 100644 --- a/compiler/tests-compiler/direct_calls.ml +++ b/compiler/tests-compiler/direct_calls.ml @@ -84,8 +84,8 @@ let%expect_test "direct calls without --enable effects" = //end function test3(x){ function F(symbol){function f(x){return x + 1 | 0;} return [0, f];} - var M1 = F([0]), M2 = F([0]), _b_ = (0, M2[1])(2); - return [0, (0, M1[1])(1), _b_]; + var M1 = F([0]), M2 = F([0]), _b_ = M2[1].call(null, 2); + return [0, M1[1].call(null, 1), _b_]; } //end function test4(x){ @@ -94,11 +94,10 @@ let%expect_test "direct calls without --enable effects" = return [0, f]; } var M1 = F([0]), M2 = F([0]); - (0, M1[1])(1); - return (0, M2[1])(2); + M1[1].call(null, 1); + return M2[1].call(null, 2); } - //end - |}] + //end |}] let%expect_test "direct calls with --enable effects" = let code = @@ -179,8 +178,8 @@ let%expect_test "direct calls with --enable effects" = //end function test3(x, cont){ function F(symbol){function f(x){return x + 1 | 0;} return [0, f];} - var M1 = F(), M2 = F(), _c_ = (0, M2[1])(2); - return cont([0, (0, M1[1])(1), _c_]); + var M1 = F(), M2 = F(), _c_ = M2[1].call(null, 2); + return cont([0, M1[1].call(null, 1), _c_]); } //end function test4(x, cont){ diff --git a/compiler/tests-compiler/dune.inc b/compiler/tests-compiler/dune.inc index 4524092ab..4a4f76bf4 100644 --- a/compiler/tests-compiler/dune.inc +++ b/compiler/tests-compiler/dune.inc @@ -659,6 +659,36 @@ (preprocess (pps ppx_expect))) +(library + ;; compiler/tests-compiler/rec.ml + (name rec_15) + (enabled_if %{env:js-enabled=}) + (modules rec) + (libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper) + (inline_tests + (enabled_if (< %{ocaml_version} 5.2)) + (deps + (file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe) + (file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe))) + (flags (:standard -open Jsoo_compiler_expect_tests_helper)) + (preprocess + (pps ppx_expect))) + +(library + ;; compiler/tests-compiler/rec52.ml + (name rec52_15) + (enabled_if %{env:js-enabled=}) + (modules rec52) + (libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper) + (inline_tests + (enabled_if (>= %{ocaml_version} 5.2)) + (deps + (file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe) + (file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe))) + (flags (:standard -open Jsoo_compiler_expect_tests_helper)) + (preprocess + (pps ppx_expect))) + (library ;; compiler/tests-compiler/scopes.ml (name scopes_15) diff --git a/compiler/tests-compiler/gen-rules/gen.ml b/compiler/tests-compiler/gen-rules/gen.ml index ef0415518..bee62eb18 100644 --- a/compiler/tests-compiler/gen-rules/gen.ml +++ b/compiler/tests-compiler/gen-rules/gen.ml @@ -47,6 +47,8 @@ let prefix : string = type enabled_if = | GE5 + | GE52 + | LT52 | B64 | Any @@ -58,12 +60,15 @@ let lib_enabled_if = function let test_enabled_if = function | "obj" | "lazy" -> GE5 | "gh1051" -> B64 + | "rec52" -> GE52 + | "rec" -> LT52 | _ -> Any -let enabled_if cond = - match cond with +let enabled_if = function | Any -> "true" | GE5 -> "(>= %{ocaml_version} 5)" + | GE52 -> "(>= %{ocaml_version} 5.2)" + | LT52 -> "(< %{ocaml_version} 5.2)" | B64 -> "%{arch_sixtyfour}" let js_enabled = function diff --git a/compiler/tests-compiler/rec.ml b/compiler/tests-compiler/rec.ml new file mode 100644 index 000000000..a5085f4ef --- /dev/null +++ b/compiler/tests-compiler/rec.ml @@ -0,0 +1,83 @@ +(* Js_of_ocaml compiler + * http://www.ocsigen.org/js_of_ocaml/ + * Copyright (C) 2024 Hugo Heuzard + * + * 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. + *) + +open Util + +let%expect_test "let rec" = + let p = + {| + let rec a x = + (* syntactic function *) + b x + and b = + (* non-syntactic function *) + let tbl : (int, int) Hashtbl.t = Hashtbl.create 17 in + fun x -> `T (tbl, c, a 0) + and c = + (* block *) + Some (d, default) + and d = + (* 'dynamic' value (not recursive *) + Array.make 5 0 + and default = + (* constant, with (spurious) use + of a recursive neighbor *) + let _ = a in + 42 + |} + in + let p = compile_and_parse p in + print_program p; + [%expect + {| + (function(globalThis){ + "use strict"; + var + runtime = globalThis.jsoo_runtime, + caml_update_dummy = runtime.caml_update_dummy; + function caml_call1(f, a0){ + return (f.l >= 0 ? f.l : f.l = f.length) === 1 + ? f(a0) + : runtime.caml_call_gen(f, [a0]); + } + function caml_call2(f, a0, a1){ + return (f.l >= 0 ? f.l : f.l = f.length) === 2 + ? f(a0, a1) + : runtime.caml_call_gen(f, [a0, a1]); + } + var + global_data = runtime.caml_get_global_data(), + Stdlib_Hashtbl = global_data.Stdlib__Hashtbl, + a = function _d_(_c_){return _d_.fun(_c_);}, + b = function _b_(_a_){return _b_.fun(_a_);}, + c = [], + d = runtime.caml_make_vect(5, 0), + default$0 = 42; + caml_update_dummy(a, function(x){return caml_call1(b, x);}); + var tbl = caml_call2(Stdlib_Hashtbl[1], 0, 17); + caml_update_dummy + (b, function(x){return [0, 84, [0, tbl, c, caml_call1(a, 0)]];}); + caml_update_dummy(c, [0, [0, d, default$0]]); + var Test = [0, a, b, c, d, default$0]; + runtime.caml_register_global(1, Test, "Test"); + return; + } + (globalThis)); + //end + |}] diff --git a/compiler/tests-compiler/rec52.ml b/compiler/tests-compiler/rec52.ml new file mode 100644 index 000000000..18d766eea --- /dev/null +++ b/compiler/tests-compiler/rec52.ml @@ -0,0 +1,80 @@ +(* Js_of_ocaml compiler + * http://www.ocsigen.org/js_of_ocaml/ + * Copyright (C) 2024 Hugo Heuzard + * + * 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. + *) + +open Util + +let%expect_test "let rec" = + let p = + {| + let rec a x = + (* syntactic function *) + b x + and b = + (* non-syntactic function *) + let tbl : (int, int) Hashtbl.t = Hashtbl.create 17 in + fun x -> `T (tbl, c, a 0) + and c = + (* block *) + Some (d, default) + and d = + (* 'dynamic' value (not recursive *) + Array.make 5 0 + and default = + (* constant, with (spurious) use + of a recursive neighbor *) + let _ = a in + 42 + |} + in + let p = compile_and_parse p in + print_program p; + [%expect + {| + (function(globalThis){ + "use strict"; + var + runtime = globalThis.jsoo_runtime, + caml_update_dummy = runtime.caml_update_dummy; + function caml_call2(f, a0, a1){ + return (f.l >= 0 ? f.l : f.l = f.length) === 2 + ? f(a0, a1) + : runtime.caml_call_gen(f, [a0, a1]); + } + var + global_data = runtime.caml_get_global_data(), + Stdlib_Hashtbl = global_data.Stdlib__Hashtbl, + letrec_function_context = [], + c = [], + d = runtime.caml_make_vect(5, 0), + default$0 = 42; + function a(x){return b(x);} + function b(x){ + var _a_ = b(0); + return [0, 84, [0, letrec_function_context[1], c, _a_]]; + } + var tbl = caml_call2(Stdlib_Hashtbl[1], 0, 17); + caml_update_dummy(letrec_function_context, [0, tbl]); + caml_update_dummy(c, [0, [0, d, default$0]]); + var Test = [0, a, b, c, d, default$0]; + runtime.caml_register_global(1, Test, "Test"); + return; + } + (globalThis)); + //end + |}] diff --git a/dune-project b/dune-project index 9a564c6bb..6be93f23c 100644 --- a/dune-project +++ b/dune-project @@ -24,12 +24,12 @@ (ppxlib (>= 0.15.0)) (re :with-test) (cmdliner (>= 1.1.0)) - (sedlex (>= 2.3)) + (sedlex (>= 3.3)) (qcheck :with-test) menhir menhirLib menhirSdk - yojson) + (yojson (>= 1.6))) (depopts ocamlfind) (conflicts diff --git a/js_of_ocaml-compiler.opam b/js_of_ocaml-compiler.opam index 273a95508..8eb65727b 100644 --- a/js_of_ocaml-compiler.opam +++ b/js_of_ocaml-compiler.opam @@ -19,12 +19,12 @@ depends: [ "ppxlib" {>= "0.15.0"} "re" {with-test} "cmdliner" {>= "1.1.0"} - "sedlex" {>= "2.3"} + "sedlex" {>= "3.3"} "qcheck" {with-test} "menhir" "menhirLib" "menhirSdk" - "yojson" + "yojson" {>= "1.6"} "odoc" {with-doc} ] depopts: ["ocamlfind"] diff --git a/lib/js_of_ocaml/dom_html.ml b/lib/js_of_ocaml/dom_html.ml index a58215b44..ed556ee03 100644 --- a/lib/js_of_ocaml/dom_html.ml +++ b/lib/js_of_ocaml/dom_html.ml @@ -452,6 +452,14 @@ and clipboardEvent = object method clipboardData : dataTransfer t readonly_prop end +and toggleEvent = object + inherit event + + method newState : js_string t readonly_prop + + method oldState : js_string t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -959,6 +967,8 @@ module Event = struct let waiting = Dom.Event.make "waiting" + let toggle = Dom.Event.make "toggle" + let make = Dom.Event.make end @@ -1372,6 +1382,16 @@ class type anchorElement = object method _type : js_string t prop end +class type detailsElement = object ('self) + inherit element + + method open_ : bool t prop + + method name : js_string t prop + + method ontoggle : ('self t, toggleEvent t) event_listener prop +end + class type imageElement = object ('self) inherit element @@ -2736,6 +2756,8 @@ module CoerceTo = struct let del e = unsafeCoerce "del" e + let details e = unsafeCoerce "details" e + let div e = unsafeCoerce "div" e let dl e = unsafeCoerce "dl" e diff --git a/lib/js_of_ocaml/dom_html.mli b/lib/js_of_ocaml/dom_html.mli index 000778d8b..5e00793cd 100644 --- a/lib/js_of_ocaml/dom_html.mli +++ b/lib/js_of_ocaml/dom_html.mli @@ -458,6 +458,14 @@ and clipboardEvent = object method clipboardData : dataTransfer t readonly_prop end +and toggleEvent = object + inherit event + + method newState : js_string t readonly_prop + + method oldState : js_string t readonly_prop +end + and dataTransfer = object method dropEffect : js_string t prop @@ -1190,6 +1198,16 @@ class type anchorElement = object method _type : js_string t prop end +class type detailsElement = object ('self) + inherit element + + method open_ : bool t prop + + method name : js_string t prop + + method ontoggle : ('self t, toggleEvent t) event_listener prop +end + class type imageElement = object ('self) inherit element @@ -2503,6 +2521,8 @@ module Event : sig val waiting : mediaEvent t typ + val toggle : toggleEvent t typ + val make : string -> 'a typ end @@ -3048,6 +3068,8 @@ module CoerceTo : sig val del : #element t -> modElement t opt + val details : #element t -> detailsElement t opt + val div : #element t -> divElement t opt val embed : #element t -> embedElement t opt diff --git a/lib/js_of_ocaml/js.ml b/lib/js_of_ocaml/js.ml index d432e8319..8a5ccdece 100644 --- a/lib/js_of_ocaml/js.ml +++ b/lib/js_of_ocaml/js.ml @@ -812,17 +812,16 @@ let parseFloat (s : js_string t) : number_t = let s = Unsafe.fun_call Unsafe.global##.parseFloat [| Unsafe.inject s |] in if isNaN s then failwith "parseFloat" else s -let _ = - Printexc.register_printer (function - | Js_error.Exn e -> Some (Js_error.to_string e) - | _ -> None) - let _ = Printexc.register_printer (fun e -> - let e : < .. > t = Obj.magic e in - if instanceof e error_constr - then Some (Js_error.to_string (Js_error.of_error e)) - else None) + if instanceof (Obj.magic e : < .. > t) error_constr + then + let e = Js_error.of_error (Obj.magic e : error t) in + Some (Js_error.to_string e) + else + match e with + | Js_error.Exn e -> Some (Js_error.to_string e) + | _ -> None) let export_js (field : js_string t) x = Unsafe.set diff --git a/lib/js_of_ocaml/sys_js.mli b/lib/js_of_ocaml/sys_js.mli index 0c06137ac..02f146e52 100644 --- a/lib/js_of_ocaml/sys_js.mli +++ b/lib/js_of_ocaml/sys_js.mli @@ -54,7 +54,7 @@ val read_file : name:string -> string val create_file : name:string -> content:string -> unit (** Register a file to a Pseudo Filesystem. [create_file ~name ~content] register the file [name] with content [content] - so it can be be opened with [open_in name] *) + so it can be opened with [open_in name] *) val update_file : name:string -> content:string -> unit (** Update a file in the Pseudo Filesystem. diff --git a/lib/tyxml/tyxml_cast.ml b/lib/tyxml/tyxml_cast.ml index 53c21ffec..9e3cad874 100644 --- a/lib/tyxml/tyxml_cast.ml +++ b/lib/tyxml/tyxml_cast.ml @@ -79,6 +79,8 @@ end) : Tyxml_cast_sigs.TO with type 'a elt = 'a C.elt = struct let of_li elt = rebuild_node "of_li" elt + let of_details elt = rebuild_node "of_details" elt + let of_dialog elt = rebuild_node "of_dialog" elt let of_div elt = rebuild_node "of_div" elt @@ -177,8 +179,6 @@ end) : Tyxml_cast_sigs.TO with type 'a elt = 'a C.elt = struct let of_dd elt = rebuild_node "of_dd" elt - let of_details elt = rebuild_node "of_details" elt - let of_dfn elt = rebuild_node "of_dfn" elt let of_dt elt = rebuild_node "of_dt" elt @@ -311,6 +311,8 @@ end) : Tyxml_cast_sigs.OF with type 'a elt = 'a C.elt = struct let of_li elt = rebuild_node "of_li" elt + let of_details elt = rebuild_node "of_details" elt + let of_dialog elt = rebuild_node "of_dialog" elt let of_div elt = rebuild_node "of_div" elt diff --git a/lib/tyxml/tyxml_cast_sigs.ml b/lib/tyxml/tyxml_cast_sigs.ml index 08d8605ce..a6ea2b76c 100644 --- a/lib/tyxml/tyxml_cast_sigs.ml +++ b/lib/tyxml/tyxml_cast_sigs.ml @@ -71,6 +71,8 @@ module type OF = sig val of_li : Dom_html.liElement Js.t -> [> Html_types.li ] elt + val of_details : Dom_html.detailsElement Js.t -> [> Html_types.details ] elt + val of_dialog : Dom_html.dialogElement Js.t -> [> Html_types.dialog ] elt val of_div : Dom_html.divElement Js.t -> [> Html_types.div ] elt @@ -182,6 +184,8 @@ module type TO = sig val of_li : [< Html_types.li ] elt -> Dom_html.liElement Js.t + val of_details : [< Html_types.details ] elt -> Dom_html.detailsElement Js.t + val of_dialog : [< Html_types.dialog ] elt -> Dom_html.dialogElement Js.t val of_div : [< Html_types.div ] elt -> Dom_html.divElement Js.t @@ -280,8 +284,6 @@ module type TO = sig val of_dd : [> Html_types.dd ] elt -> Dom_html.element Js.t - val of_details : [> Html_types.details ] elt -> Dom_html.element Js.t - val of_dfn : [> Html_types.dfn ] elt -> Dom_html.element Js.t val of_dt : [> Html_types.dt ] elt -> Dom_html.element Js.t diff --git a/lib/tyxml/tyxml_cast_sigs.mli b/lib/tyxml/tyxml_cast_sigs.mli index 42007a2ec..a09731674 100644 --- a/lib/tyxml/tyxml_cast_sigs.mli +++ b/lib/tyxml/tyxml_cast_sigs.mli @@ -70,6 +70,8 @@ module type OF = sig val of_li : Dom_html.liElement Js.t -> [> Html_types.li ] elt + val of_details : Dom_html.detailsElement Js.t -> [> Html_types.details ] elt + val of_dialog : Dom_html.dialogElement Js.t -> [> Html_types.dialog ] elt val of_div : Dom_html.divElement Js.t -> [> Html_types.div ] elt @@ -181,6 +183,8 @@ module type TO = sig val of_li : [< Html_types.li ] elt -> Dom_html.liElement Js.t + val of_details : [< Html_types.details ] elt -> Dom_html.detailsElement Js.t + val of_dialog : [< Html_types.dialog ] elt -> Dom_html.dialogElement Js.t val of_div : [< Html_types.div ] elt -> Dom_html.divElement Js.t @@ -279,8 +283,6 @@ module type TO = sig val of_dd : [> Html_types.dd ] elt -> Dom_html.element Js.t - val of_details : [> Html_types.details ] elt -> Dom_html.element Js.t - val of_dfn : [> Html_types.dfn ] elt -> Dom_html.element Js.t val of_dt : [> Html_types.dt ] elt -> Dom_html.element Js.t diff --git a/runtime/array.js b/runtime/js/array.js similarity index 78% rename from runtime/array.js rename to runtime/js/array.js index e276c1e40..280abb551 100644 --- a/runtime/array.js +++ b/runtime/js/array.js @@ -34,6 +34,13 @@ function caml_floatarray_sub(a, i, len) { return caml_array_sub(a, i, len); } +//Provides: caml_uniform_array_sub mutable +//Requires: caml_array_sub +//Version: >= 5.3 +function caml_uniform_array_sub(a, i, len) { + return caml_array_sub(a, i, len); +} + //Provides: caml_array_append mutable function caml_array_append(a1, a2) { var l1 = a1.length, @@ -55,6 +62,13 @@ function caml_floatarray_append(a1, a2) { return caml_array_append(a1, a2); } +//Provides: caml_uniform_array_append mutable +//Requires: caml_array_append +//Version: >= 5.3 +function caml_uniform_array_append(a1, a2) { + return caml_array_append(a1, a2); +} + //Provides: caml_array_concat mutable function caml_array_concat(l) { var a = [0]; @@ -82,6 +96,13 @@ function caml_floatarray_blit(a1, i1, a2, i2, len) { return caml_array_blit(a1, i1, a2, i2, len); } +//Provides: caml_uniform_array_blit +//Requires: caml_array_blit +//Version: >= 5.3 +function caml_uniform_array_blit(a1, i1, a2, i2, len) { + return caml_array_blit(a1, i1, a2, i2, len); +} + ///////////// Pervasive //Provides: caml_array_set (mutable, const, mutable) //Requires: caml_array_bound_error @@ -113,6 +134,20 @@ function caml_floatarray_fill(array, ofs, len, v) { return caml_array_fill(array, ofs, len, v); } +//Provides: caml_floatarray_fill_unboxed +//Requires: caml_array_fill +//Version: >= 5.3 +function caml_floatarray_fill_unboxed(array, ofs, len, v) { + return caml_array_fill(array, ofs, len, v); +} + +//Provides: caml_uniform_array_fill +//Requires: caml_array_fill +//Version: >= 5.3 +function caml_uniform_array_fill(array, ofs, len, v) { + return caml_array_fill(array, ofs, len, v); +} + //Provides: caml_check_bound (mutable, const) //Requires: caml_array_bound_error function caml_check_bound(array, index) { @@ -176,3 +211,17 @@ function caml_floatarray_create(len) { function caml_floatarray_make(len, init) { return caml_array_make(len, init); } + +//Provides: caml_floatarray_make_unboxed const (const) +//Requires: caml_array_make +//Version: >= 5.3 +function caml_floatarray_make_unboxed(len, init) { + return caml_array_make(len, init); +} + +//Provides: caml_uniform_array_make const (const) +//Requires: caml_array_make +//Version: >= 5.3 +function caml_uniform_array_make(len, init) { + return caml_array_make(len, init); +} diff --git a/runtime/backtrace.js b/runtime/js/backtrace.js similarity index 100% rename from runtime/backtrace.js rename to runtime/js/backtrace.js diff --git a/runtime/bigarray.js b/runtime/js/bigarray.js similarity index 100% rename from runtime/bigarray.js rename to runtime/js/bigarray.js diff --git a/runtime/bigstring.js b/runtime/js/bigstring.js similarity index 100% rename from runtime/bigstring.js rename to runtime/js/bigstring.js diff --git a/runtime/blake2.js b/runtime/js/blake2.js similarity index 89% rename from runtime/blake2.js rename to runtime/js/blake2.js index ca17a471b..e7661230c 100644 --- a/runtime/blake2.js +++ b/runtime/js/blake2.js @@ -326,7 +326,7 @@ function caml_blake2_final(ctx, hashlen) { //Provides: caml_blake2_update //Requires: blake2b //Requires: caml_uint8_array_of_string -//Version: >= 5.2 +//Version: >= 5.2, < 5.3 function caml_blake2_update(ctx, buf, ofs, len) { var input = caml_uint8_array_of_string(buf); input = input.subarray(ofs, ofs + len); @@ -334,13 +334,48 @@ function caml_blake2_update(ctx, buf, ofs, len) { return 0; } +//Provides: caml_blake2_update +//Requires: blake2b +//Requires: caml_uint8_array_of_bytes +//Version: >= 5.3 +function caml_blake2_update(ctx, buf, ofs, len) { + var input = caml_uint8_array_of_bytes(buf); + input = input.subarray(ofs, ofs + len); + blake2b.Update(ctx, input); + return 0; +} + //Provides: caml_blake2_string //Requires: caml_blake2_create //Requires: caml_blake2_update //Requires: caml_blake2_final -//Version: >= 5.2 +//Version: >= 5.2, < 5.3 function caml_blake2_string(hashlen, key, buf, ofs, len) { var ctx = caml_blake2_create(hashlen, key); caml_blake2_update(ctx, buf, ofs, len); return caml_blake2_final(ctx, hashlen); } + +//Provides: caml_blake2_string +//Requires: caml_blake2_create +//Requires: caml_blake2_update +//Requires: caml_blake2_final +//Requires: caml_bytes_of_string +//Version: >= 5.3 +function caml_blake2_string(hashlen, key, buf_str, ofs, len) { + var ctx = caml_blake2_create(hashlen, key); + var buf = caml_bytes_of_string(buf_str); + caml_blake2_update(ctx, buf, ofs, len); + return caml_blake2_final(ctx, hashlen); +} + +//Provides: caml_blake2_bytes +//Requires: caml_blake2_create +//Requires: caml_blake2_update +//Requires: caml_blake2_final +//Version: >= 5.3 +function caml_blake2_bytes(hashlen, key, buf, ofs, len) { + var ctx = caml_blake2_create(hashlen, key); + caml_blake2_update(ctx, buf, ofs, len); + return caml_blake2_final(ctx, hashlen); +} diff --git a/runtime/compare.js b/runtime/js/compare.js similarity index 99% rename from runtime/compare.js rename to runtime/js/compare.js index 609e2e613..315d76f90 100644 --- a/runtime/compare.js +++ b/runtime/js/compare.js @@ -61,7 +61,7 @@ function caml_compare_val_number_custom(num, custom, swap, total) { if (comp) { var x = swap > 0 ? comp(custom, num, total) : comp(num, custom, total); if (total && Number.isNaN(x)) return swap; // total && nan - if (Number.isNan(+x)) return +x; // nan + if (Number.isNaN(+x)) return +x; // nan if ((x | 0) !== 0) return x | 0; // !nan } return swap; diff --git a/runtime/domain.js b/runtime/js/domain.js similarity index 91% rename from runtime/domain.js rename to runtime/js/domain.js index d441b2d0d..e2808c306 100644 --- a/runtime/domain.js +++ b/runtime/js/domain.js @@ -1,8 +1,10 @@ //Provides: caml_domain_dls +//Version: >= 5 var caml_domain_dls = [0]; //Provides: caml_domain_dls_set //Requires: caml_domain_dls +//Version: >= 5 function caml_domain_dls_set(a) { caml_domain_dls = a; } @@ -18,16 +20,19 @@ function caml_domain_dls_compare_and_set(old, n) { //Provides: caml_domain_dls_get //Requires: caml_domain_dls +//Version: >= 5 function caml_domain_dls_get(unit) { return caml_domain_dls; } //Provides: caml_atomic_load +//Version: >= 5 function caml_atomic_load(ref) { return ref[1]; } //Provides: caml_atomic_cas +//Version: >= 5 function caml_atomic_cas(ref, o, n) { if (ref[1] === o) { ref[1] = n; @@ -37,6 +42,7 @@ function caml_atomic_cas(ref, o, n) { } //Provides: caml_atomic_fetch_add +//Version: >= 5 function caml_atomic_fetch_add(ref, i) { var old = ref[1]; ref[1] += i; @@ -44,6 +50,7 @@ function caml_atomic_fetch_add(ref, i) { } //Provides: caml_atomic_exchange +//Version: >= 5 function caml_atomic_exchange(ref, v) { var r = ref[1]; ref[1] = v; @@ -51,23 +58,20 @@ function caml_atomic_exchange(ref, v) { } //Provides: caml_atomic_make_contended +//Version: >= 5.2 function caml_atomic_make_contended(a) { return [0, a]; } //Provides: caml_ml_domain_unique_token -//Version: < 5.2 +//Version: >= 5.0, < 5.2 var caml_ml_domain_unique_token_ = [0]; function caml_ml_domain_unique_token(unit) { return caml_ml_domain_unique_token_; } -//Provides: caml_ml_domain_set_name -function caml_ml_domain_set_name(_name) { - return 0; -} - //Provides: caml_recommended_domain_count +//Version: >= 5 function caml_recommended_domain_count(unit) { return 1; } @@ -80,6 +84,7 @@ function caml_ml_domain_index(unit) { } //Provides: caml_domain_id +//Version: >= 5 var caml_domain_id = 0; //Provides: caml_domain_spawn @@ -104,7 +109,7 @@ function caml_domain_spawn(f, term_sync) { //Requires: caml_ml_mutex_unlock //Requires: caml_domain_id //Requires: caml_callback -//Version: < 5.2 +//Version: >= 5.0, < 5.2 var caml_domain_latest_idx = 1; function caml_domain_spawn(f, mutex) { var id = caml_domain_latest_idx++; @@ -118,11 +123,13 @@ function caml_domain_spawn(f, mutex) { //Provides: caml_ml_domain_id //Requires: caml_domain_id +//Version: >= 5.0 function caml_ml_domain_id(unit) { return caml_domain_id; } //Provides: caml_ml_domain_cpu_relax +//Version: >= 5 function caml_ml_domain_cpu_relax(unit) { return 0; } diff --git a/runtime/dune b/runtime/js/dune similarity index 100% rename from runtime/dune rename to runtime/js/dune diff --git a/runtime/dynlink.js b/runtime/js/dynlink.js similarity index 98% rename from runtime/dynlink.js rename to runtime/js/dynlink.js index 064827861..5f0f1dba4 100644 --- a/runtime/dynlink.js +++ b/runtime/js/dynlink.js @@ -73,16 +73,19 @@ function caml_dynlink_get_current_libs() { } //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/effect.js b/runtime/js/effect.js similarity index 97% rename from runtime/effect.js rename to runtime/js/effect.js index d80a44493..3856e76bf 100644 --- a/runtime/effect.js +++ b/runtime/js/effect.js @@ -130,6 +130,7 @@ function caml_perform_effect(eff, cont, k0) { //Provides: caml_alloc_stack //Requires: caml_pop_fiber, caml_fiber_stack, caml_call_gen, caml_stack_check_depth, caml_trampoline_return //If: effects +//Version: >= 5.0 function caml_alloc_stack(hv, hx, hf) { function call(i, x) { var f = caml_fiber_stack.h[i]; @@ -151,11 +152,13 @@ function caml_alloc_stack(hv, hx, hf) { //Provides: caml_alloc_stack //If: !effects +//Version: >= 5.0 function caml_alloc_stack(hv, hx, hf) { return 0; } //Provides: caml_continuation_use_noexc +//Version: >= 5.0 function caml_continuation_use_noexc(cont) { var stack = cont[1]; cont[1] = 0; @@ -164,6 +167,7 @@ function caml_continuation_use_noexc(cont) { //Provides: caml_continuation_use_and_update_handler_noexc //Requires: caml_continuation_use_noexc +//Version: >= 5.0 function caml_continuation_use_and_update_handler_noexc( cont, hval, @@ -176,26 +180,31 @@ function caml_continuation_use_and_update_handler_noexc( } //Provides: caml_get_continuation_callstack +//Version: >= 5.0 function caml_get_continuation_callstack() { return [0]; } //Provides: caml_ml_condition_new +//Version: >= 5.0 function caml_ml_condition_new(unit) { return { condition: 1 }; } //Provides: caml_ml_condition_wait +//Version: >= 5.0 function caml_ml_condition_wait(t, mutext) { return 0; } //Provides: caml_ml_condition_broadcast +//Version: >= 5.0 function caml_ml_condition_broadcast(t) { return 0; } //Provides: caml_ml_condition_signal +//Version: >= 5.0 function caml_ml_condition_signal(t) { return 0; } diff --git a/runtime/fail.js b/runtime/js/fail.js similarity index 100% rename from runtime/fail.js rename to runtime/js/fail.js diff --git a/runtime/format.js b/runtime/js/format.js similarity index 100% rename from runtime/format.js rename to runtime/js/format.js diff --git a/runtime/fs.js b/runtime/js/fs.js similarity index 100% rename from runtime/fs.js rename to runtime/js/fs.js diff --git a/runtime/fs_fake.js b/runtime/js/fs_fake.js similarity index 100% rename from runtime/fs_fake.js rename to runtime/js/fs_fake.js diff --git a/runtime/fs_node.js b/runtime/js/fs_node.js similarity index 100% rename from runtime/fs_node.js rename to runtime/js/fs_node.js diff --git a/runtime/gc.js b/runtime/js/gc.js similarity index 95% rename from runtime/gc.js rename to runtime/js/gc.js index b531156f5..3692f8997 100644 --- a/runtime/gc.js +++ b/runtime/js/gc.js @@ -52,6 +52,7 @@ function caml_gc_get() { } //Provides: caml_memprof_set +//Version: = 4.10 function caml_memprof_set(_control) { return 0; } @@ -92,21 +93,25 @@ function caml_memprof_stop(unit) { } //Provides: caml_memprof_discard +//Version: >= 5.2 function caml_memprof_discard(t) { return 0; } //Provides: caml_eventlog_resume +//Version: < 5.0 function caml_eventlog_resume(unit) { return 0; } //Provides: caml_eventlog_pause +//Version: < 5.0 function caml_eventlog_pause(unit) { return 0; } //Provides: caml_gc_huge_fallback_count +//Version: < 5.0 function caml_gc_huge_fallback_count(unit) { return 0; } @@ -127,11 +132,13 @@ function caml_get_minor_free(unit) { } //Provides: caml_get_major_bucket +//Version: < 5.0 function caml_get_major_bucket(n) { return 0; } //Provides: caml_get_major_credit +//Version: < 5.0 function caml_get_major_credit(n) { return 0; } diff --git a/runtime/graphics.js b/runtime/js/graphics.js similarity index 100% rename from runtime/graphics.js rename to runtime/js/graphics.js diff --git a/runtime/hash.js b/runtime/js/hash.js similarity index 99% rename from runtime/hash.js rename to runtime/js/hash.js index d20ee1498..61f7b617a 100644 --- a/runtime/hash.js +++ b/runtime/js/hash.js @@ -275,6 +275,7 @@ function caml_hash(count, limit, seed, obj) { //Provides: caml_string_hash //Requires: caml_hash_mix_final, caml_hash_mix_string +//Version: >= 5.0 function caml_string_hash(h, v) { var h = caml_hash_mix_string(h, v); var h = caml_hash_mix_final(h); diff --git a/runtime/ieee_754.js b/runtime/js/ieee_754.js similarity index 99% rename from runtime/ieee_754.js rename to runtime/js/ieee_754.js index aa657f8c5..96491ec15 100644 --- a/runtime/ieee_754.js +++ b/runtime/js/ieee_754.js @@ -281,6 +281,7 @@ function caml_copysign_float(x, y) { } //Provides: caml_signbit_float const +//Alias: caml_signbit function caml_signbit_float(x) { if (x === 0) x = 1 / x; return x < 0 ? 1 : 0; diff --git a/runtime/int64.js b/runtime/js/int64.js similarity index 100% rename from runtime/int64.js rename to runtime/js/int64.js diff --git a/runtime/internalMod.js b/runtime/js/internalMod.js similarity index 100% rename from runtime/internalMod.js rename to runtime/js/internalMod.js diff --git a/runtime/ints.js b/runtime/js/ints.js similarity index 100% rename from runtime/ints.js rename to runtime/js/ints.js diff --git a/runtime/io.js b/runtime/js/io.js similarity index 99% rename from runtime/io.js rename to runtime/js/io.js index 35182f876..3a56fbd1b 100644 --- a/runtime/io.js +++ b/runtime/js/io.js @@ -338,6 +338,7 @@ function caml_ml_input(chanid, b, i, l) { //Provides: caml_ml_input_bigarray //Requires: caml_ml_input_block //Requires: caml_ba_to_typed_array +//Version: >= 5.2 function caml_ml_input_bigarray(chanid, b, i, l) { var ba = caml_ba_to_typed_array(b); return caml_ml_input_block(chanid, ba, i, l); @@ -405,6 +406,7 @@ function caml_input_value(chanid) { //Provides: caml_input_value_to_outside_heap //Requires: caml_input_value +//Version: >= 5 function caml_input_value_to_outside_heap(c) { return caml_input_value(c); } @@ -584,6 +586,7 @@ function caml_ml_output_bytes(chanid, buffer, offset, len) { //Provides: caml_ml_output_bigarray //Requires: caml_ba_to_typed_array, caml_ml_output_ta +//Version: >= 5.2 function caml_ml_output_bigarray(chanid, buffer, offset, len) { var buffer = caml_ba_to_typed_array(buffer); return caml_ml_output_ta(chanid, buffer, offset, len); diff --git a/runtime/jslib.js b/runtime/js/jslib.js similarity index 100% rename from runtime/jslib.js rename to runtime/js/jslib.js diff --git a/runtime/jslib_js_of_ocaml.js b/runtime/js/jslib_js_of_ocaml.js similarity index 100% rename from runtime/jslib_js_of_ocaml.js rename to runtime/js/jslib_js_of_ocaml.js diff --git a/runtime/lexing.js b/runtime/js/lexing.js similarity index 100% rename from runtime/lexing.js rename to runtime/js/lexing.js diff --git a/runtime/marshal.js b/runtime/js/marshal.js similarity index 99% rename from runtime/marshal.js rename to runtime/js/marshal.js index ddb93f6f9..7e4aec531 100644 --- a/runtime/marshal.js +++ b/runtime/js/marshal.js @@ -233,6 +233,7 @@ function caml_float_of_bytes(a) { //Provides: caml_input_value_from_string mutable //Requires: MlStringReader, caml_input_value_from_reader +//Version: < 4.12 function caml_input_value_from_string(s, ofs) { var reader = new MlStringReader(s, typeof ofs === "number" ? ofs : ofs[0]); return caml_input_value_from_reader(reader, ofs); diff --git a/runtime/md5.js b/runtime/js/md5.js similarity index 100% rename from runtime/md5.js rename to runtime/js/md5.js diff --git a/runtime/mlBytes.js b/runtime/js/mlBytes.js similarity index 95% rename from runtime/mlBytes.js rename to runtime/js/mlBytes.js index fe7e7f9c3..a39ae3a10 100644 --- a/runtime/mlBytes.js +++ b/runtime/js/mlBytes.js @@ -353,20 +353,6 @@ function caml_bytes_set16(s, i, i16) { return 0; } -//Provides: caml_string_set16 -//Requires: caml_failwith -//If: js-string -function caml_string_set16(s, i, i16) { - caml_failwith("caml_string_set16"); -} - -//Provides: caml_string_set16 -//Requires: caml_bytes_set16 -//If: !js-string -function caml_string_set16(s, i, i16) { - return caml_bytes_set16(s, i, i16); -} - //Provides: caml_bytes_set32 //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set function caml_bytes_set32(s, i, i32) { @@ -382,20 +368,6 @@ function caml_bytes_set32(s, i, i32) { return 0; } -//Provides: caml_string_set32 -//Requires: caml_failwith -//If: js-string -function caml_string_set32(s, i, i32) { - caml_failwith("caml_string_set32"); -} - -//Provides: caml_string_set32 -//Requires: caml_bytes_set32 -//If: !js-string -function caml_string_set32(s, i, i32) { - return caml_bytes_set32(s, i, i32); -} - //Provides: caml_bytes_set64 //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set //Requires: caml_int64_to_bytes @@ -408,20 +380,6 @@ function caml_bytes_set64(s, i, i64) { return 0; } -//Provides: caml_string_set64 -//Requires: caml_failwith -//If: js-string -function caml_string_set64(s, i, i64) { - caml_failwith("caml_string_set64"); -} - -//Provides: caml_string_set64 -//Requires: caml_bytes_set64 -//If: !js-string -function caml_string_set64(s, i, i64) { - return caml_bytes_set64(s, i, i64); -} - //Provides: caml_bytes_set //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set function caml_bytes_set(s, i, c) { @@ -712,13 +670,6 @@ function caml_string_unsafe_get(s, i) { return s.charCodeAt(i); } -//Provides: caml_string_unsafe_set -//Requires: caml_failwith -//If: js-string -function caml_string_unsafe_set(s, i, c) { - caml_failwith("caml_string_unsafe_set"); -} - //Provides: caml_ml_string_length const //If: js-string function caml_ml_string_length(s) { @@ -932,12 +883,6 @@ function caml_js_to_byte_string(s) { return caml_string_of_jsbytes(s); } -//Provides: caml_new_string -//Requires: caml_string_of_jsbytes -function caml_new_string(s) { - return caml_string_of_jsbytes(s); -} - //Provides: caml_js_from_string mutable (const) //Requires: caml_jsstring_of_string function caml_js_from_string(s) { diff --git a/runtime/nat.js b/runtime/js/nat.js similarity index 98% rename from runtime/nat.js rename to runtime/js/nat.js index 0af2a0689..cbeb1db26 100644 --- a/runtime/nat.js +++ b/runtime/js/nat.js @@ -143,6 +143,11 @@ function is_digit_zero(nat, ofs) { return 0; } +//Provides: is_digit_normalized +function is_digit_normalized(nat, ofs) { + return 1; +} + //Provides: is_digit_odd function is_digit_odd(nat, ofs) { if (nat.data[ofs] & 1) return 1; @@ -418,12 +423,6 @@ function compare_nat(nat1, ofs1, len1, nat2, ofs2, len2) { return 0; } -//Provides: compare_nat_real -//Requires: compare_nat -function compare_nat_real(nat1, nat2) { - return compare_nat(nat1, 0, nat1.data.length, nat2, 0, nat2.data.length); -} - //Provides: land_digit_nat function land_digit_nat(nat1, ofs1, nat2, ofs2) { nat1.data[ofs1] &= nat2.data[ofs2]; diff --git a/runtime/obj.js b/runtime/js/obj.js similarity index 96% rename from runtime/obj.js rename to runtime/js/obj.js index 405d87560..1dd73d985 100644 --- a/runtime/obj.js +++ b/runtime/js/obj.js @@ -39,6 +39,7 @@ 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); } @@ -55,6 +56,7 @@ function caml_obj_tag(x) { } //Provides: caml_obj_set_tag (mutable, const) +//Version: < 5.0 function caml_obj_set_tag(x, tag) { x[0] = tag; return 0; @@ -86,6 +88,7 @@ function caml_obj_dup(x) { //Provides: caml_obj_truncate (mutable, const) //Requires: caml_invalid_argument +//Version: < 5.0 function caml_obj_truncate(x, s) { if (s <= 0 || s + 1 > x.length) caml_invalid_argument("Obj.truncate"); if (x.length !== s + 1) x.length = s + 1; @@ -93,6 +96,7 @@ function caml_obj_truncate(x, s) { } //Provides: caml_obj_make_forward +//Version: < 5.0 function caml_obj_make_forward(b, v) { b[0] = 250; b[1] = v; @@ -100,6 +104,7 @@ function caml_obj_make_forward(b, v) { } //Provides: caml_obj_compare_and_swap +//Version: >= 5.0 function caml_obj_compare_and_swap(x, i, old, n) { if (x[i + 1] === old) { x[i + 1] = n; @@ -109,6 +114,7 @@ function caml_obj_compare_and_swap(x, i, old, n) { } //Provides: caml_obj_is_shared +//Version: >= 5.0 function caml_obj_is_shared(x) { return 1; } @@ -182,6 +188,7 @@ function caml_obj_add_offset(v, offset) { } //Provides: caml_obj_update_tag +//Version: >= 5.0 function caml_obj_update_tag(b, o, n) { if (b[0] === o) { b[0] = n; @@ -192,6 +199,7 @@ function caml_obj_update_tag(b, o, n) { //Provides: caml_lazy_update_to_forcing //Requires: caml_obj_update_tag +//Version: >= 5.0 function caml_lazy_update_to_forcing(o) { if ( Array.isArray(o) && @@ -206,6 +214,7 @@ function caml_lazy_update_to_forcing(o) { //Provides: caml_lazy_update_to_forward //Requires: caml_obj_update_tag +//Version: >= 5.0 function caml_lazy_update_to_forward(o) { caml_obj_update_tag(o, 244, 250); return 0; // unit @@ -213,6 +222,7 @@ function caml_lazy_update_to_forward(o) { //Provides: caml_lazy_reset_to_lazy //Requires: caml_obj_update_tag +//Version: >= 5.0 function caml_lazy_reset_to_lazy(o) { caml_obj_update_tag(o, 244, 246); return 0; @@ -220,6 +230,7 @@ function caml_lazy_reset_to_lazy(o) { //Provides: caml_lazy_read_result //Requires: caml_obj_tag +//Version: >= 5.0 function caml_lazy_read_result(o) { return caml_obj_tag(o) === 250 ? o[1] : o; } diff --git a/runtime/parsing.js b/runtime/js/parsing.js similarity index 100% rename from runtime/parsing.js rename to runtime/js/parsing.js diff --git a/runtime/prng.js b/runtime/js/prng.js similarity index 75% rename from runtime/prng.js rename to runtime/js/prng.js index 9bce1eafb..b4aaad6fa 100644 --- a/runtime/prng.js +++ b/runtime/js/prng.js @@ -1,3 +1,19 @@ +//Provides: caml_lxm_M +//Requires: caml_int64_of_string +//Requires: caml_string_of_jsstring +//Version: >= 5 +var caml_lxm_M = caml_int64_of_string( + caml_string_of_jsstring("0xd1342543de82ef95"), +); + +//Provides: caml_lxm_daba +//Requires: caml_int64_of_string +//Requires: caml_string_of_jsstring +//Version: >= 5 +var caml_lxm_daba = caml_int64_of_string( + caml_string_of_jsstring("0xdaba0b6eb09322e3"), +); + //Provides: caml_lxm_next //Requires: caml_int64_shift_left //Requires: caml_int64_shift_right_unsigned @@ -7,8 +23,9 @@ //Requires: caml_int64_mul //Requires: caml_ba_get_1 //Requires: caml_ba_set_1 -//Requires: caml_int64_of_string -//Requires: caml_new_string +//Requires: caml_lxm_M +//Requires: caml_lxm_daba +//Version: >= 5 function caml_lxm_next(v) { function shift_l(x, k) { return caml_int64_shift_left(x, k); @@ -37,8 +54,8 @@ function caml_lxm_next(v) { function set(a, i, x) { return caml_ba_set_1(a, i, x); } - var M = caml_int64_of_string(caml_new_string("0xd1342543de82ef95")); - var daba = caml_int64_of_string(caml_new_string("0xdaba0b6eb09322e3")); + var M = caml_lxm_M; + var daba = caml_lxm_daba; var z, q0, q1; var st = v; var a = get(st, 0); diff --git a/runtime/runtime_events.js b/runtime/js/runtime_events.js similarity index 67% rename from runtime/runtime_events.js rename to runtime/js/runtime_events.js index 1811ec9d1..d52a274f0 100644 --- a/runtime/runtime_events.js +++ b/runtime/js/runtime_events.js @@ -1,58 +1,89 @@ //Provides: caml_custom_event_index +//Version: >= 5.1 var caml_custom_event_index = 0; //Provides: caml_runtime_events_user_register //Requires: caml_custom_event_index +//Version: >= 5.1 function caml_runtime_events_user_register(event_name, event_tag, event_type) { caml_custom_event_index += 1; return [0, caml_custom_event_index, event_name, event_type, event_tag]; } //Provides: caml_runtime_events_user_write +//Version: >= 5.1 function caml_runtime_events_user_write(event, event_content) { return 0; } //Provides: caml_runtime_events_user_resolve +//Version: >= 5.0 function caml_runtime_events_user_resolve() { return 0; } //Provides: caml_ml_runtime_events_start -//Alias: caml_runtime_events_start +//Version: >= 5.2 function caml_ml_runtime_events_start() { return 0; } +//Provides: caml_runtime_events_start +//Version: >= 5.0, < 5.2 +function caml_runtime_events_start() { + return 0; +} + //Provides: caml_ml_runtime_events_pause -//Alias: caml_runtime_events_pause +//Version: >= 5.2 function caml_ml_runtime_events_pause() { return 0; } +//Provides: caml_runtime_events_pause +//Version: >= 5.0, < 5.2 +function caml_runtime_events_pause() { + return 0; +} + //Provides: caml_ml_runtime_events_are_active //Version: >= 5.2 function caml_ml_runtime_events_are_active() { return 0; } +//Provides: caml_runtime_events_resume +//Version: >=5.0, < 5.2 +function caml_runtime_events_resume() { + return 0; +} + //Provides: caml_ml_runtime_events_resume -//Alias: caml_runtime_events_resume +//Version: >= 5.2 function caml_ml_runtime_events_resume() { return 0; } //Provides: caml_runtime_events_create_cursor +//Version: >= 5.0 function caml_runtime_events_create_cursor(target) { return {}; } //Provides: caml_runtime_events_free_cursor +//Version: >= 5.0 function caml_runtime_events_free_cursor(cursor) { return 0; } //Provides: caml_runtime_events_read_poll +//Version: >= 5.0 function caml_runtime_events_read_poll(cursor, callbacks, num) { return 0; } + +//Provides: caml_ml_runtime_events_path const +//Version: >= 5.3 +function caml_ml_runtime_events_path(_unit) { + return 0; +} diff --git a/runtime/stdlib.js b/runtime/js/stdlib.js similarity index 100% rename from runtime/stdlib.js rename to runtime/js/stdlib.js diff --git a/runtime/stdlib_modern.js b/runtime/js/stdlib_modern.js similarity index 100% rename from runtime/stdlib_modern.js rename to runtime/js/stdlib_modern.js diff --git a/runtime/str.js b/runtime/js/str.js similarity index 99% rename from runtime/str.js rename to runtime/js/str.js index e8fa271e4..8c39ee65c 100644 --- a/runtime/str.js +++ b/runtime/js/str.js @@ -389,8 +389,3 @@ function re_replacement_text(repl, groups, orig) { } return caml_string_of_jsbytes(res); } - -//Provides: caml_str_initialize -function caml_str_initialize(unit) { - return 0; -} diff --git a/runtime/sync.js b/runtime/js/sync.js similarity index 100% rename from runtime/sync.js rename to runtime/js/sync.js diff --git a/runtime/sys.js b/runtime/js/sys.js similarity index 99% rename from runtime/sys.js rename to runtime/js/sys.js index 466ad111e..c87ccf2a7 100644 --- a/runtime/sys.js +++ b/runtime/js/sys.js @@ -337,6 +337,7 @@ function caml_ml_runtime_warnings_enabled(_unit) { } //Provides: caml_spacetime_enabled const (const) +//Version: < 4.12 function caml_spacetime_enabled(_unit) { return 0; } @@ -347,12 +348,14 @@ function caml_sys_const_naked_pointers_checked(_unit) { } //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"); } @@ -365,6 +368,7 @@ function caml_xdg_defaults(_unit) { //Provides: caml_sys_is_regular_file //Requires: resolve_fs_device +//Version: >= 5.1 function caml_sys_is_regular_file(name) { var root = resolve_fs_device(name); return root.device.isFile(root.rest); diff --git a/runtime/toplevel.js b/runtime/js/toplevel.js similarity index 93% rename from runtime/toplevel.js rename to runtime/js/toplevel.js index b0e9f0599..9d54018f8 100644 --- a/runtime/toplevel.js +++ b/runtime/js/toplevel.js @@ -17,22 +17,6 @@ // 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_terminfo_setup -function caml_terminfo_setup() { - return 1; -} // Bad_term -//Provides: caml_terminfo_backup -function caml_terminfo_backup() { - return 0; -} -//Provides: caml_terminfo_standout -function caml_terminfo_standout() { - return 0; -} -//Provides: caml_terminfo_resume -function caml_terminfo_resume() { - return 0; -} //Provides: caml_terminfo_rows function caml_terminfo_rows() { return 0; @@ -151,11 +135,13 @@ function caml_static_release_bytecode() { //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; } diff --git a/runtime/unix.js b/runtime/js/unix.js similarity index 100% rename from runtime/unix.js rename to runtime/js/unix.js diff --git a/runtime/weak.js b/runtime/js/weak.js similarity index 100% rename from runtime/weak.js rename to runtime/js/weak.js diff --git a/runtime/zstd.js b/runtime/js/zstd.js similarity index 100% rename from runtime/zstd.js rename to runtime/js/zstd.js diff --git a/runtime/zstd.ts b/runtime/js/zstd.ts similarity index 100% rename from runtime/zstd.ts rename to runtime/js/zstd.ts