aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-04-02 22:03:52 +0100
committerGinger Bill <bill@gingerbill.org>2017-04-02 22:03:52 +0100
commit382a5ca6a27ea0f6dde4c0783d55f5dca8ac2575 (patch)
treefc7b7592651b166bdbbf7334649b062d584231e9 /src
parent96e8bb5b6f3c8d2cf2b0fae8c7a9c710c4e9dbb0 (diff)
Update and regression test old demos
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.c8
-rw-r--r--src/check_stmt.c4
-rw-r--r--src/ir.c12
-rw-r--r--src/parser.c3
4 files changed, 19 insertions, 8 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 797295c0f..5370f76b3 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -249,12 +249,10 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
operand->mode = Addressing_Invalid;
return;
}
- if (is_type_any(type)) {
- target_type = t_any;
- } else {
- target_type = default_type(operand->type);
+ target_type = default_type(operand->type);
+ if (!is_type_any(type)) {
+ GB_ASSERT_MSG(is_type_typed(target_type), "%s", type_to_string(type));
}
- GB_ASSERT_MSG(is_type_typed(target_type), "%s", type_to_string(type));
add_type_info_type(c, type);
add_type_info_type(c, target_type);
}
diff --git a/src/check_stmt.c b/src/check_stmt.c
index 6aec1beee..0ad48864a 100644
--- a/src/check_stmt.c
+++ b/src/check_stmt.c
@@ -1264,8 +1264,10 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case Entity_TypeName: {
Type *t = base_type(e->type);
if (is_type_union(t)) {
- for (isize i = 0; i < t->Record.variant_count; i++) {
+ TokenPos pos = ast_node_token(expr).pos;
+ for (isize i = 1; i < t->Record.variant_count; i++) {
Entity *f = t->Record.variants[i];
+ // gb_printf_err("%s\n", type_to_string(f->type));
Entity *found = scope_insert_entity(c->context.scope, f);
if (found != NULL) {
gbString expr_str = expr_to_string(expr);
diff --git a/src/ir.c b/src/ir.c
index 58d6aa7dd..13d1af22c 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -4263,8 +4263,10 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
irValue *ptr = ir_emit_conv(proc, ir_slice_elem(proc, s), t_u8_ptr);
irValue *count = ir_slice_count(proc, s);
+ irValue *capacity = ir_slice_capacity(proc, s);
count = ir_emit_arith(proc, Token_Mul, count, ir_const_int(proc->module->allocator, elem_size), t_int);
- ir_fill_slice(proc, slice, ptr, count, count);
+ capacity = ir_emit_arith(proc, Token_Mul, capacity, ir_const_int(proc->module->allocator, elem_size), t_int);
+ ir_fill_slice(proc, slice, ptr, count, capacity);
return ir_emit_load(proc, slice);
} break;
@@ -4602,6 +4604,14 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
ir_emit_store(proc, v, ir_emit_down_cast(proc, ir_build_expr(proc, ce->expr), type));
return ir_addr(v);
}
+ case Token_union_cast: {
+ ir_emit_comment(proc, str_lit("Cast - union_cast"));
+ // NOTE(bill): Needed for dereference of pointer conversion
+ Type *type = type_of_expr(proc->module->info, expr);
+ irValue *v = ir_add_local_generated(proc, type);
+ ir_emit_store(proc, v, ir_emit_union_cast(proc, ir_build_expr(proc, ce->expr), type, ast_node_token(expr).pos));
+ return ir_addr(v);
+ }
default:
GB_PANIC("Unknown cast expression");
}
diff --git a/src/parser.c b/src/parser.c
index 5169bd7bf..a9cae2710 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -2272,6 +2272,7 @@ AstNode *parse_value_decl(AstFile *f, AstNodeArray lhs) {
}
+
AstNode *parse_simple_stmt(AstFile *f, bool in_stmt_ok) {
AstNodeArray lhs = parse_lhs_expr_list(f);
Token token = f->curr_token;
@@ -3290,7 +3291,7 @@ AstNode *parse_stmt(AstFile *f) {
return ast_using_stmt(f, token, list);
}
- AstNode *decl = parse_simple_stmt(f, false);
+ AstNode *decl = parse_value_decl(f, list);
expect_semicolon(f, decl);
if (decl->kind == AstNode_ValueDecl) {