From ead1ebd0e346cf07ce8359b709b227f3cd61c291 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 22 Feb 2021 00:50:07 +0200 Subject: [PATCH] Update API usage. Fix #193 --- CMakeLists.txt | 2 ++ platforms/android/app/src/main/cpp/main.c | 6 +++--- platforms/arduino/src/main.cpp | 5 +++-- platforms/bluepill/src/main.cpp | 7 ++++--- platforms/emscripten/main.c | 18 +++++------------- platforms/esp8266/src/main.cpp | 8 +++++--- platforms/fomu/src/main.c | 6 ++++-- platforms/hifive1/src/main.c | 8 +++++--- platforms/ios/wasm3/main.c | 6 +++--- platforms/particle/src/main.ino | 4 ++-- platforms/wm_w600/main.c | 5 ++--- source/m3_env.c | 2 -- 12 files changed, 38 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a85d522..3837a32 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ if(EMSCRIPTEN OR EMSCRIPTEN_LIB) set(CMAKE_C_COMPILER "emcc") set(CMAKE_CXX_COMPILER "em++") + set(BUILD_WASI "none") + if (EMSCRIPTEN_LIB) set(APP_DIR "platforms/emscripten_lib") set(OUT_FILE "wasm3.wasm") diff --git a/platforms/android/app/src/main/cpp/main.c b/platforms/android/app/src/main/cpp/main.c index c7a93a9..a36c5b9 100644 --- a/platforms/android/app/src/main/cpp/main.c +++ b/platforms/android/app/src/main/cpp/main.c @@ -47,11 +47,11 @@ void run_wasm() result = m3_CallV (f, 40); if (result) FATAL("m3_Call: %s", result); - uint64_t value = 0; - result = m3_GetResultsV (f, &result); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); if (result) FATAL("m3_GetResults: %s", result); - printf("Result: %lld\n", value); + printf("Result: %d\n", value); } int main() diff --git a/platforms/arduino/src/main.cpp b/platforms/arduino/src/main.cpp index fec0663..b7592ac 100644 --- a/platforms/arduino/src/main.cpp +++ b/platforms/arduino/src/main.cpp @@ -8,7 +8,6 @@ #include "Arduino.h" #include "m3/wasm3.h" -#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -47,7 +46,9 @@ void run_wasm() result = m3_CallV(f, 24); if (result) FATAL("m3_Call", result); - long value = *(uint64_t*)(runtime->stack); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); Serial.print("Result: "); Serial.println(value); diff --git a/platforms/bluepill/src/main.cpp b/platforms/bluepill/src/main.cpp index 6da3a47..a4c5939 100644 --- a/platforms/bluepill/src/main.cpp +++ b/platforms/bluepill/src/main.cpp @@ -6,7 +6,6 @@ // #include "m3/wasm3.h" -#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -47,9 +46,11 @@ void run_wasm() result = m3_CallV (f, 24); if (result) FATAL("m3_Call", result); - long value = *(uint64_t*)(runtime->stack); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); - printf("Result: %ld\n", value); + printf("Result: %d\n", value); } PinC<13> led; diff --git a/platforms/emscripten/main.c b/platforms/emscripten/main.c index 9b82a65..da7633f 100644 --- a/platforms/emscripten/main.c +++ b/platforms/emscripten/main.c @@ -10,9 +10,6 @@ #include #include "wasm3.h" -#include "m3_api_wasi.h" -#include "m3_api_libc.h" -#include "m3_env.h" #include "extra/fib32.wasm.h" @@ -38,14 +35,6 @@ void run_wasm() result = m3_LoadModule (runtime, module); if (result) FATAL("m3_LoadModule: %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); @@ -54,8 +43,11 @@ void run_wasm() if (result) FATAL("Call: %s", result); - uint64_t value = *(uint64_t*)(runtime->stack); - printf("Result: %ld\n", value); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); + + printf("Result: %d\n", value); } int main (int i_argc, const char * i_argv []) diff --git a/platforms/esp8266/src/main.cpp b/platforms/esp8266/src/main.cpp index 136b0cd..87f9bfb 100644 --- a/platforms/esp8266/src/main.cpp +++ b/platforms/esp8266/src/main.cpp @@ -9,7 +9,6 @@ #include #include "m3/wasm3.h" -#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -45,8 +44,11 @@ void run_wasm() result = m3_CallV(f, 24); if (result) FATAL("m3_Call: %s", result); - long value = *(uint64_t*)(runtime->stack); - printf("Result: %ld\n", value); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); + + printf("Result: %d\n", value); } void setup() diff --git a/platforms/fomu/src/main.c b/platforms/fomu/src/main.c index e59d5af..13ab6ae 100644 --- a/platforms/fomu/src/main.c +++ b/platforms/fomu/src/main.c @@ -35,7 +35,6 @@ void uart_print(const char *str) { } #include "m3/wasm3.h" -#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -75,7 +74,10 @@ bool run_wasm() result = m3_CallV (f, 24); if (result) FATAL("m3_Call: %s", result); - long value = *(uint64_t*)(runtime->stack); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); + char buff[32]; ltoa(value, buff, 10); diff --git a/platforms/hifive1/src/main.c b/platforms/hifive1/src/main.c index f307052..a56705c 100644 --- a/platforms/hifive1/src/main.c +++ b/platforms/hifive1/src/main.c @@ -8,7 +8,6 @@ #include #include #include "m3/wasm3.h" -#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -44,8 +43,11 @@ void run_wasm() result = m3_CallV (f, 24); if (result) FATAL("m3_Call: %s", result); - long value = *(uint64_t*)(runtime->stack); - printf("Result: %ld\n", value); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); + if (result) FATAL("m3_GetResults: %s", result); + + printf("Result: %d\n", value); } int main() { diff --git a/platforms/ios/wasm3/main.c b/platforms/ios/wasm3/main.c index f36a3cd..7380fd8 100644 --- a/platforms/ios/wasm3/main.c +++ b/platforms/ios/wasm3/main.c @@ -86,11 +86,11 @@ void run_wasm() if (result) FATAL("m3_Call: %s", result); printf("Elapsed: %ld ms\n\n", (end - start) * 1000 / CLOCKS_PER_SEC); - uint64_t value = 0; - result = m3_GetResultsV (f, &result); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); if (result) FATAL("m3_GetResults: %s", result); - printf("Result: %lld\n", value); + printf("Result: %d\n", value); } static void* runMain(void* ctx) diff --git a/platforms/particle/src/main.ino b/platforms/particle/src/main.ino index 1bf3082..ea85ef6 100644 --- a/platforms/particle/src/main.ino +++ b/platforms/particle/src/main.ino @@ -49,8 +49,8 @@ void run_wasm() result = m3_CallV (f, 24); if (result) FATAL("m3_Call: %s", result); - uint64_t value = 0; - result = m3_GetResultsV (f, &result); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); if (result) FATAL("m3_GetResults: %s", result); Serial.print("Result: "); diff --git a/platforms/wm_w600/main.c b/platforms/wm_w600/main.c index 501126f..3bb444b 100644 --- a/platforms/wm_w600/main.c +++ b/platforms/wm_w600/main.c @@ -8,7 +8,6 @@ #include "wm_include.h" #include "m3/wasm3.h" -//#include "m3/m3_env.h" #include "m3/extra/fib32.wasm.h" @@ -49,8 +48,8 @@ void run_wasm() result = m3_CallV (f, 24); if (result) FATAL("m3_Call: %s", result); - uint64_t value = 0; - result = m3_GetResultsV (f, &result); + uint32_t value = 0; + result = m3_GetResultsV (f, &value); if (result) FATAL("m3_GetResults: %s", result); printf("Result: %lld\n", value); diff --git a/source/m3_env.c b/source/m3_env.c index 1798056..da53263 100644 --- a/source/m3_env.c +++ b/source/m3_env.c @@ -325,8 +325,6 @@ void * m3_GetUserData (IM3Runtime i_runtime) return i_runtime ? i_runtime->userdata : NULL; } -typedef void * (* ModuleVisitor) (IM3Module i_module, void * i_info); - void * ForEachModule (IM3Runtime i_runtime, ModuleVisitor i_visitor, void * i_info) { void * r = NULL;