Skip to content

Commit

Permalink
stage1: resolve builtin types and values via std.builtin
Browse files Browse the repository at this point in the history
rather than via `@import("builtin")`. This helps avoid the need for
`usingnamespace` used in builtin.zig or in std.builtin.
  • Loading branch information
andrewrk committed Apr 12, 2021
1 parent c4c7cb2 commit 262e09c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/stage1/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,7 @@ struct CodeGen {
ZigType *compile_var_import;
ZigType *root_import;
ZigType *start_import;
ZigType *std_builtin_import;

struct {
ZigType *entry_bool;
Expand Down
8 changes: 6 additions & 2 deletions src/stage1/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/stage1/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 262e09c

Please sign in to comment.