}
file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, bool) {
- // Currently the directory's file descriptor appears to always be 3
- DIR_FD :: 3;
-
// Requesting all of the rights because why not.
rights :=
Rights.DataSync
}
file := File.{ fd = -1 };
-
- if err := wasi.path_open(
- DIR_FD,
- .SymLinkFollow,
- path,
- open_flags,
- rights,
- rights,
- fd_flags,
- ^file.fd);
- err != .Success {
- return file, false;
- }
-
file.mode = mode;
file.rights = rights;
file.flags = fd_flags;
- return file, true;
+
+ // Currently the directory's file descriptor appears to always be 3
+ // However, this is not necessarily correct, so also try a preopened directory
+ for DIR_FD: .[ 3, 4 ] {
+ if err := wasi.path_open(
+ DIR_FD,
+ .SymLinkFollow,
+ path,
+ open_flags,
+ rights,
+ rights,
+ fd_flags,
+ ^file.fd);
+ err == .Success {
+ return file, true;
+ }
+ }
+
+ return file, false;
}
file_close :: (file: File) -> bool {
.target_file = "out.wasm",
.documentation_file = NULL,
+
+ .passthrough_argument_count = 0,
+ .passthrough_argument_data = NULL,
};
bh_arr_new(alloc, options.files, 2);
else if (!strcmp(argv[i], "--doc")) {
options.documentation_file = argv[++i];
}
+ else if (!strcmp(argv[i], "--")) {
+ options.passthrough_argument_count = argc - i - 1;
+ options.passthrough_argument_data = &argv[i + 1];
+ break;
+ }
#if defined(_BH_LINUX)
// NOTE: Fun output is only enabled for Linux because Windows command line
// is not ANSI compatible and for a silly feature, I don't want to learn
return ONYX_COMPILER_PROGRESS_SUCCESS;
}
-CompilerProgress onyx_flush_module() {
+static CompilerProgress onyx_flush_module() {
// NOTE: Output to file
bh_file output_file;
return ONYX_COMPILER_PROGRESS_SUCCESS;
}
+#ifdef ENABLE_RUN_WITH_WASMER
+static void onyx_run() {
+ bh_buffer code_buffer;
+ onyx_wasm_module_write_to_buffer(context.wasm_module, &code_buffer);
+
+ if (context.options->verbose_output > 0)
+ bh_printf("Running program:");
+
+ onyx_run_wasm(code_buffer);
+}
+#endif
+
int main(int argc, char *argv[]) {
bh_scratch_init(&global_scratch, bh_heap_allocator(), 256 * 1024); // NOTE: 256 KiB
case ONYX_COMPILE_ACTION_RUN:
compiler_progress = onyx_compile();
if (compiler_progress == ONYX_COMPILER_PROGRESS_SUCCESS) {
- bh_buffer code_buffer;
- onyx_wasm_module_write_to_buffer(context.wasm_module, &code_buffer);
- onyx_run_wasm(code_buffer);
+ onyx_run();
}
break;
#endif
#include "bh.h"
+#include "astnodes.h"
#include "wasm.h"
#include "wasmer.h"
}
wasi_config_t* wasi_config = wasi_config_new("onyx");
- wasi_config_preopen_dir(wasi_config, ".");
+ if (context.options->passthrough_argument_count > 0) {
+ fori (i, 0, context.options->passthrough_argument_count) {
+ wasi_config_arg(wasi_config, context.options->passthrough_argument_data[i]);
+ }
+ }
+
+ wasi_config_preopen_dir(wasi_config, "./");
wasi_env_t* wasi_env = wasi_env_new(wasi_config);