From: Brendan Hansen Date: Sun, 13 Mar 2022 02:34:08 +0000 (-0600) Subject: bugfixes and cleanup X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2b5d9d3838c49beb051e9e5ccace5feabdc72588;p=onyx.git bugfixes and cleanup --- diff --git a/core/onyx/cptr.onyx b/core/onyx/cptr.onyx index d5e97df0..f9243a54 100644 --- a/core/onyx/cptr.onyx +++ b/core/onyx/cptr.onyx @@ -23,6 +23,10 @@ cptr :: struct (T: type_expr) { read_i64 :: (this: cptr(i64)) => cast(i64) __cptr_read_u64(this.data); } +#operator + macro (p: cptr($T), v: i32) -> cptr(T) { + return .{ p.data + ~~(v * sizeof T) }; +} + #local { #foreign "onyx_runtime" { __cptr_make :: (x: rawptr) -> u64 --- @@ -34,9 +38,9 @@ cptr :: struct (T: type_expr) { // // The equivalent write instructions are pusposefully left out. - // Until a VERY CONVINCING REASON as to why the must be included - // arises, having them in is more of a security vulnerability than - // I want to have. + // Until a VERY CONVINCING REASON as to why they must be included + // arises, including them is more of a security vulnerability than + // I am willing to have. // } } diff --git a/core/string.onyx b/core/string.onyx index 9da43aaa..82517dea 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -227,6 +227,26 @@ strip_trailing_whitespace :: #match { }, } +to_uppercase :: (s: str) -> str { + for^ ch: s { + if *ch >= #char "a" && *ch <= #char "z" { + *ch -= 32; + } + } + + return s; +} + +to_lowercase :: (s: str) -> str { + for^ ch: s { + if *ch >= #char "A" && *ch <= #char "Z" { + *ch += 32; + } + } + + return s; +} + trim_start :: #match { (s: ^str, char: u8) { while s.data[0] == char { @@ -338,3 +358,7 @@ advance_line :: (s: ^str) { s.data += adv + 1; s.count -= adv + 1; } + +as_str :: #match { + from_cstr +} diff --git a/modules/openal/build.sh b/modules/openal/build.sh old mode 100644 new mode 100755 diff --git a/src/onyx.c b/src/onyx.c index c3611956..7863d744 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -48,7 +48,7 @@ static const char* docstring = "Onyx compiler version " VERSION "\n" "\t -VV Very verbose output.\n" "\t -VVV Very very verbose output (to be used by compiler developers).\n" "\t--wasm-mvp Use only WebAssembly MVP features.\n" - "\t---multi-threaded Enables multi-threading for this compilation.\n" + "\t--multi-threaded Enables multi-threading for this compilation.\n" "\t--doc \n" "\n" "Developer flags:\n" diff --git a/src/wasm_output.h b/src/wasm_output.h index 231a57ac..231937d5 100644 --- a/src/wasm_output.h +++ b/src/wasm_output.h @@ -21,6 +21,7 @@ typedef i32 vector_func(void*, bh_buffer*); +static const u8 ONYX_MAGIC_STRING[] = "ONYX"; static const u8 WASM_MAGIC_STRING[] = { 0x00, 0x61, 0x73, 0x6D }; static const u8 WASM_VERSION[] = { 0x01, 0x00, 0x00, 0x00 }; @@ -761,7 +762,11 @@ static i32 output_onyx_func_offset_section(OnyxWasmModule* module, bh_buffer* bu void onyx_wasm_module_write_to_buffer(OnyxWasmModule* module, bh_buffer* buffer) { bh_buffer_init(buffer, global_heap_allocator, 128); - bh_buffer_append(buffer, WASM_MAGIC_STRING, 4); + if (context.options->runtime == Runtime_Onyx) { + bh_buffer_append(buffer, ONYX_MAGIC_STRING, 4); + } else { + bh_buffer_append(buffer, WASM_MAGIC_STRING, 4); + } bh_buffer_append(buffer, WASM_VERSION, 4); output_typesection(module, buffer); diff --git a/src/wasm_runtime.c b/src/wasm_runtime.c index ff295b60..f760085e 100644 --- a/src/wasm_runtime.c +++ b/src/wasm_runtime.c @@ -210,6 +210,18 @@ static void onyx_print_trap(wasm_trap_t* trap) { b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) { runtime = &wasm_runtime; + if (wasm_bytes.data[0] != 'O' + || wasm_bytes.data[1] != 'N' + || wasm_bytes.data[2] != 'Y' + || wasm_bytes.data[3] != 'X') { + printf("Bad magic bytes for Onyx binary.\n"); + return 0; + } else { + wasm_bytes.data[0] = '\0'; + wasm_bytes.data[1] = 'a'; + wasm_bytes.data[2] = 's'; + wasm_bytes.data[3] = 'm'; + } wasm_raw_bytes = wasm_bytes; bh_arr_new(bh_heap_allocator(), linkable_functions, 4);