breaking change: top-level packages are required to be `#import`ed
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 24 Mar 2023 19:46:08 +0000 (14:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 24 Mar 2023 19:46:08 +0000 (14:46 -0500)
85 files changed:
compiler/include/astnodes.h
compiler/src/astnodes.c
compiler/src/entities.c
compiler/src/lex.c
compiler/src/parser.c
compiler/src/symres.c
compiler/src/utils.c
core/alloc/arena.onyx
core/alloc/atomic.onyx
core/alloc/fixed.onyx
core/alloc/gc.onyx
core/alloc/heap.onyx
core/alloc/logging.onyx
core/alloc/pool.onyx
core/alloc/ring.onyx
core/builtin.onyx
core/container/array.onyx
core/container/avl_tree.onyx
core/container/bucket_array.onyx
core/container/heap.onyx
core/container/iter.onyx
core/container/list.onyx
core/container/map.onyx
core/container/pair.onyx
core/container/result.onyx
core/container/set.onyx
core/conv/conv.onyx
core/conv/format.onyx
core/conv/parse.onyx
core/encoding/base64.onyx
core/encoding/csv.onyx
core/encoding/ini.onyx
core/encoding/osad.onyx
core/encoding/utf8.onyx
core/io/binary.onyx
core/io/reader.onyx
core/io/stdio.onyx
core/io/stream.onyx
core/io/writer.onyx
core/math/math.onyx
core/memory/memory.onyx
core/misc/any_utils.onyx
core/misc/arg_parse.onyx
core/net/net.onyx
core/net/tcp.onyx
core/onyx/cbindgen.onyx
core/os/dir.onyx
core/os/file.onyx
core/os/os.onyx
core/os/process.onyx
core/runtime/common.onyx
core/runtime/info/helper.onyx
core/runtime/info/proc_tags.onyx
core/runtime/platform/js/platform.onyx
core/runtime/platform/onyx/fs.onyx
core/runtime/platform/onyx/platform.onyx
core/runtime/platform/wasi/platform.onyx
core/std.onyx
core/string/buffer.onyx
core/string/string.onyx
core/string/string_pool.onyx
core/sync/mutex.onyx
core/sync/semaphore.onyx
core/test/testing.onyx
core/threads/thread.onyx
core/time/date.onyx
core/time/time.onyx
scripts/run_tests.onyx
tests/aoc-2020/day17.onyx
tests/aoc-2021/day18.onyx
tests/aoc-2021/day21.onyx
tests/arrow_notation.onyx
tests/bugs/autopoly_limits.onyx
tests/bugs/double_polymorph_yield_error.onyx
tests/bugs/method_call_source_double.onyx
tests/bugs/print_formatters.onyx
tests/char_literals.onyx
tests/dyn_str.onyx
tests/first_class_optional.onyx
tests/linked_lists.onyx
tests/no_types.onyx
tests/osad_test.onyx
tests/overload_return_type.onyx
tests/stdlib/base64.onyx
tests/utf8_test.onyx

index bb0422f2e9098b7d269551f49b63683dbacfce53..5e5aef919ef8724bfc6034077585fd659d3128c3 100644 (file)
     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;
index 98c520bcb906fb2f3a50db91242bcc952117ce60..84a928363b199253c64b76031b78e4a5e6434e7f 100644 (file)
@@ -9,6 +9,7 @@ static const char* ast_node_names[] = {
     "INCLUDE FOLDER",
     "INCLUDE ALL IN FOLDER",
     "INCLUDE LIBRARY PATH",
+    "IMPORT",
     "MEMORY RESERVATION",
 
     "BINDING",
index 8c4fa81362307c43d11fc9714f6f640cfeb0d8e1..a21ce2d6178794dc1d6ef628262703302c451fb3 100644 (file)
@@ -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;
index 7bf9aa1fec322f129057816ee83e5745f2b54a8b..4458c485822904fb348f52db0b27958a3118a673 100644 (file)
@@ -38,6 +38,7 @@ static const char* token_type_names[] = {
     "macro",
     "interface",
     "where",
+    "import",
     "", // end
 
     "->",
index aa18ca87181829647b3809ad3797083347f382af..2cf8a1a091359940e75a083dd10e80cd72dd107e 100644 (file)
@@ -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);
index fb889375ead465d33f8dab5f283c4ef0d937d0c1..e75a09bbb97e618207d6c7fe55402c4134fa48cc 100644 (file)
@@ -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;
index 2e235de9d501fb9a8d7fbca39a5df52c76d1768e..53804635e4bf140393161bf4c360c1401e1bc3f6 100644 (file)
@@ -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;
index 0f5c74f1e958c2799bb232300a1aa5a272bfbcf8..311237e79728e454341ebef9c59eae2ba6d97b96 100644 (file)
@@ -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
index 71fa0f815e7445118b4dc9dc0eb43d73d1010967..d91fd8ec6329998ba188477effd6238da257e9ff 100644 (file)
@@ -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;
index 85b8b5e117ffda42283666408280649e2602531e..b87c6bb914f1cbae0c72af879981665aff84cfd3 100644 (file)
@@ -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.
 //
index 3dc3e11d1f371e761f911b26ce566951f4ef17d3..103128daa9106a45e49d863f6f8e933221f48d4e 100644 (file)
@@ -16,6 +16,8 @@ package core.alloc.gc
 //       // Every allocation here will automatically be freed
 //   }
 
+#import core
+
 GCState :: struct {
     backing_allocator: Allocator;
     first: &GCLink;
index f5102f5f3f602950b6fb84f87202e8e9d1b797b0..e80a8b875ecfb6d922baf2c6b4f3a5d4b265a05f 100644 (file)
@@ -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
index e5e8788d763560e8613534c55a08822316836555..647a7ba268701199e0b3f6f806029d946da3e058 100644 (file)
@@ -4,6 +4,8 @@ package core.alloc.log
 // prints every allocation/deallocation made by that 
 // allocator.
 
+#import core
+
 #local
 Allocation_Action_Strings := str.[
     " alloc",
index 8e89811354b06539bdbc88dcc09e7af007d91f5c..30fb47be831242bfae122532d6c2d95e0913039a 100644 (file)
@@ -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
index 493a4572602cd25bf142c0cc91ca34b521bf1e59..f5888791311da968c2d171db1910c3aa6b23c4f0 100644 (file)
@@ -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.
index f0ab09446c6f8ee915c164b5dcbe6e893662a401..fd6a49047db8800423871f5b3d22a17f5c63c4aa 100644 (file)
@@ -1,5 +1,11 @@
 package builtin
 
+#import runtime
+
+#if #defined(package core) {
+    #import core
+}
+
 //
 // Explanation of `package builtin`
 //
index 340eeae82d209b3eb630f5994ff4d418ef6a7816..0c8bd020a995708dc9af4d5841d99edf687b03a3 100644 (file)
@@ -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 {}
 
index 5668fd88503b73bd5c2e8635538b3f40b54bfd90..50d42e518ec7a5cb5799aed3d0aa005d5222cced 100644 (file)
@@ -1,6 +1,7 @@
 package core.avl_tree
 
-use core {math}
+#import core
+#import core.math
 
 AVL_Tree :: struct (T: type_expr) {
     data: T;
index 098f0fcc31c9d7974b99259027e97083fa831b0e..b02cd2dc5b8bf1112321883cd60e67e27e66bd3a 100644 (file)
@@ -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];
index 53c5bedbaf2c39475d5378bef98819bee85072d6..eb29ff6a549325ba3c8739a0259b273f48606f69 100644 (file)
@@ -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];
index bc08cf930e455122004939600cd84c65a2b20b47..f448850b85640f4c2f1d4e86afc0e124b3a5bbc0 100644 (file)
@@ -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}
 
 
index c89d695ce7ed3fd7c6f917697f6545bc27e34cf0..6fe72cf80af3cfe17d9e4a15c6f560cf23469309 100644 (file)
@@ -1,5 +1,7 @@
 package core.list
 
+#import core
+
 ListElem :: struct (T: type_expr) {
     next: &ListElem(T) = null;
     prev: &ListElem(T) = null;
index 5722b304cac9e1fde22c642b8b6a9acfc9389dee..926ea4aeed85dacf3f64edc887e4a7bd568f7521 100644 (file)
@@ -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 }
 
 //
index d91bc18a06eb6335c9b5555c093cbcfc9ae95dfd..13f56c96d17f6d3645a5410e357b0bef76dea5f9 100644 (file)
@@ -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);
index 23fc812ab87d854f22e1be05e69e1e7fa6b6983b..ea9ac23e9b5b01bc649ef3a6c611cb736c8cae46 100644 (file)
@@ -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
index 6c7352e5000893e23a99d2dac2b3c5ef95dcc165..66584816dcac815d46d6e4a4efc2addc85317429 100644 (file)
@@ -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);
index e3975f64bba3582002fa500dd9f3685f9330928e..8296a6fdfd562341f469bf9fc2c614f544270d2f 100644 (file)
@@ -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);
index 59a4c196c71d4888aa5743a425a61fc7531b0e17..90b702342f0820b3ef3706317844d071e88f0bd6 100644 (file)
@@ -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
index d0f7fe1e3fa779271f855c136d04bac5cd19b1f1..ac5a5c9021a466a29da8761dcff514dfc6325d16 100644 (file)
@@ -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.
index e1153c39d35b1a8be6c2041e57dbff7ea506c1c7..b455caab718bc4d7451e687b1dc148f9e8a84e39 100644 (file)
@@ -1,6 +1,6 @@
 package core.encoding.base64
 
