Skip to content

Commit eb0377d

Browse files
committed
Add missing primitives
1 parent 365355f commit eb0377d

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

compiler/lib-wasm/generate.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,11 @@ 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_array_of_uniform_array", "caml_make_array"
1175+
]
11721176
in
11731177
Primitive.register "caml_make_array" `Mutable None None;
11741178
let l =

runtime/wasm/array.wat

Lines changed: 72 additions & 3 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))))
@@ -130,6 +146,21 @@
130146
(local.get $len))
131147
(local.get $fa2))
132148

149+
(func (export "caml_floatarray_sub")
150+
(param $a (ref eq)) (param $i (ref eq)) (param $vlen (ref eq))
151+
(result (ref eq))
152+
(local $len i32)
153+
(local $fa1 (ref $float_array)) (local $fa2 (ref $float_array))
154+
(local.set $len (i31.get_u (ref.cast (ref i31) (local.get $vlen))))
155+
(if (i32.eqz (local.get $len)) (then (return (global.get $empty_array))))
156+
(local.set $fa1 (ref.cast (ref $float_array) (local.get $a)))
157+
(local.set $fa2 (array.new $float_array (f64.const 0) (local.get $len)))
158+
(array.copy $float_array $float_array
159+
(local.get $fa2) (i32.const 0) (local.get $fa1)
160+
(i31.get_u (ref.cast (ref i31) (local.get $i)))
161+
(local.get $len))
162+
(local.get $fa2))
163+
133164
(func $caml_floatarray_dup (param $a (ref $float_array)) (result (ref eq))
134165
(local $a' (ref $float_array))
135166
(local $len i32)
@@ -188,6 +219,30 @@
188219
(return (local.get $fa))))
189220
(return_call $caml_floatarray_dup (local.get $fa1)))
190221

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

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
)

0 commit comments

Comments
 (0)