aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-05-27 10:49:14 +0100
committergingerBill <bill@gingerbill.org>2018-05-27 10:49:14 +0100
commit7ee9051a56ca0c04e6b60f53b9dfe47c75596496 (patch)
tree619c13b7d86105fcfda13d315c0c315e7005630a /src
parenteb11edabe092541144cd3ba18b09bd11fcf7a958 (diff)
IR now builds with the new package system
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp10
-rw-r--r--src/checker.cpp4
-rw-r--r--src/ir.cpp27
-rw-r--r--src/main.cpp4
-rw-r--r--src/parser.cpp4
-rw-r--r--src/parser.hpp2
-rw-r--r--src/string.cpp5
7 files changed, 44 insertions, 12 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 2626610de..db666da46 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -531,11 +531,15 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
check_decl_attributes(c, d->attributes, proc_decl_attribute, &ac);
}
-
e->deprecated_message = ac.deprecated_message;
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
- if (d->scope->package != nullptr && e->token.string == "main") {
+ AstPackage *package = nullptr;
+ if (d->scope->parent && d->scope->parent->is_package) {
+ package = d->scope->parent->package;
+ }
+
+ if (package != nullptr && e->token.string == "main") {
if (pt->param_count != 0 ||
pt->result_count != 0) {
gbString str = type_to_string(proc_type);
@@ -547,7 +551,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
error(e->token, "Procedure 'main' cannot have a custom calling convention");
}
pt->calling_convention = ProcCC_Contextless;
- if (d->scope->is_init) {
+ if (package->kind == ImportedPackage_Init) {
if (c->info.entry_point != nullptr) {
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
} else {
diff --git a/src/checker.cpp b/src/checker.cpp
index 2f4a37511..470cfe185 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -533,6 +533,7 @@ void init_universal_scope(void) {
// NOTE(bill): No need to free these
gbAllocator a = heap_allocator();
universal_scope = create_scope(nullptr, a);
+ universal_scope->is_package = true;
// Types
for (isize i = 0; i < gb_count_of(basic_types); i++) {
@@ -2961,6 +2962,9 @@ void check_parsed_files(Checker *c) {
for_array(j, p->files.entries) {
AstFile *f = p->files.entries[j].value;
create_scope_from_file(c, f);
+ HashKey key = hash_string(f->fullpath);
+ map_set(&c->info.files, key, f);
+
add_curr_ast_file(c, f);
check_collect_entities(c, f->decls);
}
diff --git a/src/ir.cpp b/src/ir.cpp
index ab5c38838..f20d2cafb 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -7735,7 +7735,8 @@ bool ir_gen_init(irGen *s, Checker *c) {
String init_fullpath = c->parser->init_fullpath;
if (build_context.out_filepath.len == 0) {
- s->output_name = filename_from_path(init_fullpath);
+ // s->output_name = filename_from_path(init_fullpath);
+ s->output_name = str_lit("main");
s->output_base = s->output_name;
} else {
s->output_name = build_context.out_filepath;
@@ -8255,9 +8256,17 @@ void ir_gen_tree(irGen *s) {
for_array(i, info->entities) {
Entity *e = info->entities[i];
String name = e->token.string;
+
+ bool is_global = false;
+ if (e->scope->is_package) {
+ is_global = true;
+ } else if (e->scope->parent && e->scope->parent->is_package) {
+ is_global = true;
+ }
+
if (e->kind == Entity_Variable) {
global_variable_max_count++;
- } else if (e->kind == Entity_Procedure && !e->scope->is_global) {
+ } else if (e->kind == Entity_Procedure && !is_global) {
if (e->scope->is_init && name == "main") {
GB_ASSERT(e == entry_point);
// entry_point = e;
@@ -8306,9 +8315,16 @@ void ir_gen_tree(irGen *s) {
GB_ASSERT(e->kind == Entity_Variable);
+ bool is_global = false;
+ if (e->scope->is_package) {
+ is_global = true;
+ } else if (e->scope->parent && e->scope->parent->is_package) {
+ is_global = true;
+ }
+
bool is_foreign = e->Variable.is_foreign;
bool is_export = e->Variable.is_export;
- bool no_name_mangle = e->scope->is_global || e->Variable.link_name.len > 0 || is_foreign || is_export;
+ bool no_name_mangle = is_global || e->Variable.link_name.len > 0 || is_foreign || is_export;
String name = e->token.string;
if (!no_name_mangle) {
@@ -8353,6 +8369,9 @@ void ir_gen_tree(irGen *s) {
continue;
}
+ Scope *package_scope = scope->parent;
+ GB_ASSERT(package_scope->is_package);
+
switch (e->kind) {
case Entity_Variable:
// NOTE(bill): Handled above as it requires a specific load order
@@ -8376,7 +8395,7 @@ void ir_gen_tree(irGen *s) {
String original_name = name;
- if (!scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
+ if (!package_scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
if (e->kind == Entity_Procedure && e->Procedure.is_export) {
} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
// Handle later
diff --git a/src/main.cpp b/src/main.cpp
index 9b08fda1f..733e45c30 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,11 +14,9 @@
#include "parser.cpp"
#include "docs.cpp"
#include "checker.cpp"
-#if 0
#include "ir.cpp"
#include "ir_opt.cpp"
#include "ir_print.cpp"
-#endif
// NOTE(bill): 'name' is used in debugging and profiling modes
i32 system_exec_command_line_app(char *name, bool is_silent, char *fmt, ...) {
@@ -811,7 +809,7 @@ int main(int arg_count, char **arg_ptr) {
check_parsed_files(&checker);
-#if 0
+#if 1
if (build_context.no_output_files) {
if (build_context.show_timings) {
show_timings(&checker, &timings);
diff --git a/src/parser.cpp b/src/parser.cpp
index 7e3a79613..1a7ba68a3 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -3831,7 +3831,6 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
isize init_token_cap = cast(isize)gb_max(next_pow2(cast(i64)(file_size/2ll)), 16);
array_init(&f->tokens, heap_allocator(), 0, gb_max(init_token_cap, 16));
-
if (err == TokenizerInit_Empty) {
Token token = {Token_EOF};
token.pos.file = fullpath;
@@ -4166,6 +4165,9 @@ ParseFileError parse_imported_file(Parser *p, AstPackage *package, FileInfo *fi,
AstFile *file = gb_alloc_item(heap_allocator(), AstFile);
file->package = package;
+ p->file_index += 1;
+ file->id = p->file_index;
+
TokenPos err_pos = {0};
ParseFileError err = init_ast_file(file, fi->fullpath, &err_pos);
diff --git a/src/parser.hpp b/src/parser.hpp
index 686f3ed61..ed122baea 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -40,6 +40,7 @@ struct ImportedPackage {
};
struct AstFile {
+ isize id;
AstPackage * package;
Scope * scope;
@@ -104,6 +105,7 @@ struct Parser {
isize total_line_count;
gbMutex file_add_mutex;
gbMutex file_decl_mutex;
+ isize file_index;
};
enum ProcInlining {
diff --git a/src/string.cpp b/src/string.cpp
index b63de5c76..32d97184a 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -259,7 +259,10 @@ bool string_contains_char(String const &s, u8 c) {
String filename_from_path(String s) {
isize i = string_extension_position(s);
- s = substring(s, 0, i);
+ if (i >= 0) {
+ s = substring(s, 0, i);
+ return s;
+ }
if (i > 0) {
isize j = 0;
for (j = s.len-1; j >= 0; j--) {