cleaned up core packages with newer onyx features
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 2 Oct 2022 03:59:54 +0000 (22:59 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 2 Oct 2022 03:59:54 +0000 (22:59 -0500)
39 files changed:
compiler/src/wasm_emit.c
core/alloc/arena.onyx
core/alloc/auto_heap.onyx
core/alloc/fixed.onyx
core/alloc/heap.onyx
core/alloc/logging.onyx
core/alloc/pool.onyx
core/alloc/ring.onyx
core/arg_parse.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/set.onyx
core/conv.onyx
core/io/binary.onyx
core/io/reader.onyx
core/io/stream.onyx
core/io/writer.onyx
core/math.onyx
core/net/tcp.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/js.onyx
core/runtime/onyx_run.onyx
core/runtime/wasi.onyx
core/string.onyx
core/string/buffer.onyx
core/sync/mutex.onyx
core/sync/semaphore.onyx
core/threads/thread.onyx

index db4673628455110d149f00a2c163444d7a5c5ecb..6a9b9d8c7df57b58b193cddd527c52bdffbcce84 100644 (file)
@@ -260,6 +260,9 @@ static u32 debug_introduce_symbol(OnyxWasmModule *mod, OnyxToken *token, DebugSy
 static u32 debug_get_file_id(OnyxWasmModule *mod, const char *name) {
     assert(mod && mod->debug_context);
 
+    // This is not correct at all, but it will not cause an error.
+    if (!name) return 0;
+
     i32 index = shgeti(mod->debug_context->file_info, name);
     if (index == -1) {
         u32 id = mod->debug_context->next_file_id++;
index e92c430e7ae56b1cb537c2dfee7de11e9d7f33a4..673145109b1dc329bff635173f5b582e69bcb519 100644 (file)
@@ -66,8 +66,7 @@ arena_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32,
 
         // This is incorrect, but because there is not an "old size",
         // this is the best possible.
-        memory :: package core.memory
-        memory.copy(newptr, oldptr, size);
+        core.memory.copy(newptr, oldptr, size);
 
         return newptr;
     }
@@ -92,7 +91,7 @@ make :: (backing: Allocator, arena_size: u32) -> ArenaState {
     };
 }
 
-#match (package core.alloc).as_allocator make_allocator
+#match core.alloc.as_allocator make_allocator
 make_allocator :: (rs: ^ArenaState) -> Allocator {
     return Allocator.{
         func = arena_alloc_proc,
@@ -143,13 +142,13 @@ get_allocated_bytes :: (arena: ^ArenaState) -> u32 {
 
 auto :: #match {
     macro (size := 32 * 1024, $dest: Code = #(context.allocator)) {
-        alloc :: package core.alloc
+        use core.alloc {arena, heap_allocator}
 
-        arena := alloc.arena.make(alloc.heap_allocator, size);
+        arena := arena.make(heap_allocator, size);
         old_allocator := #unquote dest;
-        (#unquote dest) = alloc.arena.make_allocator(^arena);
+        (#unquote dest) = arena.make_allocator(^arena);
         defer {
-            alloc.arena.free(^arena);
+            arena.free(^arena);
             (#unquote dest) = old_allocator;
         }
     },
index af634d7ebcf9766087f5068f67bd56f2e39e5b96..ea9ea5a4b992646dc8c3b1313c05fc2996613ea1 100644 (file)
@@ -51,7 +51,7 @@ auto_heap_free :: (hs: ^AutoHeapState) {
     hs.set->free();
 }
 
-#match (package core.alloc).as_allocator auto_heap_make_allocator
+#match core.alloc.as_allocator auto_heap_make_allocator
 auto_heap_make_allocator :: (hs: ^AutoHeapState) -> Allocator {
     return Allocator.{
         func = auto_heap_alloc_proc,
@@ -61,13 +61,13 @@ auto_heap_make_allocator :: (hs: ^AutoHeapState) -> Allocator {
 
 auto :: #match {
     macro () {
-        alloc :: package core.alloc
+        use core.alloc {heap}
         
-        auto_heap := alloc.heap.auto_heap_make();
+        auto_heap := heap.auto_heap_make();
         old_allocator := context.allocator;
-        context.allocator = alloc.heap.auto_heap_make_allocator(^auto_heap);
+        context.allocator = heap.auto_heap_make_allocator(^auto_heap);
         defer {
-            alloc.heap.auto_heap_free(^auto_heap);
+            heap.auto_heap_free(^auto_heap);
             context.allocator = old_allocator;
         }
     },
index 7c65d131b9795644b269f8b0f698867c97fc8990..b5161fe8bdb59959de996567d9b91d0d4ac0a01b 100644 (file)
@@ -32,7 +32,7 @@ make :: (ptr: rawptr, size: u32) -> FixedAllocatorData {
     };
 }
 
-#match (package core.alloc).as_allocator make_allocator
+#match core.alloc.as_allocator make_allocator
 make_allocator :: (fa_data: ^FixedAllocatorData) -> Allocator {
     return Allocator.{
         func = fixed_allocator_proc,
index fa75c232b5a62a8a6dbb603285bcf051f68a40fd..555a63bac6a5fdb4b64f8a16a9f2a6e6d047594f 100644 (file)
@@ -3,7 +3,7 @@ package core.alloc.heap
 // Enable this to enable checking for invalid blocks and other corruptions
 // that may happen on the heap, with the added overhead of checking that
 // on every alloc/resize/free.
-Enable_Debug :: #defined( (package runtime.vars).Enable_Heap_Debug )
+Enable_Debug :: #defined( runtime.vars.Enable_Heap_Debug )
 
 // 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
@@ -14,7 +14,7 @@ Enable_Debug :: #defined( (package runtime.vars).Enable_Heap_Debug )
 #load "core/intrinsics/wasm"
 
 #if runtime.Multi_Threading_Enabled {
-    sync :: package core.sync
+    use core {sync}
 
     heap_mutex: sync.Mutex
 }
@@ -24,7 +24,7 @@ init :: () {
     heap_state.next_alloc = cast(rawptr) (cast(uintptr) __heap_start + 8);
     heap_state.remaining_space = (memory_size() << 16) - cast(u32) __heap_start;
 
-    use package core.alloc { heap_allocator }
+    use core.alloc { heap_allocator }
     heap_allocator.data = ^heap_state;
     heap_allocator.func = heap_alloc_proc;
 
@@ -45,14 +45,12 @@ get_freed_size :: () => {
 }
 
 #local {
-    use package core.intrinsics.wasm {
+    use core.intrinsics.wasm {
         memory_size, memory_grow,
         memory_copy, memory_fill,
     }
 
-    memory  :: package core.memory
-    math    :: package core.math
-    runtime :: package runtime
+    use core {memory, math}
 
     uintptr :: #type u32
 
index 4ff900f99f123d7e9520184c8190ee59c9a2eb2a..44295bc4cf333067a38feb102ab0ba01a6eb1c4c 100644 (file)
@@ -13,7 +13,7 @@ logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align:
     allocator := cast(^Allocator) data;
     res := allocator.func(allocator.data, aa, size, align, oldptr);
 
-    use package core { printf }
+    use core { printf }
     printf("{} with size {}, align {}, oldptr {} returns {}\n",
         Allocation_Action_Strings[cast(u32) aa], size, align, oldptr, res);
 
index 8184902e15c47318b1a866e13b7ff61ce70cc8b6..ef54b8f11f92889cf4ddedaf257c5df15eaa4f98 100644 (file)
@@ -78,7 +78,7 @@ make :: (buffer: [] $Elem) -> PoolAllocator(Elem) {
     };
 }
 
-#match (package core.alloc).as_allocator make_allocator
+#match core.alloc.as_allocator make_allocator
 make_allocator :: (pool: ^PoolAllocator($Elem)) -> Allocator {
     return Allocator.{
         func = #solidify pool_allocator_proc { Elem = Elem },
index 0de43d3c5269bf885546251528dd7a8dea700879..2d12599d05da2e526131f23fbc5858cb58fe8e96 100644 (file)
@@ -45,7 +45,7 @@ make :: (buffer: [] u8) -> RingState {
     };
 }
 
-#match (package core.alloc).as_allocator make_allocator
+#match core.alloc.as_allocator make_allocator
 make_allocator :: (rs: ^RingState) -> Allocator {
     return .{
         func = ring_alloc_proc,
index 01255cd633ace539e6eb4881e65dc732a739425e..cde4b24e37f322b79041c75300683b782bec1257 100644 (file)
@@ -1,13 +1,13 @@
 package core.arg_parse
 
-use package core
+use core
 
 arg_parse :: (c_args: [] cstr, output: any) -> bool {
     arg_iter := iter.as_iterator(c_args)
              |> iter.map((x) => string.from_cstr(*x));
     defer arg_iter.close(arg_iter.data);
 
-    use package runtime.info;
+    use runtime.info;
 
     ptr_type := cast(^Type_Info_Pointer) get_type_info(output.type);
     if ptr_type.kind != .Pointer do return false;
index 5a3717b18967e680eef45f96518d66aa812d05b1..41e92972df3468b5a12f21fea076f3fa8fc44dbb 100644 (file)
@@ -31,12 +31,12 @@ make :: (base: [] $T, allocator := context.allocator) -> [..] T {
 
 #overload
 __make_overload :: macro (_: ^[..] $T, allocator := context.allocator) -> [..] T {
-    return (package core.array).make(T, allocator=allocator);
+    return core.array.make(T, allocator=allocator);
 }
 
 #overload
 __make_overload :: macro (_: ^[..] $T, capacity: u32, allocator := context.allocator) -> [..] T {
-    return (package core.array).make(T, capacity, allocator);
+    return core.array.make(T, capacity, allocator);
 }
 
 init :: (arr: ^[..] $T, capacity := 4, allocator := context.allocator) {
@@ -114,7 +114,7 @@ push :: (arr: ^[..] $T, x: T) -> bool {
 }
 
 // Semi-useful shortcut for adding something to an array.
-#operator << macro (arr: [..] $T, v: T) do (package core.array).push(^arr, v);
+#operator << macro (arr: [..] $T, v: T) do core.array.push(^arr, v);
 
 insert :: (arr: ^[..] $T, idx: u32, x: T) -> bool {
     if !ensure_capacity(arr, arr.count + 1) do return false;
index ff4094179f382d7be12930ac2de2590f9adf1e7c..25d587189eaf948d48a7218c4ad20a0c70ea268f 100644 (file)
@@ -1,6 +1,6 @@
 package core.avl_tree
 
-#local math :: package core.math
+use core {math}
 
 AVL_Tree :: struct (T: type_expr) {
     data: T;
index 6e07641ede5757371a995d07dfed2fc1f7e6d40b..52918f54646c6223e65e8d7eec8e06f64a00716d 100644 (file)
@@ -2,8 +2,7 @@
 
 package core.bucket_array
 
-#local array :: package core.array
-#local iter  :: package core.iter
+use core {array, iter}
 
 Bucket_Array :: struct (T: type_expr) {
     allocator : Allocator;
@@ -84,7 +83,7 @@ push :: (use b: ^Bucket_Array($T), elem: T) -> bool {
     }
 }
 
-#operator << macro (b: Bucket_Array($T), elem: T) do (package core.bucket_array).push(^b, elem);
+#operator << macro (b: Bucket_Array($T), elem: T) do core.bucket_array.push(^b, elem);
 
 pop :: (use b: ^Bucket_Array($T)) {
     last_bucket := ^buckets[buckets.count - 1];
@@ -116,7 +115,7 @@ iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) {
     c.elem_idx   = 0;
 
     next :: (use c: ^Context($T)) -> (T, bool) {
-        use package core.intrinsics.onyx
+        use core.intrinsics.onyx
 
         bucket := ^ba.buckets[bucket_idx];
         while elem_idx == bucket.count {
index 05f0fc33d7449ccc9ad38fe93b68c02234b6e9d3..d05e6ac3020c58afd1189bf30da937644a619574 100644 (file)
@@ -1,8 +1,6 @@
 package core.heap
 
-#local {
-    array :: package core.array
-}
+use core {array}
 
 Heap :: struct (T: type_expr) {
     data: [..] T;
@@ -25,7 +23,7 @@ insert :: (use heap: ^Heap, v: heap.T) {
     shift_up(heap, data.count - 1);
 }
 
-#operator << macro (heap: Heap($T), v: T) do (package core.heap).insert(^heap, v);
+#operator << macro (heap: Heap($T), v: T) do core.heap.insert(^heap, v);
 
 remove_top :: (use heap: ^Heap) -> heap.T {
     x := data[0];
index 88f53aa97d3fdf4eab4e8e0362db9cc6505f15cf..87988f21b48c914b75c5328fa9d83c734b92101b 100644 (file)
@@ -1,37 +1,6 @@
 package core.iter
 
-#local memory :: package core.memory
-#local alloc  :: package core.alloc
-
-#local {
-    //
-    // After struggling to think of a good way for iterators to manage their context
-    // data in a way that is completely degradative to the heap memory, I decided that
-    // the easiest and most programmer friendly way to do it was to completely remove
-    // their dependence on the heap. ALL iterators allocated in this file use the
-    // buffer below to store their data. This data is never "freed", but because it
-    // is a ring buffer, the data will be reused eventually. I think that 1024 bytes
-    // should be plently for the normal number of active iterators. However, it is
-    // possible that this *could* overrun, and unexpected behavior could ensue. For
-    // this reason, most allocator also support allocating their data from the context's
-    // allocator simply by passing that allocator as an arugment.
-
-    //
-    // BUG: This is not a thread-safe allocator!!
-    // Why not use context.temp_allocator?
-    //
-
-    /*
-    iter_ring_buffer: [1024] u8;
-    iter_ring: alloc.ring.RingState;
-    iter_allocator: Allocator;
-
-    #init () {
-        iter_ring = alloc.ring.make(iter_ring_buffer);
-        iter_allocator = alloc.as_allocator(^iter_ring);
-    }
-    */
-}
+use core {memory, alloc, array}
 
 as_iterator :: #match {}
 
@@ -512,7 +481,6 @@ as_iterator :: (x: ^[..] $T) -> Iterator(T) {
         //
         // This is current - 1 because current will have already
         // been incremented by the time this element calls #remove.
-        array :: package core.array
         array.delete(arr, current - 1);
         current -= 1;
     }
@@ -549,7 +517,6 @@ as_iterator :: (x: ^[..] $T, by_pointer: bool) -> Iterator(^T) {
         //
         // This is current - 1 because current will have already
         // been incremented by the time this element calls #remove.
-        array :: package core.array
         array.delete(arr, current - 1);
         current -= 1;
     }
@@ -661,8 +628,6 @@ every :: (it: Iterator($T), cond: (T) -> bool) -> bool {
 }
 
 to_array :: (it: Iterator($T), allocator := context.allocator) -> [..] T {
-    array :: package core.array
-
     arr := array.make(T, allocator=allocator);
     for v: it do array.push(^arr, v);
 
@@ -731,8 +696,7 @@ to_array :: (it: Iterator($T), allocator := context.allocator) -> [..] T {
 
     #overload
     parallel_for :: macro (iter: Iterator($T), thread_count: u32, thread_data: ^$Ctx, body: Code) {
-        thread :: package core.thread;
-        alloc  :: package core.alloc;
+        use core {thread, alloc}
         distributor :: distributor;
         as_iterator :: as_iterator;
 
index 4dce1596579a72254fef87fc3cd437e7d99d0a1a..fb1a4c95a0bccd3ae4f65dfacd19d66eb0373549 100644 (file)
@@ -127,7 +127,7 @@ fold :: (list: ^List($T), init: $R, f: (T, R) -> R) -> R {
     return val;
 }
 
-map :: #match {}
+map :: #match #local {}
 #match map (list: ^List($T), f: (^T) -> void) {
     elem := list.first;
     while elem != null {
index 63c29fb5ff93db7ee008854edd5f3b19aabc0844..618e8fffb54610754f9b07de5858c87850e5f072 100644 (file)
@@ -1,24 +1,15 @@
 package core.map
 
-#local {
-    array  :: package core.array
-    hash   :: package core.hash
-    memory :: package core.memory
-    math   :: package core.math
-    conv   :: package core.conv
+use core {array, hash, memory, math, conv}
+use core.intrinsics.onyx { __initialize }
 
-    use package core.intrinsics.onyx { __initialize }
-}
+#local ValidKey :: interface (t: $T) {
+    // In order to use a certain type as a key in a Map, you must
+    // provide an implementation of core.hash.to_u32() for that type,
+    // and you must provide an operator overload for ==.
 
-#local {
-    ValidKey :: interface (t: $T) {
-        // In order to use a certain type as a key in a Map, you must
-        // provide an implementation of core.hash.to_u32() for that type,
-        // and you must provide an operator overload for ==.
-
-        { hash.to_u32(t) } -> u32;
-        { t == t         } -> bool;
-    }
+    { hash.to_u32(t) } -> u32;
+    { t == t         } -> bool;
 }
 
 #tag conv.Custom_Format.{
@@ -80,7 +71,7 @@ free :: (use map: ^Map) {
     if entries.data != null do array.free(^entries);
 }
 
-#match (package builtin).delete (package core.map).free
+#match builtin.delete core.map.free
 
 put :: (use map: ^Map, key: map.Key_Type, value: map.Value_Type) {
     lr := lookup(map, key);
@@ -108,9 +99,9 @@ get :: (use map: ^Map, key: map.Key_Type) -> map.Value_Type {
     return default_value;
 }
 
-#operator []  macro (map: Map($K, $V), key: K) -> V do return (package core.map).get(^map, key);
-#operator []= macro (map: Map($K, $V), key: K, value: V) do (package core.map).put(^map, key, value);
-#operator ^[] macro (map: Map($K, $V), key: K) -> ^V do return (package core.map).get_ptr(^map, key);
+#operator []  macro (map: Map($K, $V), key: K) -> V do return core.map.get(^map, key);
+#operator []= macro (map: Map($K, $V), key: K, value: V) do core.map.put(^map, key, value);
+#operator ^[] macro (map: Map($K, $V), key: K) -> ^V do return core.map.get_ptr(^map, key);
 
 get_ptr :: (use map: ^Map, key: map.Key_Type) -> ^map.Value_Type {
     lr := lookup(map, key);
index 6ec63f4d41de3b8bcf46a8cf2a9f78851f409d91..8bf9d3e6accfa7757e5378203859259d2db267d2 100644 (file)
@@ -1,11 +1,6 @@
 package core.set
 
-#local {
-    array :: package core.array
-    hash  :: package core.hash
-    memory :: package core.memory
-    math :: package core.math
-}
+use core {array, hash, memory, math}
 
 #local SetValue :: interface (t: $T) {
     { hash.to_u32(t) } -> u32;
@@ -44,7 +39,8 @@ make :: ($T: type_expr, default := T.{}, allocator := context.allocator) -> Set(
     return set;
 }
 
-#match (package builtin).__make_overload macro (x: ^Set, allocator: Allocator) => (package core.set).make(x.Elem_Type, allocator = allocator);
+#overload
+builtin.__make_overload :: macro (x: ^Set, allocator: Allocator) => core.set.make(x.Elem_Type, allocator = allocator);
 
 init :: (set: ^Set($T), default := T.{}, allocator := context.allocator) {
     set.allocator = allocator;
@@ -61,7 +57,8 @@ free :: (use set: ^Set) {
     array.free(^entries);
 }
 
-#match (package builtin).delete (package core.set).free
+#overload
+builtin.delete :: core.set.free
 
 insert :: (use set: ^Set, value: set.Elem_Type) {
     if hashes.data == null do init(set);
@@ -75,7 +72,7 @@ insert :: (use set: ^Set, value: set.Elem_Type) {
     if full(set) do grow(set);
 }
 
-#operator << macro (set: Set($T), value: T) do (package core.set).insert(^set, value);
+#operator << macro (set: Set($T), value: T) do core.set.insert(^set, value);
 
 has :: (use set: ^Set, value: set.Elem_Type) -> bool {
     lr := lookup(set, value);
@@ -119,7 +116,7 @@ empty :: (use set: ^Set) -> bool {
     return entries.count == 0;
 }
 
-#match (package core.iter).as_iterator iterator
+#match core.iter.as_iterator iterator
 iterator :: (set: ^Set($T)) -> Iterator(T) {
     Context :: struct (T: type_expr) {
         set: ^Set(T);
index 4470c7e6a394dd62f9354216eb5b8e02d065faa8..ef5c4768e08fdb939d2088d692a2df47bb633abe 100644 (file)
@@ -3,9 +3,7 @@ package core.conv
 Enable_Custom_Formatters :: true
 
 #local {
-    map :: package core.map
-    string :: package core.string
-    array :: package core.array
+    use core {map, string, array, math}
 
     custom_formatters: Map(type_expr, #type (^Format_Output, ^Format, rawptr) -> void);
     custom_parsers   : Map(type_expr, #type (rawptr, str, Allocator) -> bool);
@@ -302,8 +300,6 @@ u64_to_str :: (n: u64, base: u64, buf: [] u8, min_length := 0, prefix := false)
 // This is better than what used to be, but still relies on converting the integer
 // part of the float to an integer, which could overflow.
 f64_to_str :: (f: f64, buf: [] u8, digits_after_decimal := 4) -> str {
-    math :: package core.math;
-
     if math.is_nan(f) {
         return format(buf, "NaN");
     }
index c709a3144133eb7652fbd6579c011d42166bd545..6d596cc989fd4f3ef8c6adac5f1467faeb776755 100644 (file)
@@ -1,6 +1,6 @@
 package core.io
 
-use package core
+use core
 
 BinaryWriter :: struct {
     stream: ^Stream;
index e894bd2331144a2fa58247c70cf7db4176271ead..8f50d745e3599af101e226ec8c80332f9803d8e6 100644 (file)
@@ -1,8 +1,6 @@
 package core.io
 
-memory :: package core.memory
-math   :: package core.math
-array  :: package core.array
+use core {memory, math, array}
 
 Reader :: struct {
     stream : ^Stream;
index 20ff839974eaed66aa6f08df5402bd82eb28f653..690bbe1a18d1d597d6d54a9f2fe7cb59ab42e756 100644 (file)
@@ -1,6 +1,6 @@
 package core.io
 
-use package core
+use core
 
 Stream :: struct {
     use vtable : ^Stream_Vtable;
@@ -197,14 +197,13 @@ buffer_stream_make :: #match #locked {
     }
 }
 
+#match builtin.delete buffer_stream_free
 buffer_stream_free :: (use bs: ^BufferStream) {
     if write_enabled && !fixed {
         delete(^data);
     }
 }
 
-#match builtin.delete buffer_stream_free
-
 #match core.string.as_str buffer_stream_to_str
 buffer_stream_to_str :: (use bs: ^BufferStream) -> str {
     if !write_enabled do return null_str;
index a49c0e83c46f18fcf6674772d701567def2c5917..715c846cc36576def0e4a49083788a257c770068 100644 (file)
@@ -1,6 +1,6 @@
 package core.io
 
-#local conv :: package core.conv
+use core {conv, string}
 
 Writer :: struct {
     stream : ^Stream;
@@ -32,39 +32,29 @@ write_str :: (use writer: ^Writer, s: str) {
 }
 
 write_cstr :: (use writer: ^Writer, cs: cstr) {
-    use package core
-
     s := string.from_cstr(cs);
     write_str(writer, s);
 }
 
 write_i32 :: (use writer: ^Writer, n: i32, base: u32 = 10) {
-    use package core
-
     buf : [256] u8;
     s := conv.i64_to_str(cast(i64) n, cast(u64) base, ~~buf);
     write_str(writer, s);
 }
 
 write_i64 :: (use writer: ^Writer, n: i64, base: u64 = 10) {
-    use package core
-
     buf : [256] u8;
     s := conv.i64_to_str(n, base, ~~buf);
     write_str(writer, s);
 }
 
 write_f32 :: (use writer: ^Writer, f: f32) {
-    use package core
-
     buf : [256] u8;
     s := conv.f64_to_str(cast(f64) f, ~~buf);
     write_str(writer, s);
 }
 
 write_f64 :: (use writer: ^Writer, f: f64) {
-    use package core
-
     buf : [256] u8;
     s := conv.f64_to_str(f, ~~buf);
     write_str(writer, s);
index 6ce789abe64da2df02f72d0117567bc26cc7237a..73a829e31fc371c72abc3d68926c41cd114fdca2 100644 (file)
@@ -1,6 +1,6 @@
 package core.math
 
-#local wasm :: package core.intrinsics.wasm
+use core.intrinsics {wasm}
 
 // Things that are useful in any math library:
 //  - Trigonometry
index 99d773b1f80ce774ff8442bb73d30d76c7034977..2a3349f0a834f791734ffee86211eb28b5e9190b 100644 (file)
@@ -1,14 +1,6 @@
 package core.net
 
-#local {
-    runtime :: package runtime
-    sync    :: package core.sync
-    thread  :: package core.thread
-    array   :: package core.array
-    memory  :: package core.memory
-    alloc   :: package core.alloc
-    os      :: package core.os
-}
+use core {sync, thread, array, memory, alloc, os}
 
 #if !runtime.Multi_Threading_Enabled {
     #error "Expected multi-threading to be enabled for TCP server.";
index 6accbb32e5a177d23552d1a7f12280dcf9a92609..4ec089424cb2772db1e06c31c95b37faae1c5c20 100644 (file)
@@ -1,6 +1,6 @@
 package core.os
 
-#local fs :: package runtime.fs
+use runtime {fs}
 
 Directory :: fs.DirectoryData;
 
index 62534da8f2b14d30bd8a3061a583c207c0c68e5b..0bba2aa2c79c26f51c351d005f37dcf27d0f006f 100644 (file)
@@ -1,7 +1,7 @@
 package core.os
 
-use package core
-#local fs :: package runtime.fs
+use core
+use runtime {fs}
 
 FileError :: enum {
     None       :: 0x00;
index dc16daca7c2785fd6cbaeb0ef59c281a314b8bc6..171c193e227ff0904efd16851e10f0c065380f8a 100644 (file)
@@ -5,10 +5,7 @@ package core.os
     #error "The os library is currently only available on the WASI runtime, and should only be included if that is the chosen runtime."
 }
 
-#local {
-    runtime :: package runtime
-    string  :: package core.string
-}
+use core {string}
 
 list_directory :: (path: str) -> Iterator(DirectoryEntry) {
     Context :: struct {
index ab3e53be2bab0a5f1bc07788772d2774dc0576a6..08ed47852e299fd42a67639d640cdae054b50086 100644 (file)
@@ -4,10 +4,7 @@ package core.os
     #error "This file can only be included in the 'onyx' runtime, because Wasi has not defined how to spawn and manage processes.";
 }
 
-#local {
-    runtime :: package runtime
-    io      :: package core.io
-}
+use core {io}
 
 Process :: struct {
     Handle :: #distinct i64;
index 1abf76176ea858e9542f906b3bc1091bde5e50e1..6a22b59b2b9b5c7e96aba0ddd20bf7b260d78842 100644 (file)
@@ -1,7 +1,7 @@
 package runtime
 
-use package core
-use package core.intrinsics.onyx { __initialize }
+use core
+use core.intrinsics.onyx { __initialize }
 
 // The default assert handler. This assumes that __output_string
 // and __exit are defined in the 'runtime' package.
@@ -39,7 +39,7 @@ __runtime_initialize :: () {
 // Use this procedure to initialize everything needed in the
 // standard library when you are dropped directly into a function.
 __thread_initialize :: macro () {
-    use package core.intrinsics.onyx { __initialize }
+    use core.intrinsics.onyx { __initialize }
 
     // This should only be true for the main thread.
     if __tls_base == null {
@@ -71,9 +71,7 @@ __thread_initialize :: macro () {
     }
 
     _thread_exit :: (id: i32) {
-        thread :: package core.thread
-
         raw_free(alloc.heap_allocator, __tls_base);
-        thread.__exited(id);
+        core.thread.__exited(id);
     }
 }
index 394435ea4ad695f960ea19a58fbf204ceafacf24..82cb308dcbc8a9959269bc7773c21cfc9d6fe72e 100644 (file)
@@ -1,6 +1,6 @@
 package runtime.info
 
-#local io :: package core.io
+use core {io}
 
 write_type_name :: (writer: ^io.Writer, t: type_expr) {
     info := get_type_info(t);
@@ -324,7 +324,7 @@ populate_struct_vtable :: (table: ^$Table_Type, struct_type: type_expr, safe :=
 }
 
 for_all_types :: macro (body: Code) {
-    for (package runtime.info).type_table.count {
+    for runtime.info.type_table.count {
         type_info := (package runtime.info).type_table[it];
         type_idx  : type_expr = ~~ it;
 
index 8236f99be246236fd98b762200d960c84a6ee824..669bb3d4ab237ed11dfd134a6fe8f47993a4c35d 100644 (file)
@@ -1,6 +1,8 @@
 
 package runtime.info
 
+use core {array}
+
 tagged_procedures: [] ^Tagged_Procedure
 
 Tagged_Procedure :: struct {
@@ -30,7 +32,6 @@ get_tags_for_procedure :: (func: $T) -> [] any {
 }
 
 get_procedures_with_tag :: ($tag_type: type_expr) -> [] GPWT_Result(tag_type) {
-    array :: package core.array
     results := make([..] GPWT_Result(tag_type));
 
     for proc: tagged_procedures {
index 7dc981dafdafae2245f7e7c53e10572478eb7343..f13a5e7f42e830ed8b724039e1e0d233b1066d1d 100644 (file)
@@ -2,7 +2,7 @@ package runtime
 
 #load "core/runtime/common"
 
-use package core
+use core
 
 __output_string   :: (s: str)      -> u32  #foreign "host" "print_str" ---
 __exit            :: (status: i32) -> void #foreign "host" "exit" ---
index 3a25ca424aadcfbbc1660e1825e101e51fb31956..8dd128f5ad5d8d4c4f5e8072268aa9db3ee54625 100644 (file)
@@ -2,7 +2,7 @@ package runtime
 
 #load "core/runtime/common"
 
-use package core
+use core
 
 #local {
     __stdout: os.File;
index a4338d4ee3bcd6fb0156b35a7d6bd422d32ce0a5..ebb3a4d983bc4544680d875964b370a18233a6c8 100644 (file)
@@ -3,8 +3,8 @@ package runtime
 #load "core/wasi/wasi"
 #load "core/runtime/common"
 
-use package wasi
-use package core
+use wasi
+use core
 
 __output_string :: (s: str) -> u32 {
     STDOUT_FILENO :: 1
index 0b44023bd4d76ee321d8c6ff6dd5ceb07fb936af..e840d3add174c89670cd9fab5c8cb873dc393a56 100644 (file)
@@ -1,6 +1,6 @@
 package core.string
 
-use package core
+use core
 
 as_str :: #match {}
 
index 40d92814734c7442114e6d87cd214da0f77eafe3..12bf28594524b37f9a2b6261d0e9baaf9e933337 100644 (file)
@@ -6,7 +6,7 @@
 
 package core.string
 
-#local math :: package core.math
+use core {math}
 
 String_Buffer :: struct {
     data     : ^u8;
index 6e14505433c24fbe8d7a95fa86538b98aa3ad2b6..c730b385b74cece2ed1f05fac3501977ae6da0ef 100644 (file)
@@ -1,9 +1,7 @@
 package core.sync
 
-use package core.intrinsics.atomics
-use package core.thread { Thread_ID }
-
-#local runtime :: package runtime
+use core.intrinsics.atomics
+use core.thread { Thread_ID }
 
 // `lock` has two states: 0, and 1.
 //    0 means unlocked
index ee9bf7f5968fcacc89e64726860f4e13762bb777..44e229987e8a841a0dbef8445d6da25e965169a8 100644 (file)
@@ -1,7 +1,6 @@
 package core.sync
 
-use package core.intrinsics.atomics
-#local runtime :: package runtime
+use core.intrinsics.atomics
 
 Semaphore :: struct {
     mutex   : Mutex;
index 82f277a3ced94e75d727e3ad15636e90dfb9472e..d474f491b9c3de5a919555256d5cbe78182a98d4 100644 (file)
@@ -1,11 +1,9 @@
 package core.thread
 
-use package core
-use package core.intrinsics.atomics
+use core
+use core.intrinsics.atomics
 
 #package {
-    runtime :: package runtime
-
     thread_mutex   : sync.Mutex;
     next_thread_id := 1;
     thread_map     : Map(Thread_ID, ^Thread);