|
@@ -762,6 +762,12 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
|
|
case Token_Xor:
|
|
|
case Token_AndNot: {
|
|
|
Type *type = default_type(tv.type);
|
|
|
+ if (is_type_typed(be->left->tav.type) && is_type_untyped(be->right->tav.type)) {
|
|
|
+ be->right->tav.type = be->left->tav.type;
|
|
|
+ } else if (is_type_untyped(be->left->tav.type) && is_type_typed(be->right->tav.type)) {
|
|
|
+ be->left->tav.type = type_of_expr(be->right);
|
|
|
+ }
|
|
|
+
|
|
|
lbValue left = lb_build_expr(p, be->left);
|
|
|
lbValue right = lb_build_expr(p, be->right);
|
|
|
return lb_emit_arith(p, be->op.kind, left, right, type);
|
|
@@ -2247,17 +2253,18 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
|
|
|
TokenPos expr_pos = ast_token(expr).pos;
|
|
|
TypeAndValue tv = type_and_value_of_expr(expr);
|
|
|
+ Type *type = type_of_expr(expr);
|
|
|
GB_ASSERT_MSG(tv.mode != Addressing_Invalid, "invalid expression '%s' (tv.mode = %d, tv.type = %s) @ %s\n Current Proc: %.*s : %s", expr_to_string(expr), tv.mode, type_to_string(tv.type), token_pos_to_string(expr_pos), LIT(p->name), type_to_string(p->type));
|
|
|
|
|
|
if (tv.value.kind != ExactValue_Invalid) {
|
|
|
// NOTE(bill): The commented out code below is just for debug purposes only
|
|
|
// GB_ASSERT_MSG(!is_type_untyped(tv.type), "%s @ %s\n%s", type_to_string(tv.type), token_pos_to_string(expr_pos), expr_to_string(expr));
|
|
|
- // if (is_type_untyped(tv.type)) {
|
|
|
+ // if (is_type_untyped(type)) {
|
|
|
// gb_printf_err("%s %s\n", token_pos_to_string(expr_pos), expr_to_string(expr));
|
|
|
// }
|
|
|
|
|
|
// NOTE(bill): Short on constant values
|
|
|
- return lb_const_value(p->module, tv.type, tv.value);
|
|
|
+ return lb_const_value(p->module, type, tv.value);
|
|
|
}
|
|
|
|
|
|
#if 0
|
|
@@ -2288,12 +2295,12 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
|
|
|
case_ast_node(u, Undef, expr)
|
|
|
lbValue res = {};
|
|
|
- if (is_type_untyped(tv.type)) {
|
|
|
+ if (is_type_untyped(type)) {
|
|
|
res.value = nullptr;
|
|
|
res.type = t_untyped_undef;
|
|
|
} else {
|
|
|
- res.value = LLVMGetUndef(lb_type(m, tv.type));
|
|
|
- res.type = tv.type;
|
|
|
+ res.value = LLVMGetUndef(lb_type(m, type));
|
|
|
+ res.type = type;
|
|
|
}
|
|
|
return res;
|
|
|
case_end;
|
|
@@ -2334,7 +2341,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
TypeAndValue tav = type_and_value_of_expr(expr);
|
|
|
GB_ASSERT(tav.mode == Addressing_Constant);
|
|
|
|
|
|
- return lb_const_value(p->module, tv.type, tv.value);
|
|
|
+ return lb_const_value(p->module, type, tv.value);
|
|
|
case_end;
|
|
|
|
|
|
case_ast_node(se, SelectorCallExpr, expr);
|
|
@@ -2407,7 +2414,6 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
|
|
|
case_ast_node(ta, TypeAssertion, expr);
|
|
|
TokenPos pos = ast_token(expr).pos;
|
|
|
- Type *type = tv.type;
|
|
|
lbValue e = lb_build_expr(p, ta->expr);
|
|
|
Type *t = type_deref(e.type);
|
|
|
if (is_type_union(t)) {
|
|
@@ -2427,16 +2433,16 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
lbValue e = lb_build_expr(p, tc->expr);
|
|
|
switch (tc->token.kind) {
|
|
|
case Token_cast:
|
|
|
- return lb_emit_conv(p, e, tv.type);
|
|
|
+ return lb_emit_conv(p, e, type);
|
|
|
case Token_transmute:
|
|
|
- return lb_emit_transmute(p, e, tv.type);
|
|
|
+ return lb_emit_transmute(p, e, type);
|
|
|
}
|
|
|
GB_PANIC("Invalid AST TypeCast");
|
|
|
case_end;
|
|
|
|
|
|
case_ast_node(ac, AutoCast, expr);
|
|
|
lbValue value = lb_build_expr(p, ac->expr);
|
|
|
- return lb_emit_conv(p, value, tv.type);
|
|
|
+ return lb_emit_conv(p, value, type);
|
|
|
case_end;
|
|
|
|
|
|
case_ast_node(ue, UnaryExpr, expr);
|
|
@@ -2446,7 +2452,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
|
|
default:
|
|
|
{
|
|
|
lbValue v = lb_build_expr(p, ue->expr);
|
|
|
- return lb_emit_unary_arith(p, ue->op.kind, v, tv.type);
|
|
|
+ return lb_emit_unary_arith(p, ue->op.kind, v, type);
|
|
|
}
|
|
|
}
|
|
|
case_end;
|