Skip to content

Commit

Permalink
Fix TestInt64 for 11734 (#11742)
Browse files Browse the repository at this point in the history
* [hl] Add specialized Array implementation for I64.

* [hlc] Fix HArray type generation.
  • Loading branch information
Apprentice-Alchemist authored Jul 31, 2024
1 parent d033cdb commit 03f66b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type array_impl = {
ai32 : tclass;
af32 : tclass;
af64 : tclass;
ai64 : tclass;
}

type constval =
Expand Down Expand Up @@ -151,7 +152,7 @@ let is_extern_field f =

let is_array_class name =
match name with
| "hl.types.ArrayDyn" | "hl.types.ArrayBytes_Int" | "hl.types.ArrayBytes_Float" | "hl.types.ArrayObj" | "hl.types.ArrayBytes_hl_F32" | "hl.types.ArrayBytes_hl_UI16" -> true
| "hl.types.ArrayDyn" | "hl.types.ArrayBytes_Int" | "hl.types.ArrayBytes_Float" | "hl.types.ArrayObj" | "hl.types.ArrayBytes_hl_F32" | "hl.types.ArrayBytes_hl_UI16" | "hl.types.ArrayBytes_hl_I64" -> true
| _ -> false

let is_array_type t =
Expand Down Expand Up @@ -287,6 +288,8 @@ let array_class ctx t =
ctx.array_impl.af32
| HF64 ->
ctx.array_impl.af64
| HI64 ->
ctx.array_impl.ai64
| HDyn ->
ctx.array_impl.adyn
| _ ->
Expand Down Expand Up @@ -1423,7 +1426,7 @@ and get_access ctx e =

and array_read ctx ra (at,vt) ridx p =
match at with
| HUI8 | HUI16 | HI32 | HF32 | HF64 ->
| HUI8 | HUI16 | HI32 | HF32 | HF64 | HI64 ->
(* check bounds *)
hold ctx ridx;
let length = alloc_tmp ctx HI32 in
Expand All @@ -1432,7 +1435,7 @@ and array_read ctx ra (at,vt) ridx p =
let j = jump ctx (fun i -> OJULt (ridx,length,i)) in
let r = alloc_tmp ctx (match at with HUI8 | HUI16 -> HI32 | _ -> at) in
(match at with
| HUI8 | HUI16 | HI32 ->
| HUI8 | HUI16 | HI32 | HI64 ->
op ctx (OInt (r,alloc_i32 ctx 0l));
| HF32 | HF64 ->
op ctx (OFloat (r,alloc_float ctx 0.));
Expand Down Expand Up @@ -2554,7 +2557,7 @@ and eval_expr ctx e =
op ctx (OCall2 (alloc_tmp ctx HVoid, alloc_fun_path ctx (array_class ctx at).cl_path "__expand", ra, ridx));
j();
match at with
| HI32 | HF64 | HUI16 | HF32 ->
| HI32 | HF64 | HUI16 | HF32 | HI64 ->
let b = alloc_tmp ctx HBytes in
op ctx (OField (b,ra,1));
write_mem ctx b (shl ctx ridx (type_size_bits at)) at v
Expand Down Expand Up @@ -2830,6 +2833,8 @@ and eval_expr ctx e =
array_bytes 2 HF32 "F32" (fun b i r -> OSetMem (b,i,r))
| HF64 ->
array_bytes 3 HF64 "F64" (fun b i r -> OSetMem (b,i,r))
| HI64 ->
array_bytes 3 HI64 "I64" (fun b i r -> OSetMem (b,i,r))
| _ ->
let at = if is_dynamic et then et else HDyn in
let a = alloc_tmp ctx (HArray at) in
Expand Down Expand Up @@ -3143,7 +3148,7 @@ and gen_assign_op ctx acc e1 f =
op ctx (OCall2 (alloc_tmp ctx HVoid, alloc_fun_path ctx (array_class ctx at).cl_path "__expand", ra, ridx));
j();
match at with
| HUI8 | HUI16 | HI32 | HF32 | HF64 ->
| HUI8 | HUI16 | HI32 | HF32 | HF64 | HI64->
let hbytes = alloc_tmp ctx HBytes in
op ctx (OField (hbytes, ra, 1));
let ridx = shl ctx ridx (type_size_bits at) in
Expand Down Expand Up @@ -4152,6 +4157,7 @@ let create_context com dump =
ai32 = get_class "ArrayBytes_Int";
af32 = get_class "ArrayBytes_hl_F32";
af64 = get_class "ArrayBytes_Float";
ai64 = get_class "ArrayBytes_hl_I64";
};
base_class = get_class "Class";
base_enum = get_class "Enum";
Expand Down
2 changes: 2 additions & 0 deletions src/generators/hl2c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,8 @@ let make_types_idents htypes =
"t$nul_" ^ tstr t
| DSimple (HRef t) ->
"t$ref_" ^ (match make_desc t with DSimple _ -> tstr t | d -> desc_string d)
| DSimple (HArray t) ->
"t$array_" ^ (desc_string (make_desc t))
| DSimple t ->
"t$_" ^ tstr t
| DFun _ ->
Expand Down
8 changes: 8 additions & 0 deletions std/hl/types/ArrayBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ class ArrayBase extends ArrayAccess {
a.size = length;
return a;
}

public static function allocI64(bytes:BytesAccess<I64>, length:Int) @:privateAccess {
var a:ArrayBytes.ArrayI64 = untyped $new(ArrayBytes.ArrayI64);
a.length = length;
a.bytes = bytes;
a.size = length;
return a;
}
}
1 change: 1 addition & 0 deletions std/hl/types/ArrayBytes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,4 @@ typedef ArrayI32 = ArrayBytes<Int>;
typedef ArrayUI16 = ArrayBytes<UI16>;
typedef ArrayF32 = ArrayBytes<F32>;
typedef ArrayF64 = ArrayBytes<Float>;
typedef ArrayI64 = ArrayBytes<I64>;

0 comments on commit 03f66b4

Please sign in to comment.