aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-05-27 11:03:46 +0100
committergingerBill <bill@gingerbill.org>2018-05-27 11:03:46 +0100
commit6aae381e83dddf8808feefe4a5a2470320f27342 (patch)
tree4b83602375cb42f89d68c89c60bd1389df93369a /src
parent7ee9051a56ca0c04e6b60f53b9dfe47c75596496 (diff)
Move ODIN_* platform constants to `core:os`
Diffstat (limited to 'src')
-rw-r--r--src/build_settings.cpp6
-rw-r--r--src/check_decl.cpp9
-rw-r--r--src/checker.cpp38
-rw-r--r--src/checker.hpp2
-rw-r--r--src/entity.cpp17
-rw-r--r--src/ir.cpp14
-rw-r--r--src/parser.cpp6
-rw-r--r--src/parser.hpp2
8 files changed, 35 insertions, 59 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index 13776dedb..798b94bb8 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -13,7 +13,7 @@ enum TargetArchKind {
TargetArch_Invalid,
TargetArch_amd64,
- TargetArch_x64,
+ TargetArch_x86,
TargetArch_COUNT,
};
@@ -77,7 +77,7 @@ gb_global BuildContext build_context = {0};
TargetOsKind get_target_os_from_string(String str) {
for (isize i = 0; i < TargetOs_COUNT; i++) {
- if (target_os_names[i] == str) {
+ if (str_eq_ignore_case(target_os_names[i], str)) {
return cast(TargetOsKind)i;
}
}
@@ -86,7 +86,7 @@ TargetOsKind get_target_os_from_string(String str) {
TargetArchKind get_target_arch_from_string(String str) {
for (isize i = 0; i < TargetArch_COUNT; i++) {
- if (target_os_names[i] == str) {
+ if (str_eq_ignore_case(target_arch_names[i], str)) {
return cast(TargetArchKind)i;
}
}
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index db666da46..f4545e794 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -534,12 +534,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
e->deprecated_message = ac.deprecated_message;
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
- 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 (e->package != nullptr && e->token.string == "main") {
if (pt->param_count != 0 ||
pt->result_count != 0) {
gbString str = type_to_string(proc_type);
@@ -551,7 +546,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 (package->kind == ImportedPackage_Init) {
+ if (e->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 470cfe185..f1ec0d182 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -258,8 +258,8 @@ Scope *create_scope_from_package(Checker *c, AstPackage *p) {
s->is_init = p->kind == ImportedPackage_Init;
}
- s->is_global = p->kind == ImportedPackage_Runtime;
- if (p->kind == ImportedPackage_Runtime) {
+ s->is_global = p->kind == ImportedPackage_Builtin;
+ if (p->kind == ImportedPackage_Builtin) {
universal_scope->shared = s;
}
@@ -481,7 +481,7 @@ void add_type_info_dependency(DeclInfo *d, Type *type) {
void add_preload_dependency(Checker *c, char *name) {
String n = make_string_c(name);
- Entity *e = scope_lookup_entity(c->runtime_package->scope, n);
+ Entity *e = scope_lookup_entity(c->builtin_package->scope, n);
GB_ASSERT(e != nullptr);
ptr_set_add(&c->context.decl->deps, e);
// add_type_info_type(c, e->type);
@@ -551,9 +551,9 @@ void init_universal_scope(void) {
str_lit(""), str_lit("__llvm_core")));
// TODO(bill): Set through flags in the compiler
- add_global_string_constant(str_lit("ODIN_OS"), bc->ODIN_OS);
- add_global_string_constant(str_lit("ODIN_ARCH"), bc->ODIN_ARCH);
- add_global_string_constant(str_lit("ODIN_ENDIAN"), bc->ODIN_ENDIAN);
+ // add_global_string_constant(str_lit("ODIN_OS"), bc->ODIN_OS);
+ // add_global_string_constant(str_lit("ODIN_ARCH"), bc->ODIN_ARCH);
+ // add_global_string_constant(str_lit("ODIN_ENDIAN"), bc->ODIN_ENDIAN);
add_global_string_constant(str_lit("ODIN_VENDOR"), bc->ODIN_VENDOR);
add_global_string_constant(str_lit("ODIN_VERSION"), bc->ODIN_VERSION);
add_global_string_constant(str_lit("ODIN_ROOT"), bc->ODIN_ROOT);
@@ -921,11 +921,17 @@ void add_entity_and_decl_info(Checker *c, AstNode *identifier, Entity *e, DeclIn
case Entity_LibraryName:
// NOTE(bill): Entities local to file rather than package
break;
- default:
- GB_ASSERT(scope->file->package->scope == scope->parent);
- scope = scope->file->package->scope;
+ default: {
+ AstPackage *p = scope->file->package;
+ GB_ASSERT(p->scope == scope->parent);
+ scope = p->scope;
+ if (e->package != nullptr) {
+ GB_ASSERT(e->package == p);
+ }
+ e->package = p;
break;
}
+ }
}
add_entity(c, scope, identifier, e);
}
@@ -1343,7 +1349,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
str_lit("Context"),
};
for (isize i = 0; i < gb_count_of(required_entities); i++) {
- add_dependency_to_set(c, scope_lookup_entity(c->runtime_package->scope, required_entities[i]));
+ add_dependency_to_set(c, scope_lookup_entity(c->builtin_package->scope, required_entities[i]));
}
if (!build_context.no_bounds_check) {
@@ -1353,7 +1359,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
str_lit("__dynamic_array_expr_error"),
};
for (isize i = 0; i < gb_count_of(bounds_check_entities); i++) {
- add_dependency_to_set(c, scope_lookup_entity(c->runtime_package->scope, bounds_check_entities[i]));
+ add_dependency_to_set(c, scope_lookup_entity(c->builtin_package->scope, bounds_check_entities[i]));
}
}
@@ -1473,7 +1479,7 @@ Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInfo *info) {
Entity *find_core_entity(Checker *c, String name) {
- Entity *e = current_scope_lookup_entity(c->runtime_package->scope, name);
+ Entity *e = current_scope_lookup_entity(c->builtin_package->scope, name);
if (e == nullptr) {
compiler_error("Could not find type declaration for '%.*s'\n"
"Is '_preload.odin' missing from the 'core' directory relative to odin.exe?", LIT(name));
@@ -1483,7 +1489,7 @@ Entity *find_core_entity(Checker *c, String name) {
}
Type *find_core_type(Checker *c, String name) {
- Entity *e = current_scope_lookup_entity(c->runtime_package->scope, name);
+ Entity *e = current_scope_lookup_entity(c->builtin_package->scope, name);
if (e == nullptr) {
compiler_error("Could not find type declaration for '%.*s'\n"
"Is '_preload.odin' missing from the 'core' directory relative to odin.exe?", LIT(name));
@@ -2948,9 +2954,9 @@ void check_parsed_files(Checker *c) {
if (scope->is_init) {
c->info.init_scope = scope;
}
- if (p->kind == ImportedPackage_Runtime) {
- GB_ASSERT(c->runtime_package == nullptr);
- c->runtime_package = p;
+ if (p->kind == ImportedPackage_Builtin) {
+ GB_ASSERT(c->builtin_package == nullptr);
+ c->builtin_package = p;
}
}
diff --git a/src/checker.hpp b/src/checker.hpp
index 4265a535d..f4ea5b45f 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -326,7 +326,7 @@ struct Checker {
AstFile * curr_ast_file;
- AstPackage * runtime_package;
+ AstPackage * builtin_package;
// NOTE(bill): Procedures to check
Array<ProcedureInfo> procs;
Map<Scope *> package_scopes; // Key: String (fullpath)
diff --git a/src/entity.cpp b/src/entity.cpp
index d7f7dc2df..31081e5ce 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -6,7 +6,6 @@ struct DeclInfo;
#define ENTITY_KINDS \
ENTITY_KIND(Invalid) \
- ENTITY_KIND(Package) \
ENTITY_KIND(Constant) \
ENTITY_KIND(Variable) \
ENTITY_KIND(TypeName) \
@@ -77,6 +76,7 @@ struct Entity {
AstNode * identifier; // Can be nullptr
DeclInfo * decl_info;
DeclInfo * parent_proc_decl; // nullptr if in file/global scope
+ AstPackage *package;
// TODO(bill): Cleanup how `using` works for entities
Entity * using_parent;
@@ -87,12 +87,6 @@ struct Entity {
union {
struct {
- String fullpath;
- String name;
- Scope *scope;
- // Array<Entity *> imports; // Entity_Package
- } Package;
- struct {
ExactValue value;
} Constant;
struct {
@@ -196,15 +190,6 @@ Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) {
return entity;
}
-Entity *alloc_entity_package(Scope *scope, Type *type, String fullpath, String name) {
- Token token = empty_token;
- token.string = name;
- Entity *entity = alloc_entity(Entity_Package, scope, token, type);
- entity->Package.fullpath = fullpath;
- entity->Package.name = name;
- return entity;
-}
-
Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, bool is_immutable, EntityState state = EntityState_Unresolved) {
Entity *entity = alloc_entity(Entity_Variable, scope, token, type);
entity->Variable.is_immutable = is_immutable;
diff --git a/src/ir.cpp b/src/ir.cpp
index f20d2cafb..ff364602b 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -8257,12 +8257,7 @@ void ir_gen_tree(irGen *s) {
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;
- }
+ bool is_global = e->package != nullptr;
if (e->kind == Entity_Variable) {
global_variable_max_count++;
@@ -8315,12 +8310,7 @@ 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_global = e->package != nullptr;
bool is_foreign = e->Variable.is_foreign;
bool is_export = e->Variable.is_export;
diff --git a/src/parser.cpp b/src/parser.cpp
index 1a7ba68a3..3945a9415 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4150,7 +4150,7 @@ void parse_file(Parser *p, AstFile *f) {
if (package_name.kind == Token_Ident) {
if (package_name.string == "_") {
error(package_name, "Invalid package name '_'");
- } else if (f->package->kind != ImportedPackage_Runtime && package_name.string == "runtime") {
+ } else if (f->package->kind != ImportedPackage_Builtin && package_name.string == "builtin") {
error(package_name, "Use of reserved package name '%.*s'", LIT(package_name.string));
}
}
@@ -4338,8 +4338,8 @@ ParseFileError parse_packages(Parser *p, String init_filename) {
isize shared_package_count = 0;
if (!build_context.generate_docs) {
- String s = get_fullpath_core(heap_allocator(), str_lit("runtime"));
- try_add_import_path(p, s, s, init_pos, ImportedPackage_Runtime);
+ String s = get_fullpath_core(heap_allocator(), str_lit("builtin"));
+ try_add_import_path(p, s, s, init_pos, ImportedPackage_Builtin);
shared_package_count++;
}
diff --git a/src/parser.hpp b/src/parser.hpp
index ed122baea..4f33f44d2 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -27,7 +27,7 @@ struct CommentGroup {
enum ImportedPackageKind {
ImportedPackage_Normal,
- ImportedPackage_Runtime,
+ ImportedPackage_Builtin,
ImportedPackage_Init,
};