|
|
|
@ -30,17 +30,20 @@ void uart_write(const char *str, unsigned len) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int puts(const char *str) {
|
|
|
|
|
void uart_print(const char *str) {
|
|
|
|
|
uart_write(str, strlen(str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define FATAL(msg, ...) { puts("Fatal: " msg "\n"); return false; }
|
|
|
|
|
|
|
|
|
|
#include "m3/m3.h"
|
|
|
|
|
#include "m3/m3_env.h"
|
|
|
|
|
|
|
|
|
|
#include "m3/extra/fib32.wasm.h"
|
|
|
|
|
|
|
|
|
|
#define FATAL(func, msg) { \
|
|
|
|
|
uart_print("Fatal: " func ": "); \
|
|
|
|
|
uart_print(msg); uart_print("\n"); \
|
|
|
|
|
return false; }
|
|
|
|
|
|
|
|
|
|
bool run_wasm()
|
|
|
|
|
{
|
|
|
|
|
M3Result result = m3Err_none;
|
|
|
|
@ -48,39 +51,39 @@ bool run_wasm()
|
|
|
|
|
uint8_t* wasm = (uint8_t*)fib32_wasm;
|
|
|
|
|
size_t fsize = fib32_wasm_len-1;
|
|
|
|
|
|
|
|
|
|
puts("Loading WebAssembly...\n");
|
|
|
|
|
uart_print("Loading WebAssembly...\n");
|
|
|
|
|
|
|
|
|
|
IM3Environment env = m3_NewEnvironment ();
|
|
|
|
|
if (!env) FATAL("m3_NewEnvironment failed");
|
|
|
|
|
if (!env) FATAL("m3_NewEnvironment", "failed");
|
|
|
|
|
|
|
|
|
|
IM3Runtime runtime = m3_NewRuntime (env, 1024, NULL);
|
|
|
|
|
if (!runtime) FATAL("m3_NewRuntime failed");
|
|
|
|
|
if (!runtime) FATAL("m3_NewRuntime", "failed");
|
|
|
|
|
|
|
|
|
|
IM3Module module;
|
|
|
|
|
result = m3_ParseModule (env, &module, wasm, fsize);
|
|
|
|
|
if (result) FATAL("m3_ParseModule: %s", result);
|
|
|
|
|
if (result) FATAL("m3_ParseModule", result);
|
|
|
|
|
|
|
|
|
|
result = m3_LoadModule (runtime, module);
|
|
|
|
|
if (result) FATAL("m3_LoadModule: %s", result);
|
|
|
|
|
if (result) FATAL("m3_LoadModule", result);
|
|
|
|
|
|
|
|
|
|
IM3Function f;
|
|
|
|
|
result = m3_FindFunction (&f, runtime, "fib");
|
|
|
|
|
if (result) FATAL("m3_FindFunction: %s", result);
|
|
|
|
|
if (result) FATAL("m3_FindFunction", result);
|
|
|
|
|
|
|
|
|
|
puts("Running...\n");
|
|
|
|
|
uart_print("Running...\n");
|
|
|
|
|
|
|
|
|
|
const char* i_argv[2] = { "24", NULL };
|
|
|
|
|
result = m3_CallWithArgs (f, 1, i_argv);
|
|
|
|
|
|
|
|
|
|
if (result) FATAL("m3_CallWithArgs: %s", result);
|
|
|
|
|
if (result) FATAL("m3_CallWithArgs", result);
|
|
|
|
|
|
|
|
|
|
long value = *(uint64_t*)(runtime->stack);
|
|
|
|
|
char buff[32];
|
|
|
|
|
ltoa(value, buff, 10);
|
|
|
|
|
|
|
|
|
|
puts("Result: ");
|
|
|
|
|
puts(buff);
|
|
|
|
|
puts("\n");
|
|
|
|
|
uart_print("Result: ");
|
|
|
|
|
uart_print(buff);
|
|
|
|
|
uart_print("\n");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -127,7 +130,7 @@ int main(int argc, char **argv)
|
|
|
|
|
msleep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puts("\nWasm3 v" M3_VERSION " on Fomu, build " __DATE__ " " __TIME__ "\n");
|
|
|
|
|
uart_print("\nWasm3 v" M3_VERSION " on Fomu (" M3_ARCH "), build " __DATE__ " " __TIME__ "\n");
|
|
|
|
|
|
|
|
|
|
rgb_set(0, 0, 255);
|
|
|
|
|
if (run_wasm()) {
|
|
|
|
|