From: Brendan Hansen Date: Mon, 15 Feb 2021 05:00:00 +0000 (-0600) Subject: small changes and cleanups X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e29dfd0f17a788581c27295e171de04c79d9a30e;p=onyx.git small changes and cleanups --- diff --git a/.vimspector.json b/.vimspector.json index bf898e79..7d57391f 100644 --- a/.vimspector.json +++ b/.vimspector.json @@ -5,10 +5,10 @@ "configuration": { "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/onyx", - "args": ["--verbose", "tests/struct_robustness.onyx"], + "program": "/mnt/c/dev/onyx/bin/onyx", + "args": ["-VVV", "test/basic"], "stopAtEntry": true, - "cwd": "~/dev/c/onyx", + "cwd": "/mnt/c/dev/onyx-imgui", "environment": [], "externalConsole": false, "MIMode": "gdb", diff --git a/bin/onyx b/bin/onyx index 1406205b..979752ea 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/builtin.onyx b/core/builtin.onyx index 490b27b8..73f5fb1c 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -28,6 +28,11 @@ vararg_get :: (va: vararg, ret: ^$T) -> bool { null_proc :: proc () #null --- null :: cast(rawptr) 0; +// I find myself wanting to return a completely nullified string like the +// one below that I decided to added a builtin binding for it. This might +// go away at some point and would just need to be defined in every file. +null_str :: str.{ null, 0 } + OnyxContext :: struct { allocator : Allocator; temp_allocator : Allocator; @@ -35,9 +40,16 @@ OnyxContext :: struct { assert_handler : (msg: str, file: str) -> void; } +// @Robustness +// Currently, because the only compilation target is WebAssembly, which is only +// single threaded for the moment, it is safe to store the context in a global +// variable. If other compilations targets are added, or if WebAssembly standardizes +// a multi-threading proposal, this context will need to be changed. Either it will +// need to be a thread-local variable, or it needs to be implicitly passed as the +// first parameter to ALL procedures in a compilation unit. context : OnyxContext; -assert :: (cond: bool, msg: str, file: str = str.{ null, 0 }) { +assert :: (cond: bool, msg: str, file: str = null_str) { if !cond do context.assert_handler(msg, file); } @@ -47,7 +59,8 @@ assert :: (cond: bool, msg: str, file: str = str.{ null, 0 }) { // 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. // -__DEFAULT_ALLOCATION_ALIGNMENT :: 16 +#private_file +Default_Allocation_Alignment :: 16 AllocationAction :: enum { Alloc; @@ -62,11 +75,11 @@ Allocator :: struct { func: allocator_proc; } -raw_alloc :: (use a: Allocator, size: u32, alignment := __DEFAULT_ALLOCATION_ALIGNMENT) -> rawptr { +raw_alloc :: (use a: Allocator, size: u32, alignment := Default_Allocation_Alignment) -> rawptr { return func(data, AllocationAction.Alloc, size, alignment, null); } -raw_resize :: (use a: Allocator, ptr: rawptr, size: u32, alignment := __DEFAULT_ALLOCATION_ALIGNMENT) -> rawptr { +raw_resize :: (use a: Allocator, ptr: rawptr, size: u32, alignment := Default_Allocation_Alignment) -> rawptr { return func(data, AllocationAction.Resize, size, alignment, ptr); } @@ -79,8 +92,3 @@ calloc :: (size: u32) -> rawptr do return raw_alloc(context.allocator, size); cresize :: (ptr: rawptr, size: u32) -> rawptr do return raw_resize(context.allocator, ptr, size); cfree :: (ptr: rawptr) do raw_free(context.allocator, ptr); - -// @CLEANUP: These need to move to somewhere else eventually -cmp_asc :: (a: $T, b: T) -> i32 do return cast(i32) (a - b); -cmp_dec :: (a: $T, b: T) -> i32 do return cast(i32) (b - a); - diff --git a/core/js/webgl.onyx b/core/js/webgl.onyx index 02a22b62..b1fa9c2b 100644 --- a/core/js/webgl.onyx +++ b/core/js/webgl.onyx @@ -1,7 +1,13 @@ package gl + // To be used with the corresponding gl.js // There are many things that are missing but this suffices for me. +use package build_opts as build_opts +#if build_opts.Runtime != build_opts.Runtime_Js { + #error "'webgl' can only be used with the 'js' runtime." +} + // ClearBufferMask DEPTH_BUFFER_BIT :: 0x00000100 diff --git a/examples/07_structs.onyx b/examples/07_structs.onyx index 03d56bd1..efbe9da7 100644 --- a/examples/07_structs.onyx +++ b/examples/07_structs.onyx @@ -145,9 +145,8 @@ main :: (args: [] cstr) { array_of_T : [N] T; } - // This struct takes in two parameters: A type expression T (which is only valid for struct parameters, - // not procedure parameters at the moment), and an integer N. It has two members. The first being of - // type T, and the second being an N dimensional array of type T. + // This struct takes in two parameters: A type expression T, and an integer N. It has two members. + // The first being of type T, and the second being an N dimensional array of type T. // To use a struct with parameters, simply pass them in the type. param_struct_instance : ParamStruct(f32, 10); diff --git a/examples/08_enums.onyx b/examples/08_enums.onyx index 7d0044b8..dc55b55e 100644 --- a/examples/08_enums.onyx +++ b/examples/08_enums.onyx @@ -1,5 +1,8 @@ // Enumerations (or enums for short) in Onyx work very similar to how they do -// in C and C++. +// in C and C++. Currently, they are the most underpowered feature of Onyx. +// When you define enum values explicitly, they must be numeric literals, not +// expressions. This is going to improve in the future, but for the moment, +// enums are rather limited. #load "core/std" diff --git a/onyx.exe b/onyx.exe index 1e601f20..1639c4d3 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxsymres.c b/src/onyxsymres.c index fe65a426..8c707304 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -302,6 +302,17 @@ static SymresStatus symres_field_access(AstFieldAccess** fa) { AstNode* resolution = try_symbol_resolve_from_node((AstNode *) (*fa)->expr, (*fa)->token); if (resolution) *((AstNode **) fa) = resolution; + else if ((*fa)->expr->kind == Ast_Kind_Package) { + if (report_unresolved_symbols) { + onyx_report_error((*fa)->token->pos, "'%b' was not found in package '%s'. Perhaps it is defined in a file that wasn't loaded?", + (*fa)->token->text, + (*fa)->token->length, + ((AstPackage *) (*fa)->expr)->package->name); + return Symres_Error; + } else { + return Symres_Yield_Macro; + } + } return Symres_Success; } diff --git a/tests/aoc-2020/day10.onyx b/tests/aoc-2020/day10.onyx index 20aec872..63165330 100644 --- a/tests/aoc-2020/day10.onyx +++ b/tests/aoc-2020/day10.onyx @@ -41,6 +41,7 @@ main :: proc (args: [] cstr) { // Slight hack, but having 0 in the array makes both parts easier array.push(^nums, 0); + cmp_asc :: proc (a: $T, b: T) -> i32 do return ~~(a - b); array.sort(^nums, cmp_asc); diffs: [3] u32; diff --git a/tests/aoc-2020/day5.onyx b/tests/aoc-2020/day5.onyx index 9fb1e42f..0f88f886 100644 --- a/tests/aoc-2020/day5.onyx +++ b/tests/aoc-2020/day5.onyx @@ -35,3 +35,5 @@ main :: proc (args: [] cstr) { printf("Max val: %i\n", max_val); printf("Your seat: %i\n", missing); } + +cmp_asc :: proc (a: $T, b: T) -> i32 do return ~~(a - b);