authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-12 15:54:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-12 15:54:28-07:00
log262e09c482d98a78531c049a18b7f24146fe157f
tree1846cfba5b5194c4c4eda4215b50f8dbd8ccf58c
parentc4c7cb252a4a9c54a1c4eac6c990dec4b61024d4

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.

3 files changed, 9 insertions(+), 4 deletions(-)

src/stage1/all_types.hpp+1
......@@ -2077,6 +2077,7 @@ struct CodeGen {
20772077 ZigType *compile_var_import;
20782078 ZigType *root_import;
20792079 ZigType *start_import;
2080 ZigType *std_builtin_import;
20802081
20812082 struct {
20822083 ZigType *entry_bool;
src/stage1/analyze.cpp+6-2
......@@ -8185,14 +8185,18 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {
81858185}
81868186
81878187ZigValue *get_builtin_value(CodeGen *codegen, const char *name) {
8188 ScopeDecls *builtin_scope = get_container_scope(codegen->compile_var_import);
8189 Tld *tld = find_container_decl(codegen, builtin_scope, buf_create_from_str(name));
8188 Buf *buf_name = buf_create_from_str(name);
8189
8190 ScopeDecls *builtin_scope = get_container_scope(codegen->std_builtin_import);
8191 Tld *tld = find_container_decl(codegen, builtin_scope, buf_name);
81908192 assert(tld != nullptr);
81918193 resolve_top_level_decl(codegen, tld, nullptr, false);
81928194 assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);
81938195 TldVar *tld_var = (TldVar *)tld;
81948196 ZigValue *var_value = tld_var->var->const_value;
81958197 assert(var_value != nullptr);
8198
8199 buf_destroy(buf_name);
81968200 return var_value;
81978201}
81988202
src/stage1/codegen.cpp+2-2
......@@ -9495,9 +9495,9 @@ static void gen_root_source(CodeGen *g) {
94959495 TldVar *builtin_tld_var = (TldVar*)builtin_tld;
94969496 ZigValue *builtin_val = builtin_tld_var->var->const_value;
94979497 assert(builtin_val->type->id == ZigTypeIdMetaType);
9498 ZigType *builtin_type = builtin_val->data.x_type;
9498 g->std_builtin_import = builtin_val->data.x_type;
94999499
9500 Tld *panic_tld = find_decl(g, &get_container_scope(builtin_type)->base,
9500 Tld *panic_tld = find_decl(g, &get_container_scope(g->std_builtin_import)->base,
95019501 buf_create_from_str("panic"));
95029502 assert(panic_tld != nullptr);
95039503 resolve_top_level_decl(g, panic_tld, nullptr, false);