-use core {array}
+#import core.array
 
 //
 // A simple Base64 encoding and decoding library. Currently
index 69ba266c3e43cdfe3fe8d387702f7e4baa234dc0..954a7d9491b3ba8413731c8a21bd0b2785bf715a 100644 (file)
@@ -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
index 5c3fbb43d0178e06253f935c70ef24a39ac18834..fea0ff572ba8be55a5a76ebe84f000b6e78364eb 100644 (file)
@@ -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.
index 66edc3b52e382e3fd0b5a6c0cf43203897636493..2cadc1a42d96d82c0fb65a1559ba033458201ed9 100644 (file)
@@ -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
 }
index 57fcc1f0bfb444bc1e2ab1d587cd00a2b8e862c8..9313fb148cb76162270dd3c240d0bf2d3262d97a 100644 (file)
@@ -1,6 +1,8 @@
 package core.encoding.utf8
 
-use core {string, array, iter}
+#import core.string
+#import core.array
+#import core.iter
 
 rune :: i32
 
index 1eca2021e2ce1bc23c215109fcec9c0558ae1217..433969869b1705e8cc6dae8f91500d0e8bb0455d 100644 (file)
@@ -1,6 +1,7 @@
 package core.io
 
-use core
+#import core.memory
+
 
 BinaryWriter :: struct {
     stream: &Stream;
index 5f9745f4e23150b5252355a2558b5b466dbaa07a..5c10fdd706492995e761b1f6a37d3c4330e05a0d 100644 (file)
@@ -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;
index 6a848979f2d4fbea60f512cf50b4be188ed6ab42..8e5f602ac93cc7bb0a1c787bba995c6c45706c41 100644 (file)
@@ -6,6 +6,8 @@
 // in anyway.
 package core
 
+#import runtime
+
 
 //
 // Ensure this file did not get included in a custom runtime, as it is
index a008d50e6ce3d9d630830856788177e8a58e49e2..4ec2227713fadd15e8f47a0b5976e7a8b99d479f 100644 (file)
@@ -1,5 +1,6 @@
 package core.io
 
+#import core
 use core
 
 Stream :: struct {
index 47da1f57f8b87d27ab66943025c3cc400e4906e0..8006f036d6778610052a121b4aa2aae618a6141c 100644 (file)
@@ -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
index 697adf122054fde59a9b4399c35cb18fdaffd4f3..106f7dc86d45fb4774936ede00e12c9058f24b7c 100644 (file)
@@ -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
index 9f31f13d907e91d0fba70ef5a8113469fccaf60c..7d9d58a67b76db51cde810edfabdadd2c20e6c21 100644 (file)
@@ -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;
index 31d0235182563d000bb716207d74bbd0994c78cb..88789a31813e4f89ce91198c533adf98876f8632 100644 (file)
@@ -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.
index 5e3248810d7f1d9e53e41ecb6ba29143f952cc43..d9092149427cab1b65b60d05d037b69a66791a08 100644 (file)
@@ -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)
index 810a7cf275247008893ad796dd12dd320e97a3d2..608335928196c893884b0682b9eec2e746f608e0 100644 (file)
@@ -4,6 +4,9 @@ package core.net
     #error "Cannot include this file. Platform not supported.";
 }
 
