return wrote;
}
-__exit :: (status: i32) -> void #foreign "onyx_runtime" "__exit" ---
__read_from_input :: (buffer: [] u8) -> i32 {
err, read := io.stream_read(^__stdin, buffer);
#library "onyx_runtime"
-#local __file_get_standard :: (fd: i32, out: ^fs.FileData.Handle) -> bool #foreign "onyx_runtime" "__file_get_standard" ---
+#foreign "onyx_runtime" {
+ __file_get_standard :: (fd: i32, out: ^fs.FileData.Handle) -> bool ---
+
+ __args_get :: (argv: ^^u8, arg_buf: ^u8) -> void ---
+ __args_sizes_get :: (argc: ^i32, arg_buf_size: ^i32) -> void ---
+
+ __exit :: (status: i32) -> void ---
+}
#export "_start" () {
fd: fs.FileData.Handle;
context.thread_id = 0;
args : [] cstr;
+ argv_buf_size : i32;
+ __args_sizes_get(^args.count, ^argv_buf_size);
+
+ args = memory.make_slice(cstr, args.count);
+ argv_buf := cast(cstr) calloc(argv_buf_size);
+ __args_get(args.data, argv_buf);
(package main).main(args);
wasm_store_t* wasm_store;
wasm_extern_vec_t wasm_imports;
+ int argc;
+ char **argv;
+
// HACK HACK HACK
// There should need to be this much stuff in here, but because Wasmer doesn't ship a "wasmerdll.lib"
// file for windows, it is impossible for it to link successfully against the function provided in onyx.exe.
return NULL;
}
+ONYX_DEF(__args_get, (WASM_I32, WASM_I32), ()) {
+ if (runtime->argc == 0 || runtime->argv == NULL) {
+ return NULL;
+ }
+
+ i32 buffer_base = params->data[1].of.i32;
+
+ for (int i=0; i<runtime->argc; i++) {
+ // Should this be strncpy? What would the length be?
+ strcpy(ONYX_PTR(buffer_base), runtime->argv[i]);
+ *(i32 *) ONYX_PTR(params->data[0].of.i32 + i * 4) = buffer_base;
+ buffer_base += strlen(runtime->argv[i]) + 1;
+ }
+
+ return NULL;
+}
+
+ONYX_DEF(__args_sizes_get, (WASM_I32, WASM_I32), ()) {
+ *(i32 *) ONYX_PTR(params->data[0].of.i32) = runtime->argc;
+
+ i32 argv_size = 0;
+ for (int i=0; i<runtime->argc; i++) {
+ argv_size += strlen(runtime->argv[i]) + 1;
+ }
+
+ *(i32 *) ONYX_PTR(params->data[1].of.i32) = argv_size;
+ return NULL;
+}
+
ONYX_DEF(__exit, (WASM_I32), ()) {
exit(params->data[0].of.i32);
return NULL;
ONYX_FUNC(__process_wait)
ONYX_FUNC(__process_destroy)
+ ONYX_FUNC(__args_get)
+ ONYX_FUNC(__args_sizes_get)
+
ONYX_FUNC(__exit)
NULL
};
\ No newline at end of file
wasm_runtime.wasm_store = wasm_store;
wasm_runtime.wasm_imports = wasm_imports;
+ wasm_runtime.argc = argc;
+ wasm_runtime.argv = argv;
+
// See comment in onyx_library.h about us being the linker.
wasm_runtime.wasm_memory_data = &wasm_memory_data;
wasm_runtime.wasm_extern_lookup_by_name = &wasm_extern_lookup_by_name;