From 6fcdc5ea4f6595fa3de05b58ff2b2428fdb5b53a Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 26 Mar 2023 18:23:56 -0500 Subject: [PATCH] changed: `use` now acts like `#import` `#import` will be removed soon. --- compiler/include/astnodes.h | 44 +++-- compiler/src/astnodes.c | 2 +- compiler/src/clone.c | 5 - compiler/src/entities.c | 13 -- compiler/src/parser.c | 107 +++++------- compiler/src/symres.c | 161 +++++-------------- core/builtin.onyx | 6 +- core/conv/format.onyx | 16 +- core/conv/parse.onyx | 2 +- core/encoding/osad.onyx | 10 +- core/io/stream.onyx | 2 +- core/math/math.onyx | 4 +- core/memory/memory.onyx | 2 + core/misc/arg_parse.onyx | 14 +- core/net/net.onyx | 6 +- core/os/file.onyx | 6 +- core/runtime/common.onyx | 6 +- core/runtime/platform/js/platform.onyx | 4 +- core/runtime/platform/onyx/fs.onyx | 3 +- core/runtime/platform/onyx/platform.onyx | 8 +- core/string/string.onyx | 4 +- core/sync/mutex.onyx | 7 +- core/threads/thread.onyx | 8 +- core/time/date.onyx | 5 +- core/time/time.onyx | 2 +- scripts/run_tests.onyx | 8 +- tests/aoc-2020/day11.onyx | 5 +- tests/aoc-2020/day17.onyx | 3 +- tests/aoc-2021/day18.onyx | 4 +- tests/aoc-2021/day21.onyx | 3 +- tests/bugs/autopoly_limits.onyx | 3 +- tests/bugs/double_polymorph_yield_error.onyx | 3 +- tests/bugs/method_call_source_double.onyx | 3 +- tests/bugs/namespace_aliasing.onyx | 5 +- tests/char_literals.onyx | 3 +- tests/hello_world.onyx | 3 +- tests/if_expressions.onyx | 3 +- tests/multiple_returns_robustness.onyx | 3 +- tests/new_struct_behaviour.onyx | 9 +- tests/no_types.onyx | 5 +- tests/struct_robustness.onyx | 3 +- 41 files changed, 190 insertions(+), 323 deletions(-) diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index 0043a259..fbc658ba 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -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; diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index 84a92836..5bead67d 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -84,7 +84,7 @@ static const char* ast_node_names[] = { "FOR", "WHILE", "JUMP", - "USE", + // "USE", "DEFER", "SWITCH", "CASE", diff --git a/compiler/src/clone.c b/compiler/src/clone.c index 28b8f64a..f6f0be80 100644 --- a/compiler/src/clone.c +++ b/compiler/src/clone.c @@ -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; diff --git a/compiler/src/entities.c b/compiler/src/entities.c index a21ce2d6..6cfac5a9 100644 --- a/compiler/src/entities.c +++ b/compiler/src/entities.c @@ -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; diff --git a/compiler/src/parser.c b/compiler/src/parser.c index 082e7716..c2394d4c 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -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) { diff --git a/compiler/src/symres.c b/compiler/src/symres.c index 6dd4299c..b83792b5 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -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; diff --git a/core/builtin.onyx b/core/builtin.onyx index 69fd374d..3c92bfe3 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -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 {} diff --git a/core/conv/format.onyx b/core/conv/format.onyx index fee0e326..3e1b10af 100644 --- a/core/conv/format.onyx +++ b/core/conv/format.onyx @@ -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. diff --git a/core/conv/parse.onyx b/core/conv/parse.onyx index ac5a5c90..e29fe465 100644 --- a/core/conv/parse.onyx +++ b/core/conv/parse.onyx @@ -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 { diff --git a/core/encoding/osad.onyx b/core/encoding/osad.onyx index 2cadc1a4..7b368ec0 100644 --- a/core/encoding/osad.onyx +++ b/core/encoding/osad.onyx @@ -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 diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 4ec22277..a4610191 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -1,7 +1,7 @@ package core.io -#import core use core +use core {*} Stream :: struct { use vtable : &Stream_Vtable; diff --git a/core/math/math.onyx b/core/math/math.onyx index 106f7dc8..43740c28 100644 --- a/core/math/math.onyx +++ b/core/math/math.onyx @@ -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 diff --git a/core/memory/memory.onyx b/core/memory/memory.onyx index 7d9d58a6..6dbc44be 100644 --- a/core/memory/memory.onyx +++ b/core/memory/memory.onyx @@ -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 diff --git a/core/misc/arg_parse.onyx b/core/misc/arg_parse.onyx index d9092149..1bda7de3 100644 --- a/core/misc/arg_parse.onyx +++ b/core/misc/arg_parse.onyx @@ -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; diff --git a/core/net/net.onyx b/core/net/net.onyx index 60833592..601463b0 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -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 diff --git a/core/os/file.onyx b/core/os/file.onyx index 27dbeac7..79bb717b 100644 --- a/core/os/file.onyx +++ b/core/os/file.onyx @@ -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 diff --git a/core/runtime/common.onyx b/core/runtime/common.onyx index 41bafc9d..1b41acdf 100644 --- a/core/runtime/common.onyx +++ b/core/runtime/common.onyx @@ -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. diff --git a/core/runtime/platform/js/platform.onyx b/core/runtime/platform/js/platform.onyx index 9c4e1496..fe745d65 100644 --- a/core/runtime/platform/js/platform.onyx +++ b/core/runtime/platform/js/platform.onyx @@ -1,9 +1,7 @@ package runtime.platform -#import core -#import runtime - use core +use runtime use runtime { __runtime_initialize, Multi_Threading_Enabled, diff --git a/core/runtime/platform/onyx/fs.onyx b/core/runtime/platform/onyx/fs.onyx index baf5b5bc..1056c716 100644 --- a/core/runtime/platform/onyx/fs.onyx +++ b/core/runtime/platform/onyx/fs.onyx @@ -1,7 +1,6 @@ package runtime.platform -#import core -use core +#import core {*} FileData :: #distinct i64 DirectoryData :: #distinct u64 diff --git a/core/runtime/platform/onyx/platform.onyx b/core/runtime/platform/onyx/platform.onyx index 55e2c55f..c54352ff 100644 --- a/core/runtime/platform/onyx/platform.onyx +++ b/core/runtime/platform/onyx/platform.onyx @@ -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, diff --git a/core/string/string.onyx b/core/string/string.onyx index bc45d71d..7f7a97e3 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -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 {} diff --git a/core/sync/mutex.onyx b/core/sync/mutex.onyx index 4ac03b81..e1982011 100644 --- a/core/sync/mutex.onyx +++ b/core/sync/mutex.onyx @@ -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 } // diff --git a/core/threads/thread.onyx b/core/threads/thread.onyx index a709e361..deb7df2a 100644 --- a/core/threads/thread.onyx +++ b/core/threads/thread.onyx @@ -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; diff --git a/core/time/date.onyx b/core/time/date.onyx index 3265a089..ddcf148e 100644 --- a/core/time/date.onyx +++ b/core/time/date.onyx @@ -1,8 +1,7 @@ package core.time -#import core -#import runtime -use core +use core {package, *} +use runtime Date :: struct { year: i32; diff --git a/core/time/time.onyx b/core/time/time.onyx index ecb4a8a2..32581d2c 100644 --- a/core/time/time.onyx +++ b/core/time/time.onyx @@ -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" ]; diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index cb7905fb..25042d1b 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -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; diff --git a/tests/aoc-2020/day11.onyx b/tests/aoc-2020/day11.onyx index f6ede0ff..0602689d 100644 --- a/tests/aoc-2020/day11.onyx +++ b/tests/aoc-2020/day11.onyx @@ -1,7 +1,4 @@ -#load "core/std" - -#import core -use core +use core {package, *} GameOfSeats :: struct { width : u32; diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index c9193aed..0b0efab3 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -1,7 +1,6 @@ #load "core/std" -#import core -use core +use core {package, *} OverloadsEqual :: interface (t: $T) { { T.equals(t, t) } -> bool; diff --git a/tests/aoc-2021/day18.onyx b/tests/aoc-2021/day18.onyx index d0dc8612..927c467c 100644 --- a/tests/aoc-2021/day18.onyx +++ b/tests/aoc-2021/day18.onyx @@ -2,9 +2,7 @@ PART :: 2 -#import core - -use core +use core {package, *} use core.alloc {arena} num_allocator: Allocator; diff --git a/tests/aoc-2021/day21.onyx b/tests/aoc-2021/day21.onyx index df7d2662..e3ad6317 100644 --- a/tests/aoc-2021/day21.onyx +++ b/tests/aoc-2021/day21.onyx @@ -1,5 +1,4 @@ -#import core -use core +use core {package, *} PART :: 1 diff --git a/tests/bugs/autopoly_limits.onyx b/tests/bugs/autopoly_limits.onyx index 2946b312..cd7cd445 100644 --- a/tests/bugs/autopoly_limits.onyx +++ b/tests/bugs/autopoly_limits.onyx @@ -1,5 +1,4 @@ -#import core -use core +use core {package, *} f :: ctx => { x, y := 123, 456.0f; diff --git a/tests/bugs/double_polymorph_yield_error.onyx b/tests/bugs/double_polymorph_yield_error.onyx index 98b8b531..15d715af 100644 --- a/tests/bugs/double_polymorph_yield_error.onyx +++ b/tests/bugs/double_polymorph_yield_error.onyx @@ -1,5 +1,4 @@ -#import core -use core +use core {package, *} q :: (v: &$C, g: (&C) -> $T) { println(*v); diff --git a/tests/bugs/method_call_source_double.onyx b/tests/bugs/method_call_source_double.onyx index 00cac5c9..5dc5348f 100644 --- a/tests/bugs/method_call_source_double.onyx +++ b/tests/bugs/method_call_source_double.onyx @@ -1,5 +1,4 @@ -#import core -use core +use core {package, *} Foo :: struct { use vtable: &VTable; diff --git a/tests/bugs/namespace_aliasing.onyx b/tests/bugs/namespace_aliasing.onyx index 519d8a31..1261bd98 100644 --- a/tests/bugs/namespace_aliasing.onyx +++ b/tests/bugs/namespace_aliasing.onyx @@ -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 diff --git a/tests/char_literals.onyx b/tests/char_literals.onyx index b6eaee29..7d152fc5 100644 --- a/tests/char_literals.onyx +++ b/tests/char_literals.onyx @@ -1,5 +1,4 @@ -#import core -use core +use core {*} main :: () { diff --git a/tests/hello_world.onyx b/tests/hello_world.onyx index d69e04b6..5302c31e 100644 --- a/tests/hello_world.onyx +++ b/tests/hello_world.onyx @@ -2,8 +2,7 @@ package main #load "core/std" -#import core -use core +use core {*} main :: (args: [] cstr) { println("Hello, World!"); diff --git a/tests/if_expressions.onyx b/tests/if_expressions.onyx index b42b89b9..4fb0a1a1 100644 --- a/tests/if_expressions.onyx +++ b/tests/if_expressions.onyx @@ -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!"); diff --git a/tests/multiple_returns_robustness.onyx b/tests/multiple_returns_robustness.onyx index 8400200a..52963323 100644 --- a/tests/multiple_returns_robustness.onyx +++ b/tests/multiple_returns_robustness.onyx @@ -1,7 +1,6 @@ #load "core/std" -#import core -use core +use core {package, *} foo :: () -> (i32, i32) { return 50, 60; diff --git a/tests/new_struct_behaviour.onyx b/tests/new_struct_behaviour.onyx index ac00bb4e..a9eef06a 100644 --- a/tests/new_struct_behaviour.onyx +++ b/tests/new_struct_behaviour.onyx @@ -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(); } diff --git a/tests/no_types.onyx b/tests/no_types.onyx index 767cc0b2..8ef31435 100644 --- a/tests/no_types.onyx +++ b/tests/no_types.onyx @@ -2,10 +2,7 @@ // No types are written throughout this entire program. // -#load "core/std" - -#import core -use core +use core {*} main :: () { object := .{ diff --git a/tests/struct_robustness.onyx b/tests/struct_robustness.onyx index 410d99c4..0ca71560 100644 --- a/tests/struct_robustness.onyx +++ b/tests/struct_robustness.onyx @@ -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 :: () { -- 2.25.1