small changes and cleanups
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 15 Feb 2021 05:00:00 +0000 (23:00 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 15 Feb 2021 05:00:00 +0000 (23:00 -0600)
.vimspector.json
bin/onyx
core/builtin.onyx
core/js/webgl.onyx
examples/07_structs.onyx
examples/08_enums.onyx
onyx.exe
src/onyxsymres.c
tests/aoc-2020/day10.onyx
tests/aoc-2020/day5.onyx

index bf898e79ba0e3984ee7a29a18069c8aca14f2acd..7d57391f88b5d7f120c45d3496d01460f4216df4 100644 (file)
@@ -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",
index 1406205b02ede2170a5014e449a9498d631aabef..979752ea85e957d4fb0c45d2deb0037ec58733c2 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 490b27b8a7c69182c81e78afad0edbb926989356..73f5fb1cb33f43e0561151f3382a543f9b4e1c61 100644 (file)
@@ -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);
-
index 02a22b6205aed779c35d25e9f5421c860be5c51f..b1fa9c2bd2cbcf93255fae9d11e1dfc36d6d2dbb 100644 (file)
@@ -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
index 03d56bd1e99e0de2321e85096c9e3e70edf300a8..efbe9da7edb3a654fc05ea04c135c82e2874545a 100644 (file)
@@ -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);
index 7d0044b82d88e32e15fb9caf0653f12705440506..dc55b55e04b34285ac5546c06ffb6389d706774e 100644 (file)
@@ -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"
 
index 1e601f2084d2f632d4340f8b13c6149bc1d978f8..1639c4d33ae7448de304f5ae9976b0db2603b460 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index fe65a42625c3e5886849354daa637ba10b34c297..8c707304f74c85cd70a784cd80e6d76e046c9187 100644 (file)
@@ -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;
 }
index 20aec8723bfd48504815bfd70434bc78f8e157f3..6316533087fb0379e2c341614d0b753fd52be4d0 100644 (file)
@@ -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;
index 9fb1e42fd68c0f9cccf3de1a0c7c57c78891cb65..0f88f88655e712f86fac3fbe341326aebd0391b3 100644 (file)
@@ -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);