bugfixes and cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 13 Mar 2022 02:34:08 +0000 (20:34 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 13 Mar 2022 02:34:08 +0000 (20:34 -0600)
core/onyx/cptr.onyx
core/string.onyx
modules/openal/build.sh [changed mode: 0644->0755]
src/onyx.c
src/wasm_output.h
src/wasm_runtime.c

index d5e97df088a98568ef7e4c2883c86d34cfeec32a..f9243a54538f049f2c8182b4e64c681be5358911 100644 (file)
@@ -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.
         //
     }
 }
index 9da43aaae9384e7c87a52acbf3fe8c7c823b5c24..82517deaa762445cf9b74aefdebf51018f01ef9d 100644 (file)
@@ -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
+}
old mode 100644 (file)
new mode 100755 (executable)
index c3611956b702169cc6b24d1803358e7dc5d0ca24..7863d7446b36b9daf0d462435ed127c12740c710 100644 (file)
@@ -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 <doc_file>\n"
     "\n"
     "Developer flags:\n"
index 231a57ace08986021157bd81b90f2e75f616f9f1..231937d5bc2487504acb48f4418996858107d371 100644 (file)
@@ -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);
index ff295b60943edf4bd5101d519e379cf64c4d69ce..f760085e86fed5a86ec8b0596f68f2d0d2608c71 100644 (file)
@@ -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);