@@ -2047,6 +2047,94 @@ let allocate_record = (wasm_mod, env, ttag, elts) => {
20472047 );
20482048};
20492049
2050+ let allocate_uint_uninitialized = (wasm_mod, env, is_32_bit) => {
2051+ let get_swap = () => get_swap(wasm_mod, env, 0 );
2052+ let make_alloc = () =>
2053+ heap_allocate(wasm_mod, env, if (is_32_bit) {2 } else {4 });
2054+
2055+ let (tag , label ) =
2056+ if (is_32_bit) {
2057+ (Uint32Type , "allocate_unitialized_uint32" );
2058+ } else {
2059+ (Uint64Type , "allocate_unitialized_uint64" );
2060+ };
2061+
2062+ let preamble = [
2063+ store(
2064+ ~offset= 0 ,
2065+ wasm_mod,
2066+ tee_swap(~skip_incref= true , wasm_mod, env, 0 , make_alloc() ),
2067+ Expression . Const . make(
2068+ wasm_mod,
2069+ const_int32(tag_val_of_heap_tag_type(tag)),
2070+ ),
2071+ ),
2072+ ] ;
2073+ let postamble = [ get_swap() ] ;
2074+ Expression . Block . make(
2075+ wasm_mod,
2076+ gensym_label(label),
2077+ List . concat([ preamble, postamble] ),
2078+ );
2079+ };
2080+
2081+ type alloc_uint_type =
2082+ | Uint32 (Expression . t )
2083+ | Uint64 (Expression . t );
2084+
2085+ let allocate_uint = (wasm_mod, env, uint_value) => {
2086+ let get_swap = () => get_swap(wasm_mod, env, 0 );
2087+
2088+ let (tag , instrs , needed_words , label ) =
2089+ switch (uint_value) {
2090+ | Uint32 (uint32 ) => (
2091+ Uint32Type ,
2092+ [ store(~offset= 4 , ~ty= Type . int32, wasm_mod, get_swap() , uint32)] ,
2093+ 2 ,
2094+ "allocate_uint32" ,
2095+ )
2096+ | Uint64 (uint64 ) => (
2097+ Uint64Type ,
2098+ [ store(~offset= 8 , ~ty= Type . int64, wasm_mod, get_swap() , uint64)] ,
2099+ // Allocate 4 words to store with 8-byte alignment
2100+ 4 ,
2101+ "allocate_uint64" ,
2102+ )
2103+ };
2104+
2105+ let preamble = [
2106+ store(
2107+ ~offset= 0 ,
2108+ wasm_mod,
2109+ tee_swap(
2110+ ~skip_incref= true ,
2111+ wasm_mod,
2112+ env,
2113+ 0 ,
2114+ heap_allocate(wasm_mod, env, needed_words),
2115+ ),
2116+ Expression . Const . make(
2117+ wasm_mod,
2118+ const_int32(tag_val_of_heap_tag_type(tag)),
2119+ ),
2120+ ),
2121+ ] ;
2122+ let postamble = [ get_swap() ] ;
2123+ Expression . Block . make(
2124+ wasm_mod,
2125+ gensym_label(label),
2126+ List . concat([ preamble, instrs, postamble] ),
2127+ );
2128+ };
2129+
2130+ let allocate_uint32 = (wasm_mod, env, i) => {
2131+ allocate_uint(wasm_mod, env, Uint32 (i));
2132+ };
2133+
2134+ let allocate_uint64 = (wasm_mod, env, i) => {
2135+ allocate_uint(wasm_mod, env, Uint64 (i));
2136+ };
2137+
20502138type alloc_number_type =
20512139 | Int32 (Expression . t )
20522140 | Int64 (Expression . t )
@@ -2289,6 +2377,8 @@ let compile_prim0 = (wasm_mod, env, p0): Expression.t => {
22892377 allocate_number_uninitialized(wasm_mod, env, BoxedFloat64 )
22902378 | AllocateRational =>
22912379 allocate_number_uninitialized(wasm_mod, env, BoxedRational )
2380+ | AllocateUint32 => allocate_uint_uninitialized(wasm_mod, env, true )
2381+ | AllocateUint64 => allocate_uint_uninitialized(wasm_mod, env, false )
22922382 | Unreachable => Expression . Unreachable . make(wasm_mod)
22932383 };
22942384};
@@ -2312,6 +2402,8 @@ let compile_prim1 = (wasm_mod, env, p1, arg, loc): Expression.t => {
23122402 | NewInt64 => allocate_number(wasm_mod, env, Int64 (compiled_arg))
23132403 | NewFloat32 => allocate_number(wasm_mod, env, Float32 (compiled_arg))
23142404 | NewFloat64 => allocate_number(wasm_mod, env, Float64 (compiled_arg))
2405+ | NewUint32 => allocate_uint(wasm_mod, env, Uint32 (compiled_arg))
2406+ | NewUint64 => allocate_uint(wasm_mod, env, Uint64 (compiled_arg))
23152407 | LoadAdtVariant => load(~offset= 12 , wasm_mod, compiled_arg)
23162408 | StringSize
23172409 | BytesSize => load(~offset= 4 , wasm_mod, compiled_arg)
@@ -2724,6 +2816,18 @@ let compile_allocation = (wasm_mod, env, alloc_type) =>
27242816 env,
27252817 Expression . Const . make(wasm_mod, Literal . int64(i)),
27262818 )
2819+ | MUint32 (i ) =>
2820+ allocate_uint32(
2821+ wasm_mod,
2822+ env,
2823+ Expression . Const . make(wasm_mod, Literal . int32(i)),
2824+ )
2825+ | MUint64 (i ) =>
2826+ allocate_uint64(
2827+ wasm_mod,
2828+ env,
2829+ Expression . Const . make(wasm_mod, Literal . int64(i)),
2830+ )
27272831 | MFloat32 (i ) =>
27282832 allocate_float32(
27292833 wasm_mod,
0 commit comments