Update emscripten sample
#include <time.h>
#include "m3.h"
+#include "m3_api_wasi.h"
+#include "m3_api_libc.h"
#include "m3_env.h"
#include "extra/fib32.wasm.h"
@@ -16,12 +18,10 @@ void run_wasm()
uint8_t* wasm = (uint8_t*)fib32_wasm;
size_t fsize = fib32_wasm_len-1;
- printf("Loading WebAssembly...\n");
-
IM3Environment env = m3_NewEnvironment ();
if (!env) FATAL("m3_NewEnvironment failed");
- IM3Runtime runtime = m3_NewRuntime (env, 8*1024);
+ IM3Runtime runtime = m3_NewRuntime (env, 64*1024);
if (!runtime) FATAL("m3_NewRuntime failed");
IM3Module module;
@@ -31,29 +31,30 @@ void run_wasm()
result = m3_LoadModule (runtime, module);
if (result) FATAL("m3_LoadModule: %s", result);
- IM3Function f;
- result = m3_FindFunction (&f, runtime, "__post_instantiate");
- if (! result)
- {
- result = m3_Call (f);
- if (result) FATAL("__post_instantiate: %s", result);
- }
+ /*
+ result = m3_LinkWASI (runtime->modules);
+ if (result) FATAL("m3_LinkWASI: %s", result);
+ result = m3_LinkLibC (runtime->modules);
+ if (result) FATAL("m3_LinkLibC: %s", result);
+ */
+
+ IM3Function f;
result = m3_FindFunction (&f, runtime, "fib");
if (result) FATAL("m3_FindFunction: %s", result);
- printf("Running...\n");
-
const char* i_argv[2] = { "40", NULL };
result = m3_CallWithArgs (f, 1, i_argv);
if (result) FATAL("Call: %s", result);
+ uint64_t value = *(uint64_t*)(runtime->stack);
+ printf("Result: %ld\n", value);
}
int main (int i_argc, const char * i_argv [])
{
- printf("\nwasm3 on WASM, build " __DATE__ " " __TIME__ "\n");
+ printf("wasm3 on WASM, build " __DATE__ " " __TIME__ "\n");
clock_t start = clock();
run_wasm();
