From d3e5ab86ea9bc0abf6f439a59cc3d2fe15791449 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 10 Apr 2022 18:36:39 -0500 Subject: [PATCH] bugfixes and cleanup --- core/container/array.onyx | 9 ++++----- core/onyx/cptr.onyx | 9 ++++++--- misc/onyx.vim | 4 ++-- src/lex.c | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/container/array.onyx b/core/container/array.onyx index 959a5624..2f13f645 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -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; }, } - diff --git a/core/onyx/cptr.onyx b/core/onyx/cptr.onyx index e5a8d223..5f6530a4 100644 --- a/core/onyx/cptr.onyx +++ b/core/onyx/cptr.onyx @@ -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); } } diff --git a/misc/onyx.vim b/misc/onyx.vim index ad510de2..67e93fbf 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -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]\=\>" diff --git a/src/lex.c b/src/lex.c index e65ff964..1f0dc6a3 100644 --- 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); } -- 2.25.1