From: Brendan Hansen Date: Fri, 12 Nov 2021 21:02:37 +0000 (-0600) Subject: changed #private to #package and #private_file to #local X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b54c2f6843730beb595c7daf0977aaecd1282470;p=onyx.git changed #private to #package and #private_file to #local --- diff --git a/CHANGELOG b/CHANGELOG index 8b6e71de..308b4ea5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -157,7 +157,7 @@ Additions: - Will also report errors in the cast is not possible. * Arbitrarily typed varargs. They behave similar to C-style varargs. * vararg_get builtin procedure to retrieve a value from a ... vararg. -* #private_file directive for placing a symbol at file scope. +* #local directive for placing a symbol at file scope. * a basic implentation of printf in the standard library. * use statements at the function level. * nested packages, i.e. 'core.array' @@ -201,7 +201,7 @@ Additions: * Added println to core library; print followed by a newline. * Added tests/ folder and runtests.sh which will compile and execute the programs in the folder and test against their expected output. -* #private_file for specifying symbols at the file scope. +* #local for specifying symbols at the file scope. Removals: diff --git a/core/alloc.onyx b/core/alloc.onyx index 1fc81f02..f53b2223 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -13,7 +13,7 @@ TEMPORARY_ALLOCATOR_SIZE :: 1 << 12; // 4Kb heap_allocator : Allocator; // The global temp allocator, set up upon program intialization. -#private_file +#local temp_state : ring.RingState; temp_allocator : Allocator; diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index 074317a5..8b3da21c 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -25,7 +25,7 @@ ArenaState :: struct { Arena :: struct { next : ^Arena; } -#private_file +#local arena_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { alloc_arena := cast(^ArenaState) data; diff --git a/core/alloc/fixed.onyx b/core/alloc/fixed.onyx index 2ab51ee0..3e73bf2c 100644 --- a/core/alloc/fixed.onyx +++ b/core/alloc/fixed.onyx @@ -15,7 +15,7 @@ FixedAllocatorData :: struct { size : u32; } -#private_file +#local fixed_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { fa_data := cast(^FixedAllocatorData) data; diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index 2ef8848c..afddccd2 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -35,7 +35,7 @@ init :: () { get_watermark :: () => cast(u32) heap_state.next_alloc; -#private_file { +#local { use package core.intrinsics.wasm { memory_size, memory_grow, memory_copy, memory_fill, diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index 33579f3c..4ff900f9 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -8,7 +8,7 @@ Allocation_Action_Strings := str.[ "resize", ]; -#private_file +#local logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { allocator := cast(^Allocator) data; res := allocator.func(allocator.data, aa, size, align, oldptr); diff --git a/core/alloc/pool.onyx b/core/alloc/pool.onyx index 1bf8504c..b54e5b4e 100644 --- a/core/alloc/pool.onyx +++ b/core/alloc/pool.onyx @@ -16,7 +16,7 @@ PoolAllocator :: struct (Elem: type_expr) { first_free : ^Elem; } -#private_file +#local pool_allocator_proc :: (pool: ^PoolAllocator($Elem), aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { switch aa { case .Alloc { diff --git a/core/alloc/ring.onyx b/core/alloc/ring.onyx index e9ff8b84..a0752f33 100644 --- a/core/alloc/ring.onyx +++ b/core/alloc/ring.onyx @@ -16,7 +16,7 @@ RingState :: struct { curr_ptr : rawptr; } -#private_file +#local ring_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { ss := cast(^RingState) data; diff --git a/core/builtin.onyx b/core/builtin.onyx index 7ff48650..3b4c41b0 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -3,7 +3,7 @@ package builtin // CLEANUP: Should builtin.onyx really be including other files in the compilation? // Does that complicate things too much? #load "core/runtime/build_opts" -#private_file runtime :: package runtime +#local runtime :: package runtime str :: #type []u8; cstr :: #type ^u8; @@ -61,13 +61,13 @@ OnyxContext :: struct { } #if runtime.Runtime != runtime.Runtime_Custom { - #private_file default_logger :: (data: rawptr, msg: str) { + #local default_logger :: (data: rawptr, msg: str) { use package core println(msg); } } else { - #private_file default_logger :: (data: rawptr, msg: str) { + #local default_logger :: (data: rawptr, msg: str) { // In a custom runtime, there is no way to know how to log something. } } @@ -98,7 +98,7 @@ log :: (msg: str, use logger: Logger = context.logger) { // The implementations of all of the allocators can be found in core/alloc/. // These need to be here so the context structure has the types and enum values. // -#private_file +#local Default_Allocation_Alignment :: 16 AllocationAction :: enum { @@ -107,7 +107,7 @@ AllocationAction :: enum { Resize; } -#private_file +#local allocator_proc :: #type (data: rawptr, action: AllocationAction, size: u32, align: u32, old_ptr: rawptr) -> rawptr; Allocator :: struct { diff --git a/core/container/array.onyx b/core/container/array.onyx index 26d8ff93..5f8d5239 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -158,8 +158,8 @@ fold_idx_elem :: (arr: [] $T, cmp: (T, T) -> bool) -> (i32, T) { return idx, elem; } -#private_file cmp_greater :: (x, y) => x > y; -#private_file cmp_less :: (x, y) => x < y; +#local cmp_greater :: (x, y) => x > y; +#local cmp_less :: (x, y) => x < y; greatest :: #match { (arr: [..] $T) -> (i32, T) { return fold_idx_elem(arr, cmp_greater); }, @@ -309,7 +309,7 @@ quicksort :: #match { (arr: [] $T, cmp: (^T, ^T) -> i32) do quicksort_impl(arr, cmp, 0, arr.count - 1); , } -#private_file { +#local { quicksort_impl :: (arr: [] $T, cmp: $PredicateFunction, lo, hi: i32) { if lo < 0 || hi < 0 do return; if lo >= hi do return; diff --git a/core/container/bucket_array.onyx b/core/container/bucket_array.onyx index 83b9e7ce..852985cd 100644 --- a/core/container/bucket_array.onyx +++ b/core/container/bucket_array.onyx @@ -2,7 +2,7 @@ package core.bucket_array -#private_file array :: package core.array +#local array :: package core.array Bucket_Array :: struct (T: type_expr) { allocator : Allocator; @@ -138,7 +138,7 @@ iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) { }; } -#private +#package alloc_bucket :: (use b: ^Bucket_Array($T)) -> Bucket_Array.Bucket(T) { data := raw_alloc(allocator, sizeof T * elements_per_bucket); return .{ 0, data }; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 6a70f422..f09f2e2c 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -188,7 +188,7 @@ skip :: (it: Iterator($T), count: u32) -> Iterator(T) { }; } -#private_file Zipped :: struct (T: type_expr, R: type_expr) { +#local Zipped :: struct (T: type_expr, R: type_expr) { first: T; second: R; } @@ -238,7 +238,7 @@ const :: (value: $T) -> Iterator(T) { }; } -#private_file Enumeration_Value :: struct (T: type_expr) { +#local Enumeration_Value :: struct (T: type_expr) { index: i32; value: T; } diff --git a/core/container/list.onyx b/core/container/list.onyx index ceaaf3b2..c7169efb 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -119,5 +119,5 @@ get_iterator :: (list: ^List($T)) -> Iterator(T) { }; } -#private_file +#local allocate_elem :: macro (list: ^List($T)) => new(#type ListElem(T), allocator=list.allocator); diff --git a/core/container/map.onyx b/core/container/map.onyx index f99b5dd8..a6604fa2 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -1,6 +1,6 @@ package core.map -#private_file { +#local { array :: package core.array hash :: package core.hash memory :: package core.memory @@ -9,7 +9,7 @@ package core.map use package core.intrinsics.onyx { __zero_value, __initialize } } -#private_file { +#local { ValidKey :: interface (T: type_expr) { // 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, @@ -147,7 +147,7 @@ empty :: (use map: ^Map($K, $V)) -> bool { // Private symbols // -#private_file { +#local { MapLookupResult :: struct { hash_index : i32 = -1; entry_index : i32 = -1; diff --git a/core/container/set.onyx b/core/container/set.onyx index 551e537c..89867cf3 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -1,6 +1,6 @@ package core.set -#private_file { +#local { array :: package core.array hash :: package core.hash memory :: package core.memory @@ -136,7 +136,7 @@ iterator :: (set: ^Set($T)) -> Iterator(T) { // Private symbols // -#private_file { +#local { SetLookupResult :: struct { hash_index : i32 = -1; entry_index : i32 = -1; diff --git a/core/intrinsics/atomics.onyx b/core/intrinsics/atomics.onyx index 70cd2536..542513bd 100644 --- a/core/intrinsics/atomics.onyx +++ b/core/intrinsics/atomics.onyx @@ -1,6 +1,6 @@ package core.intrinsics.atomics -#private_file { +#local { runtime :: package runtime #if !runtime.Multi_Threading_Enabled { diff --git a/core/io/file.onyx b/core/io/file.onyx index 4c3a7f1e..2606355a 100644 --- a/core/io/file.onyx +++ b/core/io/file.onyx @@ -1,13 +1,13 @@ package core.io -#private_file runtime :: package runtime +#local runtime :: package runtime #if runtime.Runtime != runtime.Runtime_Wasi { #error "The file system library is currently only available on the WASI runtime, and should only be included if that is the chosen runtime." } use package core -#private_file wasi :: package wasi +#local wasi :: package wasi use package wasi { FileDescriptor, FDFlags, OFlags, Rights, @@ -186,7 +186,7 @@ close :: (file: ^FileStream) { file.stream.vtable = null; } -#private +#package file_stream_vtable := Stream_Vtable.{ seek = (use fs: ^FileStream, to: i32, whence: SeekFrom) -> Error { // Currently, the new offset is just ignored. @@ -307,7 +307,7 @@ file_logger_close :: (logger := context.logger) { cfree(logger.data); } -#private_file +#local file_logger_proc :: (data: ^File, msg: str) { file_write(*data, msg); file_write(*data, "\n"); diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 3d785991..260c2e22 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -6,7 +6,7 @@ Stream :: struct { vtable : ^Stream_Vtable; } -// #private +// #package Stream_Vtable :: struct { seek : (s: ^Stream, to: i32, whence: SeekFrom) -> Error; tell : (s: ^Stream) -> (Error, u32); @@ -157,7 +157,7 @@ string_stream_to_str :: (use ss: ^StringStream) -> str { return .{ data.data, curr_pos }; } -#private +#package string_stream_vtable := Stream_Vtable.{ seek = (use ss: ^StringStream, to: i32, whence: SeekFrom) -> Error { if to >= data.count do return .OutOfBounds; @@ -277,7 +277,7 @@ dynamic_string_stream_to_str :: (use dds: ^DynamicStringStream) -> str { return data.data[0 .. curr_pos]; } -#private +#package dynamic_string_stream_vtable := Stream_Vtable.{ seek = (use dss: ^DynamicStringStream, to: i32, whence: SeekFrom) -> Error { dest : i32; diff --git a/core/io/writer.onyx b/core/io/writer.onyx index 6d9f32a9..8928c986 100644 --- a/core/io/writer.onyx +++ b/core/io/writer.onyx @@ -1,6 +1,6 @@ package core.io -#private_file conv :: package core.conv +#local conv :: package core.conv Writer :: struct { stream : ^Stream; diff --git a/core/math.onyx b/core/math.onyx index e544a141..592f86bb 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -1,6 +1,6 @@ package core.math -#private_file wasm :: package core.intrinsics.wasm +#local wasm :: package core.intrinsics.wasm // Things that are useful in any math library: // - Trigonometry diff --git a/core/random.onyx b/core/random.onyx index 0bc3e50e..bc633bd5 100644 --- a/core/random.onyx +++ b/core/random.onyx @@ -1,10 +1,10 @@ package core.random -#private_file seed : i64 = 8675309 +#local seed : i64 = 8675309 -#private_file RANDOM_MULTIPLIER :: 25214903917 -#private_file RANDOM_INCREMENT :: cast(i64) 11 -// #private_file RANDOM_MODULUS :: 1 << 32 +#local RANDOM_MULTIPLIER :: 25214903917 +#local RANDOM_INCREMENT :: cast(i64) 11 +// #local RANDOM_MODULUS :: 1 << 32 set_seed :: #match { (s: u32) do seed = ~~s; , diff --git a/core/std.onyx b/core/std.onyx index 9ad51a9e..d1daefdf 100644 --- a/core/std.onyx +++ b/core/std.onyx @@ -36,7 +36,7 @@ package core #load "./type_info/helper" -#private_file runtime :: package runtime +#local runtime :: package runtime #if runtime.Runtime == runtime.Runtime_Wasi { #load "./runtime/wasi" #load "./wasi/wasi" diff --git a/core/stdio.onyx b/core/stdio.onyx index 4fb13f10..1b611fbd 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -7,7 +7,7 @@ package core // in anyway. -#private_file runtime :: package runtime +#local runtime :: package runtime #if runtime.Runtime == runtime.Runtime_Custom { #error "'stdio' can only be included in the 'wasi' or 'js' runtime." } diff --git a/core/string/buffer.onyx b/core/string/buffer.onyx index 75fecbf8..40d92814 100644 --- a/core/string/buffer.onyx +++ b/core/string/buffer.onyx @@ -6,7 +6,7 @@ package core.string -#private_file math :: package core.math +#local math :: package core.math String_Buffer :: struct { data : ^u8; diff --git a/core/string/builder.onyx b/core/string/builder.onyx index b5e7f635..7ff03293 100644 --- a/core/string/builder.onyx +++ b/core/string/builder.onyx @@ -5,9 +5,9 @@ package core.string.builder #if false { -#private_file array :: package core.array -#private_file string :: package core.string -#private_file conv :: package core.conv +#local array :: package core.array +#local string :: package core.string +#local conv :: package core.conv Builder :: struct { data : [..] u8; diff --git a/core/threads/thread.onyx b/core/threads/thread.onyx index da13427e..2f1d8b65 100644 --- a/core/threads/thread.onyx +++ b/core/threads/thread.onyx @@ -3,7 +3,7 @@ package core.thread use package core use package core.intrinsics.atomics -#private { +#package { runtime :: package runtime thread_mutex : sync.Mutex; diff --git a/core/type_info/helper.onyx b/core/type_info/helper.onyx index 2bf52c36..9ddaf5ea 100644 --- a/core/type_info/helper.onyx +++ b/core/type_info/helper.onyx @@ -1,6 +1,6 @@ package builtin.type_info -#private_file io :: package core.io +#local io :: package core.io write_type_name :: (writer: ^io.Writer, t: type_expr) { info := get_type_info(t); diff --git a/core/wasi/env.onyx b/core/wasi/env.onyx index 67fabd25..dfb408d4 100644 --- a/core/wasi/env.onyx +++ b/core/wasi/env.onyx @@ -6,9 +6,9 @@ package core.env use package wasi { environ_get, environ_sizes_get, Size } -#private map :: package core.map -#private memory :: package core.memory -#private string :: package core.string +#package map :: package core.map +#package memory :: package core.memory +#package string :: package core.string Environment :: struct { vars : Map(str, str); diff --git a/docs/plan b/docs/plan index 116ef9e7..80201c99 100644 --- a/docs/plan +++ b/docs/plan @@ -159,7 +159,7 @@ HOW: [X] Pointer math - Addition and subtraction - [X] #private + [X] #package - symbol is scoped to package and not brought in from a 'use package' statement [X] Hex literals diff --git a/modules/bmfont/bmfont_loader.onyx b/modules/bmfont/bmfont_loader.onyx index 413ef4fd..3a31a340 100644 --- a/modules/bmfont/bmfont_loader.onyx +++ b/modules/bmfont/bmfont_loader.onyx @@ -1,7 +1,7 @@ package bmfont use package core -#private_file json :: package json +#local json :: package json load_bmfont :: (fnt_data: [] u8) -> BMFont { bmf := create_bmfont(); @@ -27,7 +27,7 @@ load_bmfont_from_json :: (fnt_data: [] u8) -> BMFont { extract_bmfont_from_json(^bmf, j.root); } -#private_file +#local create_bmfont :: () -> BMFont { bmf: BMFont; memory.set(^bmf, 0, sizeof BMFont); @@ -38,7 +38,7 @@ create_bmfont :: () -> BMFont { return bmf; } -#private_file +#local parse_bmfont :: (fnt_data: [] u8, font: ^BMFont) { R :: package core.string.reader @@ -151,7 +151,7 @@ parse_bmfont :: (fnt_data: [] u8, font: ^BMFont) { } } -#private_file +#local extract_bmfont_from_json :: (font: ^BMFont, root: ^json.Value) { font_info := root["info"]; font.info.face_name = font_info["face"]->as_str(); diff --git a/modules/bmfont/position.onyx b/modules/bmfont/position.onyx index 7f16298b..602fb912 100644 --- a/modules/bmfont/position.onyx +++ b/modules/bmfont/position.onyx @@ -1,6 +1,6 @@ package bmfont -#private_file { +#local { math :: package core.math renderable_glyph: Renderable_Glyph; diff --git a/modules/bmfont/utils.onyx b/modules/bmfont/utils.onyx index 5e61f5c9..118d00fc 100644 --- a/modules/bmfont/utils.onyx +++ b/modules/bmfont/utils.onyx @@ -1,6 +1,6 @@ package bmfont -#private_file math :: package core.math +#local math :: package core.math get_width :: (use font: ^BMFont, text: str, size: f32) -> f32 { max_x := 0.0f; diff --git a/modules/immediate_mode/gl_utils.onyx b/modules/immediate_mode/gl_utils.onyx index a4b90c69..a06b4877 100644 --- a/modules/immediate_mode/gl_utils.onyx +++ b/modules/immediate_mode/gl_utils.onyx @@ -1,7 +1,7 @@ package immediate_mode use package core -#private_file gl :: package gl +#local gl :: package gl // This Shader represents an OpenGL program, not a shader. The name // is confusing but conceptually for most people, shaders are a bundled diff --git a/modules/immediate_mode/module.onyx b/modules/immediate_mode/module.onyx index 47fae0fa..2e988f13 100644 --- a/modules/immediate_mode/module.onyx +++ b/modules/immediate_mode/module.onyx @@ -7,4 +7,4 @@ package immediate_mode #load "./texture" #load "./transform" -#private gl :: package gl +#package gl :: package gl diff --git a/modules/js_events/js_events.onyx b/modules/js_events/js_events.onyx index bb69ec41..38f0be35 100644 --- a/modules/js_events/js_events.onyx +++ b/modules/js_events/js_events.onyx @@ -5,7 +5,7 @@ package js_events -#private_file Max_Buffered_Events :: 16 +#local Max_Buffered_Events :: 16 // NOTE: These need to match exactly what is in the corresponding javascript DomEventKind :: enum { @@ -110,7 +110,7 @@ init :: () { event_setup(^event_storage, sizeof Event); } -#private_file processing_event: Event +#local processing_event: Event consume :: () -> Iterator(^Event) { next :: (_: rawptr) -> (^Event, bool) { if event_storage.event_count == 0 do return null, false; @@ -131,11 +131,11 @@ consume :: () -> Iterator(^Event) { /* Private members */ -#private EventStorage :: struct { +#package EventStorage :: struct { event_count : u32; max_events : u32; event_buffer : [Max_Buffered_Events] Event; } -#private event_storage : EventStorage; -#private event_setup :: (event_storage: ^EventStorage, event_size: u32) -> void #foreign "js_events" "setup" --- +#package event_storage : EventStorage; +#package event_setup :: (event_storage: ^EventStorage, event_size: u32) -> void #foreign "js_events" "setup" --- diff --git a/modules/js_events/request_file.onyx b/modules/js_events/request_file.onyx index bcddb23e..b9d74870 100644 --- a/modules/js_events/request_file.onyx +++ b/modules/js_events/request_file.onyx @@ -1,7 +1,7 @@ package js_events // 0 is reserved for dropped files -#private_file next_request_id := 1; +#local next_request_id := 1; request_file :: (filepath: str) -> u32 { js_request_file :: (event_storage: ^EventStorage, event_size: u32, filepath: str, fileid: u32) -> void #foreign "js_events" "request_file" ---; diff --git a/modules/json/parser.onyx b/modules/json/parser.onyx index 68f03efa..7bfa9105 100644 --- a/modules/json/parser.onyx +++ b/modules/json/parser.onyx @@ -1,7 +1,7 @@ package json use package core -#private +#package Parser :: struct { tokenizer : Tokenizer; allocator : Allocator; @@ -10,7 +10,7 @@ Parser :: struct { previous_token : Token; } -#private +#package make_parser :: (data: [] u8, allocator := context.allocator) -> Parser { parser: Parser; parser.tokenizer = Tokenizer.{ data = data }; @@ -19,13 +19,13 @@ make_parser :: (data: [] u8, allocator := context.allocator) -> Parser { return parser; } -#private +#package parse :: (data: [] u8, allocator := context.allocator) -> (^Value, Error) { parser := make_parser(data, allocator); return parse_value(^parser); } -#private_file +#local consume_token :: (use parser: ^Parser) -> (Token, Error) { error: Error; previous_token = current_token; @@ -33,7 +33,7 @@ consume_token :: (use parser: ^Parser) -> (Token, Error) { return previous_token, error; } -#private_file +#local consume_token_if_next :: (use parser: ^Parser, kind: Token.Kind) -> bool { if current_token.kind == kind { consume_token(parser); @@ -43,7 +43,7 @@ consume_token_if_next :: (use parser: ^Parser, kind: Token.Kind) -> bool { return false; } -#private_file +#local expect_token :: (use parser: ^Parser, kind: Token.Kind) -> (Token, Error) { previous := current_token; consume_token(parser); @@ -52,7 +52,7 @@ expect_token :: (use parser: ^Parser, kind: Token.Kind) -> (Token, Error) { return previous, error; } -#private +#package parse_value :: (use parser: ^Parser) -> (^Value, Error) { return_value: ^Value = null; @@ -120,7 +120,7 @@ parse_value :: (use parser: ^Parser) -> (^Value, Error) { return return_value, .{ .None }; } -#private_file +#local parse_array :: (use parser: ^Parser) -> (^Value_Array, Error) { value := new(Value_Array, allocator); @@ -162,7 +162,7 @@ parse_array :: (use parser: ^Parser) -> (^Value_Array, Error) { } -#private_file +#local parse_object :: (use parser: ^Parser) -> (^Value_Object, Error) { value := new(Value_Object, allocator); @@ -228,7 +228,7 @@ parse_object :: (use parser: ^Parser) -> (^Value_Object, Error) { } -#private_file +#local unescape_string :: (token: Token, allocator: Allocator) -> str { if token.kind != .String do return ""; diff --git a/modules/json/tokenizer.onyx b/modules/json/tokenizer.onyx index 0bb7eea4..32a7ed61 100644 --- a/modules/json/tokenizer.onyx +++ b/modules/json/tokenizer.onyx @@ -1,4 +1,4 @@ -// Everything in this file is marked #private because I do not think +// Everything in this file is marked #package because I do not think // that this code will be needed outside of this module. I do not see // the value of having access to the tokenizer and parser of JSON directly. @@ -6,13 +6,13 @@ package json use package core -#private +#package Tokenizer :: struct { data: [] u8; use position := Position.{ 0, 1, 1 }; } -#private +#package Token :: struct { Kind :: enum { Invalid; @@ -40,13 +40,13 @@ Token :: struct { use position := Position.{ 0, 1, 1 }; } -#private +#package Position :: struct { offset : u32; // Offset into the stream line, column : u32; // Line and column number } -#private +#package token_get :: (use tkn: ^Tokenizer) -> (Token, Error) { err := Error.{}; @@ -138,7 +138,7 @@ token_get :: (use tkn: ^Tokenizer) -> (Token, Error) { return token, err; } -#private_file +#local next_character :: (use tkn: ^Tokenizer) -> (u8, bool) { if offset >= data.count do return 0, false; @@ -149,7 +149,7 @@ next_character :: (use tkn: ^Tokenizer) -> (u8, bool) { return retval, true; } -#private_file +#local skip_whitespace :: (use tkn: ^Tokenizer) { while offset < data.count { switch data[offset] { @@ -170,7 +170,7 @@ skip_whitespace :: (use tkn: ^Tokenizer) { } } -#private_file +#local skip_alpha_numeric :: (use tkn: ^Tokenizer) { while offset < data.count { switch data[offset] { @@ -184,7 +184,7 @@ skip_alpha_numeric :: (use tkn: ^Tokenizer) { } } -#private_file +#local skip_numeric :: (use tkn: ^Tokenizer) { while offset < data.count { switch data[offset] { @@ -198,7 +198,7 @@ skip_numeric :: (use tkn: ^Tokenizer) { } } -#private_file +#local skip_escape :: (use tkn: ^Tokenizer) { switch data[offset] { case #char "u" { diff --git a/modules/ouit/module.onyx b/modules/ouit/module.onyx index 060f0ab7..3200961f 100644 --- a/modules/ouit/module.onyx +++ b/modules/ouit/module.onyx @@ -16,5 +16,6 @@ it easy to setup a web-based user interface. #load "modules/js_events/module" #load "modules/ui/module" #load "modules/webgl2/module" +#load "modules/json/module" -#load "./ouit" \ No newline at end of file +#load "./ouit" diff --git a/modules/ouit/ouit.onyx b/modules/ouit/ouit.onyx index 726d1078..24d63d4f 100644 --- a/modules/ouit/ouit.onyx +++ b/modules/ouit/ouit.onyx @@ -1,6 +1,6 @@ package ouit -#private_file { +#local { gl :: package gl gfx :: package immediate_mode events :: package js_events @@ -22,7 +22,7 @@ init :: (canvas_name: str, ouit_draw = d; } -#private { +#package { ouit_handle_event : (^events.Event) -> void; ouit_update : (dt: f32) -> void; ouit_draw : () -> void; diff --git a/modules/ttf/ttf.onyx b/modules/ttf/ttf.onyx index 07a68b50..bb9c362d 100644 --- a/modules/ttf/ttf.onyx +++ b/modules/ttf/ttf.onyx @@ -131,7 +131,7 @@ ttf_create :: (ttf_data: [] u8) -> True_Type_Font { return ttf; } -#private +#package ttf_read_offset_table :: (use ttf: ^True_Type_Font) { scalar_type = reader->get_u32(); num_tables := reader->get_u16(); @@ -162,7 +162,7 @@ ttf_read_offset_table :: (use ttf: ^True_Type_Font) { } } -#private +#package ttf_read_head_table :: (use ttf: ^True_Type_Font) { head_table_info := map.get(^tables, string_to_beu32("head")); reader->seek(head_table_info.offset); @@ -246,7 +246,7 @@ ttf_glyph_destroy :: (glyph: ^TTF_Glyph, allocator := context.allocator) { raw_free(allocator, glyph); } -#private_file +#local TTF_Glyph_Flags :: enum #flags { On_Curve :: 0x01; X_Is_Byte :: 0x02; @@ -256,7 +256,7 @@ TTF_Glyph_Flags :: enum #flags { Y_Delta :: 0x20; } -#private_file +#local ttf_read_simple_glyph :: (use ttf: ^True_Type_Font, glyph: ^TTF_Glyph) { array.init(^glyph.contour_ends, ~~glyph.contour_count); array.init(^glyph.points); @@ -423,13 +423,13 @@ ttf_lookup_glyph_by_char :: (use ttf: ^True_Type_Font, charcode: u32) -> u32 { return potential_code; } -#private_file +#local ttf_lookup_in_cmap0 :: (use ttf: ^True_Type_Font, cmap: ^TTF_Cmap0, charcode: u32) -> u32 { if charcode < 0 || charcode >= 256 do return 0; return ~~cmap.glyph_indicies[charcode]; } -#private_file +#local ttf_lookup_in_cmap4 :: (use ttf: ^True_Type_Font, cmap: ^TTF_Cmap4, charcode: u32) -> u32 { if map.has(^cmap.cache, charcode) do return map.get(^cmap.cache, charcode); @@ -511,7 +511,7 @@ ttf_lookup_horizontal_metrics :: (use ttf: ^True_Type_Font, glyph_index: u32) -> } -#private_file +#local ttf_calc_table_checksum :: (reader: ^TTF_Reader, offset: u32, length: u32) -> u32 { old := reader->seek(offset); defer reader->seek(old); @@ -522,7 +522,7 @@ ttf_calc_table_checksum :: (reader: ^TTF_Reader, offset: u32, length: u32) -> u3 return sum; } -#private_file +#local string_to_beu32 :: (s: str) -> u32 { return (cast(u32) s[0] << 24) | (cast(u32) s[1] << 16) diff --git a/modules/ui/components/scrollable_region.onyx b/modules/ui/components/scrollable_region.onyx index c9463194..b2e473bf 100644 --- a/modules/ui/components/scrollable_region.onyx +++ b/modules/ui/components/scrollable_region.onyx @@ -9,7 +9,7 @@ Scrollable_Region_State :: struct { }; } -#private +#package scrollable_region_states : Map(UI_Id, Scrollable_Region_State); Scrollable_Region_Controls :: struct { diff --git a/modules/ui/components/textbox.onyx b/modules/ui/components/textbox.onyx index 052c4753..6a96d66a 100644 --- a/modules/ui/components/textbox.onyx +++ b/modules/ui/components/textbox.onyx @@ -29,7 +29,7 @@ Textbox_Theme :: struct { default_textbox_theme := Textbox_Theme.{}; -#private_file +#local Textbox_Editing_State :: struct { hash: UI_Id = 0; @@ -39,7 +39,7 @@ Textbox_Editing_State :: struct { cursor_animation_speed := 0.02f; } -#private +#package // There is only one 'Textbox_Editing_State', not a map of them because there can only be one textbox being edited at once. textbox_editing_state := Textbox_Editing_State.{}; @@ -182,7 +182,7 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, placeholder := return result; } -#private_file +#local get_cursor_location :: (text_buffer: ^string.String_Buffer, text_x: f32, text_y: f32, text_size: f32, cursor_position: i32) -> f32 { countdown := cursor_position + 1; last_x : f32 = text_x; @@ -205,7 +205,7 @@ get_cursor_location :: (text_buffer: ^string.String_Buffer, text_x: f32, text_y: return last_x + last_w; } -#private_file +#local get_cursor_position :: (text_buffer: ^string.String_Buffer, text_x: f32, text_y: f32, text_size: f32, mouse_x: f32, mouse_y: f32) -> i32 { cursor_position := 0; diff --git a/modules/ui/components/workspace.onyx b/modules/ui/components/workspace.onyx index d5f4f275..853c28b0 100644 --- a/modules/ui/components/workspace.onyx +++ b/modules/ui/components/workspace.onyx @@ -20,7 +20,7 @@ Workspace_State :: struct { dragging := false; } -#private +#package workspace_states : Map(UI_Id, Workspace_State); workspace_start :: (use r: Rectangle, site := #callsite, state: ^Workspace_State = null) { diff --git a/modules/ui/font.onyx b/modules/ui/font.onyx index 6d8a82a7..88567247 100644 --- a/modules/ui/font.onyx +++ b/modules/ui/font.onyx @@ -2,7 +2,7 @@ package ui // A simple wrapper for a BMFont and an OpenGL Texture -#private_file RK :: enum { Luminance; Color; } +#local RK :: enum { Luminance; Color; } Font :: struct { texture : gfx.Texture; @@ -71,7 +71,7 @@ create_font :: (bmfont_data: [] u8, font_texture_data: [] u8) -> Font { Font_Index :: i32; -#private font_registry : Map(Font_Index, Font); +#package font_registry : Map(Font_Index, Font); register_font :: (index: Font_Index, font: Font) { assert(!map.has(^font_registry, index), "Font with this index already exists."); map.put(^font_registry, index, font); diff --git a/modules/ui/input.onyx b/modules/ui/input.onyx index 3d885871..604238ad 100644 --- a/modules/ui/input.onyx +++ b/modules/ui/input.onyx @@ -67,7 +67,7 @@ update_mouse_position :: (new_x: f32, new_y: f32) { mouse_state.y_ = new_y; } -#private_file Mouse_Button_Kind :: enum { Left; Right; Middle; WheelUp; WheelDown; } +#local Mouse_Button_Kind :: enum { Left; Right; Middle; WheelUp; WheelDown; } button_pressed :: (kind: Mouse_Button_Kind) { switch kind { @@ -103,7 +103,7 @@ button_released :: (kind: Mouse_Button_Kind) { } } -#private_file +#local __key_state_transition_table := Keyboard_State.Key_State.[ /* KeyUp */ /* KeyDown */ /* Up */ Keyboard_State.Key_State.Up, Keyboard_State.Key_State.Just_Down, diff --git a/modules/ui/module.onyx b/modules/ui/module.onyx index a492917b..c8837972 100644 --- a/modules/ui/module.onyx +++ b/modules/ui/module.onyx @@ -53,9 +53,9 @@ package ui #load "./components/scrollable_region" // Package inclusions that are part of all files in the "ui" package. -#private gfx :: package immediate_mode // The immediate_mode module needs to be accessible -#private gl :: package gl -#private bmfont :: package bmfont +#package gfx :: package immediate_mode // The immediate_mode module needs to be accessible +#package gl :: package gl +#package bmfont :: package bmfont -#private math :: package core.math -#private map :: package core.map \ No newline at end of file +#package math :: package core.math +#package map :: package core.map \ No newline at end of file diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index bf2ba311..02464860 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -7,7 +7,7 @@ DEFAULT_TEXT_SIZE :: 1.0f UI_Id :: #type u32 -#private { +#package { hot_item : UI_Id = 0 active_item : UI_Id = 0 hot_item_was_set := false @@ -78,8 +78,8 @@ set_active_item :: (id: UI_Id) -> bool { return true; } -#private_file hot_item_depth := 0; -#private_file hot_item_depth_needed := 0; +#local hot_item_depth := 0; +#local hot_item_depth_needed := 0; set_hot_item :: (id: UI_Id, force := false) -> bool { if active_item != 0 do return false; @@ -192,7 +192,7 @@ Animation_Theme :: struct { // Animation states are stored globally as there is not much to the state of a button. // Forcing the end user to store a structure for each button that is just the animation // state of the component feels very wrong. -#private_file animation_states : Map(UI_Id, Animation_State); +#local animation_states : Map(UI_Id, Animation_State); Animation_State :: struct { hover_time := 0.0f; @@ -249,7 +249,7 @@ move_towards :: macro (value: ^$T, target: T, step: T) { if *value > target - step && *value < target + step do *value = target; } -#private color_lerp :: macro (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 { +#package color_lerp :: macro (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 { return .{ r = c1.r * (1 - t) + c2.r * t, g = c1.g * (1 - t) + c2.g * t, diff --git a/modules/vecmath/vector2.onyx b/modules/vecmath/vector2.onyx index 2ebe62e3..cd186480 100644 --- a/modules/vecmath/vector2.onyx +++ b/modules/vecmath/vector2.onyx @@ -1,6 +1,6 @@ package vecmath -#private_file io :: package core.io +#local io :: package core.io use package core.intrinsics.onyx { __zero_value } Vector2i :: #type Vector2(i32); diff --git a/modules/wasm_utils/instructions.onyx b/modules/wasm_utils/instructions.onyx index c826c131..72380e3c 100644 --- a/modules/wasm_utils/instructions.onyx +++ b/modules/wasm_utils/instructions.onyx @@ -269,7 +269,7 @@ instructions_as_array :: (binary: ^WasmBinary, code: ^WasmCode, allocator := con |> iter.to_array(allocator=allocator); } -#private +#package parse_instruction :: (reader: ^io.Reader, binary: ^WasmBinary, code_offset := 0, current_block_depth: ^i32 = null) -> WasmInstruction { Parse_After :: enum { diff --git a/modules/wasm_utils/module.onyx b/modules/wasm_utils/module.onyx index cfb1361b..50843f81 100644 --- a/modules/wasm_utils/module.onyx +++ b/modules/wasm_utils/module.onyx @@ -11,8 +11,8 @@ package wasm_utils #load "./parser" #load "./instructions" -#private map :: package core.map -#private io :: package core.io -#private hash :: package core.hash -#private memory :: package core.memory -#private iter :: package core.iter \ No newline at end of file +#package map :: package core.map +#package io :: package core.io +#package hash :: package core.hash +#package memory :: package core.memory +#package iter :: package core.iter \ No newline at end of file diff --git a/modules/wasm_utils/parser.onyx b/modules/wasm_utils/parser.onyx index 1b509e27..03fcba51 100644 --- a/modules/wasm_utils/parser.onyx +++ b/modules/wasm_utils/parser.onyx @@ -10,7 +10,7 @@ package wasm_utils // calling any of the top-level parsing functions. Because this is here, it is // unsafe to use this library in a multi-threaded context, if Wasm ever officially // supports that. -#private_file wasm_allocator : Allocator +#local wasm_allocator : Allocator parse_type_section :: (use bin: ^WasmBinary, allocator := context.allocator) -> [] WasmFuncType { if !map.has(^sections, .Type) do return .{ null, 0 }; @@ -294,7 +294,7 @@ parse_code_section :: (use bin: ^WasmBinary, allocator := context.allocator) -> } } -#private +#package parse_vector :: macro (reader: ^io.Reader, bin: ^WasmBinary, read: (^io.Reader, ^WasmBinary) -> $T) -> [] T { wasm_allocator :: wasm_allocator; @@ -309,7 +309,7 @@ parse_vector :: macro (reader: ^io.Reader, bin: ^WasmBinary, return result; } -#private +#package parse_name :: (reader: ^io.Reader, bin: ^WasmBinary) -> [] u8 { return parse_vector(reader, bin, read_byte); @@ -318,7 +318,7 @@ parse_name :: (reader: ^io.Reader, bin: ^WasmBinary) -> [] u8 { } } -#private +#package parse_limits :: (reader: ^io.Reader, bin: ^WasmBinary) -> WasmLimits { byte := io.read_byte(reader); @@ -342,7 +342,7 @@ parse_limits :: (reader: ^io.Reader, bin: ^WasmBinary) -> WasmLimits { return .{ minimum=minimum, maximum=maximum, shared=shared }; } -#private +#package read_val_type :: (reader: ^io.Reader, binary: ^WasmBinary) -> WasmValueType { byte := io.read_byte(reader); switch byte { @@ -364,7 +364,7 @@ read_val_type :: (reader: ^io.Reader, binary: ^WasmBinary) -> WasmValueType { return ~~0; } -#private +#package parse_const_uint32 :: (reader: ^io.Reader, binary: ^WasmBinary) -> u32 { assert(io.read_byte(reader) == 65, "Expected integer constant"); value := read_uleb128(reader); @@ -373,7 +373,7 @@ parse_const_uint32 :: (reader: ^io.Reader, binary: ^WasmBinary) -> u32 { return ~~value; } -#private +#package parse_section_locations :: (use bin: ^WasmBinary) -> bool { stream := io.string_stream_make(data); reader := io.reader_make(^stream); diff --git a/modules/wasm_utils/utils.onyx b/modules/wasm_utils/utils.onyx index 326da066..c9abbd3d 100644 --- a/modules/wasm_utils/utils.onyx +++ b/modules/wasm_utils/utils.onyx @@ -1,8 +1,8 @@ package wasm_utils -#private_file io :: package core.io +#local io :: package core.io -#private +#package read_uleb128 :: (use reader: ^io.Reader) -> u64 { result: u64 = 0; shift := 0; @@ -19,7 +19,7 @@ read_uleb128 :: (use reader: ^io.Reader) -> u64 { return result; } -#private +#package read_sleb128 :: (use reader: ^io.Reader, size := 4) -> i64 { result: i64 = 0; shift := 0; diff --git a/modules/webgl2/webgl2.onyx b/modules/webgl2/webgl2.onyx index 6d45cd14..637bec2f 100644 --- a/modules/webgl2/webgl2.onyx +++ b/modules/webgl2/webgl2.onyx @@ -3,7 +3,7 @@ package gl // To be used with the corresponding gl.js // There are many things that are missing but this suffices for me. -#private_file runtime :: package runtime +#local runtime :: package runtime #if runtime.Runtime != runtime.Runtime_Js { #error "'webgl' can only be used with the 'js' runtime." } diff --git a/src/parser.c b/src/parser.c index 263fd460..f8f55a7c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2819,7 +2819,8 @@ static void parse_top_level_statement(OnyxParser* parser) { private_kind = bh_arr_last(parser->scope_flags); // :CLEANUP this very repetetive code... - if (parse_possible_directive(parser, "private")) { + if (next_tokens_are(parser, 2, '#', Token_Type_Keyword_Package)) { + consume_tokens(parser, 2); private_kind = Ast_Flag_Private_Package; if (parser->curr->type == '{') { bh_arr_push(parser->scope_flags, private_kind); @@ -2832,7 +2833,7 @@ static void parse_top_level_statement(OnyxParser* parser) { return; } } - else if (parse_possible_directive(parser, "private_file")) { + else if (parse_possible_directive(parser, "local")) { private_kind = Ast_Flag_Private_File; if (parser->curr->type == '{') { bh_arr_push(parser->scope_flags, private_kind);