diff --git a/resources/examples/raylib/raylib_arkanoid.c3 b/resources/examples/raylib/raylib_arkanoid.c3 index 316f34ee4..0d4c3048f 100644 --- a/resources/examples/raylib/raylib_arkanoid.c3 +++ b/resources/examples/raylib/raylib_arkanoid.c3 @@ -1,4 +1,5 @@ module arkanoid; + /** * * raylib - classic game: arkanoid diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 167cab83a..63704382d 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1573,6 +1573,8 @@ extern Type *type_cuint; extern const char *attribute_list[NUMBER_OF_ATTRIBUTES]; extern const char *builtin_list[NUMBER_OF_BUILTINS]; +extern const char *kw_std__builtin; + extern const char *kw_std; extern const char *kw_max; extern const char *kw_min; diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index 17a1a1d11..cbca16d8a 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -165,21 +165,29 @@ static bool decl_is_visible(CompilationUnit *unit, Decl *decl) // 2. Same top module as unit -> ok if (top == unit->module->top_module) return true; + // 3. We want to check std::builtin + Module *lookup = module; + while (lookup) + { + if (lookup->name->module == kw_std__builtin) return true; + lookup = lookup->parent_module; + } + VECEACH(unit->imports, i) { Decl *import = unit->imports[i]; Module *import_module = import->module; - // 3. Same as import + // 4. Same as import if (import_module == module) return true; - // 4. If import and decl doesn't share a top module -> no match + // 5. If import and decl doesn't share a top module -> no match if (import_module->top_module != top) continue; Module *search = module->parent_module; - // 5. Start upward from the decl module + // 6. Start upward from the decl module // break if no parent or we reached the import module. while (search && search != import_module) search = search->parent_module; - // 6. We found the import module + // 7. We found the import module if (search) return true; - // 7. Otherwise go to next + // 8. Otherwise go to next } return false; } diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index 0c17a69b0..2dd6c039e 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -39,6 +39,7 @@ static SymTab symtab; const char *attribute_list[NUMBER_OF_ATTRIBUTES]; const char *builtin_list[NUMBER_OF_BUILTINS]; +const char *kw_std__builtin; const char *kw_in; const char *kw_out; const char *kw_inout; @@ -127,6 +128,7 @@ void symtab_init(uint32_t capacity) kw_FUNC = KW_DEF("FUNC"); type = TOKEN_IDENT; + kw_std__builtin = KW_DEF("std::builtin"); kw_sizeof = KW_DEF("sizeof"); kw_in = KW_DEF("in"); kw_out = KW_DEF("out"); diff --git a/test/test_suite/assert/unreachable.c3t b/test/test_suite/assert/unreachable.c3t index 9ef45b607..7aaf8ab46 100644 --- a/test/test_suite/assert/unreachable.c3t +++ b/test/test_suite/assert/unreachable.c3t @@ -1,10 +1,8 @@ -import std; fn int foo() { return 1; } - fn void test() { int x = foo(); @@ -30,7 +28,7 @@ if.then: ; preds = %entry ret void if.exit: ; preds = %entry - call void @"std::builtin.panic"(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 12) + call void @"std::builtin.panic"(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 10) unreachable after.unreachable: ; No predecessors!