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 ---
//
// 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.
//
}
}
},
}
+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 {
s.data += adv + 1;
s.count -= adv + 1;
}
+
+as_str :: #match {
+ from_cstr
+}
"\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"
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 };
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);
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);