aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-08-25 00:23:04 +0100
committerGinger Bill <bill@gingerbill.org>2016-08-25 00:23:04 +0100
commitf93cf3827ba5cde4f054db99b9815cb2a18ba861 (patch)
treee40e0ee29127b21e473ca2139cc102d08e86d4b3 /src
parentd2c64be85ca15117b1745b254b1806ea739aef43 (diff)
Change rune literals to #rune "C"
Diffstat (limited to 'src')
-rw-r--r--src/checker/checker.cpp10
-rw-r--r--src/checker/entity.cpp34
-rw-r--r--src/checker/stmt.cpp5
-rw-r--r--src/main.cpp7
-rw-r--r--src/parser.cpp17
-rw-r--r--src/tokenizer.cpp37
6 files changed, 47 insertions, 63 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp
index 458ce0dce..fb2b9139e 100644
--- a/src/checker/checker.cpp
+++ b/src/checker/checker.cpp
@@ -251,7 +251,7 @@ void scope_lookup_parent_entity(Checker *c, Scope *s, String name, Scope **scope
if (found) {
Entity *e = *found;
if (gone_thru_proc) {
- if (e->kind == Entity_Variable && e->parent != c->global_scope) {
+ if (e->kind == Entity_Variable && e->scope != c->global_scope) {
continue;
}
}
@@ -292,8 +292,8 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) {
if (found)
return *found;
map_set(&s->elements, key, entity);
- if (entity->parent == NULL)
- entity->parent = s;
+ if (entity->scope == NULL)
+ entity->scope = s;
return NULL;
}
@@ -640,7 +640,7 @@ void check_parsed_files(Checker *c) {
case_ast_node(td, TypeDecl, decl);
ast_node(n, Ident, td->name);
Entity *e = make_entity_type_name(c->allocator, c->global_scope, n->token, NULL);
- DeclInfo *d = make_declaration_info(c->allocator, e->parent);
+ DeclInfo *d = make_declaration_info(c->allocator, e->scope);
d->type_expr = td->type;
add_file_entity(c, td->name, e, d);
case_end;
@@ -650,7 +650,7 @@ void check_parsed_files(Checker *c) {
Token token = n->token;
Entity *e = make_entity_procedure(c->allocator, c->global_scope, token, NULL);
add_entity(c, c->global_scope, pd->name, e);
- DeclInfo *d = make_declaration_info(c->allocator, e->parent);
+ DeclInfo *d = make_declaration_info(c->allocator, e->scope);
d->proc_decl = decl;
map_set(&c->info.entities, hash_pointer(e), d);
case_end;
diff --git a/src/checker/entity.cpp b/src/checker/entity.cpp
index b59481319..90c4f3198 100644
--- a/src/checker/entity.cpp
+++ b/src/checker/entity.cpp
@@ -31,7 +31,7 @@ struct Entity {
EntityKind kind;
EntityGuid guid;
- Scope *parent;
+ Scope *scope;
Token token;
Type *type;
@@ -54,52 +54,52 @@ EntityGuid next_entity_guid(void) {
return cast(EntityGuid)gb_atomic64_fetch_add(&entity_guid_counter, 1);
}
-Entity *alloc_entity(gbAllocator a, EntityKind kind, Scope *parent, Token token, Type *type) {
+Entity *alloc_entity(gbAllocator a, EntityKind kind, Scope *scope, Token token, Type *type) {
Entity *entity = gb_alloc_item(a, Entity);
entity->kind = kind;
entity->guid = next_entity_guid();
- entity->parent = parent;
+ entity->scope = scope;
entity->token = token;
entity->type = type;
return entity;
}
-Entity *make_entity_variable(gbAllocator a, Scope *parent, Token token, Type *type) {
- Entity *entity = alloc_entity(a, Entity_Variable, parent, token, type);
+Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *type) {
+ Entity *entity = alloc_entity(a, Entity_Variable, scope, token, type);
return entity;
}
-Entity *make_entity_constant(gbAllocator a, Scope *parent, Token token, Type *type, ExactValue value) {
- Entity *entity = alloc_entity(a, Entity_Constant, parent, token, type);
+Entity *make_entity_constant(gbAllocator a, Scope *scope, Token token, Type *type, ExactValue value) {
+ Entity *entity = alloc_entity(a, Entity_Constant, scope, token, type);
entity->Constant.value = value;
return entity;
}
-Entity *make_entity_type_name(gbAllocator a, Scope *parent, Token token, Type *type) {
- Entity *entity = alloc_entity(a, Entity_TypeName, parent, token, type);
+Entity *make_entity_type_name(gbAllocator a, Scope *scope, Token token, Type *type) {
+ Entity *entity = alloc_entity(a, Entity_TypeName, scope, token, type);
return entity;
}
-Entity *make_entity_param(gbAllocator a, Scope *parent, Token token, Type *type) {
- Entity *entity = make_entity_variable(a, parent, token, type);
+Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type) {
+ Entity *entity = make_entity_variable(a, scope, token, type);
entity->Variable.used = true;
return entity;
}
-Entity *make_entity_field(gbAllocator a, Scope *parent, Token token, Type *type, b32 is_anonymous) {
- Entity *entity = make_entity_variable(a, parent, token, type);
+Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type, b32 is_anonymous) {
+ Entity *entity = make_entity_variable(a, scope, token, type);
entity->Variable.is_field = true;
entity->Variable.anonymous = cast(b8)is_anonymous;
return entity;
}
-Entity *make_entity_procedure(gbAllocator a, Scope *parent, Token token, Type *signature_type) {
- Entity *entity = alloc_entity(a, Entity_Procedure, parent, token, signature_type);
+Entity *make_entity_procedure(gbAllocator a, Scope *scope, Token token, Type *signature_type) {
+ Entity *entity = alloc_entity(a, Entity_Procedure, scope, token, signature_type);
return entity;
}
-Entity *make_entity_builtin(gbAllocator a, Scope *parent, Token token, Type *type, BuiltinProcId id) {
- Entity *entity = alloc_entity(a, Entity_Builtin, parent, token, type);
+Entity *make_entity_builtin(gbAllocator a, Scope *scope, Token token, Type *type, BuiltinProcId id) {
+ Entity *entity = alloc_entity(a, Entity_Builtin, scope, token, type);
entity->Builtin.id = id;
return entity;
}
diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp
index e120a467f..e4dc5f7f3 100644
--- a/src/checker/stmt.cpp
+++ b/src/checker/stmt.cpp
@@ -380,6 +380,7 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
push_procedure(c, type);
ast_node(bs, BlockStmt, body);
+ // TODO(bill): Check declarations first (except mutable variable declarations)
check_stmt_list(c, bs->list, 0);
if (type->Proc.result_count > 0) {
if (!check_is_terminating(c, body)) {
@@ -394,7 +395,7 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
GB_ASSERT(e->type == NULL);
- Type *proc_type = make_type_proc(c->allocator, e->parent, NULL, 0, NULL, 0);
+ Type *proc_type = make_type_proc(c->allocator, e->scope, NULL, 0, NULL, 0);
e->type = proc_type;
ast_node(pd, ProcDecl, d->proc_decl);
@@ -864,7 +865,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
add_entity(c, c->context.scope, pd->name, e);
DeclInfo decl = {};
- init_declaration_info(&decl, e->parent);
+ init_declaration_info(&decl, e->scope);
decl.proc_decl = node;
check_proc_decl(c, e, &decl, false);
destroy_declaration_info(&decl);
diff --git a/src/main.cpp b/src/main.cpp
index c2cbb124b..26ef255ce 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -82,11 +82,16 @@ int main(int argc, char **argv) {
char const *output_name = ssa.output_file.filename;
isize base_name_len = gb_path_extension(output_name)-1 - output_name;
- i32 exit_code = win32_exec_command_line_app(
+
+
+ i32 exit_code = 0;
+ exit_code = win32_exec_command_line_app(
"../misc/llvm-bin/opt -mem2reg %s -o %.*s.bc",
output_name, cast(int)base_name_len, output_name);
if (exit_code != 0)
return exit_code;
+#if 1
+#endif
exit_code = win32_exec_command_line_app(
"clang -o %.*s.exe %.*s.bc "
diff --git a/src/parser.cpp b/src/parser.cpp
index ca090a9c7..1691e76de 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1144,7 +1144,22 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
case Token_Hash: {
operand = parse_tag_expr(f, NULL);
- operand->TagExpr.expr = parse_expr(f, false);
+ String name = operand->TagExpr.name.string;
+ if (are_strings_equal(name, make_string("rune"))) {
+ if (f->cursor[0].kind == Token_String) {
+ Token *s = &f->cursor[0];
+
+ if (gb_utf8_strnlen(s->string.text, s->string.len) != 1) {
+ ast_file_err(f, *s, "Invalid rune literal %.*s", LIT(s->string));
+ }
+ s->kind = Token_Rune; // NOTE(bill): Change it
+ } else {
+ expect_token(f, Token_String);
+ }
+ operand = parse_operand(f, lhs);
+ } else {
+ operand->TagExpr.expr = parse_expr(f, false);
+ }
return operand;
}
diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp
index c931a7eb0..a5d8c8c82 100644
--- a/src/tokenizer.cpp
+++ b/src/tokenizer.cpp
@@ -698,43 +698,6 @@ Token tokenizer_get_token(Tokenizer *t) {
}
} break;
- case '$': { // Rune Literal
- b32 valid = true;
- isize len = 0;
- token.kind = Token_Rune;
- for (;;) {
- Rune r = t->curr_rune;
- if (r == '\n' || r < 0) {
- if (valid)
- tokenizer_err(t, "Rune literal not terminated");
- break;
- }
- advance_to_next_rune(t);
- if (r == '$')
- break;
- len++;
- if (r == '\\') {
- if (!scan_escape(t, '$'))
- valid = false;
- }
- }
-
- token.string.len = t->curr - token.string.text;
- if (valid && len != 1) {
- tokenizer_err(t, "Invalid rune literal %.*s", LIT(token.string));
- } else {
- i32 success = unquote_string(gb_heap_allocator(), &token.string);
- if (success > 0) {
- if (success == 2) {
- gb_array_append(t->allocated_strings, token.string);
- }
- return token;
- } else {
- tokenizer_err(t, "Invalid rune literal %.*s", LIT(token.string));
- }
- }
- } break;
-
case '.':
token.kind = Token_Period; // Default
if (gb_is_between(t->curr_rune, '0', '9')) { // Might be a number