@@ -190,7 +190,7 @@ def gen_source_files(self, source_files):
190
190
CGen (self .comp ).gen (self .out_rir )
191
191
if self .comp .prefs .build_mode == prefs .BuildMode .Test :
192
192
exit_code = os .system (self .comp .prefs .mod_output )
193
- os .remove (self .comp .prefs .mod_output )
193
+ # os.remove(self.comp.prefs.mod_output)
194
194
# assert exit_code == 0
195
195
if exit_code != 0 :
196
196
exit (1 )
@@ -441,7 +441,7 @@ def gen_stmt(self, stmt):
441
441
if not stmt .value .is_ref or (
442
442
isinstance (value_t_ir , ir .Pointer ) and value_t_ir .is_managed
443
443
):
444
- value = ir .Inst (ir .InstKind .LoadPtr , [value ])
444
+ value = ir .Inst (ir .InstKind .LoadPtr , [value ], value_t_ir )
445
445
unique_ir_name = self .cur_func .unique_name (stmt .value .name )
446
446
self .cur_func .inline_alloca (value_t_ir , unique_ir_name , value )
447
447
stmt .scope .update_ir_name (stmt .value .name , unique_ir_name )
@@ -618,6 +618,7 @@ def gen_expr_with_cast(self, expected_typ_, expr, custom_tmp = None):
618
618
619
619
expr_sym = expr .typ .symbol ()
620
620
expected_sym = expected_typ_ .symbol ()
621
+
621
622
if expected_sym .kind == TypeKind .Trait and expr_typ != expected_typ_ and expr_sym != expected_sym and expr .typ != self .comp .none_t :
622
623
res_expr = self .trait_value (res_expr , expr_typ , expected_typ_ )
623
624
elif expr_sym .kind == TypeKind .Enum and expr_sym .info .is_tagged and expr_sym .info .has_variant (
@@ -1126,7 +1127,7 @@ def gen_expr(self, expr, custom_tmp = None):
1126
1127
)
1127
1128
is_vtable_call = True
1128
1129
if not isinstance (self_expr .typ , ir .Pointer ):
1129
- self_expr = ir .Inst (ir .InstKind .LoadPtr , [self_expr ])
1130
+ self_expr = ir .Inst (ir .InstKind .LoadPtr , [self_expr ], self_expr . typ . typ )
1130
1131
if left_sym .kind == TypeKind .Trait :
1131
1132
if left2_sym .kind == TypeKind .Trait and left_sym != left2_sym :
1132
1133
id_value = ir .Inst (
@@ -1218,7 +1219,7 @@ def gen_expr(self, expr, custom_tmp = None):
1218
1219
elif isinstance (
1219
1220
receiver .typ , type .Ptr
1220
1221
) and not expr .sym .self_is_ptr :
1221
- self_expr = ir .Inst (ir .InstKind .LoadPtr , [self_expr ])
1222
+ self_expr = ir .Inst (ir .InstKind .LoadPtr , [self_expr ], self_expr . typ . typ )
1222
1223
args .append (self_expr )
1223
1224
args_len = expr .sym .args_len ()
1224
1225
for i , arg in enumerate (expr .args ):
@@ -1301,11 +1302,11 @@ def gen_expr(self, expr, custom_tmp = None):
1301
1302
value = ir .Inst (ir .InstKind .Cast , [inst , ret_typ .ptr ()])
1302
1303
if custom_tmp :
1303
1304
self .cur_func .store (
1304
- custom_tmp , ir .Inst (ir .InstKind .LoadPtr , [value ])
1305
+ custom_tmp , ir .Inst (ir .InstKind .LoadPtr , [value ], ret_typ . typ )
1305
1306
)
1306
1307
else :
1307
1308
self .cur_func .inline_alloca (
1308
- ret_typ , tmp , ir .Inst (ir .InstKind .LoadPtr , [value ])
1309
+ ret_typ , tmp , ir .Inst (ir .InstKind .LoadPtr , [value ], ret_typ )
1309
1310
)
1310
1311
else :
1311
1312
if custom_tmp :
@@ -1463,7 +1464,7 @@ def gen_expr(self, expr, custom_tmp = None):
1463
1464
old_inside_selector_expr = self .inside_selector_expr
1464
1465
self .inside_selector_expr = True
1465
1466
left_sym = expr .left_typ .symbol ()
1466
- left = self .gen_expr_with_cast ( expr . left_typ , expr .left )
1467
+ left = self .gen_expr ( expr .left )
1467
1468
self .inside_selector_expr = old_inside_selector_expr
1468
1469
ir_left_typ = self .ir_type (expr .left_typ )
1469
1470
ir_typ = self .ir_type (expr .typ )
@@ -1498,10 +1499,8 @@ def gen_expr(self, expr, custom_tmp = None):
1498
1499
return ir .IntLit (ir .UINT_T , str (left .len ))
1499
1500
elif left_sym .kind == TypeKind .Array and expr .field_name == "len" :
1500
1501
return ir .IntLit (ir .UINT_T , str (left_sym .info .size ))
1501
- elif left_sym .kind == TypeKind .Trait :
1502
- return ir .Selector (ir_typ .ptr (), left , ir .Name (expr .field_name ))
1503
- if isinstance (left .typ , ir .Pointer ):
1504
- left = ir .Inst (ir .InstKind .LoadPtr , [left ], left .typ .typ )
1502
+ if left_sym .kind == TypeKind .Trait :
1503
+ ir_typ = ir_typ .ptr (True )
1505
1504
return ir .Selector (
1506
1505
ir_typ , left ,
1507
1506
ir .Name (
@@ -1670,7 +1669,7 @@ def gen_expr(self, expr, custom_tmp = None):
1670
1669
ir .InstKind .GetElementPtr , [left , idx ], expr_typ_ir
1671
1670
)
1672
1671
if not expr .is_ref :
1673
- value = ir .Inst (ir .InstKind .LoadPtr , [value ])
1672
+ value = ir .Inst (ir .InstKind .LoadPtr , [value ], expr_typ_ir )
1674
1673
elif s .kind == TypeKind .String :
1675
1674
value = ir .Inst (
1676
1675
ir .InstKind .Call , [
@@ -1736,7 +1735,7 @@ def gen_expr(self, expr, custom_tmp = None):
1736
1735
expr_right_typ = expr .right .typ
1737
1736
if isinstance (expr_left_typ , type .Option ):
1738
1737
if expr .op in (Kind .Eq , Kind .Ne ):
1739
- left = self .gen_expr_with_cast ( expr_left_typ , expr .left )
1738
+ left = self .gen_expr ( expr .left )
1740
1739
if expr_left_typ .is_pointer ():
1741
1740
op = "==" if expr .op == Kind .Eq else "!="
1742
1741
return ir .Inst (
@@ -1750,7 +1749,7 @@ def gen_expr(self, expr, custom_tmp = None):
1750
1749
elif expr .op == Kind .OrElse :
1751
1750
expr_typ = expr_left_typ
1752
1751
is_not_never = expr .right .typ != self .comp .never_t
1753
- left = self .gen_expr_with_cast ( expr_typ , expr .left )
1752
+ left = self .gen_expr ( expr .left )
1754
1753
is_none_label = self .cur_func .local_name ()
1755
1754
is_not_none_label = self .cur_func .local_name ()
1756
1755
exit_label = self .cur_func .local_name (
@@ -1878,7 +1877,7 @@ def gen_expr(self, expr, custom_tmp = None):
1878
1877
if not ((
1879
1878
isinstance (var_t2 , ir .Pointer ) and var_t2 .is_managed
1880
1879
) or expr .var .is_ref ):
1881
- val = ir .Inst (ir .InstKind .LoadPtr , [val ], var_t2 )
1880
+ val = ir .Inst (ir .InstKind .LoadPtr , [val ], var_t2 . typ )
1882
1881
unique_name = self .cur_func .unique_name (expr .var .name )
1883
1882
expr .scope .update_ir_name (expr .var .name , unique_name )
1884
1883
self .cur_func .inline_alloca (var_t , unique_name , val )
@@ -1887,7 +1886,7 @@ def gen_expr(self, expr, custom_tmp = None):
1887
1886
elif expr .op in (Kind .KwIn , Kind .KwNotIn ):
1888
1887
expr_left_typ = self .comp .comptime_number_to_type (expr_left_typ )
1889
1888
left = self .gen_expr_with_cast (expr_left_typ , expr .left )
1890
- right = self .gen_expr_with_cast ( expr . right . typ , expr .right )
1889
+ right = self .gen_expr ( expr .right )
1891
1890
left_sym = expr_left_typ .symbol ()
1892
1891
right_sym = expr .right .typ .symbol ()
1893
1892
contains_method = f"contains_{ right_sym .id } "
@@ -2154,7 +2153,7 @@ def gen_expr(self, expr, custom_tmp = None):
2154
2153
isinstance (var_t , ir .Pointer )
2155
2154
and var_t .is_managed
2156
2155
):
2157
- val = ir .Inst (ir .InstKind .LoadPtr , [val ])
2156
+ val = ir .Inst (ir .InstKind .LoadPtr , [val ], var_t . typ )
2158
2157
unique_name = self .cur_func .unique_name (b .var_name )
2159
2158
b .scope .update_ir_name (b .var_name , unique_name )
2160
2159
self .cur_func .inline_alloca (var_t , unique_name , val )
@@ -2342,8 +2341,9 @@ def gen_left_assign(self, expr, right, assign_op):
2342
2341
else :
2343
2342
left = self .gen_expr_with_cast (expr .typ , expr )
2344
2343
elif isinstance (expr , ast .SelectorExpr ):
2345
- if expr .is_indirect :
2346
- left = ir .Inst (ir .InstKind .LoadPtr , [self .gen_expr (expr .left )])
2344
+ if expr .is_indirect or expr .is_boxed_indirect :
2345
+ left_ir = self .gen_expr (expr .left )
2346
+ left = ir .Inst (ir .InstKind .LoadPtr , [left_ir ], left_ir .typ .typ )
2347
2347
else :
2348
2348
left = self .gen_expr_with_cast (expr .typ , expr )
2349
2349
elif isinstance (expr , ast .IndexExpr ):
@@ -2666,8 +2666,7 @@ def trait_value(self, value, value_typ, trait_typ):
2666
2666
value_sym = self .comp .comptime_number_to_type (value_typ ).symbol ()
2667
2667
trait_sym = trait_typ .symbol ()
2668
2668
size , _ = self .comp .type_size (value_typ )
2669
- trait_size , _ = self .comp .type_size (trait_typ )
2670
- tmp = self .boxed_instance (self .ir_type (trait_typ ), trait_size )
2669
+ tmp = self .boxed_instance (self .ir_type (trait_typ ), str (self .comp .pointer_size * 3 ))
2671
2670
is_ptr = isinstance (value .typ , ir .Pointer )
2672
2671
for f in trait_sym .fields :
2673
2672
f_typ = self .ir_type (f .typ )
@@ -2818,7 +2817,7 @@ def gen_return_trace_clear(self):
2818
2817
)
2819
2818
2820
2819
def gen_guard_expr (self , expr , entry_label , exit_label , gen_cond = True ):
2821
- gexpr = self .gen_expr_with_cast ( expr . typ , expr .expr )
2820
+ gexpr = self .gen_expr ( expr .expr )
2822
2821
var_name = self .cur_func .unique_name (expr .vars [0 ].name )
2823
2822
expr .scope .update_ir_name (expr .vars [0 ].name , var_name )
2824
2823
if expr .is_result :
@@ -2947,9 +2946,7 @@ def ir_type(self, typ, gen_self_arg = False):
2947
2946
typ_ = typ_ .ptr (True )
2948
2947
return typ_
2949
2948
res = ir .Type (cg_utils .mangle_symbol (typ_sym ))
2950
- if typ_sym .kind == TypeKind .Trait or (
2951
- isinstance (typ , type .Type ) and typ .is_boxed
2952
- ):
2949
+ if (isinstance (typ , type .Type ) and typ .is_boxed ) or typ_sym .kind == TypeKind .Trait :
2953
2950
return res .ptr (True )
2954
2951
return res
2955
2952
@@ -3196,6 +3193,7 @@ def generate_contains_method(
3196
3193
self , left_sym , right_sym , right_is_dyn_array , expr_left_typ ,
3197
3194
expr_right_typ , full_name
3198
3195
):
3196
+ elem_typ = right_sym .info .elem_typ
3199
3197
right_sym .info .has_contains_method = True
3200
3198
if right_is_dyn_array :
3201
3199
self_idx_ = ir .Ident (ir .DYN_ARRAY_T , "self" )
@@ -3247,15 +3245,15 @@ def generate_contains_method(
3247
3245
self .ir_type (expr_left_typ ).ptr ()
3248
3246
]
3249
3247
)
3250
- if is_primitive or right_elem_typ_sym . is_boxed ( ):
3251
- cur_elem = ir .Inst (ir .InstKind .LoadPtr , [cur_elem ])
3248
+ if is_primitive or ( isinstance ( elem_typ , type . Type ) and elem_typ . is_boxed ):
3249
+ cur_elem = ir .Inst (ir .InstKind .LoadPtr , [cur_elem ], cur_elem . typ )
3252
3250
else :
3253
3251
cur_elem = ir .Inst (
3254
3252
ir .InstKind .GetElementPtr , [self_idx_ , inc_v ],
3255
3253
self .ir_type (expr_left_typ )
3256
3254
)
3257
- if is_primitive or right_elem_typ_sym . is_boxed ( ):
3258
- cur_elem = ir .Inst (ir .InstKind .LoadPtr , [cur_elem ])
3255
+ if is_primitive or ( isinstance ( elem_typ , type . Type ) and elem_typ . is_boxed ):
3256
+ cur_elem = ir .Inst (ir .InstKind .LoadPtr , [cur_elem ], cur_elem . typ )
3259
3257
if is_primitive :
3260
3258
cond = ir .Inst (
3261
3259
ir .InstKind .Cmp , [ir .Name ("==" ), cur_elem , elem_idx_ ]
0 commit comments