mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Move ODIN_* platform constants to core:os
This commit is contained in:
+18
-16
@@ -1,5 +1,7 @@
|
|||||||
package bits
|
package bits
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
|
||||||
U8_MIN :: u8(0);
|
U8_MIN :: u8(0);
|
||||||
U16_MIN :: u16(0);
|
U16_MIN :: u16(0);
|
||||||
U32_MIN :: u32(0);
|
U32_MIN :: u32(0);
|
||||||
@@ -95,29 +97,29 @@ reverse_bits32 :: proc(i: u32) -> u32 { return __llvm_bitreverse32(i); }
|
|||||||
reverse_bits64 :: proc(i: u64) -> u64 { return __llvm_bitreverse64(i); }
|
reverse_bits64 :: proc(i: u64) -> u64 { return __llvm_bitreverse64(i); }
|
||||||
|
|
||||||
from_be_u8 :: proc(i: u8) -> u8 { return i; }
|
from_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||||
from_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
from_be_u16 :: proc(i: u16) -> u16 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
from_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
from_be_u32 :: proc(i: u32) -> u32 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
from_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
from_be_u64 :: proc(i: u64) -> u64 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
from_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
from_be_uint :: proc(i: uint) -> uint { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
|
|
||||||
from_le_u8 :: proc(i: u8) -> u8 { return i; }
|
from_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||||
from_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
from_le_u16 :: proc(i: u16) -> u16 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
from_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
from_le_u32 :: proc(i: u32) -> u32 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
from_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
from_le_u64 :: proc(i: u64) -> u64 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
from_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
from_le_uint :: proc(i: uint) -> uint { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
|
|
||||||
to_be_u8 :: proc(i: u8) -> u8 { return i; }
|
to_be_u8 :: proc(i: u8) -> u8 { return i; }
|
||||||
to_be_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
to_be_u16 :: proc(i: u16) -> u16 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
to_be_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
to_be_u32 :: proc(i: u32) -> u32 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
to_be_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
to_be_u64 :: proc(i: u64) -> u64 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
to_be_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
to_be_uint :: proc(i: uint) -> uint { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
|
||||||
|
|
||||||
|
|
||||||
to_le_u8 :: proc(i: u8) -> u8 { return i; }
|
to_le_u8 :: proc(i: u8) -> u8 { return i; }
|
||||||
to_le_u16 :: proc(i: u16) -> u16 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
to_le_u16 :: proc(i: u16) -> u16 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
to_le_u32 :: proc(i: u32) -> u32 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
to_le_u32 :: proc(i: u32) -> u32 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
to_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
to_le_u64 :: proc(i: u64) -> u64 { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
to_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
to_le_uint :: proc(i: uint) -> uint { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||||
|
|
||||||
|
|
||||||
overflowing_add_u8 :: proc(lhs, rhs: u8) -> (u8, bool) { foreign __llvm_core @(link_name="llvm.uadd.with.overflow.i8") op :: proc(u8, u8) -> (u8, bool) ---; return op(lhs, rhs); }
|
overflowing_add_u8 :: proc(lhs, rhs: u8) -> (u8, bool) { foreign __llvm_core @(link_name="llvm.uadd.with.overflow.i8") op :: proc(u8, u8) -> (u8, bool) ---; return op(lhs, rhs); }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package runtime
|
package builtin
|
||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:unicode/utf8"
|
import "core:unicode/utf8"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package runtime
|
package builtin
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@(link_name="__multi3")
|
@(link_name="__multi3")
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package os;
|
||||||
|
|
||||||
|
ARCH :: "amd64";
|
||||||
|
ENDIAN :: "little";
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
|
OS :: "essence";
|
||||||
|
|
||||||
// foreign import api "system:api"
|
// foreign import api "system:api"
|
||||||
|
|
||||||
// Handle :: distinct int;
|
// Handle :: distinct int;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ foreign import libc "system:c"
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
|
||||||
|
OS :: "linux";
|
||||||
|
|
||||||
Handle :: distinct i32;
|
Handle :: distinct i32;
|
||||||
File_Time :: distinct u64;
|
File_Time :: distinct u64;
|
||||||
Errno :: distinct i32;
|
Errno :: distinct i32;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ foreign import libc "system:c"
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
|
||||||
|
OS :: "osx";
|
||||||
|
|
||||||
Handle :: distinct i32;
|
Handle :: distinct i32;
|
||||||
File_Time :: distinct u64;
|
File_Time :: distinct u64;
|
||||||
Errno :: distinct int;
|
Errno :: distinct int;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package os
|
|||||||
import "core:sys/win32"
|
import "core:sys/win32"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
|
||||||
|
OS :: "windows";
|
||||||
|
|
||||||
Handle :: distinct uintptr;
|
Handle :: distinct uintptr;
|
||||||
File_Time :: distinct u64;
|
File_Time :: distinct u64;
|
||||||
Errno :: distinct int;
|
Errno :: distinct int;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package os;
|
||||||
|
|
||||||
|
ARCH :: "x86";
|
||||||
|
ENDIAN :: "little";
|
||||||
@@ -488,7 +488,7 @@ prefix_table := [?]string{
|
|||||||
};
|
};
|
||||||
|
|
||||||
threading_example :: proc() {
|
threading_example :: proc() {
|
||||||
when ODIN_OS == "windows" {
|
when os.OS == "windows" {
|
||||||
fmt.println("# threading_example");
|
fmt.println("# threading_example");
|
||||||
|
|
||||||
unordered_remove :: proc(array: ^[dynamic]$T, index: int, loc := #caller_location) {
|
unordered_remove :: proc(array: ^[dynamic]$T, index: int, loc := #caller_location) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ enum TargetArchKind {
|
|||||||
TargetArch_Invalid,
|
TargetArch_Invalid,
|
||||||
|
|
||||||
TargetArch_amd64,
|
TargetArch_amd64,
|
||||||
TargetArch_x64,
|
TargetArch_x86,
|
||||||
|
|
||||||
TargetArch_COUNT,
|
TargetArch_COUNT,
|
||||||
};
|
};
|
||||||
@@ -77,7 +77,7 @@ gb_global BuildContext build_context = {0};
|
|||||||
|
|
||||||
TargetOsKind get_target_os_from_string(String str) {
|
TargetOsKind get_target_os_from_string(String str) {
|
||||||
for (isize i = 0; i < TargetOs_COUNT; i++) {
|
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;
|
return cast(TargetOsKind)i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ TargetOsKind get_target_os_from_string(String str) {
|
|||||||
|
|
||||||
TargetArchKind get_target_arch_from_string(String str) {
|
TargetArchKind get_target_arch_from_string(String str) {
|
||||||
for (isize i = 0; i < TargetArch_COUNT; i++) {
|
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;
|
return cast(TargetArchKind)i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-7
@@ -534,12 +534,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
|||||||
e->deprecated_message = ac.deprecated_message;
|
e->deprecated_message = ac.deprecated_message;
|
||||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
|
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
|
||||||
|
|
||||||
AstPackage *package = nullptr;
|
if (e->package != nullptr && e->token.string == "main") {
|
||||||
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 ||
|
if (pt->param_count != 0 ||
|
||||||
pt->result_count != 0) {
|
pt->result_count != 0) {
|
||||||
gbString str = type_to_string(proc_type);
|
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");
|
error(e->token, "Procedure 'main' cannot have a custom calling convention");
|
||||||
}
|
}
|
||||||
pt->calling_convention = ProcCC_Contextless;
|
pt->calling_convention = ProcCC_Contextless;
|
||||||
if (package->kind == ImportedPackage_Init) {
|
if (e->package->kind == ImportedPackage_Init) {
|
||||||
if (c->info.entry_point != nullptr) {
|
if (c->info.entry_point != nullptr) {
|
||||||
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
|
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+22
-16
@@ -258,8 +258,8 @@ Scope *create_scope_from_package(Checker *c, AstPackage *p) {
|
|||||||
s->is_init = p->kind == ImportedPackage_Init;
|
s->is_init = p->kind == ImportedPackage_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->is_global = p->kind == ImportedPackage_Runtime;
|
s->is_global = p->kind == ImportedPackage_Builtin;
|
||||||
if (p->kind == ImportedPackage_Runtime) {
|
if (p->kind == ImportedPackage_Builtin) {
|
||||||
universal_scope->shared = s;
|
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) {
|
void add_preload_dependency(Checker *c, char *name) {
|
||||||
String n = make_string_c(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);
|
GB_ASSERT(e != nullptr);
|
||||||
ptr_set_add(&c->context.decl->deps, e);
|
ptr_set_add(&c->context.decl->deps, e);
|
||||||
// add_type_info_type(c, e->type);
|
// add_type_info_type(c, e->type);
|
||||||
@@ -551,9 +551,9 @@ void init_universal_scope(void) {
|
|||||||
str_lit(""), str_lit("__llvm_core")));
|
str_lit(""), str_lit("__llvm_core")));
|
||||||
|
|
||||||
// TODO(bill): Set through flags in the compiler
|
// 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_OS"), bc->ODIN_OS);
|
||||||
add_global_string_constant(str_lit("ODIN_ARCH"), bc->ODIN_ARCH);
|
// 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_ENDIAN"), bc->ODIN_ENDIAN);
|
||||||
add_global_string_constant(str_lit("ODIN_VENDOR"), bc->ODIN_VENDOR);
|
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_VERSION"), bc->ODIN_VERSION);
|
||||||
add_global_string_constant(str_lit("ODIN_ROOT"), bc->ODIN_ROOT);
|
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:
|
case Entity_LibraryName:
|
||||||
// NOTE(bill): Entities local to file rather than package
|
// NOTE(bill): Entities local to file rather than package
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
GB_ASSERT(scope->file->package->scope == scope->parent);
|
AstPackage *p = scope->file->package;
|
||||||
scope = scope->file->package->scope;
|
GB_ASSERT(p->scope == scope->parent);
|
||||||
|
scope = p->scope;
|
||||||
|
if (e->package != nullptr) {
|
||||||
|
GB_ASSERT(e->package == p);
|
||||||
|
}
|
||||||
|
e->package = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_entity(c, scope, identifier, e);
|
add_entity(c, scope, identifier, e);
|
||||||
}
|
}
|
||||||
@@ -1343,7 +1349,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
|
|||||||
str_lit("Context"),
|
str_lit("Context"),
|
||||||
};
|
};
|
||||||
for (isize i = 0; i < gb_count_of(required_entities); i++) {
|
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) {
|
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"),
|
str_lit("__dynamic_array_expr_error"),
|
||||||
};
|
};
|
||||||
for (isize i = 0; i < gb_count_of(bounds_check_entities); i++) {
|
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 *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) {
|
if (e == nullptr) {
|
||||||
compiler_error("Could not find type declaration for '%.*s'\n"
|
compiler_error("Could not find type declaration for '%.*s'\n"
|
||||||
"Is '_preload.odin' missing from the 'core' directory relative to odin.exe?", LIT(name));
|
"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) {
|
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) {
|
if (e == nullptr) {
|
||||||
compiler_error("Could not find type declaration for '%.*s'\n"
|
compiler_error("Could not find type declaration for '%.*s'\n"
|
||||||
"Is '_preload.odin' missing from the 'core' directory relative to odin.exe?", LIT(name));
|
"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) {
|
if (scope->is_init) {
|
||||||
c->info.init_scope = scope;
|
c->info.init_scope = scope;
|
||||||
}
|
}
|
||||||
if (p->kind == ImportedPackage_Runtime) {
|
if (p->kind == ImportedPackage_Builtin) {
|
||||||
GB_ASSERT(c->runtime_package == nullptr);
|
GB_ASSERT(c->builtin_package == nullptr);
|
||||||
c->runtime_package = p;
|
c->builtin_package = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -326,7 +326,7 @@ struct Checker {
|
|||||||
|
|
||||||
|
|
||||||
AstFile * curr_ast_file;
|
AstFile * curr_ast_file;
|
||||||
AstPackage * runtime_package;
|
AstPackage * builtin_package;
|
||||||
// NOTE(bill): Procedures to check
|
// NOTE(bill): Procedures to check
|
||||||
Array<ProcedureInfo> procs;
|
Array<ProcedureInfo> procs;
|
||||||
Map<Scope *> package_scopes; // Key: String (fullpath)
|
Map<Scope *> package_scopes; // Key: String (fullpath)
|
||||||
|
|||||||
+1
-16
@@ -6,7 +6,6 @@ struct DeclInfo;
|
|||||||
|
|
||||||
#define ENTITY_KINDS \
|
#define ENTITY_KINDS \
|
||||||
ENTITY_KIND(Invalid) \
|
ENTITY_KIND(Invalid) \
|
||||||
ENTITY_KIND(Package) \
|
|
||||||
ENTITY_KIND(Constant) \
|
ENTITY_KIND(Constant) \
|
||||||
ENTITY_KIND(Variable) \
|
ENTITY_KIND(Variable) \
|
||||||
ENTITY_KIND(TypeName) \
|
ENTITY_KIND(TypeName) \
|
||||||
@@ -77,6 +76,7 @@ struct Entity {
|
|||||||
AstNode * identifier; // Can be nullptr
|
AstNode * identifier; // Can be nullptr
|
||||||
DeclInfo * decl_info;
|
DeclInfo * decl_info;
|
||||||
DeclInfo * parent_proc_decl; // nullptr if in file/global scope
|
DeclInfo * parent_proc_decl; // nullptr if in file/global scope
|
||||||
|
AstPackage *package;
|
||||||
|
|
||||||
// TODO(bill): Cleanup how `using` works for entities
|
// TODO(bill): Cleanup how `using` works for entities
|
||||||
Entity * using_parent;
|
Entity * using_parent;
|
||||||
@@ -86,12 +86,6 @@ struct Entity {
|
|||||||
String deprecated_message;
|
String deprecated_message;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
|
||||||
String fullpath;
|
|
||||||
String name;
|
|
||||||
Scope *scope;
|
|
||||||
// Array<Entity *> imports; // Entity_Package
|
|
||||||
} Package;
|
|
||||||
struct {
|
struct {
|
||||||
ExactValue value;
|
ExactValue value;
|
||||||
} Constant;
|
} Constant;
|
||||||
@@ -196,15 +190,6 @@ Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) {
|
|||||||
return entity;
|
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 *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 *entity = alloc_entity(Entity_Variable, scope, token, type);
|
||||||
entity->Variable.is_immutable = is_immutable;
|
entity->Variable.is_immutable = is_immutable;
|
||||||
|
|||||||
+2
-12
@@ -8257,12 +8257,7 @@ void ir_gen_tree(irGen *s) {
|
|||||||
Entity *e = info->entities[i];
|
Entity *e = info->entities[i];
|
||||||
String name = e->token.string;
|
String name = e->token.string;
|
||||||
|
|
||||||
bool is_global = false;
|
bool is_global = e->package != nullptr;
|
||||||
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) {
|
if (e->kind == Entity_Variable) {
|
||||||
global_variable_max_count++;
|
global_variable_max_count++;
|
||||||
@@ -8315,12 +8310,7 @@ void ir_gen_tree(irGen *s) {
|
|||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
|
|
||||||
|
|
||||||
bool is_global = false;
|
bool is_global = e->package != nullptr;
|
||||||
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_foreign = e->Variable.is_foreign;
|
||||||
bool is_export = e->Variable.is_export;
|
bool is_export = e->Variable.is_export;
|
||||||
|
|||||||
+3
-3
@@ -4150,7 +4150,7 @@ void parse_file(Parser *p, AstFile *f) {
|
|||||||
if (package_name.kind == Token_Ident) {
|
if (package_name.kind == Token_Ident) {
|
||||||
if (package_name.string == "_") {
|
if (package_name.string == "_") {
|
||||||
error(package_name, "Invalid package name '_'");
|
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));
|
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;
|
isize shared_package_count = 0;
|
||||||
if (!build_context.generate_docs) {
|
if (!build_context.generate_docs) {
|
||||||
String s = get_fullpath_core(heap_allocator(), str_lit("runtime"));
|
String s = get_fullpath_core(heap_allocator(), str_lit("builtin"));
|
||||||
try_add_import_path(p, s, s, init_pos, ImportedPackage_Runtime);
|
try_add_import_path(p, s, s, init_pos, ImportedPackage_Builtin);
|
||||||
shared_package_count++;
|
shared_package_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ struct CommentGroup {
|
|||||||
|
|
||||||
enum ImportedPackageKind {
|
enum ImportedPackageKind {
|
||||||
ImportedPackage_Normal,
|
ImportedPackage_Normal,
|
||||||
ImportedPackage_Runtime,
|
ImportedPackage_Builtin,
|
||||||
ImportedPackage_Init,
|
ImportedPackage_Init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user