Skip to content

Commit 65e727a

Browse files
committed
Fix creation of float arrays
1 parent fdbc151 commit 65e727a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

compiler/lib/wasm/wa_generate.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,10 +1159,7 @@ end
11591159

11601160
let init () =
11611161
let l =
1162-
[ "caml_make_array", "%identity"
1163-
; "caml_ensure_stack_capacity", "%identity"
1164-
; "caml_callback", "caml_trampoline"
1165-
]
1162+
[ "caml_ensure_stack_capacity", "%identity"; "caml_callback", "caml_trampoline" ]
11661163
in
11671164

11681165
let l =

runtime/wasm/array.wat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@
6464
(if (i32.eqz (local.get $sz)) (then (return (global.get $empty_array))))
6565
(array.new $float_array (f64.const 0) (local.get $sz)))
6666

67+
(func (export "caml_make_array") (param $vinit (ref eq)) (result (ref eq))
68+
(local $init (ref $block)) (local $res (ref $float_array))
69+
(local $size i32) (local $i i32)
70+
(local.set $init (ref.cast (ref $block) (local.get $vinit)))
71+
(local.set $size (array.len (local.get $init)))
72+
(if (i32.ne (local.get $size) (i32.const 1))
73+
(then
74+
(if (ref.test (ref $float)
75+
(array.get $block (local.get $init) (i32.const 1)))
76+
(then
77+
(local.set $size (i32.sub (local.get $size) (i32.const 1)))
78+
(local.set $res
79+
(array.new $float_array (f64.const 0) (local.get $size)))
80+
(loop $loop
81+
(array.set $float_array (local.get $res) (local.get $i)
82+
(struct.get $float 0
83+
(ref.cast (ref $float)
84+
(array.get $block (local.get $init)
85+
(i32.add (local.get $i) (i32.const 1))))))
86+
(local.set $i (i32.add (local.get $i) (i32.const 1)))
87+
(br_if $loop (i32.lt_u (local.get $i) (local.get $size))))
88+
(return (local.get $res))))))
89+
(return (local.get $init)))
90+
6791
(func (export "caml_floatarray_unsafe_get")
6892
(param $a (ref eq)) (param $i (ref eq)) (result (ref eq))
6993
(struct.new $float

0 commit comments

Comments
 (0)