From 09ffd13316493fcca9ea5407719b171360060237 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 1 Oct 2022 22:59:54 -0500 Subject: [PATCH] cleaned up core packages with newer onyx features --- compiler/src/wasm_emit.c | 3 +++ core/alloc/arena.onyx | 13 +++++------ core/alloc/auto_heap.onyx | 10 ++++---- core/alloc/fixed.onyx | 2 +- core/alloc/heap.onyx | 12 ++++------ core/alloc/logging.onyx | 2 +- core/alloc/pool.onyx | 2 +- core/alloc/ring.onyx | 2 +- core/arg_parse.onyx | 4 ++-- core/container/array.onyx | 6 ++--- core/container/avl_tree.onyx | 2 +- core/container/bucket_array.onyx | 7 +++--- core/container/heap.onyx | 6 ++--- core/container/iter.onyx | 40 ++------------------------------ core/container/list.onyx | 2 +- core/container/map.onyx | 33 ++++++++++---------------- core/container/set.onyx | 17 ++++++-------- core/conv.onyx | 6 +---- core/io/binary.onyx | 2 +- core/io/reader.onyx | 4 +--- core/io/stream.onyx | 5 ++-- core/io/writer.onyx | 12 +--------- core/math.onyx | 2 +- core/net/tcp.onyx | 10 +------- core/os/dir.onyx | 2 +- core/os/file.onyx | 4 ++-- core/os/os.onyx | 5 +--- core/os/process.onyx | 5 +--- core/runtime/common.onyx | 10 ++++---- core/runtime/info/helper.onyx | 4 ++-- core/runtime/info/proc_tags.onyx | 3 ++- core/runtime/js.onyx | 2 +- core/runtime/onyx_run.onyx | 2 +- core/runtime/wasi.onyx | 4 ++-- core/string.onyx | 2 +- core/string/buffer.onyx | 2 +- core/sync/mutex.onyx | 6 ++--- core/sync/semaphore.onyx | 3 +-- core/threads/thread.onyx | 6 ++--- 39 files changed, 88 insertions(+), 176 deletions(-) diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index db467362..6a9b9d8c 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -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++; diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index e92c430e..67314510 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -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; } }, diff --git a/core/alloc/auto_heap.onyx b/core/alloc/auto_heap.onyx index af634d7e..ea9ea5a4 100644 --- a/core/alloc/auto_heap.onyx +++ b/core/alloc/auto_heap.onyx @@ -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; } }, diff --git a/core/alloc/fixed.onyx b/core/alloc/fixed.onyx index 7c65d131..b5161fe8 100644 --- a/core/alloc/fixed.onyx +++ b/core/alloc/fixed.onyx @@ -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, diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index fa75c232..555a63ba 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -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 diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index 4ff900f9..44295bc4 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -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); diff --git a/core/alloc/pool.onyx b/core/alloc/pool.onyx index 8184902e..ef54b8f1 100644 --- a/core/alloc/pool.onyx +++ b/core/alloc/pool.onyx @@ -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 }, diff --git a/core/alloc/ring.onyx b/core/alloc/ring.onyx index 0de43d3c..2d12599d 100644 --- a/core/alloc/ring.onyx +++ b/core/alloc/ring.onyx @@ -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, diff --git a/core/arg_parse.onyx b/core/arg_parse.onyx index 01255cd6..cde4b24e 100644 --- a/core/arg_parse.onyx +++ b/core/arg_parse.onyx @@ -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; diff --git a/core/container/array.onyx b/core/container/array.onyx index 5a3717b1..41e92972 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -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; diff --git a/core/container/avl_tree.onyx b/core/container/avl_tree.onyx index ff409417..25d58718 100644 --- a/core/container/avl_tree.onyx +++ b/core/container/avl_tree.onyx @@ -1,6 +1,6 @@ package core.avl_tree -#local math :: package core.math +use 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 6e07641e..52918f54 100644 --- a/core/container/bucket_array.onyx +++ b/core/container/bucket_array.onyx @@ -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 { diff --git a/core/container/heap.onyx b/core/container/heap.onyx index 05f0fc33..d05e6ac3 100644 --- a/core/container/heap.onyx +++ b/core/container/heap.onyx @@ -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]; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 88f53aa9..87988f21 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -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; diff --git a/core/container/list.onyx b/core/container/list.onyx index 4dce1596..fb1a4c95 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -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 { diff --git a/core/container/map.onyx b/core/container/map.onyx index 63c29fb5..618e8fff 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -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); diff --git a/core/container/set.onyx b/core/container/set.onyx index 6ec63f4d..8bf9d3e6 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -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); diff --git a/core/conv.onyx b/core/conv.onyx index 4470c7e6..ef5c4768 100644 --- a/core/conv.onyx +++ b/core/conv.onyx @@ -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"); } diff --git a/core/io/binary.onyx b/core/io/binary.onyx index c709a314..6d596cc9 100644 --- a/core/io/binary.onyx +++ b/core/io/binary.onyx @@ -1,6 +1,6 @@ package core.io -use package core +use core BinaryWriter :: struct { stream: ^Stream; diff --git a/core/io/reader.onyx b/core/io/reader.onyx index e894bd23..8f50d745 100644 --- a/core/io/reader.onyx +++ b/core/io/reader.onyx @@ -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; diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 20ff8399..690bbe1a 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -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; diff --git a/core/io/writer.onyx b/core/io/writer.onyx index a49c0e83..715c846c 100644 --- a/core/io/writer.onyx +++ b/core/io/writer.onyx @@ -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); diff --git a/core/math.onyx b/core/math.onyx index 6ce789ab..73a829e3 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -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 diff --git a/core/net/tcp.onyx b/core/net/tcp.onyx index 99d773b1..2a3349f0 100644 --- a/core/net/tcp.onyx +++ b/core/net/tcp.onyx @@ -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."; diff --git a/core/os/dir.onyx b/core/os/dir.onyx index 6accbb32..4ec08942 100644 --- a/core/os/dir.onyx +++ b/core/os/dir.onyx @@ -1,6 +1,6 @@ package core.os -#local fs :: package runtime.fs +use runtime {fs} Directory :: fs.DirectoryData; diff --git a/core/os/file.onyx b/core/os/file.onyx index 62534da8..0bba2aa2 100644 --- a/core/os/file.onyx +++ b/core/os/file.onyx @@ -1,7 +1,7 @@ package core.os -use package core -#local fs :: package runtime.fs +use core +use runtime {fs} FileError :: enum { None :: 0x00; diff --git a/core/os/os.onyx b/core/os/os.onyx index dc16daca..171c193e 100644 --- a/core/os/os.onyx +++ b/core/os/os.onyx @@ -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 { diff --git a/core/os/process.onyx b/core/os/process.onyx index ab3e53be..08ed4785 100644 --- a/core/os/process.onyx +++ b/core/os/process.onyx @@ -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; diff --git a/core/runtime/common.onyx b/core/runtime/common.onyx index 1abf7617..6a22b59b 100644 --- a/core/runtime/common.onyx +++ b/core/runtime/common.onyx @@ -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); } } diff --git a/core/runtime/info/helper.onyx b/core/runtime/info/helper.onyx index 394435ea..82cb308d 100644 --- a/core/runtime/info/helper.onyx +++ b/core/runtime/info/helper.onyx @@ -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; diff --git a/core/runtime/info/proc_tags.onyx b/core/runtime/info/proc_tags.onyx index 8236f99b..669bb3d4 100644 --- a/core/runtime/info/proc_tags.onyx +++ b/core/runtime/info/proc_tags.onyx @@ -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 { diff --git a/core/runtime/js.onyx b/core/runtime/js.onyx index 7dc981da..f13a5e7f 100644 --- a/core/runtime/js.onyx +++ b/core/runtime/js.onyx @@ -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" --- diff --git a/core/runtime/onyx_run.onyx b/core/runtime/onyx_run.onyx index 3a25ca42..8dd128f5 100644 --- a/core/runtime/onyx_run.onyx +++ b/core/runtime/onyx_run.onyx @@ -2,7 +2,7 @@ package runtime #load "core/runtime/common" -use package core +use core #local { __stdout: os.File; diff --git a/core/runtime/wasi.onyx b/core/runtime/wasi.onyx index a4338d4e..ebb3a4d9 100644 --- a/core/runtime/wasi.onyx +++ b/core/runtime/wasi.onyx @@ -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 diff --git a/core/string.onyx b/core/string.onyx index 0b44023b..e840d3ad 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -1,6 +1,6 @@ package core.string -use package core +use core as_str :: #match {} diff --git a/core/string/buffer.onyx b/core/string/buffer.onyx index 40d92814..12bf2859 100644 --- a/core/string/buffer.onyx +++ b/core/string/buffer.onyx @@ -6,7 +6,7 @@ package core.string -#local math :: package core.math +use core {math} String_Buffer :: struct { data : ^u8; diff --git a/core/sync/mutex.onyx b/core/sync/mutex.onyx index 6e145054..c730b385 100644 --- a/core/sync/mutex.onyx +++ b/core/sync/mutex.onyx @@ -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 diff --git a/core/sync/semaphore.onyx b/core/sync/semaphore.onyx index ee9bf7f5..44e22998 100644 --- a/core/sync/semaphore.onyx +++ b/core/sync/semaphore.onyx @@ -1,7 +1,6 @@ package core.sync -use package core.intrinsics.atomics -#local runtime :: package runtime +use core.intrinsics.atomics Semaphore :: struct { mutex : Mutex; diff --git a/core/threads/thread.onyx b/core/threads/thread.onyx index 82f277a3..d474f491 100644 --- a/core/threads/thread.onyx +++ b/core/threads/thread.onyx @@ -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); -- 2.25.1