Skip to content

Commit 245bde3

Browse files
committed
WIP
1 parent 0eaeecc commit 245bde3

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

compiler/lib-wasm/gc_target.ml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ module Type = struct
442442
; typ = Value (Ref { nullable = false; typ = Type custom_operations })
443443
}
444444
; { mut = true; typ = Value (Ref { nullable = false; typ = Extern }) }
445+
; { mut = true; typ = Value (Ref { nullable = false; typ = Extern }) }
445446
; { mut = false
446447
; typ = Value (Ref { nullable = false; typ = Type int_array })
447448
}
@@ -1390,7 +1391,7 @@ module Bigarray = struct
13901391
let* ty = Type.bigarray_type in
13911392
Memory.wasm_array_get
13921393
~ty:Type.int_array_type
1393-
(Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2)
1394+
(Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 3)
13941395
(Arith.const 0l)
13951396

13961397
let get ~kind a i =
@@ -1399,15 +1400,15 @@ module Bigarray = struct
13991400
let* f =
14001401
register_import
14011402
~import_module:"bindings"
1402-
~name:"ta_get_ui8"
1403+
~name:"dv_get_ui8"
14031404
(Fun
14041405
{ W.params = [ Ref { nullable = false; typ = Extern }; I32 ]
14051406
; result = [ I32 ]
14061407
})
14071408
in
14081409
let* ty = Type.bigarray_type in
1409-
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 1 in
1410-
let* i = Value.int_val i in
1410+
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
1411+
let* i = i in
14111412
return (W.Call (f, [ ta; i ]))
14121413
| _ -> assert false
14131414

@@ -1417,20 +1418,16 @@ module Bigarray = struct
14171418
let* f =
14181419
register_import
14191420
~import_module:"bindings"
1420-
~name:"ta_set_ui8"
1421+
~name:"dv_set_ui8"
14211422
(Fun
1422-
{ W.params =
1423-
[ Ref { nullable = false; typ = Extern }
1424-
; I32
1425-
; Ref { nullable = false; typ = I31 }
1426-
]
1423+
{ W.params = [ Ref { nullable = false; typ = Extern }; I32; I32 ]
14271424
; result = []
14281425
})
14291426
in
14301427
let* ty = Type.bigarray_type in
1431-
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 1 in
1432-
let* i = Value.int_val i in
1433-
let* v = cast I31 v in
1428+
let* ta = Memory.wasm_struct_get ty (Memory.wasm_cast ty a) 2 in
1429+
let* i = i in
1430+
let* v = v in
14341431
instr (W.CallInstr (f, [ ta; i; v ]))
14351432
| _ -> assert false
14361433
end

compiler/lib-wasm/generate.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -889,31 +889,31 @@ module Generate (Target : Target_sig.S) = struct
889889
match l with
890890
| [ x; y ] -> (
891891
let x' = transl_prim_arg ctx x in
892-
let y' = transl_prim_arg ctx y in
893892
match get_type ctx x with
894893
| Bigarray { kind = (Int8_unsigned | Char) as kind; layout = C } ->
894+
let y' = transl_prim_arg ctx ~typ:(Int Unnormalized) y in
895895
seq
896-
(let* cond = Arith.uge (Value.int_val y') (Bigarray.dim1 x') in
896+
(let* cond = Arith.uge y' (Bigarray.dim1 x') in
897897
instr (W.Br_if (label_index context bound_error_pc, cond)))
898898
(Bigarray.get ~kind x' y')
899899
| _ ->
900900
let* f =
901901
register_import ~name:"caml_ba_get_1" (Fun (Type.primitive_type 2))
902902
in
903903
let* x' = x' in
904-
let* y' = y' in
904+
let* y' = transl_prim_arg ctx y in
905905
return (W.Call (f, [ x'; y' ])))
906906
| _ -> invalid_arity "caml_ba_get_1" l ~expected:2);
907907
register_prim "caml_ba_set_1" `Mutator (fun ctx context l ->
908908
match l with
909909
| [ x; y; z ] -> (
910910
let x' = transl_prim_arg ctx x in
911-
let y' = transl_prim_arg ctx y in
912-
let z' = transl_prim_arg ctx z in
913911
match get_type ctx x with
914912
| Bigarray { kind = (Int8_unsigned | Char) as kind; layout = C } ->
913+
let y' = transl_prim_arg ctx ~typ:(Int Normalized) y in
914+
let z' = transl_prim_arg ctx ~typ:(Int Unnormalized) z in
915915
seq
916-
(let* cond = Arith.uge (Value.int_val y') (Bigarray.dim1 x') in
916+
(let* cond = Arith.uge y' (Bigarray.dim1 x') in
917917
let* () = instr (W.Br_if (label_index context bound_error_pc, cond)) in
918918
Bigarray.set ~kind x' y' z')
919919
Value.unit
@@ -922,8 +922,8 @@ module Generate (Target : Target_sig.S) = struct
922922
register_import ~name:"caml_ba_set_1" (Fun (Type.primitive_type 3))
923923
in
924924
let* x' = x' in
925-
let* y' = y' in
926-
let* z' = z' in
925+
let* y' = transl_prim_arg ctx y in
926+
let* z' = transl_prim_arg ctx z in
927927
return (W.Call (f, [ x'; y'; z' ])))
928928
| _ -> invalid_arity "caml_ba_set_1" l ~expected:3)
929929

0 commit comments

Comments
 (0)