Implement nova64 API with native yield function and registration

This commit is contained in:
Lukas Höppner
2026-08-10 12:43:13 +02:00
parent 1cfcd5a169
commit 27c3aaf88f
7 changed files with 79 additions and 4 deletions
+30 -2
View File
@@ -1,6 +1,7 @@
#include "wasm_runner.h"
#include "nova64_fs.h"
#include "nova64_internal.h"
#include "nova64_api.h"
#include "wasm_export.h"
#include <stdlib.h>
@@ -17,6 +18,7 @@ uint32_t stack_size = 8092, heap_size = 8092;
bool wasm_runner_initialize(void) {
wasm_runtime_init();
register_nova64_imports();
nova64_log("WASM runtime initialized successfully.\n");
const char *module_file = "SYS:/init.wasm";
@@ -44,7 +46,33 @@ bool wasm_runner_initialize(void) {
wasm_module_inst_t module_inst = wasm_runtime_instantiate(
module, stack_size, heap_size, error_buf, sizeof(error_buf));
wasm_exec_env_t exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
wasm_function_inst_t start_func =
wasm_runtime_lookup_function(module_inst, "_start");
if (start_func == NULL) {
nova64_log("Failed to find '_start' function in WASM module: %s\n",
wasm_runtime_get_exception(module_inst));
free(buffer);
return false;
}
wasm_exec_env_t exec_env =
wasm_runtime_create_exec_env(module_inst, stack_size);
uint32_t argv[2] = {5, 3}; // Example arguments for the "add" function
if (wasm_runtime_call_wasm(exec_env, start_func, 2, argv)) {
nova64_log("WASM module executed successfully. Sum: %d\n", argv[0]);
} else {
nova64_log("Failed to execute WASM module: %s\n",
wasm_runtime_get_exception(module_inst));
}
wasm_runtime_destroy_exec_env(exec_env);
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
free(buffer);
wasm_runtime_destroy();
return true;
}