stage1: resolve builtin types and values via std.builtin

rather than via `@import("builtin")`. This helps avoid the need for
`usingnamespace` used in builtin.zig or in std.builtin.
This commit is contained in:
Andrew Kelley 2021-04-12 15:54:28 -07:00
parent c4c7cb252a
commit 262e09c482
3 changed files with 9 additions and 4 deletions

View File

@ -2077,6 +2077,7 @@ struct CodeGen {
ZigType *compile_var_import;
ZigType *root_import;
ZigType *start_import;
ZigType *std_builtin_import;
struct {
ZigType *entry_bool;

View File

@ -8185,14 +8185,18 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {
}
ZigValue *get_builtin_value(CodeGen *codegen, const char *name) {
ScopeDecls *builtin_scope = get_container_scope(codegen->compile_var_import);
Tld *tld = find_container_decl(codegen, builtin_scope, buf_create_from_str(name));
Buf *buf_name = buf_create_from_str(name);
ScopeDecls *builtin_scope = get_container_scope(codegen->std_builtin_import);
Tld *tld = find_container_decl(codegen, builtin_scope, buf_name);
assert(tld != nullptr);
resolve_top_level_decl(codegen, tld, nullptr, false);
assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);
TldVar *tld_var = (TldVar *)tld;
ZigValue *var_value = tld_var->var->const_value;
assert(var_value != nullptr);
buf_destroy(buf_name);
return var_value;
}

View File

@ -9495,9 +9495,9 @@ static void gen_root_source(CodeGen *g) {
TldVar *builtin_tld_var = (TldVar*)builtin_tld;
ZigValue *builtin_val = builtin_tld_var->var->const_value;
assert(builtin_val->type->id == ZigTypeIdMetaType);
ZigType *builtin_type = builtin_val->data.x_type;
g->std_builtin_import = builtin_val->data.x_type;
Tld *panic_tld = find_decl(g, &get_container_scope(builtin_type)->base,
Tld *panic_tld = find_decl(g, &get_container_scope(g->std_builtin_import)->base,
buf_create_from_str("panic"));
assert(panic_tld != nullptr);
resolve_top_level_decl(g, panic_tld, nullptr, false);