Skip to content

Commit 8fd1de5

Browse files
authored
Merge pull request #136 from ocaml-wasm/5.3
Updates for OCaml 5.3
2 parents 50bdad2 + a05e05a commit 8fd1de5

File tree

10 files changed

+105
-16
lines changed

10 files changed

+105
-16
lines changed

.github/workflows/build-wasm_of_ocaml.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- 5.00.x
2121
- 5.01.x
2222
- 5.02.x
23+
- ocaml-compiler.5.3.0~beta2
2324
separate_compilation:
2425
- true
2526
include:

compiler/lib-wasm/generate.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,13 @@ end
11681168

11691169
let init () =
11701170
let l =
1171-
[ "caml_ensure_stack_capacity", "%identity"; "caml_callback", "caml_trampoline" ]
1171+
[ "caml_ensure_stack_capacity", "%identity"
1172+
; "caml_process_pending_actions_with_root", "%identity"
1173+
; "caml_callback", "caml_trampoline"
1174+
; "caml_make_array", "caml_array_of_uniform_array"
1175+
]
11721176
in
1173-
Primitive.register "caml_make_array" `Mutable None None;
1177+
Primitive.register "caml_array_of_uniform_array" `Mutable None None;
11741178
let l =
11751179
if Config.Flag.effects ()
11761180
then ("caml_alloc_stack", "caml_cps_alloc_stack") :: l

compiler/lib/flow.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ let rec block_escape st x =
198198
| Immutable -> ()
199199
| Maybe_mutable -> Code.Var.ISet.add st.possibly_mutable y);
200200
Array.iter l ~f:(fun z -> block_escape st z)
201-
| Expr (Prim (Extern "caml_make_array", [ Pv y ])) -> block_escape st y
201+
| Expr
202+
(Prim (Extern ("caml_make_array" | "caml_array_of_uniform_array"), [ Pv y ]))
203+
-> block_escape st y
202204
| _ -> Code.Var.ISet.add st.possibly_mutable y))
203205
(Var.Tbl.get st.known_origins x)
204206