+#import core
+#import runtime
+
 use core
 
 Socket :: struct {
index dbd5919ab9b841be6cbff8147cb5784a7a082d79..bb0f64cb4179b04527c2a6b61cd319b950597606 100644 (file)
@@ -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;
index 4624d3815286bad31bbe36515dd18d6127b45abb..7a225e2f4caf38a5845d8fd03e9f15e2aaf25410 100644 (file)
@@ -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    
index 40887cc799ee9515cf1086a17bbcfb880850e7e1..7ac13fcd169874f5bcfc786cf9f23bcc2089cd34 100644 (file)
@@ -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;
index 9a2e7b32fc7145385b96d7e67e00024bce1cb48a..9cfd9eaec4ba575b414cda24f52218235db02017 100644 (file)
@@ -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
 
 
index 03c183e1894c7c7edb2ca525237d717f357a7f4d..7f07dce05153d5dfd0e424769e30f536957cd949 100644 (file)
@@ -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.";
index 72face8982ba650bb00a756c0338d52b1d293729..a4a551384f19d76ffe5b0d9de866d33d0e6f1742 100644 (file)
@@ -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,
index d16e717aee5f5d4de42f55da372a74b630a60aff..41bafc9d891070dea7cbd7422096246fcf814cdc 100644 (file)
@@ -1,5 +1,7 @@
 package runtime
 
+#import core
+
 use core
 use core.intrinsics.onyx { __initialize }
 use platform { __output_string }
index 13a97ec500a60b2940769b1da98477a03a5ebd4a..39b85bf29bd61114191737f74f2f23a6288b99e0 100644 (file)
@@ -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);
index 1c29e4f919bd38e049912a7f46047f4fec207f11..234d792517d5a4bc97c60f70cf47188ae1c9776c 100644 (file)
@@ -1,7 +1,7 @@
 
 package runtime.info
 
