Merge branch 'master' into windows-llvm-13.0.0

This commit is contained in:
gingerBill
2022-09-12 14:44:09 +01:00
16 changed files with 95 additions and 170 deletions

View File

@@ -1355,6 +1355,12 @@ bool init_build_paths(String init_filename) {
// [BuildPathMainPackage] Turn given init path into a `Path`, which includes normalizing it into a full path.
bc->build_paths[BuildPath_Main_Package] = path_from_string(ha, init_filename);
{
String build_project_name = last_path_element(bc->build_paths[BuildPath_Main_Package].basename);
GB_ASSERT(build_project_name.len > 0);
bc->ODIN_BUILD_PROJECT_NAME = build_project_name;
}
bool produces_output_file = false;
if (bc->command_kind == Command_doc && bc->cmd_doc_flags & CmdDocFlag_DocFormat) {
produces_output_file = true;
@@ -1538,12 +1544,6 @@ bool init_build_paths(String init_filename) {
enable_target_feature({}, bc->target_features_string);
}
{
String build_project_name = last_path_element(bc->build_paths[BuildPath_Main_Package].basename);
GB_ASSERT(build_project_name.len > 0);
bc->ODIN_BUILD_PROJECT_NAME = build_project_name;
}
return true;
}

View File

@@ -2006,22 +2006,21 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
}
}
}
if (pt->tags & ProcTag_optional_second) {
if (pt->tags & ProcTag_optional_allocator_error) {
if (optional_ok) {
error(proc_type_node, "A procedure type cannot have both an #optional_ok tag and #optional_second");
error(proc_type_node, "A procedure type cannot have both an #optional_ok tag and #optional_allocator_error");
}
optional_ok = true;
if (result_count != 2) {
error(proc_type_node, "A procedure type with the #optional_second tag requires 2 return values, got %td", result_count);
error(proc_type_node, "A procedure type with the #optional_allocator_error tag requires 2 return values, got %td", result_count);
} else {
bool ok = false;
AstFile *file = proc_type_node->file();
if (file && file->pkg) {
ok = file->pkg->scope == ctx->info->runtime_package->scope;
}
init_mem_allocator(c->checker);
if (!ok) {
error(proc_type_node, "A procedure type with the #optional_second may only be allowed within 'package runtime'");
Type *type = results->Tuple.variables[1]->type;
if (!are_types_identical(type, t_allocator_error)) {
gbString t = type_to_string(type);
error(proc_type_node, "A procedure type with the #optional_allocator_error expects a `runtime.Allocator_Error`, got '%s'", t);
gb_string_free(t);
}
}
}

View File

@@ -2809,17 +2809,9 @@ void init_mem_allocator(Checker *c) {
if (t_allocator != nullptr) {
return;
}
AstPackage *pkg = get_core_package(&c->info, str_lit("runtime"));
String name = str_lit("Allocator");
Entity *e = scope_lookup_current(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 = find_core_type(c, str_lit("Allocator"));
t_allocator_ptr = alloc_type_pointer(t_allocator);
t_allocator_error = find_core_type(c, str_lit("Allocator_Error"));
}
void init_core_context(Checker *c) {
@@ -2827,7 +2819,6 @@ void init_core_context(Checker *c) {
return;
}
t_context = find_core_type(c, str_lit("Context"));
GB_ASSERT(t_context != nullptr);
t_context_ptr = alloc_type_pointer(t_context);
}

View File

@@ -578,7 +578,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
GB_ASSERT(!is_blank_ident(e->token));
lbAddr res = {};
if (return_ptr_value.value) {
if (return_ptr_value.value != nullptr) {
lbValue ptr = return_ptr_value;
if (results->variables.count != 1) {
ptr = lb_emit_struct_ep(p, ptr, cast(i32)i);
@@ -586,6 +586,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
res = lb_addr(ptr);
lb_add_entity(p->module, e, ptr);
lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
} else {
res = lb_add_local(p, e->type, e);
}
@@ -594,8 +595,10 @@ void lb_begin_procedure_body(lbProcedure *p) {
lbValue c = lb_handle_param_value(p, e->type, e->Variable.param_value, e->token.pos);
lb_addr_store(p, res, c);
}
}
}
}
}
if (p->type->Proc.calling_convention == ProcCC_Odin) {

View File

@@ -1857,7 +1857,7 @@ void parse_proc_tags(AstFile *f, u64 *tags) {
if (false) {}
ELSE_IF_ADD_TAG(optional_ok)
ELSE_IF_ADD_TAG(optional_second)
ELSE_IF_ADD_TAG(optional_allocator_error)
ELSE_IF_ADD_TAG(require_results)
ELSE_IF_ADD_TAG(bounds_check)
ELSE_IF_ADD_TAG(no_bounds_check)

View File

@@ -232,7 +232,7 @@ enum ProcTag {
ProcTag_require_results = 1<<4,
ProcTag_optional_ok = 1<<5,
ProcTag_optional_second = 1<<6,
ProcTag_optional_allocator_error = 1<<6,
};
enum ProcCallingConvention : i32 {

View File

@@ -681,6 +681,7 @@ gb_global Type *t_allocator = nullptr;
gb_global Type *t_allocator_ptr = nullptr;
gb_global Type *t_context = nullptr;
gb_global Type *t_context_ptr = nullptr;
gb_global Type *t_allocator_error = nullptr;
gb_global Type *t_source_code_location = nullptr;
gb_global Type *t_source_code_location_ptr = nullptr;