@@ -208,7 +210,7 @@ let expr_escape st _x e =
208210
| Apply { args; _ } -> List.iter args ~f:(fun x -> block_escape st x)
209211
| Prim (Array_get, [ Pv x; _ ]) -> block_escape st x
210212
| Prim ((Vectlength | Array_get | Not | IsInt | Eq | Neq | Lt | Le | Ult), _) -> ()
211-
| Prim (Extern "caml_make_array", [ Pv _ ]) -> ()
213+
| Prim (Extern ("caml_make_array" | "caml_array_of_uniform_array"), [ Pv _ ]) -> ()
212214
| Prim (Extern name, l) ->
213215
let ka =
214216
match Primitive.kind_args name with
@@ -233,7 +235,10 @@ let expr_escape st _x e =
233235
| Expr (Constant (Tuple _)) -> ()
234236
| Expr (Block (_, a, _, _)) ->
235237
Array.iter a ~f:(fun x -> block_escape st x)
236-
| Expr (Prim (Extern "caml_make_array", [ Pv y ])) -> (
238+
| Expr
239+
(Prim
240+
( Extern ("caml_make_array" | "caml_array_of_uniform_array")
241+
, [ Pv y ] )) -> (
237242
match st.defs.(Var.idx y) with
238243
| Expr (Block (_, a, _, _)) ->
239244
Array.iter a ~f:(fun x -> block_escape st x)
@@ -416,7 +421,7 @@ let the_native_string_of ~target info x =
416421
let the_block_contents_of info x =
417422
match the_def_of info x with
418423
| Some (Block (_, a, _, _)) -> Some a
419-
| Some (Prim (Extern "caml_make_array", [ x ])) -> (
424+
| Some (Prim (Extern ("caml_make_array" | "caml_array_of_uniform_array"), [ x ])) -> (
420425
match the_def_of info x with
421426
| Some (Block (_, a, _, _)) -> Some a
422427
| _ -> None)

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
(description
140140
"Wasm_of_ocaml is a compiler from OCaml bytecode to WebAssembly. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js")
141141
(depends
142-
(ocaml (and (>= 4.14) (< 5.3)))
142+
(ocaml (>= 4.14))
143143
(js_of_ocaml (= :version))
144144
(num :with-test)
145145
(ppx_expect (and (>= v0.14.2) :with-test))

ppx/ppx_js/tests/dune

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
(rule
88
(targets ppx.mlt.corrected)
99
(enabled_if
10-
(>= %{ocaml_version} 5.2))
10+
(and
11+
(>= %{ocaml_version} 5.2)
12+
(< %{ocaml_version} 5.3)))
1113
(action
1214
(run %{exe:main.bc} %{dep:ppx.mlt})))
1315

1416
(rule
1517
(alias runtest)
1618
(package js_of_ocaml-ppx)
1719
(enabled_if
18-
(>= %{ocaml_version} 5.2))
20+
(and
21+
(>= %{ocaml_version} 5.2)
22+
(< %{ocaml_version} 5.3)))
1923
(action
2024
(diff ppx.mlt ppx.mlt.corrected)))

runtime/wasm/array.wat

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
(global $empty_array (ref eq)
3030
(array.new_fixed $block 1 (ref.i31 (i32.const 0))))
3131

32-
(func $caml_make_vect (export "caml_make_vect")
32+
(func $caml_make_vect (export "caml_make_vect") (export "caml_array_make")
3333
(param $n (ref eq)) (param $v (ref eq)) (result (ref eq))
3434
(local $sz i32) (local $b (ref $block)) (local $f f64)
3535
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
@@ -51,8 +51,24 @@
5151
(array.set $block (local.get $b) (i32.const 0) (ref.i31 (i32.const 0)))
5252
(local.get $b))
5353

54-
(export "caml_make_float_vect" (func $caml_floatarray_create))
55-
(func $caml_floatarray_create (export "caml_floatarray_create")
54+
(func (export "caml_floatarray_make")
55+
(param $n (ref eq)) (param $v (ref eq)) (result (ref eq))
56+
(local $sz i32) (local $f f64)
57+
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
58+
(if (i32.lt_s (local.get $sz) (i32.const 0))
59+
(then
60+
(call $caml_invalid_argument
61+
(array.new_data $string $Array_make
62+
(i32.const 0) (i32.const 10)))))
63+
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
64+
(local.set $f
65+
(struct.get $float 0
66+
(ref.cast (ref $float) (local.get $v))))
67+
(array.new $float_array (local.get $f) (local.get $sz)))
68+
69+
(func $caml_floatarray_create
70+
(export "caml_make_float_vect") (export "caml_floatarray_create")
71+
(export "caml_array_create_float")
5672
(param $n (ref eq)) (result (ref eq))
5773
(local $sz i32)
5874
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
@@ -64,7 +80,8 @@
6480
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
6581
(array.new $float_array (f64.const 0) (local.get $sz)))
6682

67-
(func (export "caml_make_array") (param $vinit (ref eq)) (result (ref eq))
83+
(func (export "caml_array_of_uniform_array")
84+
(param $vinit (ref eq)) (result (ref eq))
6885
(local $init (ref $block)) (local $res (ref $float_array))
6986
(local $size i32) (local $i i32)
7087
(local.set $init (ref.cast (ref $block) (local.get $vinit)))
@@ -130,6 +147,21 @@
130147
(local.get $len))
131148
(local.get $fa2))
132149

150+
(func (export "caml_floatarray_sub")
151+
(param $a (ref eq)) (param $i (ref eq)) (param $vlen (ref eq))
152+
(result (ref eq))
153+
(local $len i32)
154+
(local $fa1 (ref $float_array)) (local $fa2 (ref $float_array))
155+
(local.set $len (i31.get_u (ref.cast (ref i31) (local.get $vlen))))
156+
(if (i32.eqz (local.get $len)) (then (return (global.get $empty_array))))
157+
(local.set $fa1 (ref.cast (ref $float_array) (local.get $a)))
158+
(local.set $fa2 (array.new $float_array (f64.const 0) (local.get $len)))
159+
(array.copy $float_array $float_array
160+
(local.get $fa2) (i32.const 0) (local.get $fa1)
161+
(i31.get_u (ref.cast (ref i31) (local.get $i)))
162+
(local.get $len))
163+
(local.get $fa2))
164+
133165
(func $caml_floatarray_dup (param $a (ref $float_array)) (result (ref eq))
134166
(local $a' (ref $float_array))
135167
(local $len i32)
@@ -188,6 +220,30 @@
188220
(return (local.get $fa))))
189221
(return_call $caml_floatarray_dup (local.get $fa1)))
190222

223+
(func (export "caml_floatarray_append")
224+
(param $va1 (ref eq)) (param $va2 (ref eq)) (result (ref eq))
225+
(local $fa1 (ref $float_array)) (local $fa2 (ref $float_array))
226+
(local $fa (ref $float_array))
227+
(local $l1 i32) (local $l2 i32)
228+
(local.set $fa1 (ref.cast (ref $float_array) (local.get $va1)))
229+
(drop (block $a2_not_float_array (result (ref eq))
230+
(local.set $fa2
231+
(br_on_cast_fail $a2_not_float_array (ref eq) (ref $float_array)
232+
(local.get $va2)))
233+
(local.set $l1 (array.len (local.get $fa1)))
234+
(local.set $l2 (array.len (local.get $fa2)))
235+
(local.set $fa
236+
(array.new $float_array (f64.const 0)
237+
(i32.add (local.get $l1) (local.get $l2))))
238+
(array.copy $float_array $float_array
239+
(local.get $fa) (i32.const 0) (local.get $fa1) (i32.const 0)
240+
(local.get $l1))
241+
(array.copy $float_array $float_array
242+
(local.get $fa) (local.get $l1) (local.get $fa2) (i32.const 0)
243+
(local.get $l2))
244+
(return (local.get $fa))))
245+
(return_call $caml_floatarray_dup (local.get $fa1)))
246+
191247
(func (export "caml_array_concat") (param (ref eq)) (result (ref eq))
192248
(local $i i32) (local $len i32)
193249
(local $l (ref eq)) (local $v (ref eq))
@@ -334,4 +390,18 @@
334390
(struct.get $float 0 (ref.cast (ref $float) (local.get $v)))
335391
(local.get $len))))
336392
(ref.i31 (i32.const 0)))
393+
394+
(func (export "caml_floatarray_fill")
395+
(param $a (ref eq)) (param $i (ref eq)) (param $vlen (ref eq))
396+
(param $v (ref eq)) (result (ref eq))
397+
(local $len i32)
398+
(local.set $len (i31.get_u (ref.cast (ref i31) (local.get $vlen))))
399+
(if (local.get $len)
400+
(then
401+
(array.fill $float_array
402+
(ref.cast (ref $float_array) (local.get $a))
403+
(i31.get_u (ref.cast (ref i31) (local.get $i)))
404+
(struct.get $float 0 (ref.cast (ref $float) (local.get $v)))
405+
(local.get $len))))
406+
(ref.i31 (i32.const 0)))
337407
)

