aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-01-01 16:58:38 +0000
committerGinger Bill <bill@gingerbill.org>2017-01-01 16:58:38 +0000
commit311b5cb6e211aa49d8dc0e081173204d7271964f (patch)
tree34e46ebf224736b737f72b2873d5afcaab8d5f17 /src
parent6fef74317cdd0e403fb913ebe965dc08b3dfb22d (diff)
Add enum type info and fix enum casting
Diffstat (limited to 'src')
-rw-r--r--src/checker/checker.c3
-rw-r--r--src/checker/decl.c6
-rw-r--r--src/checker/entity.c12
-rw-r--r--src/checker/expr.c14
-rw-r--r--src/checker/stmt.c5
-rw-r--r--src/parser.c13
-rw-r--r--src/ssa.c14
-rw-r--r--src/tokenizer.c1
8 files changed, 29 insertions, 39 deletions
diff --git a/src/checker/checker.c b/src/checker/checker.c
index 79ca9eef6..98107c9d0 100644
--- a/src/checker/checker.c
+++ b/src/checker/checker.c
@@ -1177,7 +1177,6 @@ void check_global_collect_entities_from_file(Checker *c, Scope *parent_scope, As
case_end;
case_ast_node(vs, ValueSpec, spec);
switch (vs->keyword) {
- case Token_let:
case Token_var: {
// NOTE(bill): You need to store the entity information here unline a constant declaration
isize entity_count = vs->names.count;
@@ -1202,7 +1201,7 @@ void check_global_collect_entities_from_file(Checker *c, Scope *parent_scope, As
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
continue;
}
- Entity *e = make_entity_variable(c->allocator, parent_scope, name->Ident, NULL, vs->keyword == Token_let);
+ Entity *e = make_entity_variable(c->allocator, parent_scope, name->Ident, NULL);
e->identifier = name;
entities[entity_index++] = e;
diff --git a/src/checker/decl.c b/src/checker/decl.c
index 0c4d3f075..d73c79e35 100644
--- a/src/checker/decl.c
+++ b/src/checker/decl.c
@@ -95,18 +95,20 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra
error(lhs[0]->token, "Assignment count mismatch `%td` = `%td`", lhs_count, rhs_count);
}
+#if 0
if (lhs[0]->kind == Entity_Variable &&
lhs[0]->Variable.is_let) {
if (lhs_count != rhs_count) {
error(lhs[0]->token, "`let` variables must be initialized, `%td` = `%td`", lhs_count, rhs_count);
}
}
+#endif
gb_temp_arena_memory_end(tmp);
}
void check_var_spec_node(Checker *c, AstNodeValueSpec *vs) {
- GB_ASSERT(vs->keyword == Token_var || vs->keyword == Token_let);
+ GB_ASSERT(vs->keyword == Token_var);
isize entity_count = vs->names.count;
isize entity_index = 0;
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
@@ -123,7 +125,7 @@ void check_var_spec_node(Checker *c, AstNodeValueSpec *vs) {
found = current_scope_lookup_entity(c->context.scope, str);
}
if (found == NULL) {
- entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, vs->keyword == Token_let);
+ entity = make_entity_variable(c->allocator, c->context.scope, token, NULL);
add_entity_definition(&c->info, name, entity);
} else {
TokenPos pos = found->token.pos;
diff --git a/src/checker/entity.c b/src/checker/entity.c
index 7dcee62d0..85e4c5d8d 100644
--- a/src/checker/entity.c
+++ b/src/checker/entity.c
@@ -57,7 +57,6 @@ struct Entity {
struct {
i32 field_index;
i32 field_src_index;
- bool is_let;
} Variable;
i32 TypeName;
struct {
@@ -97,9 +96,8 @@ Entity *alloc_entity(gbAllocator a, EntityKind kind, Scope *scope, Token token,
return entity;
}
-Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *type, bool is_let) {
+Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *type) {
Entity *entity = alloc_entity(a, Entity_Variable, scope, token, type);
- entity->Variable.is_let = is_let;
return entity;
}
@@ -124,7 +122,7 @@ Entity *make_entity_type_name(gbAllocator a, Scope *scope, Token token, Type *ty
}
Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous) {
- Entity *entity = make_entity_variable(a, scope, token, type, false);
+ Entity *entity = make_entity_variable(a, scope, token, type);
entity->flags |= EntityFlag_Used;
entity->flags |= EntityFlag_Anonymous*(anonymous != 0);
entity->flags |= EntityFlag_Param;
@@ -132,7 +130,7 @@ Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type,
}
Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous, i32 field_src_index) {
- Entity *entity = make_entity_variable(a, scope, token, type, false);
+ Entity *entity = make_entity_variable(a, scope, token, type);
entity->Variable.field_src_index = field_src_index;
entity->Variable.field_index = field_src_index;
entity->flags |= EntityFlag_Field;
@@ -141,7 +139,7 @@ Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type,
}
Entity *make_entity_vector_elem(gbAllocator a, Scope *scope, Token token, Type *type, i32 field_src_index) {
- Entity *entity = make_entity_variable(a, scope, token, type, false);
+ Entity *entity = make_entity_variable(a, scope, token, type);
entity->Variable.field_src_index = field_src_index;
entity->Variable.field_index = field_src_index;
entity->flags |= EntityFlag_Field;
@@ -186,6 +184,6 @@ Entity *make_entity_implicit_value(gbAllocator a, String name, Type *type, Impli
Entity *make_entity_dummy_variable(gbAllocator a, Scope *file_scope, Token token) {
token.string = str_lit("_");
- return make_entity_variable(a, file_scope, token, NULL, false);
+ return make_entity_variable(a, file_scope, token, NULL);
}
diff --git a/src/checker/expr.c b/src/checker/expr.c
index 7b9b0db52..d0116e8b2 100644
--- a/src/checker/expr.c
+++ b/src/checker/expr.c
@@ -791,7 +791,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
continue;
}
- GB_ASSERT(c->context.iota.kind == ExactValue_Invalid);
+ ExactValue context_iota = c->context.iota;
c->context.iota = e->Constant.value;
e->Constant.value = (ExactValue){0};
@@ -799,7 +799,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
check_expr(c, &operand, init);
check_init_constant(c, e, &operand);
- c->context.iota = (ExactValue){0};
+ c->context.iota = context_iota;
if (operand.mode == Addressing_Constant) {
HashKey key = hash_string(name);
@@ -1001,9 +1001,9 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
}
#else
o->mode = Addressing_Variable;
- if (e->Variable.is_let) {
- o->mode = Addressing_Value;
- }
+ // if (e->Variable.is_let) {
+ // o->mode = Addressing_Value;
+ // }
#endif
break;
@@ -1770,8 +1770,8 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
}
Type *x = operand->type;
- Type *xb = base_type(x);
- Type *yb = base_type(y);
+ Type *xb = base_type(base_enum_type(x));
+ Type *yb = base_type(base_enum_type(y));
if (are_types_identical(xb, yb)) {
return true;
}
diff --git a/src/checker/stmt.c b/src/checker/stmt.c
index 5b7d7887f..4c82267fc 100644
--- a/src/checker/stmt.c
+++ b/src/checker/stmt.c
@@ -848,7 +848,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
tt = make_type_pointer(c->allocator, case_type);
add_type_info_type(c, tt);
}
- Entity *tag_var = make_entity_variable(c->allocator, c->context.scope, ms->var->Ident, tt, false);
+ Entity *tag_var = make_entity_variable(c->allocator, c->context.scope, ms->var->Ident, tt);
tag_var->flags |= EntityFlag_Used;
add_entity(c, c->context.scope, ms->var, tag_var);
add_entity_use(c, ms->var, tag_var);
@@ -1106,7 +1106,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case_end;
case_ast_node(vs, ValueSpec, spec);
switch (vs->keyword) {
- case Token_let:
case Token_var: {
isize entity_count = vs->names.count;
isize entity_index = 0;
@@ -1124,7 +1123,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
found = current_scope_lookup_entity(c->context.scope, str);
}
if (found == NULL) {
- entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, vs->keyword == Token_let);
+ entity = make_entity_variable(c->allocator, c->context.scope, token, NULL);
add_entity_definition(&c->info, name, entity);
} else {
TokenPos pos = found->token.pos;
diff --git a/src/parser.c b/src/parser.c
index a7d9b4282..2d61c9e92 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1211,7 +1211,6 @@ void fix_advance_to_next_stmt(AstFile *f) {
return;
case Token_var:
- case Token_let:
case Token_const:
case Token_type:
case Token_proc:
@@ -2154,7 +2153,6 @@ PARSE_SPEC_PROC(parse_value_spec) {
switch (keyword) {
case Token_var:
- case Token_let:
if (type == NULL && values.count == 0 && names.count > 0) {
syntax_error(f->curr_token, "Missing type or initialization");
return make_bad_decl(f, f->curr_token, f->curr_token);
@@ -2240,7 +2238,6 @@ PARSE_SPEC_PROC(parse_include_spec) {
AstNode *parse_decl(AstFile *f) {
switch (f->curr_token.kind) {
case Token_var:
- case Token_let:
case Token_const:
return parse_generic_decl(f, f->curr_token.kind, parse_value_spec);
@@ -2269,7 +2266,6 @@ AstNode *parse_decl(AstFile *f) {
AstNode *parse_simple_stmt(AstFile *f) {
switch (f->curr_token.kind) {
case Token_var:
- case Token_let:
case Token_const:
return parse_decl(f);
}
@@ -2555,9 +2551,11 @@ AstNode *parse_identifier_or_type(AstFile *f) {
base_type = parse_type(f);
}
Token open = expect_token(f, Token_OpenBrace);
- AstNodeArray fields = parse_element_list(f);
+
+ AstNodeArray values = parse_element_list(f);
Token close = expect_token(f, Token_CloseBrace);
- return make_enum_type(f, token, base_type, fields);
+
+ return make_enum_type(f, token, base_type, values);
}
case Token_proc: {
@@ -3026,7 +3024,6 @@ AstNode *parse_stmt(AstFile *f) {
return s;
case Token_var:
- case Token_let:
case Token_const:
case Token_proc:
case Token_type:
@@ -3071,8 +3068,6 @@ AstNode *parse_stmt(AstFile *f) {
case AstNode_GenericDecl:
if (node->GenericDecl.token.kind == Token_var) {
valid = true;
- } else if (node->GenericDecl.token.kind == Token_let) {
- valid = true;
}
break;
}
diff --git a/src/ssa.c b/src/ssa.c
index d53b5fcf6..10a54bf40 100644
--- a/src/ssa.c
+++ b/src/ssa.c
@@ -1233,8 +1233,7 @@ ssaValue *ssa_add_local_generated(ssaProcedure *proc, Type *type) {
Entity *e = make_entity_variable(proc->module->allocator,
scope,
empty_token,
- type,
- false);
+ type);
return ssa_add_local(proc, e);
}
@@ -1920,8 +1919,8 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) {
return value;
}
- Type *src = base_type(src_type);
- Type *dst = base_type(t);
+ Type *src = base_type(base_enum_type(src_type));
+ Type *dst = base_type(base_enum_type(t));
if (value->kind == ssaValue_Constant) {
if (is_type_any(dst)) {
@@ -3934,7 +3933,6 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) {
switch (vs->keyword) {
case Token_const:
break;
- case Token_let:
case Token_var: {
ssaModule *m = proc->module;
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
@@ -4784,7 +4782,7 @@ void ssa_init_module(ssaModule *m, Checker *c, BuildContext *build_context) {
{
String name = str_lit(SSA_TYPE_INFO_DATA_NAME);
isize count = c->info.type_info_map.entries.count;
- Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_type_info, count), false);
+ Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_type_info, count));
ssaValue *g = ssa_make_value_global(m->allocator, e, NULL);
g->Global.is_private = true;
ssa_module_add_value(m, e, g);
@@ -4816,7 +4814,7 @@ void ssa_init_module(ssaModule *m, Checker *c, BuildContext *build_context) {
String name = str_lit(SSA_TYPE_INFO_DATA_MEMBER_NAME);
Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name),
- make_type_array(m->allocator, t_type_info_member, count), false);
+ make_type_array(m->allocator, t_type_info_member, count));
ssaValue *g = ssa_make_value_global(m->allocator, e, NULL);
ssa_module_add_value(m, e, g);
map_ssa_value_set(&m->members, hash_string(name), g);
@@ -5504,7 +5502,7 @@ void ssa_gen_tree(ssaGen *s) {
token.string.text = gb_alloc_array(a, u8, name_len);
token.string.len = gb_snprintf(cast(char *)token.string.text, name_len,
"%s-%d", name_base, id)-1;
- Entity *e = make_entity_variable(a, NULL, token, make_type_array(a, t_string, count), false);
+ Entity *e = make_entity_variable(a, NULL, token, make_type_array(a, t_string, count));
name_array = ssa_make_value_global(a, e, NULL);
name_array->Global.is_private = true;
ssa_module_add_value(m, e, name_array);
diff --git a/src/tokenizer.c b/src/tokenizer.c
index a35ed070e..c80f7bf2a 100644
--- a/src/tokenizer.c
+++ b/src/tokenizer.c
@@ -85,7 +85,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
TOKEN_KIND(Token_type, "type"), \
TOKEN_KIND(Token_proc, "proc"), \
TOKEN_KIND(Token_var, "var"), \
- TOKEN_KIND(Token_let, "let"), \
TOKEN_KIND(Token_const, "const"), \
TOKEN_KIND(Token_import, "import"), \
TOKEN_KIND(Token_include, "include"), \