mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-20 18:06:42 +00:00
Remove special shared scope for runtime stuff
This commit is contained in:
@@ -4125,7 +4125,6 @@ void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count,
|
||||
o.mode = Addressing_Invalid;
|
||||
}
|
||||
|
||||
|
||||
if (o.type == nullptr || o.type->kind != Type_Tuple) {
|
||||
if (allow_ok && lhs_count == 2 && rhs.count == 1 &&
|
||||
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk)) {
|
||||
@@ -5913,7 +5912,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node,
|
||||
return kind;
|
||||
}
|
||||
|
||||
add_package_dependency(c, "runtime", "__type_assertion_check");
|
||||
add_package_dependency(c, "runtime", "type_assertion_check");
|
||||
case_end;
|
||||
|
||||
case_ast_node(tc, TypeCast, node);
|
||||
@@ -6218,8 +6217,8 @@ ExprKind check_expr_base(CheckerContext *c, Operand *o, AstNode *node, Type *typ
|
||||
type = nullptr;
|
||||
break;
|
||||
case Addressing_Constant:
|
||||
type = o->type;
|
||||
value = o->value;
|
||||
type = o->type;
|
||||
break;
|
||||
default:
|
||||
type = o->type;
|
||||
|
||||
161
src/checker.cpp
161
src/checker.cpp
@@ -272,7 +272,6 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *p) {
|
||||
|
||||
if (p->kind == Package_Runtime) {
|
||||
s->is_global = true;
|
||||
universal_scope->shared = s;
|
||||
}
|
||||
|
||||
if (s->is_init || s->is_global) {
|
||||
@@ -377,31 +376,7 @@ void scope_lookup_parent_entity(Scope *scope, String name, Scope **scope_, Entit
|
||||
|
||||
if (s->is_proc) {
|
||||
gone_thru_proc = true;
|
||||
} else if (s->shared) {
|
||||
Entity **found = map_get(&s->shared->elements, key);
|
||||
if (found) {
|
||||
Entity *e = *found;
|
||||
if (e->kind == Entity_Variable &&
|
||||
!e->scope->is_file) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e->scope->parent != s->shared) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((e->kind == Entity_ImportName ||
|
||||
e->kind == Entity_LibraryName)
|
||||
&& gone_thru_package) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity_) *entity_ = e;
|
||||
if (scope_) *scope_ = s->shared;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (s->is_package) {
|
||||
gone_thru_package = true;
|
||||
}
|
||||
@@ -511,7 +486,7 @@ void add_package_dependency(CheckerContext *c, char *package_name, char *name) {
|
||||
String n = make_string_c(name);
|
||||
AstPackage *p = get_core_package(&c->checker->info, make_string_c(package_name));
|
||||
Entity *e = scope_lookup_entity(p->scope, n);
|
||||
GB_ASSERT(e != nullptr);
|
||||
GB_ASSERT_MSG(e != nullptr, "%s", name);
|
||||
ptr_set_add(&c->decl->deps, e);
|
||||
// add_type_info_type(c, e->type);
|
||||
}
|
||||
@@ -841,7 +816,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
return;
|
||||
}
|
||||
if (mode == Addressing_Constant && type == t_invalid) {
|
||||
compiler_error("add_type_and_value - invalid type: %s", type_to_string(type));
|
||||
return;
|
||||
}
|
||||
|
||||
TypeAndValue tv = {};
|
||||
@@ -939,20 +914,11 @@ void add_entity_and_decl_info(CheckerContext *c, AstNode *identifier, Entity *e,
|
||||
|
||||
if (e->scope != nullptr) {
|
||||
Scope *scope = e->scope;
|
||||
if (scope->is_file) {
|
||||
switch (e->kind) {
|
||||
case Entity_ImportName:
|
||||
case Entity_LibraryName:
|
||||
// NOTE(bill): Entities local to file rather than package
|
||||
break;
|
||||
default: {
|
||||
AstPackage *pkg = scope->file->pkg;
|
||||
GB_ASSERT(pkg->scope == scope->parent);
|
||||
GB_ASSERT(c->pkg == pkg);
|
||||
scope = pkg->scope;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scope->is_file && is_entity_kind_exported(e->kind)) {
|
||||
AstPackage *pkg = scope->file->pkg;
|
||||
GB_ASSERT(pkg->scope == scope->parent);
|
||||
GB_ASSERT(c->pkg == pkg);
|
||||
scope = pkg->scope;
|
||||
}
|
||||
add_entity(c->checker, scope, identifier, e);
|
||||
}
|
||||
@@ -1346,12 +1312,11 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
|
||||
String required_builtin_entities[] = {
|
||||
str_lit("__init_context"),
|
||||
|
||||
str_lit("__args__"),
|
||||
str_lit("__type_table"),
|
||||
str_lit("args__"),
|
||||
str_lit("type_table"),
|
||||
|
||||
str_lit("Type_Info"),
|
||||
str_lit("Source_Code_Location"),
|
||||
str_lit("Allocator"),
|
||||
str_lit("Context"),
|
||||
};
|
||||
for (isize i = 0; i < gb_count_of(required_builtin_entities); i++) {
|
||||
@@ -1360,18 +1325,27 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
|
||||
|
||||
AstPackage *mem = get_core_package(&c->info, str_lit("mem"));
|
||||
String required_mem_entities[] = {
|
||||
str_lit("default_allocator"),
|
||||
str_lit("zero"),
|
||||
str_lit("Allocator"),
|
||||
};
|
||||
for (isize i = 0; i < gb_count_of(required_mem_entities); i++) {
|
||||
add_dependency_to_set(c, scope_lookup_entity(mem->scope, required_mem_entities[i]));
|
||||
}
|
||||
|
||||
AstPackage *os = get_core_package(&c->info, str_lit("os"));
|
||||
String required_os_entities[] = {
|
||||
str_lit("default_allocator"),
|
||||
};
|
||||
for (isize i = 0; i < gb_count_of(required_os_entities); i++) {
|
||||
add_dependency_to_set(c, scope_lookup_entity(os->scope, required_mem_entities[i]));
|
||||
}
|
||||
|
||||
|
||||
if (!build_context.no_bounds_check) {
|
||||
String bounds_check_entities[] = {
|
||||
str_lit("__bounds_check_error"),
|
||||
str_lit("__slice_expr_error"),
|
||||
str_lit("__dynamic_array_expr_error"),
|
||||
str_lit("bounds_check_error"),
|
||||
str_lit("slice_expr_error"),
|
||||
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->info.runtime_package->scope, bounds_check_entities[i]));
|
||||
@@ -1497,7 +1471,7 @@ Entity *find_core_entity(Checker *c, String name) {
|
||||
Entity *e = current_scope_lookup_entity(c->info.runtime_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));
|
||||
, LIT(name));
|
||||
// NOTE(bill): This will exit the program as it's cannot continue without it!
|
||||
}
|
||||
return e;
|
||||
@@ -1507,7 +1481,7 @@ Type *find_core_type(Checker *c, String name) {
|
||||
Entity *e = current_scope_lookup_entity(c->info.runtime_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));
|
||||
, LIT(name));
|
||||
// NOTE(bill): This will exit the program as it's cannot continue without it!
|
||||
}
|
||||
return e->type;
|
||||
@@ -1624,7 +1598,16 @@ void init_core_allocator(Checker *c) {
|
||||
if (t_allocator != nullptr) {
|
||||
return;
|
||||
}
|
||||
t_allocator = find_core_type(c, str_lit("Allocator"));
|
||||
AstPackage *pkg = get_core_package(&c->info, str_lit("mem"));
|
||||
|
||||
String name = str_lit("Allocator");
|
||||
Entity *e = current_scope_lookup_entity(pkg->scope, name);
|
||||
if (e == nullptr) {
|
||||
compiler_error("Could not find type declaration for '%.*s'\n", LIT(name));
|
||||
// NOTE(bill): This will exit the program as it's cannot continue without it!
|
||||
}
|
||||
|
||||
t_allocator = e->type;
|
||||
t_allocator_ptr = alloc_type_pointer(t_allocator);
|
||||
}
|
||||
|
||||
@@ -1646,11 +1629,11 @@ void init_core_source_code_location(Checker *c) {
|
||||
|
||||
void init_core_map_type(Checker *c) {
|
||||
if (t_map_key == nullptr) {
|
||||
t_map_key = find_core_type(c, str_lit("__Map_Key"));
|
||||
t_map_key = find_core_type(c, str_lit("Map_Key"));
|
||||
}
|
||||
|
||||
if (t_map_header == nullptr) {
|
||||
t_map_header = find_core_type(c, str_lit("__Map_Header"));
|
||||
t_map_header = find_core_type(c, str_lit("Map_Header"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1767,7 +1750,8 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
|
||||
ac->thread_local_model = str_lit("default");
|
||||
} else if (value.kind == ExactValue_String) {
|
||||
String model = value.value_string;
|
||||
if (model == "localdynamic" ||
|
||||
if (model == "default" ||
|
||||
model == "localdynamic" ||
|
||||
model == "initialexec" ||
|
||||
model == "localexec") {
|
||||
ac->thread_local_model = model;
|
||||
@@ -1935,6 +1919,66 @@ void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *w
|
||||
}
|
||||
}
|
||||
|
||||
void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array<AstNode *> *attributes) {
|
||||
switch (e->kind) {
|
||||
case Entity_ProcGroup:
|
||||
case Entity_Procedure:
|
||||
case Entity_TypeName:
|
||||
// Okay
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (!(ctx->scope->is_file && ctx->scope->file->pkg->kind == Package_Runtime)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for_array(j, *attributes) {
|
||||
AstNode *attr = (*attributes)[j];
|
||||
if (attr->kind != AstNode_Attribute) continue;
|
||||
for (isize k = 0; k < attr->Attribute.elems.count; k++) {
|
||||
AstNode *elem = attr->Attribute.elems[k];
|
||||
String name = {};
|
||||
AstNode *value = nullptr;
|
||||
|
||||
switch (elem->kind) {
|
||||
case_ast_node(i, Ident, elem);
|
||||
name = i->token.string;
|
||||
case_end;
|
||||
case_ast_node(fv, FieldValue, elem);
|
||||
GB_ASSERT(fv->field->kind == AstNode_Ident);
|
||||
name = fv->field->Ident.token.string;
|
||||
value = fv->value;
|
||||
case_end;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name == "builtin") {
|
||||
add_entity(ctx->checker, universal_scope, nullptr, e);
|
||||
GB_ASSERT(scope_lookup_entity(universal_scope, e->token.string) != nullptr);
|
||||
if (value != nullptr) {
|
||||
error(value, "'builtin' cannot have a field value");
|
||||
}
|
||||
// Remove the builtin tag
|
||||
attr->Attribute.elems[k] = attr->Attribute.elems[attr->Attribute.elems.count-1];
|
||||
attr->Attribute.elems.count -= 1;
|
||||
k--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (isize i = 0; i < attributes->count; i++) {
|
||||
AstNode *attr = (*attributes)[i];
|
||||
if (attr->kind != AstNode_Attribute) continue;
|
||||
if (attr->Attribute.elems.count == 0) {
|
||||
(*attributes)[i] = (*attributes)[attributes->count-1];
|
||||
attributes->count--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void check_collect_value_decl(CheckerContext *c, AstNode *decl) {
|
||||
ast_node(vd, ValueDecl, decl);
|
||||
|
||||
@@ -2093,6 +2137,7 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) {
|
||||
}
|
||||
}
|
||||
|
||||
check_builtin_attributes(c, e, &d->attributes);
|
||||
|
||||
add_entity_and_decl_info(c, name, e, d);
|
||||
}
|
||||
@@ -2446,6 +2491,11 @@ Array<ImportPathItem> find_import_path(Checker *c, AstPackage *start, AstPackage
|
||||
}
|
||||
GB_ASSERT(pkg != nullptr && pkg->scope != nullptr);
|
||||
|
||||
if (pkg->kind == Package_Runtime) {
|
||||
// NOTE(bill): Allow cyclic imports within the runtime package for the time being
|
||||
continue;
|
||||
}
|
||||
|
||||
ImportPathItem item = {pkg, decl};
|
||||
if (pkg == end) {
|
||||
auto path = array_make<ImportPathItem>(heap_allocator());
|
||||
@@ -2821,6 +2871,7 @@ void check_import_entities(Checker *c) {
|
||||
return item.pkg->name;
|
||||
};
|
||||
|
||||
#if 1
|
||||
if (path.count == 1) {
|
||||
// TODO(bill): Should this be allowed or disabled?
|
||||
#if 0
|
||||
@@ -2839,12 +2890,12 @@ void check_import_entities(Checker *c) {
|
||||
}
|
||||
error(item.decl, "'%.*s'", LIT(pkg_name));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
for_array(i, n->pred.entries) {
|
||||
ImportGraphNode *p = n->pred.entries[i].ptr;
|
||||
p->dep_count = gb_max(p->dep_count-1, 0);
|
||||
// p->dep_count -= 1;
|
||||
priority_queue_fix(&pq, p->index);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ struct DeclInfo;
|
||||
struct AstFile;
|
||||
struct Checker;
|
||||
struct CheckerInfo;
|
||||
struct CheckerContext;
|
||||
|
||||
enum AddressingMode {
|
||||
Addressing_Invalid, // invalid addressing mode
|
||||
@@ -177,6 +178,26 @@ struct BlockLabel {
|
||||
AstNode *label; // AstNode_Label;
|
||||
};
|
||||
|
||||
struct AttributeContext {
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
isize init_expr_list_count;
|
||||
String thread_local_model;
|
||||
String deprecated_message;
|
||||
};
|
||||
|
||||
AttributeContext make_attribute_context(String link_prefix) {
|
||||
AttributeContext ac = {};
|
||||
ac.link_prefix = link_prefix;
|
||||
return ac;
|
||||
}
|
||||
|
||||
#define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, AstNode *elem, String name, ExactValue value, AttributeContext *ac)
|
||||
typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc);
|
||||
|
||||
void check_decl_attributes(CheckerContext *c, Array<AstNode *> const &attributes, DeclAttributeProc *proc, AttributeContext *ac);
|
||||
|
||||
|
||||
// DeclInfo is used to store information of certain declarations to allow for "any order" usage
|
||||
struct DeclInfo {
|
||||
DeclInfo * parent; // NOTE(bill): only used for procedure literals at the moment
|
||||
@@ -218,7 +239,7 @@ struct Scope {
|
||||
Scope * last_child;
|
||||
Map<Entity *> elements; // Key: String
|
||||
PtrSet<Entity *> implicit;
|
||||
Scope * shared;
|
||||
// Scope * shared;
|
||||
|
||||
Array<AstNode *> delayed_directives;
|
||||
Array<AstNode *> delayed_imports;
|
||||
@@ -392,25 +413,6 @@ void check_collect_entities(CheckerContext *c, Array<AstNode *> const &nodes);
|
||||
void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *ws);
|
||||
void check_delayed_file_import_entity(CheckerContext *c, AstNode *decl);
|
||||
|
||||
struct AttributeContext {
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
isize init_expr_list_count;
|
||||
String thread_local_model;
|
||||
String deprecated_message;
|
||||
};
|
||||
|
||||
AttributeContext make_attribute_context(String link_prefix) {
|
||||
AttributeContext ac = {};
|
||||
ac.link_prefix = link_prefix;
|
||||
return ac;
|
||||
}
|
||||
|
||||
#define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, AstNode *elem, String name, ExactValue value, AttributeContext *ac)
|
||||
typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc);
|
||||
|
||||
void check_decl_attributes(CheckerContext *c, Array<AstNode *> const &attributes, DeclAttributeProc *proc, AttributeContext *ac);
|
||||
|
||||
CheckerTypePath *new_checker_type_path();
|
||||
void destroy_checker_type_path(CheckerTypePath *tp);
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ GB_ALLOCATOR_PROC(heap_allocator_proc);
|
||||
gbAllocator heap_allocator(void) {
|
||||
gbAllocator a;
|
||||
a.proc = heap_allocator_proc;
|
||||
a.data = NULL;
|
||||
a.data = nullptr;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
GB_ALLOCATOR_PROC(heap_allocator_proc) {
|
||||
void *ptr = NULL;
|
||||
void *ptr = nullptr;
|
||||
gb_unused(allocator_data);
|
||||
gb_unused(old_size);
|
||||
|
||||
@@ -348,7 +348,7 @@ void *pool_alloc(Pool *pool, isize size, isize align) {
|
||||
}
|
||||
|
||||
GB_ALLOCATOR_PROC(pool_allocator_proc) {
|
||||
void *ptr = NULL;
|
||||
void *ptr = nullptr;
|
||||
Pool *pool = cast(Pool *)allocator_data;
|
||||
|
||||
|
||||
|
||||
102
src/ir.cpp
102
src/ir.cpp
@@ -1534,7 +1534,7 @@ irDebugInfo *ir_add_debug_info_proc(irProcedure *proc, Entity *entity, String na
|
||||
//
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
irValue *ir_emit_global_call (irProcedure *proc, char const *name_, Array<irValue *> args, AstNode *expr = nullptr);
|
||||
irValue *ir_emit_runtime_call (irProcedure *proc, char const *name_, Array<irValue *> args, AstNode *expr = nullptr);
|
||||
irValue *ir_emit_package_call(irProcedure *proc, char const *package_name_, char const *name_, Array<irValue *> args, AstNode *expr = nullptr);
|
||||
|
||||
|
||||
@@ -1593,7 +1593,7 @@ void ir_emit_init_context(irProcedure *proc, irValue *c = nullptr) {
|
||||
gbAllocator a = m->allocator;
|
||||
auto args = array_make<irValue *>(a, 1);
|
||||
args[0] = c ? c : m->global_default_context;
|
||||
ir_emit_global_call(proc, "__init_context", args);
|
||||
ir_emit_runtime_call(proc, "__init_context", args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1637,7 +1637,7 @@ irValue *ir_find_or_generate_context_ptr(irProcedure *proc) {
|
||||
|
||||
irValue *ep = ir_emit_struct_ep(proc, c, 0);
|
||||
Array<irValue *> args = {};
|
||||
irValue *v = ir_emit_package_call(proc, "mem", "default_allocator", args);
|
||||
irValue *v = ir_emit_package_call(proc, "os", "default_allocator", args);
|
||||
ir_emit_store(proc, ep, v);
|
||||
|
||||
return c;
|
||||
@@ -1702,7 +1702,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> args) {
|
||||
return result;
|
||||
}
|
||||
|
||||
irValue *ir_emit_global_call(irProcedure *proc, char const *name_, Array<irValue *> args, AstNode *expr) {
|
||||
irValue *ir_emit_runtime_call(irProcedure *proc, char const *name_, Array<irValue *> args, AstNode *expr) {
|
||||
String name = make_string_c(cast(char *)name_);
|
||||
|
||||
AstPackage *p = proc->module->info->runtime_package;
|
||||
@@ -1879,7 +1879,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
|
||||
} else {
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = str;
|
||||
hashed_str = ir_emit_global_call(proc, "__default_hash_string", args);
|
||||
hashed_str = ir_emit_runtime_call(proc, "__default_hash_string", args);
|
||||
}
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), hashed_str);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 1), str);
|
||||
@@ -1941,7 +1941,7 @@ irValue *ir_insert_dynamic_map_key_and_value(irProcedure *proc, irValue *addr, T
|
||||
args[1] = key;
|
||||
args[2] = ir_emit_conv(proc, ptr, t_rawptr);
|
||||
args[3] = ir_emit_source_code_location(proc, nullptr);
|
||||
return ir_emit_global_call(proc, "__dynamic_map_set", args);
|
||||
return ir_emit_runtime_call(proc, "__dynamic_map_set", args);
|
||||
}
|
||||
|
||||
|
||||
@@ -2041,7 +2041,7 @@ irValue *ir_addr_load(irProcedure *proc, irAddr const &addr) {
|
||||
args[0] = h;
|
||||
args[1] = key;
|
||||
|
||||
irValue *ptr = ir_emit_global_call(proc, "__dynamic_map_get", args);
|
||||
irValue *ptr = ir_emit_runtime_call(proc, "__dynamic_map_get", args);
|
||||
irValue *ok = ir_emit_conv(proc, ir_emit_comp(proc, Token_NotEq, ptr, v_raw_nil), t_bool);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 1), ok);
|
||||
|
||||
@@ -2543,7 +2543,7 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 2);
|
||||
args[0] = left;
|
||||
args[1] = right;
|
||||
return ir_emit_global_call(proc, runtime_proc, args);
|
||||
return ir_emit_runtime_call(proc, runtime_proc, args);
|
||||
}
|
||||
|
||||
if (is_type_complex(a)) {
|
||||
@@ -2568,7 +2568,7 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 2);
|
||||
args[0] = left;
|
||||
args[1] = right;
|
||||
return ir_emit_global_call(proc, runtime_proc, args);
|
||||
return ir_emit_runtime_call(proc, runtime_proc, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -2893,7 +2893,7 @@ irValue *ir_cstring_len(irProcedure *proc, irValue *value) {
|
||||
GB_ASSERT(is_type_cstring(ir_type(value)));
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = ir_emit_conv(proc, value, t_cstring);
|
||||
return ir_emit_global_call(proc, "__cstring_len", args);
|
||||
return ir_emit_runtime_call(proc, "__cstring_len", args);
|
||||
}
|
||||
|
||||
|
||||
@@ -3140,7 +3140,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
irValue *c = ir_emit_conv(proc, value, t_cstring);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = c;
|
||||
irValue *s = ir_emit_global_call(proc, "__cstring_to_string", args);
|
||||
irValue *s = ir_emit_runtime_call(proc, "__cstring_to_string", args);
|
||||
return ir_emit_conv(proc, s, dst);
|
||||
}
|
||||
|
||||
@@ -3161,13 +3161,13 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
// case 4: {
|
||||
// auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
// args[0] = value;
|
||||
// return ir_emit_global_call(proc, "__gnu_h2f_ieee", args);
|
||||
// return ir_emit_runtime_call(proc, "__gnu_h2f_ieee", args);
|
||||
// break;
|
||||
// }
|
||||
// case 8: {
|
||||
// auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
// args[0] = value;
|
||||
// return ir_emit_global_call(proc, "__f16_to_f64", args);
|
||||
// return ir_emit_runtime_call(proc, "__f16_to_f64", args);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
@@ -3177,13 +3177,13 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
// case 4: {
|
||||
// auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
// args[0] = value;
|
||||
// return ir_emit_global_call(proc, "__gnu_f2h_ieee", args);
|
||||
// return ir_emit_runtime_call(proc, "__gnu_f2h_ieee", args);
|
||||
// break;
|
||||
// }
|
||||
// case 8: {
|
||||
// auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
// args[0] = value;
|
||||
// return ir_emit_global_call(proc, "__truncdfhf2", args);
|
||||
// return ir_emit_runtime_call(proc, "__truncdfhf2", args);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
@@ -3509,7 +3509,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token
|
||||
|
||||
args[4] = ir_typeid(proc->module, src_type);
|
||||
args[5] = ir_typeid(proc->module, dst_type);
|
||||
ir_emit_global_call(proc, "__type_assertion_check", args);
|
||||
ir_emit_runtime_call(proc, "type_assertion_check", args);
|
||||
}
|
||||
|
||||
return ir_emit_load(proc, ir_emit_struct_ep(proc, v, 0));
|
||||
@@ -3569,7 +3569,7 @@ irAddr ir_emit_any_cast_addr(irProcedure *proc, irValue *value, Type *type, Toke
|
||||
|
||||
args[4] = any_typeid;
|
||||
args[5] = dst_typeid;
|
||||
ir_emit_global_call(proc, "__type_assertion_check", args);
|
||||
ir_emit_runtime_call(proc, "type_assertion_check", args);
|
||||
|
||||
return ir_addr(ir_emit_struct_ep(proc, v, 0));
|
||||
}
|
||||
@@ -3713,7 +3713,7 @@ void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValu
|
||||
args[3] = index;
|
||||
args[4] = len;
|
||||
|
||||
ir_emit_global_call(proc, "__bounds_check_error", args);
|
||||
ir_emit_runtime_call(proc, "bounds_check_error", args);
|
||||
}
|
||||
|
||||
void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, irValue *len, bool is_substring) {
|
||||
@@ -3739,7 +3739,7 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir
|
||||
args[4] = high;
|
||||
args[5] = len;
|
||||
|
||||
ir_emit_global_call(proc, "__slice_expr_error", args);
|
||||
ir_emit_runtime_call(proc, "slice_expr_error", args);
|
||||
}
|
||||
|
||||
void ir_emit_dynamic_array_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, irValue *max) {
|
||||
@@ -3765,7 +3765,7 @@ void ir_emit_dynamic_array_bounds_check(irProcedure *proc, Token token, irValue
|
||||
args[4] = high;
|
||||
args[5] = max;
|
||||
|
||||
ir_emit_global_call(proc, "__dynamic_array_expr_error", args);
|
||||
ir_emit_runtime_call(proc, "dynamic_array_expr_error", args);
|
||||
}
|
||||
|
||||
|
||||
@@ -4062,8 +4062,8 @@ irValue *ir_emit_min(irProcedure *proc, Type *t, irValue *x, irValue *y) {
|
||||
args[0] = x;
|
||||
args[1] = y;
|
||||
switch (sz) {
|
||||
case 32: return ir_emit_global_call(proc, "__min_f32", args);
|
||||
case 64: return ir_emit_global_call(proc, "__min_f64", args);
|
||||
case 32: return ir_emit_runtime_call(proc, "__min_f32", args);
|
||||
case 64: return ir_emit_runtime_call(proc, "__min_f64", args);
|
||||
}
|
||||
GB_PANIC("Unknown float type");
|
||||
}
|
||||
@@ -4080,8 +4080,8 @@ irValue *ir_emit_max(irProcedure *proc, Type *t, irValue *x, irValue *y) {
|
||||
args[0] = x;
|
||||
args[1] = y;
|
||||
switch (sz) {
|
||||
case 32: return ir_emit_global_call(proc, "__max_f32", args);
|
||||
case 64: return ir_emit_global_call(proc, "__max_f64", args);
|
||||
case 32: return ir_emit_runtime_call(proc, "__max_f32", args);
|
||||
case 64: return ir_emit_runtime_call(proc, "__max_f64", args);
|
||||
}
|
||||
GB_PANIC("Unknown float type");
|
||||
}
|
||||
@@ -4221,7 +4221,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = ir_build_expr(proc, arg);
|
||||
return ir_emit_global_call(proc, "__type_info_of", args);
|
||||
return ir_emit_runtime_call(proc, "__type_info_of", args);
|
||||
}
|
||||
|
||||
case BuiltinProc_typeid_of: {
|
||||
@@ -4236,7 +4236,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = ir_emit_conv(proc, ir_build_expr(proc, arg), t_type_info_ptr);
|
||||
return ir_emit_global_call(proc, "__typeid_of", args);
|
||||
return ir_emit_runtime_call(proc, "__typeid_of", args);
|
||||
}
|
||||
|
||||
case BuiltinProc_len: {
|
||||
@@ -4315,7 +4315,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue **args = gb_alloc_array(a, irValue *, 2);
|
||||
args[0] = ir_const_int(a, size);
|
||||
args[1] = ir_const_int(a, align);
|
||||
irValue *call = ir_emit_global_call(proc, "alloc", args, 2);
|
||||
irValue *call = ir_emit_runtime_call(proc, "alloc", args, 2);
|
||||
irValue *v = ir_emit_conv(proc, call, ptr_type);
|
||||
if (type != allocation_type) {
|
||||
Type *u = base_type(allocation_type);
|
||||
@@ -4387,7 +4387,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
args[0] = header;
|
||||
args[1] = cap;
|
||||
args[2] = ir_emit_source_code_location(proc, ce->args[0]);
|
||||
ir_emit_global_call(proc, "__dynamic_map_reserve", args);
|
||||
ir_emit_runtime_call(proc, "__dynamic_map_reserve", args);
|
||||
|
||||
return ir_emit_load(proc, map);
|
||||
} else if (is_type_dynamic_array(type)) {
|
||||
@@ -4412,7 +4412,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
args[3] = len;
|
||||
args[4] = cap;
|
||||
args[5] = ir_emit_source_code_location(proc, ce->args[0]);
|
||||
ir_emit_global_call(proc, "__dynamic_array_make", args);
|
||||
ir_emit_runtime_call(proc, "__dynamic_array_make", args);
|
||||
return ir_emit_load(proc, array);
|
||||
}
|
||||
break;
|
||||
@@ -4438,7 +4438,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue **args = gb_alloc_array(a, irValue *, 1);
|
||||
args[0] = da_allocator;
|
||||
args[1] = ptr;
|
||||
return ir_emit_global_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
return ir_emit_runtime_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
} else if (is_type_map(type)) {
|
||||
irValue *map = ir_build_expr(proc, node);
|
||||
irValue *map_ptr = ir_address_from_load_or_generate_local(proc, map);
|
||||
@@ -4453,7 +4453,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue **args = gb_alloc_array(a, irValue *, 1);
|
||||
args[0] = da_allocator;
|
||||
args[1] = da_ptr;
|
||||
ir_emit_global_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
ir_emit_runtime_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
}
|
||||
{
|
||||
irValue *array = ir_emit_struct_ep(proc, map_ptr, 1);
|
||||
@@ -4465,7 +4465,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue **args = gb_alloc_array(a, irValue *, 1);
|
||||
args[0] = da_allocator;
|
||||
args[1] = da_ptr;
|
||||
ir_emit_global_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
ir_emit_runtime_call(proc, "free_ptr_with_allocator", args, 2);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -4490,7 +4490,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
irValue **args = gb_alloc_array(a, irValue *, 1);
|
||||
args[0] = ptr;
|
||||
return ir_emit_global_call(proc, "free_ptr", args, 1);
|
||||
return ir_emit_runtime_call(proc, "free_ptr", args, 1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -4519,12 +4519,12 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
args[1] = elem_size;
|
||||
args[2] = elem_align;
|
||||
args[3] = capacity;
|
||||
return ir_emit_global_call(proc, "__dynamic_array_reserve", args, 4);
|
||||
return ir_emit_runtime_call(proc, "__dynamic_array_reserve", args, 4);
|
||||
} else if (is_type_map(type)) {
|
||||
irValue **args = gb_alloc_array(a, irValue *, 2);
|
||||
args[0] = ir_gen_map_header(proc, ptr, type);
|
||||
args[1] = capacity;
|
||||
return ir_emit_global_call(proc, "__dynamic_map_reserve", args, 2);
|
||||
return ir_emit_runtime_call(proc, "__dynamic_map_reserve", args, 2);
|
||||
} else {
|
||||
GB_PANIC("Unknown type for 'reserve'");
|
||||
}
|
||||
@@ -4664,9 +4664,9 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
daa_args[4] = ir_emit_conv(proc, item_count, t_int);
|
||||
|
||||
if (is_slice) {
|
||||
return ir_emit_global_call(proc, "__slice_append", daa_args, 5);
|
||||
return ir_emit_runtime_call(proc, "__slice_append", daa_args, 5);
|
||||
}
|
||||
return ir_emit_global_call(proc, "__dynamic_array_append", daa_args, 5);
|
||||
return ir_emit_runtime_call(proc, "__dynamic_array_append", daa_args, 5);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -4685,7 +4685,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue **args = gb_alloc_array(a, irValue *, 2);
|
||||
args[0] = ir_gen_map_header(proc, addr, map_type);
|
||||
args[1] = ir_gen_map_key(proc, key, key_type);
|
||||
return ir_emit_global_call(proc, "__dynamic_map_delete", args, 2);
|
||||
return ir_emit_runtime_call(proc, "__dynamic_map_delete", args, 2);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -4806,8 +4806,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = x;
|
||||
switch (sz) {
|
||||
case 64: return ir_emit_global_call(proc, "__abs_complex64", args);
|
||||
case 128: return ir_emit_global_call(proc, "__abs_complex128", args);
|
||||
case 64: return ir_emit_runtime_call(proc, "__abs_complex64", args);
|
||||
case 128: return ir_emit_runtime_call(proc, "__abs_complex128", args);
|
||||
}
|
||||
GB_PANIC("Unknown complex type");
|
||||
} else if (is_type_float(t)) {
|
||||
@@ -4815,8 +4815,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = x;
|
||||
switch (sz) {
|
||||
case 32: return ir_emit_global_call(proc, "__abs_f32", args);
|
||||
case 64: return ir_emit_global_call(proc, "__abs_f64", args);
|
||||
case 32: return ir_emit_runtime_call(proc, "__abs_f32", args);
|
||||
case 64: return ir_emit_runtime_call(proc, "__abs_f64", args);
|
||||
}
|
||||
GB_PANIC("Unknown float type");
|
||||
}
|
||||
@@ -5053,7 +5053,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
args[4] = ir_typeid(proc->module, src_type);
|
||||
args[5] = ir_typeid(proc->module, dst_type);
|
||||
ir_emit_global_call(proc, "__type_assertion_check", args);
|
||||
ir_emit_runtime_call(proc, "type_assertion_check", args);
|
||||
|
||||
irValue *data_ptr = v;
|
||||
return ir_emit_conv(proc, data_ptr, tv.type);
|
||||
@@ -5078,7 +5078,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
args[4] = any_id;
|
||||
args[5] = id;
|
||||
ir_emit_global_call(proc, "__type_assertion_check", args);
|
||||
ir_emit_runtime_call(proc, "type_assertion_check", args);
|
||||
|
||||
return ir_emit_conv(proc, data_ptr, tv.type);
|
||||
} else {
|
||||
@@ -5917,7 +5917,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
args[0] = ir_gen_map_header(proc, v, type);
|
||||
args[1] = ir_const_int(a, 2*cl->elems.count);
|
||||
args[2] = ir_emit_source_code_location(proc, proc_name, pos);
|
||||
ir_emit_global_call(proc, "__dynamic_map_reserve", args);
|
||||
ir_emit_runtime_call(proc, "__dynamic_map_reserve", args);
|
||||
}
|
||||
for_array(field_index, cl->elems) {
|
||||
AstNode *elem = cl->elems[field_index];
|
||||
@@ -5945,7 +5945,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
args[2] = align;
|
||||
args[3] = ir_const_int(a, 2*cl->elems.count);
|
||||
args[4] = ir_emit_source_code_location(proc, proc_name, pos);
|
||||
ir_emit_global_call(proc, "__dynamic_array_reserve", args);
|
||||
ir_emit_runtime_call(proc, "__dynamic_array_reserve", args);
|
||||
}
|
||||
|
||||
i64 item_count = cl->elems.count;
|
||||
@@ -5966,7 +5966,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
args[3] = ir_emit_conv(proc, items, t_rawptr);
|
||||
args[4] = ir_const_int(a, item_count);
|
||||
args[5] = ir_emit_source_code_location(proc, proc_name, pos);
|
||||
ir_emit_global_call(proc, "__dynamic_array_append", args);
|
||||
ir_emit_runtime_call(proc, "__dynamic_array_append", args);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -6490,7 +6490,7 @@ void ir_build_range_string(irProcedure *proc, irValue *expr, Type *val_type,
|
||||
irValue *str_len = ir_emit_arith(proc, Token_Sub, count, offset, t_int);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = ir_emit_string(proc, str_elem, str_len);
|
||||
irValue *rune_and_len = ir_emit_global_call(proc, "__string_decode_rune", args);
|
||||
irValue *rune_and_len = ir_emit_runtime_call(proc, "__string_decode_rune", args);
|
||||
irValue *len = ir_emit_struct_ev(proc, rune_and_len, 1);
|
||||
ir_emit_store(proc, offset_, ir_emit_arith(proc, Token_Add, offset, len, t_int));
|
||||
|
||||
@@ -7869,7 +7869,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
CheckerInfo *info = m->info;
|
||||
|
||||
if (true) {
|
||||
irValue *global_type_table = ir_find_global_variable(proc, str_lit("__type_table"));
|
||||
irValue *global_type_table = ir_find_global_variable(proc, str_lit("type_table"));
|
||||
Type *type = base_type(type_deref(ir_type(ir_global_type_info_data)));
|
||||
GB_ASSERT(is_type_array(type));
|
||||
irValue *len = ir_const_int(proc->module->allocator, type->Array.count);
|
||||
@@ -8657,7 +8657,7 @@ void ir_gen_tree(irGen *s) {
|
||||
irValue *argc = ir_emit_load(proc, *map_get(&proc->module->values, hash_entity(proc_params->Tuple.variables[0])));
|
||||
irValue *argv = ir_emit_load(proc, *map_get(&proc->module->values, hash_entity(proc_params->Tuple.variables[1])));
|
||||
|
||||
irValue *global_args = ir_find_global_variable(proc, str_lit("__args__"));
|
||||
irValue *global_args = ir_find_global_variable(proc, str_lit("args__"));
|
||||
|
||||
ir_fill_slice(proc, global_args, argv, ir_emit_conv(proc, argc, t_int));
|
||||
|
||||
@@ -8714,7 +8714,7 @@ void ir_gen_tree(irGen *s) {
|
||||
e->Procedure.link_name = name;
|
||||
|
||||
ir_begin_procedure_body(proc);
|
||||
ir_emit_global_call(proc, "main", nullptr, 0);
|
||||
ir_emit_runtime_call(proc, "main", nullptr, 0);
|
||||
ir_emit_return(proc, v_one32);
|
||||
ir_end_procedure_body(proc);
|
||||
}
|
||||
|
||||
@@ -3680,7 +3680,8 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
elems = array_make<AstNode *>(heap_allocator());
|
||||
while (f->curr_token.kind != Token_CloseParen &&
|
||||
f->curr_token.kind != Token_EOF) {
|
||||
AstNode *elem = parse_ident(f);
|
||||
AstNode *elem = nullptr;
|
||||
elem = parse_ident(f);
|
||||
if (f->curr_token.kind == Token_Eq) {
|
||||
Token eq = expect_token(f, Token_Eq);
|
||||
AstNode *value = parse_value(f);
|
||||
|
||||
Reference in New Issue
Block a user