runtime/wasm/domain.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
(global $caml_domain_latest_id (export "caml_domain_latest_id") (mut i32)
9696
(i32.const 1))
9797

98-
(func (export "caml_ml_domain_id") (param (ref eq)) (result (ref eq))
98+
(func (export "caml_ml_domain_id") (export "caml_ml_domain_index")
99+
(param (ref eq)) (result (ref eq))
99100
(ref.i31 (global.get $caml_domain_id)))
100101

101102
(func (export "caml_ml_domain_cpu_relax") (param (ref eq)) (result (ref eq))

runtime/wasm/md5.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
(field (ref $int_array)) ;; buffer
3333
(field (ref $string)))) ;; intermediate buffer
3434

35-
(func (export "caml_md5_string")
35+
(func (export "caml_md5_string") (export "caml_md5_bytes")
3636
(param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq))
3737
(local $ctx (ref $context))
3838
(local.set $ctx (call $MD5Init))

runtime/wasm/runtime_events.wat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@
6262
(func (export "caml_runtime_events_read_poll")
6363
(param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq))
6464
(ref.i31 (i32.const 0)))
65+
66+
(func (export "caml_ml_runtime_events_path")
67+
(param (ref eq)) (result (ref eq))
68+
(ref.i31 (i32.const 0)))
6569
)

wasm_of_ocaml-compiler.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview"
1313
bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues"
1414
depends: [
1515
"dune" {>= "3.17"}
16-
"ocaml" {>= "4.14" & < "5.3"}
16+
"ocaml" {>= "4.14"}
1717
"js_of_ocaml" {= version}
1818
"num" {with-test}
1919
"ppx_expect" {>= "v0.14.2" & with-test}

0 commit comments

Comments
 (0)