Fix match statements for the new AstNodeArray type

This commit is contained in:
Ginger Bill
2016-09-08 18:28:18 +01:00
parent c6d02e4778
commit 56dd12c54c
12 changed files with 1530 additions and 187 deletions
+31 -11
View File
@@ -57,11 +57,31 @@ void add_type_info_type(Checker *c, Type *t) {
}
map_set(&c->info.type_info_types, hash_pointer(t), t);
if (t->kind == Type_Named) {
// NOTE(bill): Just in case
add_type_info_type(c, t->Named.base);
return;
}
Type *bt = get_base_type(t);
switch (bt->kind) {
case Type_Named: add_type_info_type(c, bt->Named.base); break;
case Type_Array: add_type_info_type(c, bt->Array.elem); break;
case Type_Slice: add_type_info_type(c, bt->Slice.elem); break;
case Type_Basic: {
if (bt->Basic.kind == Basic_string) {
add_type_info_type(c, make_type_pointer(c->allocator, t_u8));
add_type_info_type(c, t_int);
}
} break;
case Type_Array:
add_type_info_type(c, bt->Array.elem);
add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem));
add_type_info_type(c, t_int);
break;
case Type_Slice:
add_type_info_type(c, bt->Slice.elem);
add_type_info_type(c, make_type_pointer(c->allocator, bt->Slice.elem));
add_type_info_type(c, t_int);
break;
case Type_Vector: add_type_info_type(c, bt->Vector.elem); break;
case Type_Pointer: add_type_info_type(c, bt->Pointer.elem); break;
case Type_Record: {
@@ -1372,7 +1392,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) {
x->mode = Addressing_Value;
}
b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
b32 check_is_castable_to(Checker *c, Operand *operand, Type *y) {
if (check_is_assignable_to(c, operand, y))
return true;
@@ -1387,20 +1407,20 @@ b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
// Cast between booleans and integers
if (is_type_boolean(x) || is_type_integer(x)) {
if (is_type_boolean(y) || is_type_integer(y))
if (is_type_boolean(xb) || is_type_integer(xb)) {
if (is_type_boolean(yb) || is_type_integer(yb))
return true;
}
// Cast between numbers
if (is_type_integer(x) || is_type_float(x)) {
if (is_type_integer(y) || is_type_float(y))
if (is_type_integer(xb) || is_type_float(xb)) {
if (is_type_integer(yb) || is_type_float(yb))
return true;
}
// Cast between pointers
if (is_type_pointer(x)) {
if (is_type_pointer(y))
if (is_type_pointer(xb)) {
if (is_type_pointer(yb))
return true;
}
@@ -1494,7 +1514,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
can_convert = true;
}
}
} else if (check_castable_to(c, x, type)) {
} else if (check_is_castable_to(c, x, type)) {
x->mode = Addressing_Value;
can_convert = true;
}
+15 -10
View File
@@ -706,8 +706,8 @@ void selection_add_index(Selection *s, isize index) {
gb_array_append(s->index, index);
}
gb_global Entity *entity_any_type_info = NULL;
gb_global Entity *entity_any_data = NULL;
gb_global Entity *entity__any_type_info = NULL;
gb_global Entity *entity__any_data = NULL;
Selection lookup_field(Type *type_, String field_name, b32 is_type, Selection sel = empty_selection) {
GB_ASSERT(type_ != NULL);
@@ -721,29 +721,31 @@ Selection lookup_field(Type *type_, String field_name, b32 is_type, Selection se
type = get_base_type(type);
if (type->kind == Type_Basic) {
if (type->Basic.kind == Basic_any) {
switch (type->Basic.kind) {
case Basic_any: {
String type_info_str = make_string("type_info");
String data_str = make_string("data");
if (entity_any_type_info == NULL) {
if (entity__any_type_info == NULL) {
Token token = {Token_Identifier};
token.string = type_info_str;
entity_any_type_info = make_entity_field(gb_heap_allocator(), NULL, token, t_type_info_ptr, false);
entity__any_type_info = make_entity_field(gb_heap_allocator(), NULL, token, t_type_info_ptr, false);
}
if (entity_any_data == NULL) {
if (entity__any_data == NULL) {
Token token = {Token_Identifier};
token.string = data_str;
entity_any_data = make_entity_field(gb_heap_allocator(), NULL, token, t_type_info_ptr, false);
entity__any_data = make_entity_field(gb_heap_allocator(), NULL, token, t_rawptr, false);
}
if (are_strings_equal(field_name, type_info_str)) {
selection_add_index(&sel, 0);
sel.entity = entity_any_type_info;
sel.entity = entity__any_type_info;
return sel;
} else if (are_strings_equal(field_name, data_str)) {
selection_add_index(&sel, 1);
sel.entity = entity_any_data;
sel.entity = entity__any_data;
return sel;
}
} break;
}
return sel;
@@ -916,8 +918,11 @@ i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
if (size > 0)
return size;
}
if (kind == Basic_string)
if (kind == Basic_string) {
return 2 * s.word_size;
} else if (kind == Basic_any) {
return 2 * s.word_size;
}
} break;
case Type_Array: {
+2 -2
View File
@@ -3184,9 +3184,9 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
fall = ssa__make_block(proc, clause, make_string("match.fall.body"));
}
if (gb_array_count(cc->list)) {
if (gb_array_count(cc->list) == 0) {
// default case
default_stmts = cc->stmts;
default_stmts = cc->stmts;
default_fall = fall;
default_block = body;
continue;
+2 -1
View File
@@ -78,6 +78,7 @@ enum CallExprKind {
AstNodeArray make_ast_node_array(AstFile *f) {
AstNodeArray a;
gb_array_init(a, gb_arena_allocator(&f->arena));
GB_ASSERT(a != NULL);
return a;
}
@@ -2220,7 +2221,7 @@ AstNode *parse_for_stmt(AstFile *f) {
AstNode *parse_case_clause(AstFile *f) {
Token token = f->cursor[0];
AstNodeArray list = NULL;
AstNodeArray list = make_ast_node_array(f);
if (allow_token(f, Token_case)) {
list = parse_rhs_expr_list(f);
} else {
+1
View File
@@ -323,6 +323,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) {
char *c_str = gb_alloc_array(gb_heap_allocator(), char, fullpath.len+1);
memcpy(c_str, fullpath.text, fullpath.len);
c_str[fullpath.len] = '\0';
defer (gb_free(gb_heap_allocator(), c_str));
gbFileContents fc = gb_file_read_contents(gb_heap_allocator(), true, c_str);