fixed: distinct string types not storing correctly
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 3 Jan 2024 00:19:48 +0000 (18:19 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 3 Jan 2024 00:19:48 +0000 (18:19 -0600)
compiler/src/wasm_emit.c

index 58fce47facc11308194ff0cf9fbc29ba0ee32b8c..bac95f334f9186e1008cca9317ee85e688822538 100644 (file)
@@ -999,6 +999,8 @@ EMIT_FUNC(compound_assignment, AstBinaryOp* assign) {
 EMIT_FUNC(store_instruction, Type* type, u32 offset) {
     bh_arr(WasmInstruction) code = *pcode;
 
+    while (type->kind == Type_Kind_Distinct) type = type->Distinct.base_type;
+
     if (onyx_type_is_stored_in_memory(type)) {
         emit_struct_store(mod, pcode, type, offset);
         return;
@@ -1018,8 +1020,6 @@ EMIT_FUNC(store_instruction, Type* type, u32 offset) {
     if (type->kind == Type_Kind_Struct)   type = type_struct_is_just_one_basic_value(type);
     if (type->kind == Type_Kind_Enum)     type = type->Enum.backing;
 
-    while (type->kind == Type_Kind_Distinct) type = type->Distinct.base_type;
-
     assert(type);
 
     u32 alignment = type_get_alignment_log2(type);
@@ -1117,6 +1117,8 @@ EMIT_FUNC(load_with_ignored_instruction, Type* type, u32 offset, i32 ignored_val
 EMIT_FUNC(load_instruction, Type* type, u32 offset) {
     bh_arr(WasmInstruction) code = *pcode;
 
+    while (type->kind == Type_Kind_Distinct) type = type->Distinct.base_type;
+
     if (type->kind == Type_Kind_Array || onyx_type_is_stored_in_memory(type)) {
         if (offset != 0) {
             WID(NULL, WI_PTR_CONST, offset);
@@ -1136,8 +1138,6 @@ EMIT_FUNC(load_instruction, Type* type, u32 offset) {
     if (type->kind == Type_Kind_Enum)     type = type->Enum.backing;
     if (type->kind == Type_Kind_Function) assert(1234 && 0);
 
-    while (type->kind == Type_Kind_Distinct) type = type->Distinct.base_type;
-
     assert(type);
 
     i32 load_size   = type_size_of(type);