Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ _build
compiler/tests-*
manual
examples
benchmarks/build
74 changes: 4 additions & 70 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
#dev

## Features/Changes
* Compiler/wasm: omit code pointer from closures when not used (#2059, #2093)

## Bug fixes
* Compiler: fix purity of comparison functions (again) (#2092)
* Runtime/wasm: fix Unix.times (#2096)

# 6.2.0 (2025-07-30) - Lille

## Features/Changes
* Compiler: exit-loop-early in more cases (#2077)
* Runtime: support rename in fake filesystem (#2080)
* Compiler: remove reserved keyword in ecmascript 3
* Compiler/wasm: omit code pointer from closures when not used (#2059)

## Bug fixes
* Compiler: Fix inlining. do not inline recursive functions (#2084)
* Compiler: fix purity of caml_compare and caml_lxm_next
* Runtime: fix Sys.rename for directories on windows

# 6.1.1 (2025-07-07) - Lille

## Bug fixes
* Compiler: Fix shape loading (#2074)

# 6.1.0 (2025-07-01) - Lille
# dev

## Features/Changes
* Misc: drop support for OCaml 4.12 and bellow
* Misc: switch to dune.3.19
* Misc: initial support for ocaml 5.4 (#2030, #2058)
* Compiler: use a Wasm text files preprocessor (#1822)
* Compiler: support for OCaml 4.14.3+trunk (#1844)
* Compiler: add the `--empty-sourcemap` flag
* Compiler: improve debug/sourcemap location of closures (#1947)
* Compiler: optimize compilation of switches (#1921, #2057)
* Compiler: evaluate statically more primitives (#1912, #1915, #1965, #1969)
* Compiler: rewrote inlining pass (#1935, #2018, #2027)
* Compiler: improve tailcall optimization (#1943)
* Compiler: improve deadcode optimization (#1963, #1962, #1967)
* Compiler: deadcode elimination of cyclic values (#1978)
* Compiler: remove empty blocks (#1934)
* Compiler: improve coloring optimization (#1971, #1984, #1986, #1989)
* Compiler: faster constant sharing (#1988)
* Compiler: faster js code generation (#1985, #2066)
* Compiler: improve performance of Javascript linking
* Compiler: more efficient code generation from bytecode (#1972)
* Compiler: faster compilation by improving the scheduling of optimization passes (#1962, #2001, #2012, #2027)
* Compiler: faster compilation by stopping sooner when optimizations become unproductive (#1939)
* Compiler: Propagate arity between compilation units (#1594)
* Compiler: Add flags to enable/disable warnings (#2052)
* Compiler/wasm: directly write Wasm binary modules (#2000, #2003)
* Compiler/wasm: faster wat output (#1992)
* Compiler/wasm: use a Wasm text files preprocessor (#1822)
* Compiler/wasm: optimize integer operations (#2032)
* Compiler/wasm: use type analysis to remove some unnecessary uses of JavasScript strict equality (#2040)
* Compiler/wasm: use more precise environment types (#2041)
* Compiler/wasm: optimize calls to statically known function (#2044)
* Runtime: use es6 class (#1840)
* Runtime: support more Unix functions (#1829)
* Runtime: remove polyfill for Map to simplify MlObjectTable implementation (#1846)
Expand All @@ -65,41 +12,28 @@
* Runtime: make Obj.dup work with floats and boxed numbers (#1871)
* Runtime: delete BigStringReader, one should use UInt8ArrayReader instead
* Runtime: less conversion during un-marshalling (#1889)
* Runtime: use TextEncoder/TextDecoder for utf8-utf16 conversions
* Runtime: use Dataview to convert between floats and bit representation
* Runtime: optimize Str.search_forward/search_backward (#2056)
* Runtime: deprecate caml_ba_create_from (#2056)
* Runtime: check for unused variable in the runtime (#2056)
* Runtime/wasm: implement BLAKE2b primitives for Wasm (#1873)
* Runtime/wasm: support jsoo_env and keep track of backtrace status (#1881)
* Runtime/wasm: support unmarshaling compressed data (#1898)
* Runtime/wasm: make resuming a continuation more efficient in Wasm (#1892)
* Runtime/wasm: use imported string constants for JavaScript strings (#2022)
* Runtime/wasm: use DataView primitives to implement bigarrays (#1979)
* Compiler: improve performance of Javascript linking
* Ppx: explicitly disallow polymorphic method (#1897)
* Ppx: allow "function" in object literals (#1897)
* Lib: add Dom_html.window.matchMedia & Dom_html.mediaQueryList (#2017)
* Lib: make the Wasm version of Json.output work with native ints and JavaScript objects (#1872)

## Bug fixes
* Compiler: fix stack overflow issues with double translation (#1869)
* Compiler: minifier fix (#1867)
* Compiler: fix shortvar with --enable es6 (AssignTarget was not properly handled)
* Compiler: fix assert failure with double translation (#1870)
* Compiler: fix path rewriting of Wasm source maps (#1882)
* Compiler: fix global dead code in presence of dead tailcall (#2010)
* Compiler/wasm: fix bound check for empty float array (#1904)
* Lib: fix Dom_html.Keyboard_code.of_event (#1878)
* Runtime: fix path normalization (#1848)
* Runtime: fix reading from the pseudo-filesystem (#1859)
* Runtime: fix initialization of standard streams under Windows (#1849)
* Runtime: fix Int64.of_string overflow check (#1874)
* Runtime: fix caml_string_concat when not using JS strings (#1874)
* Runtime: consistent bigarray hashing across all architectures (#1977)
* Runtime: fix caml_utf8_of_utf16 bug in high surrogate case (#2008)
* Runtime: fix method lookup (#2034, #2038, #2039)
* Lib: fix Dom_html.Keyboard_code.of_event (#1878)
* Tools: fix jsoo_mktop and jsoo_mkcmis (#1877)
* Toplevel: fix for when use-js-strings is disabled (#1997)

# 6.0.1 (2025-02-07) - Lille

Expand Down
4 changes: 0 additions & 4 deletions ECMASCRIPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ Features are grouped by ECMAScript version.

- [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap#browser_compatibility)

### DataView

- [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#browser_compatibility)

## ECMAScript 2016

### async function
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ fmt:
git diff --exit-code

fmt-js:
npx @biomejs/biome@1.9 format --write
npx @biomejs/biome format --write

lint-js:
npx @biomejs/biome@1.9 lint
npx @biomejs/biome lint

clean:
dune clean
Expand Down
44 changes: 42 additions & 2 deletions README_wasm_of_ocaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ one can enable the CPS transformation from `js_of_ocaml` by passing the
`--effects=jspi` and emit code utilizing
- [the JavaScript-Promise Integration extension](https://github.com/WebAssembly/js-promise-integration/blob/main/proposals/js-promise-integration/Overview.md).

## Installation and usage

Installation and usage documentation can be found in [the js_of_ocaml manual](https://ocsigen.org/js_of_ocaml/dev/manual/wasm_overview).
## Installation

The following commands will perform a minimal installation:
```
git clone https://github.com/ocsigen/js_of_ocaml
cd js_of_ocaml
opam pin add -n --with-version 6.0.0 .
opam install dune.3.17.0 wasm_of_ocaml-compiler
```
You may want to install additional packages. For instance:

```
opam install js_of_ocaml js_of_ocaml-ppx js_of_ocaml-lwt
```

## Running the test suite

Expand All @@ -36,6 +48,34 @@ opam install . --deps-only --with-test
WASM_OF_OCAML=true dune build @runtest-wasm
```

## Usage

You can try compiling the program in `examples/cubes`. Your program must first be compiled using the OCaml bytecode compiler `ocamlc`. JavaScript bindings are provided by the `js_of_ocaml` package. The syntax extension is provided by `js_of_ocaml-ppx` package. Package `js_of_ocaml-lwt` provides Javascript specific Lwt functions.

```
ocamlfind ocamlc -package js_of_ocaml,js_of_ocaml-ppx,js_of_ocaml-lwt -linkpkg -o cubes.byte cubes.mli cubes.ml
```

Then, run the `wasm_of_ocaml` compiler to produce WebAssembly code:

```
wasm_of_ocaml cubes.byte -o cubes.bc.js
```

This outputs a file `cubes.bc.js` which loads the WebAssembly code from file `cube.bc.wasm`. For debugging, we currently also output the generated WebAssembly code in text file to `cube.wat`. Since Chrome does not allow loading from the filesystem, you need to serve the files using some Web server. For instance:
```
python3 -m http.server 8000 --directory .
```

As a larger example, you can try [CAMLBOY](https://github.com/linoscope/CAMLBOY). You need to install a forked version of [Brr](https://github.com/ocaml-wasm/brr/tree/wasm). Once the Js_of_ocaml UI is compiled (with `dune build --profile release`), you can generate WebAssembly code instead with the following command:
```
wasm_of_ocaml _build/default/bin/web/index.bc-for-jsoo
```

## Implementation status

A large part of the runtime is [implemented](https://github.com/ocaml-wasm/wasm_of_ocaml/issues/5). File-related functions and dynamic linking are not supported yet.

## Compatibility with Js_of_ocaml

Since the value representation is different, some adaptations are necessary.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.0
6.0.1
3 changes: 2 additions & 1 deletion compiler/bin-js_of_ocaml/build_fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ function jsoo_create_file_extern(name,content){
let code = Code.prepend Code.empty instr in
Filename.gen_file output_file (fun chan ->
let pfs_fmt = Pretty_print.to_out_channel chan in
let (_ : Source_map.info * Shape.t StringMap.t) =
let (_ : Source_map.info) =
Driver.f
~standalone:true
~wrap_with_fun:`Iife
~link:`Needed
~formatter:pfs_fmt
~source_map:false
(Parse_bytecode.Debug.create ~include_cmis:false false)
code
in
())
Expand Down
22 changes: 4 additions & 18 deletions compiler/bin-js_of_ocaml/check_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ open Js_of_ocaml_compiler
let group_by_snd l =
l
|> List.sort_uniq ~cmp:(fun (n1, l1) (n2, l2) ->
match List.compare ~cmp:String.compare l1 l2 with
match Poly.compare l1 l2 with
| 0 -> String.compare n1 n2
| c -> c)
|> List.group ~f:(fun (_, g1) (_, g2) -> List.equal ~eq:String.equal g1 g2)
|> List.group ~f:(fun (_, g1) (_, g2) -> Poly.equal g1 g2)

let print_groups output l =
List.iter l ~f:(fun group ->
Expand Down Expand Up @@ -91,30 +91,16 @@ let f (runtime_files, bytecode, target_env) =
in
let needed = StringSet.of_list (List.map ~f:fst needed) in
let needed =
(* this list was copied from parse_bytecode *)
List.fold_left
~f:(fun acc x -> StringSet.remove x acc)
~init:needed
[ (* this list was copied from parse_bytecode *)
"caml_ensure_stack_capacity"
[ "caml_ensure_stack_capacity"
; "caml_process_pending_actions_with_root"
; "caml_make_array"
; "caml_array_of_uniform_array"
]
in
let needed =
(* internal primitives *)
List.fold_left
~f:(fun acc x -> StringSet.add x acc)
~init:needed
[ "caml_register_global"
; "caml_js_set"
; "caml_js_get"
; "caml_get_global_data"
; "caml_oo_cache_id"
; "caml_get_public_method"
; "caml_get_cached_method"
]
in
let from_runtime1 = Linker.list_all () in
let from_runtime2 = Primitive.get_external () in
(* [from_runtime2] is a superset of [from_runtime1].
Expand Down
Loading