@@ -1298,27 +1298,12 @@ let compile_array_op = (wasm_mod, env, arr_imm, op) => {
12981298 Op . or_int32,
12991299 Expression . Binary . make(
13001300 wasm_mod,
1301- Op . or_int32,
1302- Expression . Binary . make(
1303- wasm_mod,
1304- Op . eq_int32,
1305- get_swap(1 ),
1306- Expression . Const . make(
1307- wasm_mod,
1308- const_int32(
1309- tag_val_of_boxed_number_tag_type(BoxedInt32 ),
1310- ),
1311- ),
1312- ),
1313- Expression . Binary . make(
1301+ Op . eq_int32,
1302+ get_swap(1 ),
1303+ Expression . Const . make(
13141304 wasm_mod,
1315- Op . eq_int32,
1316- get_swap(1 ),
1317- Expression . Const . make(
1318- wasm_mod,
1319- const_int32(
1320- tag_val_of_boxed_number_tag_type(BoxedInt64 ),
1321- ),
1305+ const_int32(
1306+ tag_val_of_boxed_number_tag_type(BoxedInt64 ),
13221307 ),
13231308 ),
13241309 ),
@@ -2046,17 +2031,21 @@ let allocate_record = (wasm_mod, env, ttag, elts) => {
20462031 );
20472032};
20482033
2049- let allocate_uint_uninitialized = (wasm_mod, env, is_32_bit) => {
2034+ // "Alt" number here is defined as one not belonging to the `Number` type
2035+ let allocate_alt_num_uninitialized = (wasm_mod, env, tag) => {
20502036 let get_swap = () => get_swap(wasm_mod, env, 0 );
2051- let make_alloc = () =>
2052- heap_allocate(wasm_mod, env, if (is_32_bit) {2 } else {4 });
2053-
2054- let (tag , label ) =
2055- if (is_32_bit) {
2056- (Uint32Type , "allocate_unitialized_uint32" );
2057- } else {
2058- (Uint64Type , "allocate_unitialized_uint64" );
2037+ let (num_words , label ) =
2038+ switch (tag) {
2039+ | Int32Type => (2 , "allocate_unitialized_int32" )
2040+ | Float32Type => (2 , "allocate_unitialized_float32" )
2041+ | Uint32Type => (2 , "allocate_unitialized_uint32" )
2042+ | Uint64Type => (4 , "allocate_unitialized_uint64" )
2043+ | _ =>
2044+ failwith (
2045+ "Impossible: allocate_alt_num_uninitialized given non-alt-num tag" ,
2046+ )
20592047 };
2048+ let make_alloc = () => heap_allocate(wasm_mod, env, num_words);
20602049
20612050 let preamble = [
20622051 store(
@@ -2077,15 +2066,29 @@ let allocate_uint_uninitialized = (wasm_mod, env, is_32_bit) => {
20772066 );
20782067};
20792068
2080- type alloc_uint_type =
2069+ type alloc_alt_num_type =
2070+ | Int32 (Expression . t )
2071+ | Float32 (Expression . t )
20812072 | Uint32 (Expression . t )
20822073 | Uint64 (Expression . t );
20832074
2084- let allocate_uint = (wasm_mod, env, uint_value ) => {
2075+ let allocate_alt_num = (wasm_mod, env, num_value ) => {
20852076 let get_swap = () => get_swap(wasm_mod, env, 0 );
20862077
20872078 let (tag , instrs , needed_words , label ) =
2088- switch (uint_value) {
2079+ switch (num_value) {
2080+ | Int32 (int32 ) => (
2081+ Int32Type ,
2082+ [ store(~offset= 4 , ~ty= Type . int32, wasm_mod, get_swap() , int32)] ,
2083+ 2 ,
2084+ "allocate_int32" ,
2085+ )
2086+ | Float32 (float32 ) => (
2087+ Float32Type ,
2088+ [ store(~offset= 4 , ~ty= Type . float32, wasm_mod, get_swap() , float32)] ,
2089+ 2 ,
2090+ "allocate_float32" ,
2091+ )
20892092 | Uint32 (uint32 ) => (
20902093 Uint32Type ,
20912094 [ store(~offset= 4 , ~ty= Type . int32, wasm_mod, get_swap() , uint32)] ,
@@ -2126,18 +2129,8 @@ let allocate_uint = (wasm_mod, env, uint_value) => {
21262129 );
21272130};
21282131
2129- let allocate_uint32 = (wasm_mod, env, i) => {
2130- allocate_uint(wasm_mod, env, Uint32 (i));
2131- };
2132-
2133- let allocate_uint64 = (wasm_mod, env, i) => {
2134- allocate_uint(wasm_mod, env, Uint64 (i));
2135- };
2136-
21372132type alloc_number_type =
2138- | Int32 (Expression . t )
21392133 | Int64 (Expression . t )
2140- | Float32 (Expression . t )
21412134 | Float64 (Expression . t )
21422135 | Rational (Expression . t , Expression . t )
21432136 | BigInt (Expression . t , list (Expression . t ));
@@ -2150,14 +2143,6 @@ let allocate_number = (wasm_mod, env, number) => {
21502143
21512144 let (number_tag , swap_slot , instrs , needed_words ) =
21522145 switch (number) {
2153- | Int32 (int32 ) =>
2154- let slot = 0 ;
2155- (
2156- BoxedInt32 ,
2157- slot,
2158- [ store(~offset= 8 , ~ty= Type . int32, wasm_mod, get_swap(slot), int32)] ,
2159- 3 ,
2160- );
21612146 | Int64 (int64 ) =>
21622147 let slot = 0 ;
21632148 (
@@ -2166,22 +2151,6 @@ let allocate_number = (wasm_mod, env, number) => {
21662151 [ store(~offset= 8 , ~ty= Type . int64, wasm_mod, get_swap(slot), int64)] ,
21672152 4 ,
21682153 );
2169- | Float32 (float32 ) =>
2170- let slot = 0 ;
2171- (
2172- BoxedFloat32 ,
2173- slot,
2174- [
2175- store(
2176- ~offset= 8 ,
2177- ~ty= Type . float32,
2178- wasm_mod,
2179- get_swap(slot),
2180- float32,
2181- ),
2182- ] ,
2183- 3 ,
2184- );
21852154 | Float64 (float64 ) =>
21862155 let slot = 0 ;
21872156 (
@@ -2343,15 +2312,15 @@ let allocate_number_uninitialized =
23432312};
23442313
23452314let allocate_float32 = (wasm_mod, env, i) => {
2346- allocate_number (wasm_mod, env, Float32 (i));
2315+ allocate_alt_num (wasm_mod, env, Float32 (i));
23472316};
23482317
23492318let allocate_float64 = (wasm_mod, env, i) => {
23502319 allocate_number(wasm_mod, env, Float64 (i));
23512320};
23522321
23532322let allocate_int32 = (wasm_mod, env, i) => {
2354- allocate_number (wasm_mod, env, Int32 (i));
2323+ allocate_alt_num (wasm_mod, env, Int32 (i));
23552324};
23562325
23572326let allocate_int64 = (wasm_mod, env, i) => {
@@ -2366,6 +2335,14 @@ let allocate_big_int = (wasm_mod, env, n, d) => {
23662335 allocate_number(wasm_mod, env, BigInt (n, d));
23672336};
23682337
2338+ let allocate_uint32 = (wasm_mod, env, i) => {
2339+ allocate_alt_num(wasm_mod, env, Uint32 (i));
2340+ };
2341+
2342+ let allocate_uint64 = (wasm_mod, env, i) => {
2343+ allocate_alt_num(wasm_mod, env, Uint64 (i));
2344+ };
2345+
23692346let tag_short_value = (wasm_mod, compiled_arg, tag) => {
23702347 Expression . Binary . make(
23712348 wasm_mod,
@@ -2382,16 +2359,18 @@ let tag_short_value = (wasm_mod, compiled_arg, tag) => {
23822359
23832360let compile_prim0 = (wasm_mod, env, p0): Expression . t => {
23842361 switch (p0) {
2385- | AllocateInt32 => allocate_number_uninitialized (wasm_mod, env, BoxedInt32 )
2362+ | AllocateInt32 => allocate_alt_num_uninitialized (wasm_mod, env, Int32Type )
23862363 | AllocateInt64 => allocate_number_uninitialized(wasm_mod, env, BoxedInt64 )
23872364 | AllocateFloat32 =>
2388- allocate_number_uninitialized (wasm_mod, env, BoxedFloat32 )
2365+ allocate_alt_num_uninitialized (wasm_mod, env, Float32Type )
23892366 | AllocateFloat64 =>
23902367 allocate_number_uninitialized(wasm_mod, env, BoxedFloat64 )
23912368 | AllocateRational =>
23922369 allocate_number_uninitialized(wasm_mod, env, BoxedRational )
2393- | AllocateUint32 => allocate_uint_uninitialized(wasm_mod, env, true )
2394- | AllocateUint64 => allocate_uint_uninitialized(wasm_mod, env, false )
2370+ | AllocateUint32 =>
2371+ allocate_alt_num_uninitialized(wasm_mod, env, Uint32Type )
2372+ | AllocateUint64 =>
2373+ allocate_alt_num_uninitialized(wasm_mod, env, Uint64Type )
23952374 | WasmMemorySize => Expression . Memory_size . make(wasm_mod)
23962375 | Unreachable => Expression . Unreachable . make(wasm_mod)
23972376 };
@@ -2412,12 +2391,12 @@ let compile_prim1 = (wasm_mod, env, p1, arg, loc): Expression.t => {
24122391 env,
24132392 BoxedBigInt ,
24142393 )
2415- | NewInt32 => allocate_number (wasm_mod, env, Int32 (compiled_arg))
2394+ | NewInt32 => allocate_alt_num (wasm_mod, env, Int32 (compiled_arg))
24162395 | NewInt64 => allocate_number(wasm_mod, env, Int64 (compiled_arg))
2417- | NewFloat32 => allocate_number (wasm_mod, env, Float32 (compiled_arg))
2396+ | NewFloat32 => allocate_alt_num (wasm_mod, env, Float32 (compiled_arg))
24182397 | NewFloat64 => allocate_number(wasm_mod, env, Float64 (compiled_arg))
2419- | NewUint32 => allocate_uint (wasm_mod, env, Uint32 (compiled_arg))
2420- | NewUint64 => allocate_uint (wasm_mod, env, Uint64 (compiled_arg))
2398+ | NewUint32 => allocate_alt_num (wasm_mod, env, Uint32 (compiled_arg))
2399+ | NewUint64 => allocate_alt_num (wasm_mod, env, Uint64 (compiled_arg))
24212400 | LoadAdtVariant => load(~offset= 12 , wasm_mod, compiled_arg)
24222401 | StringSize
24232402 | BytesSize => load(~offset= 4 , wasm_mod, compiled_arg)
0 commit comments