-use core {array}
+#import core.array
 
 tagged_procedures: [] &Tagged_Procedure
 
index 38b01b7f0fe04b5906e1d1a619f08a9a8e3f86b6..9c4e14961db9114aacafee881ab3ea0e67f0e1f9 100644 (file)
@@ -1,5 +1,8 @@
 package runtime.platform
 
+#import core
+#import runtime
+
 use core
 use runtime {
     __runtime_initialize,
index 3b49f1bfa6ed8238bccd5c8ca7519b2cc3f2f217..baf5b5bc0ab513c124513fa9a1dc5add58410fef 100644 (file)
@@ -1,5 +1,6 @@
 package runtime.platform
 
+#import core
 use core
 
 FileData :: #distinct i64
index d54f8677ea7dff4ba2dbfb8ef4698e5531aa0925..8fa49b97ce187b59f2348515dcc758420348a75b 100644 (file)
@@ -1,5 +1,8 @@
 package runtime.platform
 
+#import core
+#import runtime
+
 use core
 use runtime {
     __runtime_initialize,
index fc8fdabe888afd9bbc0596e16ab120e1ff37c0bb..803f416a2f6a723887972694153215920b5ca0ce 100644 (file)
@@ -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,
index d33b78ad66f57182d6973cfff641c9c8b4d0811f..996d19b4f2e932f58764f54ec43823768a6a6f67 100644 (file)
@@ -1,5 +1,7 @@
 package core
 
+#import runtime
+
 
 #load "./alloc/alloc"
 #load "./memory/memory"
index ea9128208b73504f7d6d06728353e4c8e68d9918..d235ed23335b9fd8bcc78b80adb974126fdd5106 100644 (file)
@@ -6,7 +6,7 @@
 
 package core.string
 
-use core {math}
+#import core.math
 
 String_Buffer :: struct {
     data     : [&] u8;
index ab4dc6f8d1e2687002223ac700a9e819108f15ee..e643d84078ec7ef9f5207d66bb57ae88e6a6463c 100644 (file)
@@ -1,5 +1,7 @@
 package core.string
 
+#import core
+
 use core
 
 #doc "Generic procedure for turning something into a string."
index e7fc2500bd5cabf568be9d2f923e0425eaaa0aaf..200ddb289f2bc00d2fb4bee3eeebd96c829ea5f5 100644 (file)
@@ -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
index fd9089979708a5efcaee42408dcb9bd4882ab7e8..4ac03b810659081d971a46bcbaea9cf8a5ddcf0d 100644 (file)
@@ -1,5 +1,8 @@
 package core.sync
 
+#import runtime
+#import core
+
 use core.intrinsics.atomics
 use core.thread { Thread_ID }
 
index d7df97a18dd96939ac91c20cbec515116ceec025..66112573152adb87b40d0b325edeedda9c8728a6 100644 (file)
@@ -1,5 +1,8 @@
 package core.sync
 
+#import runtime
+#import core
+
 use core.intrinsics.atomics
 
 //
index 667bf69ba6005d13e576407773e11147f84eb29c..d47fd5b5426efef7698ae4df53989cc6e92af3ef 100644 (file)
@@ -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.
index 327ac513d63c952d9347cbc17c9a0509b7f95abc..a709e361f3574eac6932012ed05f1df4b89f40ca 100644 (file)
@@ -1,5 +1,8 @@
 package core.thread
 
+#import core
+#import runtime
+
 use core
 use core.intrinsics.atomics
 
index 9e2e99cdd9c441fdafd6b98f13b293b8c78b1c68..3265a08981c3d3db30ec1fab44cef9b965a5112c 100644 (file)
@@ -1,5 +1,7 @@
 package core.time
 
+#import core
+#import runtime
 use core
 
 Date :: struct {
index 99d066d7260badc04baefe4139f0914df912f97b..ecb4a8a2ea0d6bf7257515e0fe551f6deaa9e6fd 100644 (file)
@@ -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,
index 66acda8ab6bfc7303485f1f63ab2a81fc856c647..cb7905fbe6dafcf344578adae6b6bb3d1c5cbb2d 100644 (file)
@@ -5,6 +5,9 @@
 
 #load "core/std"
 
+#import core
+#import runtime
+
 use core
 use core.intrinsics.onyx { init }
 
index eb3ef5968ea2f18554c7bb6b481fc827c485d2f7..c9193aed7c4ff43856f0bf29b782dc19efbf21c1 100644 (file)
@@ -1,5 +1,6 @@
 #load "core/std"
 
+#import core
 use core
 
 OverloadsEqual :: interface (t: $T) {
index ca33d3ee27f76d8a9b81f9b59847c2554759f48c..d0dc8612adb6a556d312b29738da96e73a41eb83 100644 (file)
@@ -2,6 +2,8 @@
 
 PART :: 2
 
+#import core
+
 use core
 use core.alloc {arena}
 
index dd552be3e2ae2cf0a86aff633f6e43aefd868679..df7d266269b4e0dedce33619e15a9fa7716d352c 100644 (file)
@@ -1,3 +1,4 @@
+#import core
 use core
 
 PART :: 1
index dcbbd11b5a3df063a4f049f25f597b1f87d76715..162e1fa3918419a1c55dee581d37b74988a52ff4 100644 (file)
@@ -1,6 +1,9 @@
 #load "core/std"
 
-use core
+#import core
+#import core.conv
+
+use core {println}
 
 #tag conv.Custom_Format.{format}
 V2 :: struct {
index 945f37ac8a92c7c15e5f312d7d605448c683b4fb..2946b312957a975d5e2839fc9bd5c99d989e8a9b 100644 (file)
@@ -1,3 +1,4 @@
+#import core
 use core
 
 f :: ctx => {
index 790f5779b9748259cc3e4fc180c0afea5eefbe95..98b8b5316324e1f1210a88dec467cfbeae9c938e 100644 (file)
@@ -1,5 +1,4 @@
-#load "core/std"
-
+#import core
 use core
 
 q :: (v: &$C, g: (&C) -> $T) {
index 884f559c93dde615cedd6befccf4bb1316ea3cda..00cac5c911eb33ee7bddf69174cbb093879f5ba9 100644 (file)
@@ -1,5 +1,4 @@
-#load "core/std"
-
+#import core
 use core
 
 Foo :: struct {
index ccd5ecf61b3c4bb1b30ee0fabd0b67e71f98bed7..b30370aecae7a3553fa689e38a4d715368f15c94 100644 (file)
@@ -1,4 +1,5 @@
-use core
+#import core
+use core {printf}
 
 main :: () {
     printf("{\n");
index af73600b94819c0a2587b2f8bc9b341677049904..b6eaee29e1d45a857820ecafa246ba9459c03c70 100644 (file)
@@ -1,3 +1,4 @@
+#import core
 use core
 
 
index 5a0d2593af47ab30821dbb3a0a6f672e73f7c929..668a829f9cd798e01d55360c1e785e8ea1692228 100644 (file)
@@ -1,4 +1,10 @@
-use core
+#import core.string
+#import core.conv
+#import core
+
+use core {
+    println
+}
 
 
 main :: () {
index 1fc21d4d5dc32ac83cd731f547adfba7a11c8593..f86c33c94d985c57dc50c1ccecc9ad19e9489675 100644 (file)
@@ -1,4 +1,5 @@
-use core
+#import core
+use core {println}
 
 foo :: (x: ?i32) -> i32 {
     return x? + 10;
index 89435a5e5f4be835997c8ca9324420468b4e69ea..7d07555254bc108e64ff4b5f6f24d3989a872566 100644 (file)
@@ -1,4 +1,7 @@
-use core
+#import core
+#import core.list
+
+use core {println}
 
 main :: () {
     l := list.make(i32);
index 6a1340371a8babfb66d0162e15aa505282098ad8..767cc0b23b4b5f2e6462811bd6dd1845cdfd965b 100644 (file)
@@ -4,6 +4,7 @@
 
 #load "core/std"
 
+#import core
 use core
 
 main :: () {
index 6bf1882f48181f308112299c928c5dd024ef74df..ff1072ebf7cbcc71d83c3a69b6dd9efa0068cfa0 100644 (file)
@@ -1,5 +1,7 @@
-use core
-use core.encoding {osad}
+#import core
+#import core.encoding.osad
+
+use core {printf}
 
 Foo :: struct {
     nums: [] i32;
index 0726802e4d152e56aa25e4e67abfe445e7bdc5ff..868462c1bb07b18cd52191c863cfb2cbda6b1e12 100644 (file)
@@ -1,5 +1,6 @@
 
-use core
+#import core
+use core { println }
 
 main :: () {
     overloaded_proc(i32.{}) |> println();
index db7645cb1dab77dcba4aee44a63d77f70cad90ca..faf2330a8787c75ba04aeae14bf3b7bf8d1d85f5 100644 (file)
@@ -1,4 +1,5 @@
-use core.encoding
+#import core
+#import core.encoding.base64
 
 decode_test :: () {
     for .[
index d6d2c51d3163c928b51645105e568cc985f67a25..aa80aa04317e192afcffaa2cb04bee09ec710be8 100644 (file)
@@ -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