From: Brendan Hansen Date: Fri, 24 Mar 2023 19:46:08 +0000 (-0500) Subject: breaking change: top-level packages are required to be `#import`ed X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3dbfd29b26187bc6e1182a8c438d9d5506985e3c;p=onyx.git breaking change: top-level packages are required to be `#import`ed --- diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index bb0422f2..5e5aef91 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -107,6 +107,7 @@ NODE(ForeignBlock) \ \ NODE(Package) \ + NODE(Import) \ \ NODE(ZeroValue) @@ -132,6 +133,7 @@ typedef enum AstKind { Ast_Kind_Load_Path, Ast_Kind_Load_All, Ast_Kind_Library_Path, + Ast_Kind_Import, Ast_Kind_Memres, Ast_Kind_Binding, @@ -1170,6 +1172,13 @@ struct AstPackage { Package* package; }; +struct AstImport { + AstNode_base; + + AstPackage *imported_package; +}; + + // // Polymorphic procedures // @@ -1458,6 +1467,7 @@ typedef enum EntityType { Entity_Type_Load_File, Entity_Type_Binding, Entity_Type_Use_Package, + Entity_Type_Import, Entity_Type_Static_If, Entity_Type_String_Literal, Entity_Type_File_Contents, @@ -1511,6 +1521,7 @@ typedef struct Entity { union { AstDirectiveError *error; AstInclude *include; + AstImport *import; AstBinding *binding; AstIf *static_if; AstFunction *function; diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index 98c520bc..84a92836 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -9,6 +9,7 @@ static const char* ast_node_names[] = { "INCLUDE FOLDER", "INCLUDE ALL IN FOLDER", "INCLUDE LIBRARY PATH", + "IMPORT", "MEMORY RESERVATION", "BINDING", diff --git a/compiler/src/entities.c b/compiler/src/entities.c index 8c4fa813..a21ce2d6 100644 --- a/compiler/src/entities.c +++ b/compiler/src/entities.c @@ -400,6 +400,14 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s break; } + case Ast_Kind_Import: { + ent.type = Entity_Type_Import; + ent.import = (AstImport *) node; + ent.state = Entity_State_Resolve_Symbols; + ENTITY_INSERT(ent); + break; + } + default: { ent.type = Entity_Type_Expression; ent.expr = (AstTyped *) node; diff --git a/compiler/src/lex.c b/compiler/src/lex.c index 7bf9aa1f..4458c485 100644 --- a/compiler/src/lex.c +++ b/compiler/src/lex.c @@ -38,6 +38,7 @@ static const char* token_type_names[] = { "macro", "interface", "where", + "import", "", // end "->", diff --git a/compiler/src/parser.c b/compiler/src/parser.c index aa18ca87..2cf8a1a0 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -78,6 +78,7 @@ static AstBinding* parse_top_level_binding(OnyxParser* parser, OnyxToken* sym static void parse_top_level_statement(OnyxParser* parser); static AstPackage* parse_package_expression(OnyxParser* parser); static void parse_top_level_statements_until(OnyxParser* parser, TokenType tt); +static AstImport* parse_import_statement(OnyxParser* parser, OnyxToken *token); static void consume_token(OnyxParser* parser) { if (parser->hit_unexpected_token) return; @@ -3526,6 +3527,11 @@ static void parse_top_level_statement(OnyxParser* parser) { expect_token(parser, Token_Type_Literal_String); return; } + else if (parse_possible_directive(parser, "import")) { + AstImport *import = parse_import_statement(parser, dir_token); + ENTITY_SUBMIT(import); + return; + } else { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = parser->curr; @@ -3592,49 +3598,68 @@ submit_binding_to_entities: } } -static AstPackage* parse_package_expression(OnyxParser* parser) { - AstPackage* package_node = make_node(AstPackage, Ast_Kind_Package); - package_node->flags |= Ast_Flag_Comptime; - package_node->type_node = builtin_package_id_type; - package_node->token = expect_token(parser, Token_Type_Keyword_Package); - - bh_arr_new(global_heap_allocator, package_node->path, 2); +static b32 parse_package_name(OnyxParser *parser, AstPackage *package) { + bh_arr_new(global_heap_allocator, package->path, 2); while (parser->curr->type == Token_Type_Symbol) { - if (parser->hit_unexpected_token) return package_node; + if (parser->hit_unexpected_token) return 0; OnyxToken* symbol = expect_token(parser, Token_Type_Symbol); + bh_arr_push(package->path, symbol); - bh_arr_push(package_node->path, symbol); - - if (consume_token_if_next(parser, '.')); - else break; + if (!consume_token_if_next(parser, '.')) break; } i32 total_package_name_length = 0; - bh_arr_each(OnyxToken *, token, package_node->path) { + bh_arr_each(OnyxToken *, token, package->path) { total_package_name_length += (*token)->length + 1; } char* package_name = bh_alloc_array(context.ast_alloc, char, total_package_name_length); *package_name = '\0'; - bh_arr_each(OnyxToken *, token, package_node->path) { + bh_arr_each(OnyxToken *, token, package->path) { token_toggle_end(*token); strncat(package_name, (*token)->text, total_package_name_length - 1); token_toggle_end(*token); - if (token != &bh_arr_last(package_node->path)) { + if (token != &bh_arr_last(package->path)) { strncat(package_name, ".", total_package_name_length - 1); } } - package_node->package_name = package_name; - package_node->package = package_lookup(package_name); + package->package_name = package_name; + return 1; +} + +static AstPackage* parse_package_expression(OnyxParser* parser) { + AstPackage* package_node = make_node(AstPackage, Ast_Kind_Package); + package_node->flags |= Ast_Flag_Comptime; + package_node->type_node = builtin_package_id_type; + package_node->token = expect_token(parser, Token_Type_Keyword_Package); + + if (!parse_package_name(parser, package_node)) return NULL; return package_node; } +static AstImport* parse_import_statement(OnyxParser* parser, OnyxToken *token) { + AstImport* import_node = make_node(AstImport, Ast_Kind_Import); + import_node->flags |= Ast_Flag_Comptime; + import_node->token = token; + + AstPackage* package_node = make_node(AstPackage, Ast_Kind_Package); + package_node->flags |= Ast_Flag_Comptime; + package_node->type_node = builtin_package_id_type; + package_node->token = token; + + if (!parse_package_name(parser, package_node)) return NULL; + + import_node->imported_package = package_node; + + return import_node; +} + static Package* parse_file_package(OnyxParser* parser) { if (parser->curr->type != Token_Type_Keyword_Package) { return package_lookup_or_create("main", context.global_scope, parser->allocator, parser->curr->pos); diff --git a/compiler/src/symres.c b/compiler/src/symres.c index fb889375..e75a09bb 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -1768,6 +1768,17 @@ static SymresStatus symres_file_contents(AstFileContents* fc) { return Symres_Success; } +static SymresStatus symres_import(AstImport* import) { + SYMRES(package, import->imported_package); + + symbol_introduce( + current_entity->scope, + bh_arr_last(import->imported_package->path), + (AstNode *) import->imported_package); + + return Symres_Complete; +} + void symres_entity(Entity* ent) { current_entity = ent; if (ent->scope) scope_enter(ent->scope); @@ -1805,6 +1816,9 @@ void symres_entity(Entity* ent) { next_state = Entity_State_Finalized; break; + case Entity_Type_Import: ss = symres_import(ent->import); break; + + case Entity_Type_Polymorphic_Proc: ss = symres_polyproc(ent->poly_proc); next_state = Entity_State_Finalized; break; diff --git a/compiler/src/utils.c b/compiler/src/utils.c index 2e235de9..53804635 100644 --- a/compiler/src/utils.c +++ b/compiler/src/utils.c @@ -55,7 +55,17 @@ Package* package_lookup_or_create(char* package_name, Scope* parent_scope, bh_al shput(context.packages, pac_name, package); - if (!charset_contains(pac_name, '.')) { + // if (!charset_contains(pac_name, '.')) { + // AstPackage* package_node = onyx_ast_node_new(alloc, sizeof(AstPackage), Ast_Kind_Package); + // package_node->package_name = package->name; + // package_node->package = package; + // package_node->type_node = builtin_package_id_type; + // package_node->flags |= Ast_Flag_Comptime; + + // symbol_raw_introduce(context.global_scope, pac_name, pos, (AstNode *) package_node); + // } + + if (!strcmp(pac_name, "builtin")) { AstPackage* package_node = onyx_ast_node_new(alloc, sizeof(AstPackage), Ast_Kind_Package); package_node->package_name = package->name; package_node->package = package; diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index 0f5c74f1..311237e7 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -1,5 +1,7 @@ package core.alloc.arena +#import core + // This allocator is mostly used for making many fixed-size // allocation (i.e. allocations that will not need to change // in size, such as game entities or position structs). The diff --git a/core/alloc/atomic.onyx b/core/alloc/atomic.onyx index 71fa0f81..d91fd8ec 100644 --- a/core/alloc/atomic.onyx +++ b/core/alloc/atomic.onyx @@ -6,7 +6,7 @@ package core.alloc.atomic // is not needed for the general purpose heap allocator, // as that already has a thread-safe implementation. -use core {sync} +#import core.sync AtomicAllocator :: struct { a: Allocator; diff --git a/core/alloc/fixed.onyx b/core/alloc/fixed.onyx index 85b8b5e1..b87c6bb9 100644 --- a/core/alloc/fixed.onyx +++ b/core/alloc/fixed.onyx @@ -1,5 +1,7 @@ package core.alloc.fixed +#import core + // This allocator is very simple and always returns the same pointer, // unless too much memory is asked for, in which case it returns null. // diff --git a/core/alloc/gc.onyx b/core/alloc/gc.onyx index 3dc3e11d..103128da 100644 --- a/core/alloc/gc.onyx +++ b/core/alloc/gc.onyx @@ -16,6 +16,8 @@ package core.alloc.gc // // Every allocation here will automatically be freed // } +#import core + GCState :: struct { backing_allocator: Allocator; first: &GCLink; diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index f5102f5f..e80a8b87 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -1,5 +1,8 @@ package core.alloc.heap +#import runtime +#import core + // This is the implementation for the general purpose heap allocator. // It is a simple bump allocator, with a free list. It is not very good diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index e5e8788d..647a7ba2 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -4,6 +4,8 @@ package core.alloc.log // prints every allocation/deallocation made by that // allocator. +#import core + #local Allocation_Action_Strings := str.[ " alloc", diff --git a/core/alloc/pool.onyx b/core/alloc/pool.onyx index 8e898113..30fb47be 100644 --- a/core/alloc/pool.onyx +++ b/core/alloc/pool.onyx @@ -1,5 +1,7 @@ package core.alloc.pool +#import core + // A pool allocator is an O(1) allocator that is capable of allocating and freeing. // It is able to do both in constant time because it maintains a linked list of all // the free elements in the pool. When an element is requested the first element of diff --git a/core/alloc/ring.onyx b/core/alloc/ring.onyx index 493a4572..f5888791 100644 --- a/core/alloc/ring.onyx +++ b/core/alloc/ring.onyx @@ -1,5 +1,7 @@ package core.alloc.ring +#import core + // This allocator is great for temporary memory, such as returning // a pointer from a function, or storing a formatted string. The // memory allocated using this allocator does not need to be freed. diff --git a/core/builtin.onyx b/core/builtin.onyx index f0ab0944..fd6a4904 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -1,5 +1,11 @@ package builtin +#import runtime + +#if #defined(package core) { + #import core +} + // // Explanation of `package builtin` // diff --git a/core/container/array.onyx b/core/container/array.onyx index 340eeae8..0c8bd020 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -1,5 +1,7 @@ package core.array +#import core + // [..] T == Array(T) // where // Array :: struct (T: type_expr) { @@ -31,12 +33,12 @@ make :: (base: [] $T, allocator := context.allocator) -> [..] T { #overload __make_overload :: macro (_: &[..] $T, allocator := context.allocator) -> [..] T { - return core.array.make(T, allocator=allocator); + return #this_package.make(T, allocator=allocator); } #overload __make_overload :: macro (_: &[..] $T, capacity: u32, allocator := context.allocator) -> [..] T { - return core.array.make(T, capacity, allocator); + return #this_package.make(T, capacity, allocator); } init :: (arr: &[..] $T, capacity := 4, allocator := context.allocator) { @@ -56,7 +58,7 @@ free :: (arr: &[..] $T) { #overload builtin.delete :: macro (x: &[..] $T) { - core.array.free(x); + #this_package.free(x); } copy :: #match #locked { @@ -114,7 +116,7 @@ push :: (arr: &[..] $T, x: T) -> bool { } // Semi-useful shortcut for adding something to an array. -#operator << macro (arr: [..] $T, v: T) do core.array.push(&arr, v); +#operator << macro (arr: [..] $T, v: T) do #this_package.push(&arr, v); insert :: #match #local {} diff --git a/core/container/avl_tree.onyx b/core/container/avl_tree.onyx index 5668fd88..50d42e51 100644 --- a/core/container/avl_tree.onyx +++ b/core/container/avl_tree.onyx @@ -1,6 +1,7 @@ package core.avl_tree -use core {math} +#import core +#import core.math AVL_Tree :: struct (T: type_expr) { data: T; diff --git a/core/container/bucket_array.onyx b/core/container/bucket_array.onyx index 098f0fcc..b02cd2dc 100644 --- a/core/container/bucket_array.onyx +++ b/core/container/bucket_array.onyx @@ -2,7 +2,9 @@ package core.bucket_array -use core {array, iter} +#import core +#import core.array +#import core.iter Bucket_Array :: struct (T: type_expr) { allocator : Allocator; @@ -83,7 +85,7 @@ push :: (use b: &Bucket_Array($T), elem: T) -> bool { } } -#operator << macro (b: Bucket_Array($T), elem: T) do core.bucket_array.push(&b, elem); +#operator << macro (b: Bucket_Array($T), elem: T) do #this_package.push(&b, elem); pop :: (use b: &Bucket_Array($T)) { last_bucket := &buckets[buckets.count - 1]; diff --git a/core/container/heap.onyx b/core/container/heap.onyx index 53c5bedb..eb29ff6a 100644 --- a/core/container/heap.onyx +++ b/core/container/heap.onyx @@ -1,6 +1,6 @@ package core.heap -use core {array} +#import core.array Heap :: struct (T: type_expr) { data: [..] T; @@ -23,7 +23,7 @@ insert :: (use heap: &Heap, v: heap.T) { shift_up(heap, data.count - 1); } -#operator << macro (heap: Heap($T), v: T) do core.heap.insert(&heap, v); +#operator << macro (heap: Heap($T), v: T) do #this_package.insert(&heap, v); remove_top :: (use heap: &Heap) -> heap.T { x := data[0]; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index bc08cf93..f448850b 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -1,6 +1,12 @@ package core.iter -use core {memory, alloc, array, Pair} +#import core +#import core.memory +#import core.alloc +#import core.array +#import runtime + +use core {Pair} use core.intrinsics.types {type_is_struct} diff --git a/core/container/list.onyx b/core/container/list.onyx index c89d695c..6fe72cf8 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -1,5 +1,7 @@ package core.list +#import core + ListElem :: struct (T: type_expr) { next: &ListElem(T) = null; prev: &ListElem(T) = null; diff --git a/core/container/map.onyx b/core/container/map.onyx index 5722b304..926ea4ae 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -1,6 +1,13 @@ package core.map -use core {array, hash, memory, math, conv, Optional} +#import core +#import core.array +#import core.hash +#import core.memory +#import core.math +#import core.conv + +use core {Optional} use core.intrinsics.onyx { __initialize } // diff --git a/core/container/pair.onyx b/core/container/pair.onyx index d91bc18a..13f56c96 100644 --- a/core/container/pair.onyx +++ b/core/container/pair.onyx @@ -1,5 +1,6 @@ package core + // // A `Pair` represents a pair of values of heterogenous types. // This structure does not do much on its own; however, it @@ -24,7 +25,7 @@ Pair :: struct (First_Type: type_expr, Second_Type: type_expr) { } #overload -core.hash.hash :: (p: Pair($First_Type/hash.Hashable, $Second_Type/hash.Hashable)) => { +hash.hash :: (p: Pair($First_Type/hash.Hashable, $Second_Type/hash.Hashable)) => { h := 7; h += h << 5 + hash.hash(p.first); h += h << 5 + hash.hash(p.second); diff --git a/core/container/result.onyx b/core/container/result.onyx index 23fc812a..ea9ac23e 100644 --- a/core/container/result.onyx +++ b/core/container/result.onyx @@ -8,8 +8,10 @@ package core // helper methods that make it easier to work with Results. // +#import core +#import core.conv -use core {Optional, conv} +use core {Optional} #doc """ Result(T, E) is a structure that represents either an Ok value diff --git a/core/container/set.onyx b/core/container/set.onyx index 6c7352e5..66584816 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -1,6 +1,12 @@ package core.set -use core {array, hash, memory, math, Optional} +#import core +#import core.array +#import core.hash +#import core.memory +#import core.math + +use core {Optional} #local SetValue :: interface (t: $T) { { hash.hash(t) } -> u32; @@ -43,7 +49,7 @@ make :: ($T: type_expr, default := T.{}, allocator := context.allocator) -> Set( } #overload -builtin.__make_overload :: macro (x: &Set, allocator: Allocator) => core.set.make(x.Elem_Type, allocator = allocator); +builtin.__make_overload :: macro (x: &Set, allocator: Allocator) => #this_package.make(x.Elem_Type, allocator = allocator); init :: (set: &Set($T), default := T.{}, allocator := context.allocator) { set.allocator = allocator; @@ -61,7 +67,7 @@ free :: (use set: &Set) { } #overload -builtin.delete :: core.set.free +builtin.delete :: #this_package.free insert :: (use set: &Set, value: set.Elem_Type) { if hashes.data == null do init(set); @@ -75,7 +81,7 @@ insert :: (use set: &Set, value: set.Elem_Type) { if full(set) do grow(set); } -#operator << macro (set: Set($T), value: T) do core.set.insert(&set, value); +#operator << macro (set: Set($T), value: T) do #this_package.insert(&set, value); has :: (use set: &Set, value: set.Elem_Type) -> bool { lr := lookup(set, value); diff --git a/core/conv/conv.onyx b/core/conv/conv.onyx index e3975f64..8296a6fd 100644 --- a/core/conv/conv.onyx +++ b/core/conv/conv.onyx @@ -2,7 +2,8 @@ package core.conv Enable_Custom_Formatters :: true -use core {string, math} +#import core.string +#import core.math // // Converts a string into an integer. Works with positive and @@ -19,8 +20,6 @@ str_to_i64 :: macro (s: str, base: u32 = 10) -> i64 { #overload str_to_i64 :: (s: &str, base: u32 = 10) -> i64 { - use package core - string.strip_leading_whitespace(s); value: i64 = 0; @@ -79,8 +78,6 @@ str_to_f64 :: macro (s: str) -> f64 { #overload str_to_f64 :: (s: &str) -> f64 { - use package core - string.strip_leading_whitespace(s); sign := parse_sign(s); diff --git a/core/conv/format.onyx b/core/conv/format.onyx index 59a4c196..90b70234 100644 --- a/core/conv/format.onyx +++ b/core/conv/format.onyx @@ -1,6 +1,11 @@ package core.conv -use core {map, string, array, math} +#import core.map +#import core.string +#import core.array +#import core.math +#import core.io +#import runtime #package { custom_formatters: Map(type_expr, #type (&Format_Output, &Format, rawptr) -> void); @@ -401,8 +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 package runtime.info - array :: package core.array; + use runtime.info; // // Dereference the any if the '*' format specifier was given. @@ -522,8 +526,6 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) { case type_expr { value := *(cast(&type_expr) v.data); - io :: package core.io - buf : [256] u8; // This is a little gross but the only way to output the type name for a type_expr diff --git a/core/conv/parse.onyx b/core/conv/parse.onyx index d0f7fe1e..ac5a5c90 100644 --- a/core/conv/parse.onyx +++ b/core/conv/parse.onyx @@ -1,6 +1,10 @@ package core.conv -use core {map, string, array, math} +#import core.map +#import core.string +#import core.array +#import core.math +#import runtime // // Parses many different types from a string into a value. diff --git a/core/encoding/base64.onyx b/core/encoding/base64.onyx index e1153c39..b455caab 100644 --- a/core/encoding/base64.onyx +++ b/core/encoding/base64.onyx @@ -1,6 +1,6 @@ package core.encoding.base64 -use core {array} +#import core.array // // A simple Base64 encoding and decoding library. Currently diff --git a/core/encoding/csv.onyx b/core/encoding/csv.onyx index 69ba266c..954a7d94 100644 --- a/core/encoding/csv.onyx +++ b/core/encoding/csv.onyx @@ -9,7 +9,15 @@ package core.encoding.csv // it ergonomic to work with. // -use core {string, array, iter, conv, io} +#import core +#import core.string +#import core.array +#import core.iter +#import core.conv +#import core.io +#import core.test +#import runtime + use core.misc {any_as} use runtime.info { get_type_info, @@ -162,8 +170,8 @@ CSV_Column :: struct { // Example and test case // -@core.test.test.{"CSV Test"} -(t: &core.test.T) { +@test.test.{"CSV Test"} +(t: &test.T) { data := """first,second,third 1,test 1,1.2 2,test 2,2.4 diff --git a/core/encoding/ini.onyx b/core/encoding/ini.onyx index 5c3fbb43..fea0ff57 100644 --- a/core/encoding/ini.onyx +++ b/core/encoding/ini.onyx @@ -32,13 +32,13 @@ package core.encoding.ini // display_name=Player // -use core { - alloc, conv, string, io, - aprintf -} -use core.intrinsics.types { - type_is_struct -} +#import core.alloc +#import core.conv +#import core.string +#import core.io + +use core { aprintf } +use core.intrinsics.types { type_is_struct } // // Represents if the parsing was successful or encountered an error. diff --git a/core/encoding/osad.onyx b/core/encoding/osad.onyx index 66edc3b5..2cadc1a4 100644 --- a/core/encoding/osad.onyx +++ b/core/encoding/osad.onyx @@ -1,7 +1,11 @@ package core.encoding.osad +#import core.io +#import core.string +#import core.array +#import core.memory +#import runtime -use core {io, string, array, memory} use runtime { type_info :: info } diff --git a/core/encoding/utf8.onyx b/core/encoding/utf8.onyx index 57fcc1f0..9313fb14 100644 --- a/core/encoding/utf8.onyx +++ b/core/encoding/utf8.onyx @@ -1,6 +1,8 @@ package core.encoding.utf8 -use core {string, array, iter} +#import core.string +#import core.array +#import core.iter rune :: i32 diff --git a/core/io/binary.onyx b/core/io/binary.onyx index 1eca2021..43396986 100644 --- a/core/io/binary.onyx +++ b/core/io/binary.onyx @@ -1,6 +1,7 @@ package core.io -use core +#import core.memory + BinaryWriter :: struct { stream: &Stream; diff --git a/core/io/reader.onyx b/core/io/reader.onyx index 5f9745f4..5c10fdd7 100644 --- a/core/io/reader.onyx +++ b/core/io/reader.onyx @@ -8,7 +8,10 @@ package core.io // reader could not, like 'read the next line', // or 'read until a period'. -use core {memory, math, array, iter} +#import core.memory +#import core.math +#import core.array +#import core.iter Reader :: struct { stream: &Stream; diff --git a/core/io/stdio.onyx b/core/io/stdio.onyx index 6a848979..8e5f602a 100644 --- a/core/io/stdio.onyx +++ b/core/io/stdio.onyx @@ -6,6 +6,8 @@ // in anyway. package core +#import runtime + // // Ensure this file did not get included in a custom runtime, as it is diff --git a/core/io/stream.onyx b/core/io/stream.onyx index a008d50e..4ec22277 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -1,5 +1,6 @@ package core.io +#import core use core Stream :: struct { diff --git a/core/io/writer.onyx b/core/io/writer.onyx index 47da1f57..8006f036 100644 --- a/core/io/writer.onyx +++ b/core/io/writer.onyx @@ -1,6 +1,8 @@ package core.io -use core {conv, string, memory} +#import core.conv +#import core.string +#import core.memory // io.Writer is a buffered-writer. The important thing to not forget // when using io.Writer is that it has to be flushed when you are done diff --git a/core/math/math.onyx b/core/math/math.onyx index 697adf12..106f7dc8 100644 --- a/core/math/math.onyx +++ b/core/math/math.onyx @@ -1,6 +1,7 @@ package core.math -use core.intrinsics {wasm} +#import core +#import 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 9f31f13d..7d9d58a6 100644 --- a/core/memory/memory.onyx +++ b/core/memory/memory.onyx @@ -69,7 +69,7 @@ align :: (size: u64, align: u64) -> u64 { // // Allows for make([] i32). #overload -builtin.__make_overload :: macro (_: &[] $T, count: u32, allocator := context.allocator) -> [] T { +__make_overload :: macro (_: &[] $T, count: u32, allocator := context.allocator) -> [] T { ret := #this_package.make_slice(T, count, allocator); #this_package.set(ret.data, 0, sizeof T * count); return ret; diff --git a/core/misc/any_utils.onyx b/core/misc/any_utils.onyx index 31d02351..88789a31 100644 --- a/core/misc/any_utils.onyx +++ b/core/misc/any_utils.onyx @@ -1,5 +1,10 @@ package core.misc +#import runtime +#import core.iter +#import core.array +#import core.string + use runtime.info { get_type_info, Type_Info_Pointer, @@ -11,8 +16,6 @@ use runtime.info { get_struct_member } -use core { iter, array, string } - // Either to_any or as_any will work. I prefer `as_any` because // much of the rest of the standard library uses `as_...` for // conversion. diff --git a/core/misc/arg_parse.onyx b/core/misc/arg_parse.onyx index 5e324881..d9092149 100644 --- a/core/misc/arg_parse.onyx +++ b/core/misc/arg_parse.onyx @@ -22,7 +22,13 @@ package core.arg_parse // false and are true if one or more of the option values are present. // -use core +#import core +#import core.iter +#import core.conv +#import core.string +#import runtime + +use core {printf} arg_parse :: (c_args: [] cstr, output: any) -> bool { arg_iter := iter.as_iter(c_args) diff --git a/core/net/net.onyx b/core/net/net.onyx index 810a7cf2..60833592 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -4,6 +4,9 @@ package core.net #error "Cannot include this file. Platform not supported."; } +#import core +#import runtime + use core Socket :: struct { diff --git a/core/net/tcp.onyx b/core/net/tcp.onyx index dbd5919a..bb0f64cb 100644 --- a/core/net/tcp.onyx +++ b/core/net/tcp.onyx @@ -4,7 +4,14 @@ package core.net #error "Cannot include this file. Platform not supported."; } -use core {sync, thread, array, memory, alloc, os, iter} +#import core.sync +#import core.thread +#import core.array +#import core.memory +#import core.alloc +#import core.os +#import core.iter +#import runtime #if !runtime.Multi_Threading_Enabled { #error "Expected multi-threading to be enabled for TCP server."; @@ -365,7 +372,7 @@ wait_to_get_client_messages :: (use server: &TCP_Server) -> [] &TCP_Server.Clien } } - status_buffer := alloc.array_from_stack(core.net.Socket_Poll_Status, client_count); + status_buffer := alloc.array_from_stack(Socket_Poll_Status, client_count); socket_poll_all(cast([] &Socket) active_clients, pulse_time_ms, status_buffer); recv_clients: [..] &TCP_Server.Client; diff --git a/core/onyx/cbindgen.onyx b/core/onyx/cbindgen.onyx index 4624d381..7a225e2f 100644 --- a/core/onyx/cbindgen.onyx +++ b/core/onyx/cbindgen.onyx @@ -41,6 +41,9 @@ package cbindgen #if #defined (runtime.Generated_Foreign_Info) { +#import core +#import runtime + #if runtime.compiler_os == .Linux { #if #defined (runtime.vars.CC) { Linux_Compiler :: runtime.vars.CC diff --git a/core/os/dir.onyx b/core/os/dir.onyx index 40887cc7..7ac13fcd 100644 --- a/core/os/dir.onyx +++ b/core/os/dir.onyx @@ -4,7 +4,9 @@ package core.os #error "Cannot include this file. Platform not supported."; } -use core {string} +#import core.string +#import runtime + #local fs :: runtime.platform Directory :: fs.DirectoryData; diff --git a/core/os/file.onyx b/core/os/file.onyx index 9a2e7b32..9cfd9eae 100644 --- a/core/os/file.onyx +++ b/core/os/file.onyx @@ -4,7 +4,11 @@ package core.os #error "Cannot include this file. Platform not supported."; } +#import core +#import runtime + use core + #local fs :: package runtime.platform diff --git a/core/os/os.onyx b/core/os/os.onyx index 03c183e1..7f07dce0 100644 --- a/core/os/os.onyx +++ b/core/os/os.onyx @@ -1,6 +1,6 @@ package core.os -use core {string} +#import runtime #if !runtime.platform.Supports_Os { #error "Cannot include this file. Platform not supported."; diff --git a/core/os/process.onyx b/core/os/process.onyx index 72face89..a4a55138 100644 --- a/core/os/process.onyx +++ b/core/os/process.onyx @@ -4,7 +4,9 @@ package core.os #error "Cannot include this file. Platform not supported."; } -use core {io} +#import core.io +#import runtime + use runtime.platform { __process_spawn, __process_destroy, diff --git a/core/runtime/common.onyx b/core/runtime/common.onyx index d16e717a..41bafc9d 100644 --- a/core/runtime/common.onyx +++ b/core/runtime/common.onyx @@ -1,5 +1,7 @@ package runtime +#import core + use core use core.intrinsics.onyx { __initialize } use platform { __output_string } diff --git a/core/runtime/info/helper.onyx b/core/runtime/info/helper.onyx index 13a97ec5..39b85bf2 100644 --- a/core/runtime/info/helper.onyx +++ b/core/runtime/info/helper.onyx @@ -1,6 +1,7 @@ package runtime.info -use core {io} +#import core +#import core.io write_type_name :: (writer: &io.Writer, t: type_expr) { info := get_type_info(t); diff --git a/core/runtime/info/proc_tags.onyx b/core/runtime/info/proc_tags.onyx index 1c29e4f9..234d7925 100644 --- a/core/runtime/info/proc_tags.onyx +++ b/core/runtime/info/proc_tags.onyx @@ -1,7 +1,7 @@ package runtime.info -use core {array} +#import core.array tagged_procedures: [] &Tagged_Procedure diff --git a/core/runtime/platform/js/platform.onyx b/core/runtime/platform/js/platform.onyx index 38b01b7f..9c4e1496 100644 --- a/core/runtime/platform/js/platform.onyx +++ b/core/runtime/platform/js/platform.onyx @@ -1,5 +1,8 @@ package runtime.platform +#import core +#import runtime + use core use runtime { __runtime_initialize, diff --git a/core/runtime/platform/onyx/fs.onyx b/core/runtime/platform/onyx/fs.onyx index 3b49f1bf..baf5b5bc 100644 --- a/core/runtime/platform/onyx/fs.onyx +++ b/core/runtime/platform/onyx/fs.onyx @@ -1,5 +1,6 @@ package runtime.platform +#import core use core FileData :: #distinct i64 diff --git a/core/runtime/platform/onyx/platform.onyx b/core/runtime/platform/onyx/platform.onyx index d54f8677..8fa49b97 100644 --- a/core/runtime/platform/onyx/platform.onyx +++ b/core/runtime/platform/onyx/platform.onyx @@ -1,5 +1,8 @@ package runtime.platform +#import core +#import runtime + use core use runtime { __runtime_initialize, diff --git a/core/runtime/platform/wasi/platform.onyx b/core/runtime/platform/wasi/platform.onyx index fc8fdabe..803f416a 100644 --- a/core/runtime/platform/wasi/platform.onyx +++ b/core/runtime/platform/wasi/platform.onyx @@ -3,6 +3,10 @@ package runtime.platform #load "./wasi_defs" #load "./wasi_fs" +#import core +#import wasi +#import runtime + use core use wasi { IOVec, SubscriptionTagged, Subscription, Event, Size, diff --git a/core/std.onyx b/core/std.onyx index d33b78ad..996d19b4 100644 --- a/core/std.onyx +++ b/core/std.onyx @@ -1,5 +1,7 @@ package core +#import runtime + #load "./alloc/alloc" #load "./memory/memory" diff --git a/core/string/buffer.onyx b/core/string/buffer.onyx index ea912820..d235ed23 100644 --- a/core/string/buffer.onyx +++ b/core/string/buffer.onyx @@ -6,7 +6,7 @@ package core.string -use core {math} +#import core.math String_Buffer :: struct { data : [&] u8; diff --git a/core/string/string.onyx b/core/string/string.onyx index ab4dc6f8..e643d840 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -1,5 +1,7 @@ package core.string +#import core + use core #doc "Generic procedure for turning something into a string." diff --git a/core/string/string_pool.onyx b/core/string/string_pool.onyx index e7fc2500..200ddb28 100644 --- a/core/string/string_pool.onyx +++ b/core/string/string_pool.onyx @@ -1,7 +1,8 @@ package core.string -use core { alloc, memory } -use core.alloc { arena } +#import core.alloc +#import core.alloc.arena +#import core.memory // // Many times, storing strings is annoying because you need diff --git a/core/sync/mutex.onyx b/core/sync/mutex.onyx index fd908997..4ac03b81 100644 --- a/core/sync/mutex.onyx +++ b/core/sync/mutex.onyx @@ -1,5 +1,8 @@ package core.sync +#import runtime +#import core + use core.intrinsics.atomics use core.thread { Thread_ID } diff --git a/core/sync/semaphore.onyx b/core/sync/semaphore.onyx index d7df97a1..66112573 100644 --- a/core/sync/semaphore.onyx +++ b/core/sync/semaphore.onyx @@ -1,5 +1,8 @@ package core.sync +#import runtime +#import core + use core.intrinsics.atomics // diff --git a/core/test/testing.onyx b/core/test/testing.onyx index 667bf69b..d47fd5b5 100644 --- a/core/test/testing.onyx +++ b/core/test/testing.onyx @@ -1,6 +1,11 @@ package core.test -use core {array, string, printf} +#import core +#import core.array +#import core.string +#import runtime + +use core {printf} #doc """ Test tag. Use this to mark a function as a test. diff --git a/core/threads/thread.onyx b/core/threads/thread.onyx index 327ac513..a709e361 100644 --- a/core/threads/thread.onyx +++ b/core/threads/thread.onyx @@ -1,5 +1,8 @@ package core.thread +#import core +#import runtime + use core use core.intrinsics.atomics diff --git a/core/time/date.onyx b/core/time/date.onyx index 9e2e99cd..3265a089 100644 --- a/core/time/date.onyx +++ b/core/time/date.onyx @@ -1,5 +1,7 @@ package core.time +#import core +#import runtime use core Date :: struct { diff --git a/core/time/time.onyx b/core/time/time.onyx index 99d066d7..ecb4a8a2 100644 --- a/core/time/time.onyx +++ b/core/time/time.onyx @@ -1,6 +1,10 @@ package core.time -use core {os, conv} +#import core +#import core.os +#import core.conv +#import runtime + use runtime.platform { __time_gmtime, __time_localtime, diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 66acda8a..cb7905fb 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -5,6 +5,9 @@ #load "core/std" +#import core +#import runtime + use core use core.intrinsics.onyx { init } diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index eb3ef596..c9193aed 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -1,5 +1,6 @@ #load "core/std" +#import core use core OverloadsEqual :: interface (t: $T) { diff --git a/tests/aoc-2021/day18.onyx b/tests/aoc-2021/day18.onyx index ca33d3ee..d0dc8612 100644 --- a/tests/aoc-2021/day18.onyx +++ b/tests/aoc-2021/day18.onyx @@ -2,6 +2,8 @@ PART :: 2 +#import core + use core use core.alloc {arena} diff --git a/tests/aoc-2021/day21.onyx b/tests/aoc-2021/day21.onyx index dd552be3..df7d2662 100644 --- a/tests/aoc-2021/day21.onyx +++ b/tests/aoc-2021/day21.onyx @@ -1,3 +1,4 @@ +#import core use core PART :: 1 diff --git a/tests/arrow_notation.onyx b/tests/arrow_notation.onyx index dcbbd11b..162e1fa3 100644 --- a/tests/arrow_notation.onyx +++ b/tests/arrow_notation.onyx @@ -1,6 +1,9 @@ #load "core/std" -use core +#import core +#import core.conv + +use core {println} #tag conv.Custom_Format.{format} V2 :: struct { diff --git a/tests/bugs/autopoly_limits.onyx b/tests/bugs/autopoly_limits.onyx index 945f37ac..2946b312 100644 --- a/tests/bugs/autopoly_limits.onyx +++ b/tests/bugs/autopoly_limits.onyx @@ -1,3 +1,4 @@ +#import core use core f :: ctx => { diff --git a/tests/bugs/double_polymorph_yield_error.onyx b/tests/bugs/double_polymorph_yield_error.onyx index 790f5779..98b8b531 100644 --- a/tests/bugs/double_polymorph_yield_error.onyx +++ b/tests/bugs/double_polymorph_yield_error.onyx @@ -1,5 +1,4 @@ -#load "core/std" - +#import core use core q :: (v: &$C, g: (&C) -> $T) { diff --git a/tests/bugs/method_call_source_double.onyx b/tests/bugs/method_call_source_double.onyx index 884f559c..00cac5c9 100644 --- a/tests/bugs/method_call_source_double.onyx +++ b/tests/bugs/method_call_source_double.onyx @@ -1,5 +1,4 @@ -#load "core/std" - +#import core use core Foo :: struct { diff --git a/tests/bugs/print_formatters.onyx b/tests/bugs/print_formatters.onyx index ccd5ecf6..b30370ae 100644 --- a/tests/bugs/print_formatters.onyx +++ b/tests/bugs/print_formatters.onyx @@ -1,4 +1,5 @@ -use core +#import core +use core {printf} main :: () { printf("{\n"); diff --git a/tests/char_literals.onyx b/tests/char_literals.onyx index af73600b..b6eaee29 100644 --- a/tests/char_literals.onyx +++ b/tests/char_literals.onyx @@ -1,3 +1,4 @@ +#import core use core diff --git a/tests/dyn_str.onyx b/tests/dyn_str.onyx index 5a0d2593..668a829f 100644 --- a/tests/dyn_str.onyx +++ b/tests/dyn_str.onyx @@ -1,4 +1,10 @@ -use core +#import core.string +#import core.conv +#import core + +use core { + println +} main :: () { diff --git a/tests/first_class_optional.onyx b/tests/first_class_optional.onyx index 1fc21d4d..f86c33c9 100644 --- a/tests/first_class_optional.onyx +++ b/tests/first_class_optional.onyx @@ -1,4 +1,5 @@ -use core +#import core +use core {println} foo :: (x: ?i32) -> i32 { return x? + 10; diff --git a/tests/linked_lists.onyx b/tests/linked_lists.onyx index 89435a5e..7d075552 100644 --- a/tests/linked_lists.onyx +++ b/tests/linked_lists.onyx @@ -1,4 +1,7 @@ -use core +#import core +#import core.list + +use core {println} main :: () { l := list.make(i32); diff --git a/tests/no_types.onyx b/tests/no_types.onyx index 6a134037..767cc0b2 100644 --- a/tests/no_types.onyx +++ b/tests/no_types.onyx @@ -4,6 +4,7 @@ #load "core/std" +#import core use core main :: () { diff --git a/tests/osad_test.onyx b/tests/osad_test.onyx index 6bf1882f..ff1072eb 100644 --- a/tests/osad_test.onyx +++ b/tests/osad_test.onyx @@ -1,5 +1,7 @@ -use core -use core.encoding {osad} +#import core +#import core.encoding.osad + +use core {printf} Foo :: struct { nums: [] i32; diff --git a/tests/overload_return_type.onyx b/tests/overload_return_type.onyx index 0726802e..868462c1 100644 --- a/tests/overload_return_type.onyx +++ b/tests/overload_return_type.onyx @@ -1,5 +1,6 @@ -use core +#import core +use core { println } main :: () { overloaded_proc(i32.{}) |> println(); diff --git a/tests/stdlib/base64.onyx b/tests/stdlib/base64.onyx index db7645cb..faf2330a 100644 --- a/tests/stdlib/base64.onyx +++ b/tests/stdlib/base64.onyx @@ -1,4 +1,5 @@ -use core.encoding +#import core +#import core.encoding.base64 decode_test :: () { for .[ diff --git a/tests/utf8_test.onyx b/tests/utf8_test.onyx index d6d2c51d..aa80aa04 100644 --- a/tests/utf8_test.onyx +++ b/tests/utf8_test.onyx @@ -1,5 +1,8 @@ -use core -use core.encoding {utf8} +#import core +#import core.encoding.utf8 +#import runtime + +use core {print, println, printf} #inject runtime.vars.Enable_Heap_Debug :: true