changed: `use` now acts like `#import`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 26 Mar 2023 23:23:56 +0000 (18:23 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 26 Mar 2023 23:23:56 +0000 (18:23 -0500)
`#import` will be removed soon.

41 files changed:
compiler/include/astnodes.h
compiler/src/astnodes.c
compiler/src/clone.c
compiler/src/entities.c
compiler/src/parser.c
compiler/src/symres.c
core/builtin.onyx
core/conv/format.onyx
core/conv/parse.onyx
core/encoding/osad.onyx
core/io/stream.onyx
core/math/math.onyx
core/memory/memory.onyx
core/misc/arg_parse.onyx
core/net/net.onyx
core/os/file.onyx
core/runtime/common.onyx
core/runtime/platform/js/platform.onyx
core/runtime/platform/onyx/fs.onyx
core/runtime/platform/onyx/platform.onyx
core/string/string.onyx
core/sync/mutex.onyx
core/threads/thread.onyx
core/time/date.onyx
core/time/time.onyx
scripts/run_tests.onyx
tests/aoc-2020/day11.onyx
tests/aoc-2020/day17.onyx
tests/aoc-2021/day18.onyx
tests/aoc-2021/day21.onyx
tests/bugs/autopoly_limits.onyx
tests/bugs/double_polymorph_yield_error.onyx
tests/bugs/method_call_source_double.onyx
tests/bugs/namespace_aliasing.onyx
tests/char_literals.onyx
tests/hello_world.onyx
tests/if_expressions.onyx
tests/multiple_returns_robustness.onyx
tests/new_struct_behaviour.onyx
tests/no_types.onyx
tests/struct_robustness.onyx

index 0043a259ae573b88f76d4ac09cc79248ba3d4da3..fbc658bae881fe71c077ad1210e0d07aef360bd9 100644 (file)
@@ -48,7 +48,6 @@
                                \
     NODE(Return)               \
     NODE(Jump)                 \
-    NODE(Use)                  \
                                \
     NODE(Block)                \
     NODE(IfWhile)              \
@@ -208,7 +207,7 @@ typedef enum AstKind {
     Ast_Kind_For,
     Ast_Kind_While,
     Ast_Kind_Jump,
-    Ast_Kind_Use,
+    // Ast_Kind_Use,
     Ast_Kind_Defer,
     Ast_Kind_Switch,
     Ast_Kind_Switch_Case,
@@ -777,16 +776,16 @@ struct AstDirectiveSolidify {
 struct AstReturn        { AstNode_base; AstTyped* expr; u32 count; }; // Note: This count is one less than it should be, because internal codegen with macros would have to know about this and that is error prone.
 struct AstJump          { AstNode_base; JumpType jump; u32 count; };
 
-typedef struct QualifiedUse {
-    OnyxToken* symbol_name;
-    OnyxToken* as_name;
-} QualifiedUse;
-struct AstUse           {
-    AstNode_base;
-
-    AstTyped* expr;
-    bh_arr(QualifiedUse) only;
-};
+// typedef struct QualifiedUse {
+//     OnyxToken* symbol_name;
+//     OnyxToken* as_name;
+// } QualifiedUse;
+// struct AstUse           {
+//     AstNode_base;
+// 
+//     AstTyped* expr;
+//     bh_arr(QualifiedUse) only;
+// };
 
 // Structure Nodes
 struct AstBlock         {
@@ -1172,12 +1171,30 @@ struct AstPackage {
     Package* package;
 };
 
+typedef struct QualifiedImport {
+    OnyxToken* symbol_name;
+    OnyxToken* as_name;
+} QualifiedImport;
+
 struct AstImport {
     AstNode_base;
 
     AstPackage *imported_package;
 
-    AstUse *implicit_use_node;
+    bh_arr(QualifiedImport) only;
+
+    // When true, it means a list of imports
+    // was specified and the top-level package
+    // should not be imported.
+    b32 specified_imports;
+
+    // When true, even if a list of specified
+    // imports was given, the package name should
+    // also be imported.
+    //
+    //     use core {package, *}
+    //
+    b32 also_import_package;
 };
 
 
@@ -1540,7 +1557,6 @@ typedef struct Entity {
         AstPolyQuery          *poly_query;
         AstForeignBlock       *foreign_block;
         AstMacro              *macro;
-        AstUse                *use;
         AstInterface          *interface;
         AstConstraint         *constraint;
         AstDirectiveLibrary   *library;
index 84a928363b199253c64b76031b78e4a5e6434e7f..5bead67d970c1663efff5a7c3d108f23b3c2de76 100644 (file)
@@ -84,7 +84,7 @@ static const char* ast_node_names[] = {
     "FOR",
     "WHILE",
     "JUMP",
-    "USE",
+    // "USE",
     "DEFER",
     "SWITCH",
     "CASE",
index 28b8f64af11b6bb2b877f88db3b692392bb258ce..f6f0be809692ab483bcfa1e2694d187f7fc58941 100644 (file)
@@ -100,7 +100,6 @@ static inline i32 ast_kind_to_size(AstNode* node) {
         case Ast_Kind_For: return sizeof(AstFor);
         case Ast_Kind_While: return sizeof(AstIfWhile);
         case Ast_Kind_Jump: return sizeof(AstJump);
-        case Ast_Kind_Use: return sizeof(AstUse);
         case Ast_Kind_Defer: return sizeof(AstDefer);
         case Ast_Kind_Switch: return sizeof(AstSwitch);
         case Ast_Kind_Switch_Case: return sizeof(AstSwitchCase);
@@ -524,10 +523,6 @@ AstNode* ast_clone(bh_allocator a, void* n) {
             break;
         }
 
-        case Ast_Kind_Use:
-            C(AstUse, expr);
-            break;
-
         case Ast_Kind_Directive_Solidify: {
             AstDirectiveSolidify* dd = (AstDirectiveSolidify *) nn;
             AstDirectiveSolidify* sd = (AstDirectiveSolidify *) node;
index a21ce2d6178794dc1d6ef628262703302c451fb3..6cfac5a9c9bd515df868db7e12f7569276f6fe3b 100644 (file)
@@ -299,19 +299,6 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s
             break;
         }
 
-        case Ast_Kind_Use: {
-            if (((AstUse *) node)->expr->kind == Ast_Kind_Package) {
-                ent.state = Entity_State_Resolve_Symbols;
-                ent.type = Entity_Type_Use_Package;
-            } else {
-                ent.type = Entity_Type_Use;
-            }
-
-            ent.use = (AstUse *) node;
-            ENTITY_INSERT(ent);
-            break;
-        }
-
         case Ast_Kind_Memres: {
             ent.type = Entity_Type_Memory_Reservation_Type;
             ent.mem_res = (AstMemRes *) node;
index 082e77166fd25a4724b65702f0e46e04b25003f6..c2394d4c71def1e4a938cfccbc68806465414fbb 100644 (file)
@@ -51,7 +51,6 @@ static AstSwitchCase* parse_case_stmt(OnyxParser* parser);
 static AstSwitch*     parse_switch_stmt(OnyxParser* parser);
 static i32            parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret);
 static AstReturn*     parse_return_stmt(OnyxParser* parser);
-static AstNode*       parse_use_stmt(OnyxParser* parser);
 static AstBlock*      parse_block(OnyxParser* parser, b32 make_a_new_scope, char* block_name);
 static AstNode*       parse_statement(OnyxParser* parser);
 static void           parse_polymorphic_variable(OnyxParser* parser, AstType*** next_insertion);
@@ -1494,54 +1493,6 @@ static AstReturn* parse_return_stmt(OnyxParser* parser) {
     return return_node;
 }
 
-static b32 parse_use_stmt_internal(OnyxParser* parser, AstUse* use_node) {
-    if (consume_token_if_next(parser, '{')) {
-        if (next_tokens_are(parser, 2, '*', '}')) {
-            consume_tokens(parser, 2);
-            return 1;
-        }
-
-        bh_arr_new(global_heap_allocator, use_node->only, 4);
-        while (!consume_token_if_next(parser, '}')) {
-            if (parser->hit_unexpected_token) return 0;
-
-            QualifiedUse qu;
-            qu.as_name = expect_token(parser, Token_Type_Symbol);
-            qu.symbol_name = qu.as_name;
-
-            if (consume_token_if_next(parser, ':')) {
-                expect_token(parser, ':');
-                qu.symbol_name = expect_token(parser, Token_Type_Symbol);
-            }
-
-            bh_arr_push(use_node->only, qu);
-
-            if (parser->curr->type != '}')
-                expect_token(parser, ',');
-        }
-    }
-
-    return 1;
-}
-
-static AstNode* parse_use_stmt(OnyxParser* parser) {
-    OnyxToken* use_token = expect_token(parser, Token_Type_Keyword_Use);
-    AstUse* use_node = make_node(AstUse, Ast_Kind_Use);
-    use_node->token = use_token;
-    use_node->expr = parse_expression(parser, 1);
-    if (!use_node->expr) return NULL;
-
-    if (!parse_use_stmt_internal(parser, use_node)) return NULL;
-
-    if (use_node->expr->kind == Ast_Kind_Package) {
-        ENTITY_SUBMIT(use_node);
-        return NULL;
-
-    } else {
-        return (AstNode *) use_node;
-    }
-}
-
 static AstNode* parse_jump_stmt(OnyxParser* parser, TokenType token_type, JumpType jump_type) {
     AstJump* jnode = make_node(AstJump, Ast_Kind_Jump);
     jnode->token = expect_token(parser, token_type);
@@ -1660,7 +1611,9 @@ static AstNode* parse_statement(OnyxParser* parser) {
         case Token_Type_Keyword_Use: {
             needs_semicolon = 0;
 
-            retval = (AstNode *) parse_use_stmt(parser);
+            OnyxToken *use_token = expect_token(parser, Token_Type_Keyword_Use);
+            parse_import_statement(parser, use_token);
+
             break;
         }
 
@@ -3285,8 +3238,8 @@ static void parse_top_level_statement(OnyxParser* parser) {
 
     switch ((u16) parser->curr->type) {
         case Token_Type_Keyword_Use: {
-            AstNode* use_node = parse_use_stmt(parser);
-            if (use_node) ENTITY_SUBMIT(use_node);
+            OnyxToken *use_token = expect_token(parser, Token_Type_Keyword_Use);
+            parse_import_statement(parser, use_token);
             return;
         }
 
@@ -3669,23 +3622,49 @@ static void parse_import_statement(OnyxParser* parser, OnyxToken *token) {
 
     if (!parse_package_name(parser, package_node)) return;
 
-    if (parser->curr->type == '{') {
-        AstUse *use_node = make_node(AstUse, Ast_Kind_Use);
-        use_node->token = token;
-        use_node->expr = (AstTyped *) package_node;
+    AstImport *import_node = make_node(AstImport, Ast_Kind_Import);
+    import_node->flags |= Ast_Flag_Comptime;
+    import_node->token = token;
+    import_node->imported_package = package_node;
+    import_node->also_import_package = 1;
 
-        if (!parse_use_stmt_internal(parser, use_node)) return;
+    if (consume_token_if_next(parser, '{')) {
+        import_node->specified_imports = 1;
+        import_node->also_import_package = 0;
 
-        ENTITY_SUBMIT(use_node);
+        if (consume_token_if_next(parser, Token_Type_Keyword_Package)) {
+            import_node->also_import_package = 1;
+            if (parser->curr->type != '}')
+                expect_token(parser, ',');
+        }
 
-    } else {
-        AstImport* import_node = make_node(AstImport, Ast_Kind_Import);
-        import_node->flags |= Ast_Flag_Comptime;
-        import_node->token = token;
-        import_node->imported_package = package_node;
+        if (next_tokens_are(parser, 2, '*', '}')) {
+            consume_tokens(parser, 2);
+            goto import_parsed;
+        }
 
-        ENTITY_SUBMIT(import_node);
+        bh_arr_new(global_heap_allocator, import_node->only, 4);
+        while (!consume_token_if_next(parser, '}')) {
+            if (parser->hit_unexpected_token) return;
+
+            QualifiedImport qi;
+            qi.as_name = expect_token(parser, Token_Type_Symbol);
+            qi.symbol_name = qi.as_name;
+
+            if (consume_token_if_next(parser, ':')) {
+                expect_token(parser, ':');
+                qi.symbol_name = expect_token(parser, Token_Type_Symbol);
+            }
+
+            bh_arr_push(import_node->only, qi);
+
+            if (parser->curr->type != '}')
+                expect_token(parser, ',');
+        }
     }
+
+  import_parsed:
+    ENTITY_SUBMIT(import_node);
 }
 
 static Package* parse_file_package(OnyxParser* parser) {
index 6dd4299ce2224f3e650174e0f7fb4cb4ec51c2f5..b83792b57524415f13d9fac380271acc73ef4f3e 100644 (file)
@@ -53,7 +53,6 @@ static SymresStatus symres_while(AstIfWhile* whilenode);
 static SymresStatus symres_for(AstFor* fornode);
 static SymresStatus symres_case(AstSwitchCase *casenode);
 static SymresStatus symres_switch(AstSwitch* switchnode);
-static SymresStatus symres_use(AstUse* use);
 static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid);
 static SymresStatus symres_directive_defined(AstDirectiveDefined** pdefined);
 static SymresStatus symres_directive_insert(AstDirectiveInsert* insert);
@@ -788,108 +787,6 @@ static SymresStatus symres_switch(AstSwitch* switchnode) {
     return Symres_Success;
 }
 
-static SymresStatus symres_use(AstUse* use) {
-    SYMRES(expression, &use->expr);
-
-    AstTyped *use_expr = (AstTyped *) strip_aliases((AstNode *) use->expr);
-
-    Scope* used_scope = NULL;
-
-    // :EliminatingSymres
-    if (use_expr->kind == Ast_Kind_Package) {
-        AstPackage* package = (AstPackage *) use_expr;
-        SYMRES(package, package);
-
-        if (!use->entity) {
-            add_entities_for_node(NULL, (AstNode *) use, current_scope, NULL);
-        }
-
-        package_track_use_package(package->package, use->entity);
-        used_scope = package->package->scope;
-    }
-
-    if (use_expr->kind == Ast_Kind_Foreign_Block) {
-        AstForeignBlock* fb = (AstForeignBlock *) use_expr;
-        if (fb->entity->state <= Entity_State_Resolve_Symbols) return Symres_Yield_Macro;
-
-        used_scope = fb->scope;
-    }
-
-    if (use_expr->kind == Ast_Kind_Enum_Type) {
-        AstEnumType* et = (AstEnumType *) use_expr;
-        used_scope = et->scope;
-    }
-
-    if (use_expr->kind == Ast_Kind_Struct_Type) {
-        AstStructType* st = (AstStructType *) use_expr;
-        if (!st->scope) return Symres_Success;
-
-        used_scope = st->scope;
-    }
-
-    if (used_scope) {
-        if (used_scope == current_scope) return Symres_Success;
-
-        if (use->only == NULL) {
-            OnyxFilePos pos = { 0 };
-            if (use->token != NULL)
-                pos = use->token->pos;
-
-            scope_include(current_scope, used_scope, pos);
-
-        } else {
-            bh_arr_each(QualifiedUse, qu, use->only) {
-                AstNode* thing = symbol_resolve(used_scope, qu->symbol_name);
-                if (thing == NULL) { // :SymresStall
-                    if (report_unresolved_symbols) {
-                        onyx_report_error(qu->symbol_name->pos, Error_Critical, 
-                                "The symbol '%b' was not found in the used scope.",
-                                qu->symbol_name->text, qu->symbol_name->length);
-                        return Symres_Error;
-                    } else {
-                        return Symres_Yield_Macro;
-                    }
-                }
-
-                symbol_introduce(current_scope, qu->as_name, thing);
-            }
-        }
-
-        return Symres_Success;
-    }
-
-    if (use_expr->type_node == NULL && use_expr->type == NULL) goto cannot_use;
-
-    // :EliminatingSymres
-    AstType* effective_type = use_expr->type_node;
-    if (effective_type->kind == Ast_Kind_Pointer_Type)
-        effective_type = ((AstPointerType *) effective_type)->elem;
-
-    if (effective_type->kind == Ast_Kind_Struct_Type ||
-            effective_type->kind == Ast_Kind_Poly_Call_Type) {
-
-        if (use_expr->type == NULL)
-            use_expr->type = type_build_from_ast(context.ast_alloc, use_expr->type_node);
-        if (use_expr->type == NULL) goto cannot_use;
-
-        Type* st = use_expr->type;
-        if (st->kind == Type_Kind_Pointer)
-            st = st->Pointer.elem;
-
-        fori (i, 0, shlen(st->Struct.members)) {
-            StructMember* value = st->Struct.members[i].value;
-            AstFieldAccess* fa = make_field_access(context.ast_alloc, use_expr, value->name);
-            symbol_raw_introduce(current_scope, value->name, use->token->pos, (AstNode *) fa);
-        }
-
-        return Symres_Success;
-    }
-
-cannot_use:
-    onyx_report_error(use->token->pos, Error_Critical, "Cannot use this because its type is unknown.");
-    return Symres_Error;
-}
-
 static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) {
     AstDirectiveSolidify* solid = *psolid;
 
@@ -969,11 +866,6 @@ static SymresStatus symres_statement(AstNode** stmt, b32 *remove) {
             SYMRES(local, (AstLocal **) stmt);
             break;
 
-        case Ast_Kind_Use:
-            if (remove) *remove = 1;
-            SYMRES(use, (AstUse *) *stmt);
-            break;
-
         case Ast_Kind_Import:
             if (remove) *remove = 1;
             break;
@@ -1773,12 +1665,50 @@ static SymresStatus symres_file_contents(AstFileContents* fc) {
 }
 
 static SymresStatus symres_import(AstImport* import) {
-    SYMRES(package, import->imported_package);
+    AstPackage* package = import->imported_package;
+    SYMRES(package, package);
+
+    if (import->also_import_package) {
+        symbol_introduce(
+                current_entity->scope,
+                bh_arr_last(package->path),
+                (AstNode *) package);
+    }
+
+    if (import->specified_imports) {
+        package_track_use_package(package->package, import->entity);
 
-    symbol_introduce(
-            current_entity->scope,
-            bh_arr_last(import->imported_package->path),
-            (AstNode *) import->imported_package);
+        Scope *import_scope = package->package->scope;
+        if (import_scope == current_scope) return Symres_Complete;
+
+        // use X { * }
+        if (import->only == NULL) {
+            OnyxFilePos pos = import->token->pos;
+            scope_include(current_scope, import_scope, pos);
+            return Symres_Complete;
+        }
+
+
+        // use X { a, b, c }
+        bh_arr_each(QualifiedImport, qi, import->only) {
+            AstNode* imported = symbol_resolve(import_scope, qi->symbol_name);
+            if (imported == NULL) { // :SymresStall
+                if (report_unresolved_symbols) {
+                    // TODO: Change package->name to package->qualified_name when
+                    // merged with the documentation generation branch.
+                    onyx_report_error(qi->symbol_name->pos, Error_Critical, 
+                            "The symbol '%b' was not found the package '%s'.",
+                            qi->symbol_name->text, qi->symbol_name->length, package->package->name);
+
+                    return Symres_Error;
+                } else {
+                    return Symres_Yield_Macro;
+                }
+            }
+
+            symbol_introduce(current_scope, qi->as_name, imported);
+        }
+    }
 
     return Symres_Complete;
 }
@@ -1815,11 +1745,6 @@ void symres_entity(Entity* ent) {
 
         case Entity_Type_Global_Header:           ss = symres_global(ent->global); break;
 
-        case Entity_Type_Use_Package:
-        case Entity_Type_Use:                     ss = symres_use(ent->use);
-                                                  next_state = Entity_State_Finalized;
-                                                  break;
-
         case Entity_Type_Import:                  ss = symres_import(ent->import); break;
 
 
index 69fd374ddde567275c3be4764f24bae49224dd2c..3c92bfe3ce189356d15ea6ed1e8a69e542189cb1 100644 (file)
@@ -197,7 +197,7 @@ default_log_level :: (level: Log_Level) {
 
 #if runtime.runtime != .Custom {
     #local default_logger_proc :: (logger: &Default_Logger, level: Log_Level, msg: str, module: str) {
-        #import core;
+        use core;
 
         if level < logger.minimum_level do return;
 
@@ -265,8 +265,8 @@ cfree   :: (ptr: rawptr)            => raw_free(context.allocator, ptr);
 // This cannot be used in a custom runtime, as the other core
 // packages are not included.
 #if runtime.runtime != .Custom {
-    #import core
-    #import core.memory
+    use core
+    use core.memory
 
     new :: #match #local {}
 
index fee0e326ee1c3fa21cdcec4f655ce9b53ec05414..3e1b10afe9e6b77b9c061f591559ddc1c8f71187 100644 (file)
@@ -1,11 +1,11 @@
 package core.conv
 
-#import core.map
-#import core.string
-#import core.array
-#import core.math
-#import core.io
-#import runtime
+use core.map
+use core.string
+use core.array
+use core.math
+use core.io
+use runtime
 
 #package {
     custom_formatters: Map(type_expr, #type (&Format_Output, &Format, rawptr) -> void);
@@ -21,7 +21,7 @@ custom_formatters_initialized :: #init () {
     map.init(&custom_parsers,    default=null_proc);
 
     #if Enable_Custom_Formatters {
-        use runtime.info;
+        use runtime.info {*};
 
         for type_idx: type_table.count {
             type := type_table[type_idx];
@@ -406,7 +406,7 @@ format_va :: (output: &Format_Output, format: str, va: [] any) -> str {
 // If a custom formatter is specified for the type, that is used instead.
 // This procedure is generally not used directly; instead, through format or format_va.
 format_any :: (output: &Format_Output, formatting: &Format, v: any) {
-    use runtime.info;
+    use runtime.info {*};
 
     //
     // Dereference the any if the '*' format specifier was given.
index ac5a5c9021a466a29da8761dcff514dfc6325d16..e29fe465d133366001e75982722341efd9326e4b 100644 (file)
@@ -22,7 +22,7 @@ parse_any :: (target: rawptr, data_type: type_expr, to_parse: str, string_alloca
         return custom_parsers[data_type](target, to_parse, string_allocator);
     }
 
-    use runtime.info;
+    use runtime.info {*};
     info := get_type_info(data_type);
 
     switch data_type {
index 2cadc1a42d96d82c0fb65a1559ba033458201ed9..7b368ec03d36e3d8a29adb99529dd30d0a5dabb6 100644 (file)
@@ -1,10 +1,10 @@
 package core.encoding.osad
 
-#import core.io
-#import core.string
-#import core.array
-#import core.memory
-#import runtime
+use core.io
+use core.string
+use core.array
+use core.memory
+use runtime
 
 use runtime {
     type_info :: info
index 4ec2227713fadd15e8f47a0b5976e7a8b99d479f..a4610191e921aeda66a8bf7a94219b10b5d847b7 100644 (file)
@@ -1,7 +1,7 @@
 package core.io
 
-#import core
 use core
+use core {*}
 
 Stream :: struct {
     use vtable : &Stream_Vtable;
index 106f7dc86d45fb4774936ede00e12c9058f24b7c..43740c2803dbee37fbd73001861bff3967339855 100644 (file)
@@ -1,7 +1,7 @@
 package core.math
 
-#import core
-#import core.intrinsics.wasm
+use core
+use core.intrinsics.wasm
 
 // Things that are useful in any math library:
 //  - Trigonometry
index 7d9d58a67b76db51cde810edfabdadd2c20e6c21..6dbc44be9035bfe7c468259f5bcca790b1004d99 100644 (file)
@@ -1,5 +1,7 @@
 package core.memory
 
+use core
+
 //
 // Re-exports the memory_copy intrinsics. Behaves like memmove() in C.
 copy :: core.intrinsics.wasm.memory_copy
index d9092149427cab1b65b60d05d037b69a66791a08..1bda7de3a9390b99ce43ef72f4ff94fd5caea6b6 100644 (file)
@@ -22,20 +22,18 @@ package core.arg_parse
 // false and are true if one or more of the option values are present.
 //
 
-#import core
-#import core.iter
-#import core.conv
-#import core.string
-#import runtime
-
-use core {printf}
+use core {package, printf}
+use core.iter
+use core.conv
+use core.string
+use runtime
 
 arg_parse :: (c_args: [] cstr, output: any) -> bool {
     arg_iter := iter.as_iter(c_args)
              |> iter.map(string.from_cstr);
     defer arg_iter.close(arg_iter.data);
 
-    use runtime.info;
+    use runtime.info {*};
 
     ptr_type := cast(&Type_Info_Pointer) get_type_info(output.type);
     if ptr_type.kind != .Pointer do return false;
index 608335928196c893884b0682b9eec2e746f608e0..601463b07056b14763704aaa0c08f0b365d27dc0 100644 (file)
@@ -4,10 +4,8 @@ package core.net
     #error "Cannot include this file. Platform not supported.";
 }
 
-#import core
-#import runtime
-
-use core
+use core {*}
+use runtime
 
 Socket :: struct {
     Handle :: #distinct i32
index 27dbeac7ad682972dd6e3b9e2f968943cdd64582..79bb717be1faa394cb6c239ff44771fee9c2e5d0 100644 (file)
@@ -4,10 +4,8 @@ package core.os
     #error "Cannot include this file. Platform not supported.";
 }
 
-#import core
-#import runtime
-
-use core
+use core {*}
+use runtime
 
 
 #local fs :: runtime.platform
index 41bafc9d891070dea7cbd7422096246fcf814cdc..1b41acdf801ec1b841d822ba3d624ff0700d77d5 100644 (file)
@@ -1,10 +1,8 @@
 package runtime
 
-#import core
-
-use core
+use core {package, *}
 use core.intrinsics.onyx { __initialize }
-use platform { __output_string }
+use runtime.platform { __output_string }
 
 //
 // Export the __start function from the platform layer.
index 9c4e14961db9114aacafee881ab3ea0e67f0e1f9..fe745d653492e5a9dea379fc01b9719ffad798c8 100644 (file)
@@ -1,9 +1,7 @@
 package runtime.platform
 
-#import core
-#import runtime
-
 use core
+use runtime
 use runtime {
     __runtime_initialize,
     Multi_Threading_Enabled,
index baf5b5bc0ab513c124513fa9a1dc5add58410fef..1056c7164318ceda046707f8eef49e1aeaee7f10 100644 (file)
@@ -1,7 +1,6 @@
 package runtime.platform
 
-#import core
-use core
+#import core {*}
 
 FileData :: #distinct i64
 DirectoryData :: #distinct u64
index 55e2c55fc3247b13288eb1cae945471c5c2a73e5..c54352ff134fe6cf1a8b1906f4693dd3bc60d383 100644 (file)
@@ -1,11 +1,9 @@
 package runtime.platform
 
-#import core
-#import runtime
-#import main
-
-use core
+use main
+use core {package, *}
 use runtime {
+    package,
     __runtime_initialize,
     Multi_Threading_Enabled,
     _thread_start,
index bc45d71df6c88d162a55a3dc79a98ec0cb35fc45..7f7a97e3a9e2d5bee579d66c878e43b2b79a8d2b 100644 (file)
@@ -1,8 +1,6 @@
 package core.string
 
-#import core
-
-use core
+use core {package, *}
 
 #doc "Generic procedure for turning something into a string."
 as_str :: #match -> str {}
index 4ac03b810659081d971a46bcbaea9cf8a5ddcf0d..e1982011a7706c71e936bd6d833d4657b423bc32 100644 (file)
@@ -1,9 +1,8 @@
 package core.sync
 
-#import runtime
-#import core
-
-use core.intrinsics.atomics
+use runtime
+use core
+use core.intrinsics.atomics {*}
 use core.thread { Thread_ID }
 
 //
index a709e361f3574eac6932012ed05f1df4b89f40ca..deb7df2aad295bf88713cea736300388c4728aeb 100644 (file)
@@ -1,10 +1,8 @@
 package core.thread
 
-#import core
-#import runtime
-
-use core
-use core.intrinsics.atomics
+use runtime
+use core {*}
+use core.intrinsics.atomics {*}
 
 #package {
     thread_mutex   : sync.Mutex;
index 3265a08981c3d3db30ec1fab44cef9b965a5112c..ddcf148ef74a7af99c76cbcaff5f8c774cf3faa8 100644 (file)
@@ -1,8 +1,7 @@
 package core.time
 
-#import core
-#import runtime
-use core
+use core {package, *}
+use runtime
 
 Date :: struct {
     year: i32;
index ecb4a8a2ea0d6bf7257515e0fe551f6deaa9e6fd..32581d2c9e68e3f6f7c064b5bd3b4650f3ab280c 100644 (file)
@@ -109,7 +109,7 @@ strftime :: (buf: [] u8, format: [] u8, tm: &Timestamp) -> str {
 }
 
 strptime :: (buf_: [] u8, format_: [] u8, tm: &Timestamp) -> bool {
-    use core
+    use core {*}
 
     #persist weekdays   := str.[ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ];
     #persist monthnames := str.[ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ];
index cb7905fbe6dafcf344578adae6b6bb3d1c5cbb2d..25042d1b0a8bf6183f9339c55310bb123b649f4e 100644 (file)
@@ -5,10 +5,8 @@
 
 #load "core/std"
 
-#import core
-#import runtime
-
-use core
+use runtime
+use core {package, *}
 use core.intrinsics.onyx { init }
 
 Color :: enum {
@@ -123,7 +121,7 @@ main :: (args) => {
 
     iter.parallel_for(cases, settings.threads, &exec_context) {
         // Weird macros mean I have to forward external names
-        use core
+        use core {*}
         print_color :: print_color;
 
         args: [] str;
index f6ede0ffd20bee0f8a8acea57356ff018b0ef70d..0602689d7601ad956f93b51b3dc6d66cba82e95b 100644 (file)
@@ -1,7 +1,4 @@
-#load "core/std"
-
-#import core
-use core
+use core {package, *}
 
 GameOfSeats :: struct {
     width  : u32;
index c9193aed7c4ff43856f0bf29b782dc19efbf21c1..0b0efab31ab58f5940faae02dabfe379118c6d17 100644 (file)
@@ -1,7 +1,6 @@
 #load "core/std"
 
-#import core
-use core
+use core {package, *}
 
 OverloadsEqual :: interface (t: $T) {
     { T.equals(t, t) } -> bool;
index d0dc8612adb6a556d312b29738da96e73a41eb83..927c467c2bb69cee79ec2ba95f686568544ae508 100644 (file)
@@ -2,9 +2,7 @@
 
 PART :: 2
 
-#import core
-
-use core
+use core {package, *}
 use core.alloc {arena}
 
 num_allocator: Allocator;
index df7d266269b4e0dedce33619e15a9fa7716d352c..e3ad63177f35f2ef0ebb2aaa52c2e72391d1c945 100644 (file)
@@ -1,5 +1,4 @@
-#import core
-use core
+use core {package, *}
 
 PART :: 1
 
index 2946b312957a975d5e2839fc9bd5c99d989e8a9b..cd7cd445a8873d50b75bb68ad22739f12cc0c1fe 100644 (file)
@@ -1,5 +1,4 @@
-#import core
-use core
+use core {package, *}
 
 f :: ctx => {
     x, y := 123, 456.0f;
index 98b8b5316324e1f1210a88dec467cfbeae9c938e..15d715af263a3710d0c0b850e4db915a8d7452b5 100644 (file)
@@ -1,5 +1,4 @@
-#import core
-use core
+use core {package, *}
 
 q :: (v: &$C, g: (&C) -> $T) {
     println(*v);
index 00cac5c911eb33ee7bddf69174cbb093879f5ba9..5dc5348ff2c27cdfd0d675aa6497d49c00be53d3 100644 (file)
@@ -1,5 +1,4 @@
-#import core
-use core
+use core {package, *}
 
 Foo :: struct {
     use vtable: &VTable;
index 519d8a311eee6f15bb2e9b12b1bc185a165b99ee..1261bd980c22e0a584288e555d650c9f36e3e347 100644 (file)
@@ -15,8 +15,9 @@ main :: (args) => {
     }
 
     {
-        use SomeNamespace;
+        // This is no longer a feature, and cannot be used anymore
+        //     use SomeNamespace;
 
-        foo();
+        SomeNamespace.foo();
     }
 }
\ No newline at end of file
index b6eaee29e1d45a857820ecafa246ba9459c03c70..7d152fc52c7c17ae3a6c3d473ec168307c40e608 100644 (file)
@@ -1,5 +1,4 @@
-#import core
-use core
+use core {*}
 
 
 main :: () {
index d69e04b625b4f7ab8e2528502ab09da9f784512e..5302c31e970001316f56a08d37ef894ac9ea0724 100644 (file)
@@ -2,8 +2,7 @@ package main
 
 #load "core/std"
 
-#import core
-use core
+use core {*}
 
 main :: (args: [] cstr) {
     println("Hello, World!");
index b42b89b954aeda56a9fa924a59159c0e306199d1..4fb0a1a1b801fdcf4da240d427fff4ba9e27ce2b 100644 (file)
@@ -1,7 +1,6 @@
 #load "core/std"
 
-#import core
-use core {println, printf}
+use core {package, println, printf}
 
 some_function :: () -> f32 {
     println("In some function!");
index 8400200a273d46fae67e7946b8a17a9f866bcce9..52963323cedb519cad39605603989bb537ea86eb 100644 (file)
@@ -1,7 +1,6 @@
 #load "core/std"
 
-#import core
-use core
+use core {package, *}
 
 foo :: () -> (i32, i32) {
     return 50, 60;
index ac00bb4e43e3840997a628a506152ae0bc5d4b6b..a9eef06a8e4536db739cd65c1ab8a4789320d796 100644 (file)
@@ -71,11 +71,12 @@ main :: (args: [] cstr) {
     {
         BasicallyANamespace.function_3();
 
-        use BasicallyANamespace;
-        function_2();
+        // TODO: Revisit this test case when `use struct` is added.
+        // use BasicallyANamespace;
+        BasicallyANamespace.function_2();
 
-        use SubNamespace;
-        function_4();
+        // use SubNamespace;
+        BasicallyANamespace.SubNamespace.function_4();
     }
 
 
index 767cc0b23b4b5f2e6462811bd6dd1845cdfd965b..8ef314354159a066326f38d220d16d3223355943 100644 (file)
@@ -2,10 +2,7 @@
 // No types are written throughout this entire program.
 //
 
-#load "core/std"
-
-#import core
-use core
+use core {*}
 
 main :: () {
     object := .{
index 410d99c40665724deab769efe155206f8cd7a5e9..0ca71560acda4ca206d26aaf4917353fe3845754 100644 (file)
@@ -26,11 +26,10 @@ main :: (args: [] cstr) {
 
         ss: SimpleStruct = SimpleStruct.{ 41, 67, "Steve" };
 
-        use ss;
         printf("SimpleStruct<{}, {}>({}, {}, {})\n",
             sizeof SimpleStruct,
             alignof SimpleStruct,
-            cast(u32) age, height, name);
+            cast(u32) ss.age, ss.height, ss.name);
     }
 
     test_simple_union :: () {