bugfixes and cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 10 Apr 2022 23:36:39 +0000 (18:36 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 10 Apr 2022 23:36:39 +0000 (18:36 -0500)
core/container/array.onyx
core/onyx/cptr.onyx
misc/onyx.vim
src/lex.c

index 959a5624107e7abdcfe64f0328ceb820b1aea1f5..2f13f645e0f0502902c6430202f5688eb3e1fa00 100644 (file)
@@ -55,10 +55,10 @@ copy :: #match {
 
         for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
         return new_arr;
-    }, 
+    },
 
     (arr: [] $T, allocator := context.allocator) -> [] T {
-        new_arr := make([] T, arr.count);       
+        new_arr := make([] T, arr.count);
         for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
         return new_arr;
     }
@@ -186,14 +186,14 @@ filter :: macro (arr: ^[..] $T, body: Code) {
 fold_idx_elem :: (arr: [] $T, cmp: (T, T) -> bool) -> (i32, T) {
     idx  := 0;
     elem := arr[0];
-    
+
     for i: 1 .. arr.count {
         if cmp(arr[i], elem) {
             idx  = i;
             elem = arr[i];
         }
     }
-    
+
     return idx, elem;
 }
 
@@ -512,4 +512,3 @@ count_where :: #match {
         return count;
     },
 }
-
index e5a8d223e6eecc8cff0ca2b8c96c69e8f6050b74..5f6530a43df628e7256f1fa16555e66f99075eea 100644 (file)
@@ -29,9 +29,12 @@ cptr :: struct (T: type_expr) {
         if this.data == 0 do return null;
 
         wasm :: package core.intrinsics.wasm
-        mem_base_ptr := __cptr_make(0);
-        assert(mem_base_ptr <= this.data && this.data <= mem_base_ptr + (wasm.memory_size() << 16), "Invalid conversion from cptr to rawptr: pointer value out of Onyx memory range.");
-        return ~~(this.data - mem_base_ptr);
+        // Using 1 instead of 0 because a null pointer (0) converts
+        // to the memory address 0, not the base address for the WASM
+        // memory.
+        mem_base_ptr := __cptr_make(cast(rawptr) 1);
+        assert(mem_base_ptr <= this.data + 1 && this.data + 1 <= mem_base_ptr + ~~(wasm.memory_size() << 16), "Invalid conversion from cptr to rawptr: pointer value out of Onyx memory range.");
+        return ~~(this.data - mem_base_ptr + 1);
     }
 }
 
index ad510de219e7599290ad11bb77578487ee8866c9..67e93fbfc3735ef3641007fc87fc15f9dd811899 100644 (file)
@@ -10,7 +10,7 @@ endif
 let s:cpo_save = &cpo
 set cpo&vim
 
-syn keyword onyxKeyword package struct enum proc use global macro
+syn keyword onyxKeyword package struct enum use global macro
 syn keyword onyxKeyword if elseif else where interface
 syn keyword onyxKeyword for while do
 syn keyword onyxKeyword switch case
@@ -27,7 +27,7 @@ syn keyword onyxType str cstr
 syn keyword onyxType i8x16 i16x8 i32x4 i64x2 f32x4 f64x2 v128
 syn keyword onyxType type_expr any
 
-syn keyword onyxConstant        true false null null_proc
+syn keyword onyxConstant        true false null null_proc it
 
 syn match onyxNumber            "\<0x[a-fA-F0-9]\+\>"
 syn match onyxNumber            "\<\d\+[lf]\=\>"
index e65ff9647e06196487b50be2ed753d71283d00aa..1f0dc6a337d54366a24c94fdf146d396b96c4fc6 100644 (file)
--- a/src/lex.c
+++ b/src/lex.c
@@ -471,7 +471,7 @@ whitespace_skipped:
     // Symbols
     if (char_is_alpha(*tk.text) || *tokenizer->curr == '_') {
         u64 len = 0;
-        while (char_is_alphanum(*tokenizer->curr) || charset_contains("_$", *tokenizer->curr)) {
+        while (char_is_alphanum(*tokenizer->curr) || *tokenizer->curr == '_') {
             len++;
             INCREMENT_CURR_TOKEN(tokenizer);
         }