Skip to content

Commit d9ea686

Browse files
committed
WIP
1 parent a0309ff commit d9ea686

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

compiler/lib-wasm/gc_target.ml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,19 +1415,30 @@ module Bigarray = struct
14151415
| Int -> "dv_get_i32", I32, 2, Fun.id
14161416
| Complex32 | Complex64 | Float16 -> assert false (*ZZZ*)
14171417
in
1418+
let* little_endian =
1419+
register_import
1420+
~import_module:"bindings"
1421+
~name:"littleEndian"
1422+
(Global { mut = false; typ = I32 })
1423+
in
14181424
let* f =
14191425
register_import
14201426
~import_module:"bindings"
14211427
~name
14221428
(Fun
1423-
{ W.params = [ Ref { nullable = false; typ = Extern }; I32 ]
1429+
{ W.params =
1430+
Ref { nullable = true; typ = Extern }
1431+
:: I32
1432+
:: (if size = 0 then [] else [ I32 ])
14241433
; result = [ typ ]
14251434
})
14261435
in
14271436
let* ty = Type.bigarray_type in
14281437
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
14291438
let* ofs = Arith.(i lsl const (Int32.of_int size)) in
1430-
box (return (W.Call (f, [ ta; ofs ])))
1439+
box
1440+
(return
1441+
(W.Call (f, ta :: ofs :: (if size = 0 then [] else [ W.GlobalGet little_endian ]))))
14311442

14321443
let set ~kind a i v =
14331444
let name, (typ : Wasm_ast.value_type), size, unbox =
@@ -1452,16 +1463,28 @@ module Bigarray = struct
14521463
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
14531464
let* ofs = Arith.(i lsl const (Int32.of_int size)) in
14541465
let* v = unbox v in
1466+
let* little_endian =
1467+
register_import
1468+
~import_module:"bindings"
1469+
~name:"littleEndian"
1470+
(Global { mut = false; typ = I32 })
1471+
in
14551472
let* f =
14561473
register_import
14571474
~import_module:"bindings"
14581475
~name
14591476
(Fun
1460-
{ W.params = [ Ref { nullable = false; typ = Extern }; I32; typ ]
1477+
{ W.params =
1478+
Ref { nullable = true; typ = Extern }
1479+
:: I32
1480+
:: typ
1481+
:: (if size = 0 then [] else [ I32 ])
14611482
; result = []
14621483
})
14631484
in
1464-
instr (W.CallInstr (f, [ ta; ofs; v ]))
1485+
instr
1486+
(W.CallInstr
1487+
(f, ta :: ofs :: v :: (if size = 0 then [] else [ W.GlobalGet little_endian ])))
14651488
end
14661489

14671490
module JavaScript = struct

0 commit comments

Comments
 (0)