Skip to content

Commit

Permalink
Update to v0.4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Dec 28, 2020
1 parent d43f26e commit 66ca1a3
Show file tree
Hide file tree
Showing 26 changed files with 903 additions and 589 deletions.
8 changes: 7 additions & 1 deletion examples/Wasm_Blink/Wasm_Blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ void wasm_task(void*)
Serial.print(" (");
Serial.print(info.message);
Serial.println(")");
if (info.file && strlen(info.file) && info.line) {
Serial.print("At ");
Serial.print(info.file);
Serial.print(":");
Serial.println(info.line);
}
}
}

Expand All @@ -224,7 +230,7 @@ void setup()
// Needed for native USB port only
while(!Serial) {}

Serial.println("\nWasm3 v" M3_VERSION ", build " __DATE__ " " __TIME__);
Serial.println("\nWasm3 v" M3_VERSION " (" M3_ARCH "), build " __DATE__ " " __TIME__);

#ifdef ESP32
// On ESP32, we can launch in a separate thread
Expand Down
119 changes: 119 additions & 0 deletions examples/Wasm_Fibonacci/Wasm_Fibonacci.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Wasm3 - high performance WebAssembly interpreter written in C.
* Copyright © 2020 Volodymyr Shymanskyy, Steven Massey.
* All rights reserved.
*/

#include <wasm3.h>
#include <m3_env.h>

/*
* Configuration
*/
#define FIB_ARG "24"
#define WASM_STACK_SLOTS 1024

/*
* WebAssembly app (recursive Fibonacci)
*/

unsigned char fib_wasm[] = {
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03,
0x66, 0x69, 0x62, 0x00, 0x00, 0x0a, 0x1f, 0x01, 0x1d, 0x00, 0x20, 0x00,
0x41, 0x02, 0x49, 0x04, 0x40, 0x20, 0x00, 0x0f, 0x0b, 0x20, 0x00, 0x41,
0x02, 0x6b, 0x10, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6b, 0x10, 0x00, 0x6a,
0x0f, 0x0b
};

/*
* Engine start, liftoff!
*/

#define FATAL(func, msg) { Serial.print("Fatal: " func " "); Serial.println(msg); return; }
#define TSTART() { tstart = micros(); }
#define TFINISH(s) { tend = micros(); Serial.print(s " in "); Serial.print(tend-tstart); Serial.println(" us"); }

void wasm_task(void*)
{
uint32_t tend, tstart;
TSTART();

M3Result result = m3Err_none;

IM3Environment env = m3_NewEnvironment ();
if (!env) FATAL("NewEnvironment", "failed");

IM3Runtime runtime = m3_NewRuntime (env, WASM_STACK_SLOTS, NULL);
if (!runtime) FATAL("NewRuntime", "failed");

IM3Module module;
result = m3_ParseModule (env, &module, fib_wasm, sizeof(fib_wasm)-1);
if (result) FATAL("ParseModule", result);

result = m3_LoadModule (runtime, module);
if (result) FATAL("LoadModule", result);

IM3Function f;
result = m3_FindFunction (&f, runtime, "fib");
if (result) FATAL("FindFunction", result);

TFINISH("Init");

Serial.println("Running fib(" FIB_ARG ")...");

TSTART();

const char* i_argv[2] = { FIB_ARG , NULL };
result = m3_CallWithArgs (f, 1, i_argv);

TFINISH("Done");

if (result == m3Err_none) {
uint32_t value = *(uint32_t*)(runtime->stack);
Serial.print("Result: ");
Serial.println(value);
} else {
M3ErrorInfo info;
m3_GetErrorInfo (runtime, &info);
Serial.print("Error: ");
Serial.print(result);
Serial.print(" (");
Serial.print(info.message);
Serial.println(")");
if (info.file && strlen(info.file) && info.line) {
Serial.print("At ");
Serial.print(info.file);
Serial.print(":");
Serial.println(info.line);
}
}
#ifdef ESP32
vTaskDelete(NULL);
#endif
}

void setup()
{
Serial.begin(115200);
delay(100);

// Wait for serial port to connect
// Needed for native USB port only
while(!Serial) {}

Serial.println("\nWasm3 v" M3_VERSION " (" M3_ARCH "), build " __DATE__ " " __TIME__);

#ifdef ESP32
// On ESP32, we can launch in a separate thread (with 16Kb stack)
Serial.println("Running a separate task");
xTaskCreate(&wasm_task, "wasm3", 16*1024, NULL, 5, NULL);
#else
wasm_task(NULL);
#endif
}

void loop()
{
delay(100);
}
14 changes: 14 additions & 0 deletions examples_pio/Wasm_Advanced/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ src_build_flags =
-DESP8266 -Dd_m3FixedHeap=0x6000
-O3 -flto

[env:AdafruitPyBadge]
platform = atmelsam
board = adafruit_pybadge_m4

src_build_flags =
${env.src_build_flags}
-DLED_PIN=13
-O3 -flto

#build_flags =
# -Dd_m3LogNativeStack=1
# -Dd_m3LogOutput=1
# -Dd_m3VerboseLogs=1

[env:Arduino101]
platform = intel_arc32
board = genuino101
Expand Down
8 changes: 7 additions & 1 deletion examples_pio/Wasm_Advanced/wasm_vm/wasm_vm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ void wasm_task(void*)
Serial.print(" (");
Serial.print(info.message);
Serial.println(")");
if (info.file && strlen(info.file) && info.line) {
Serial.print("At ");
Serial.print(info.file);
Serial.print(":");
Serial.println(info.line);
}
}
}

Expand All @@ -218,7 +224,7 @@ void setup()
// Needed for native USB port only
while(!Serial) {}

Serial.println("\nWasm3 v" M3_VERSION ", build " __DATE__ " " __TIME__);
Serial.println("\nWasm3 v" M3_VERSION " (" M3_ARCH "), build " __DATE__ " " __TIME__);

#ifdef ESP32
// On ESP32, we can launch in a separate thread
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Wasm3",
"version": "0.4.5",
"version": "0.4.8",
"description": "The fastest WebAssembly interpreter. It allows you to run WASM files directly on a wide range of devices, including microcontrollers, routers, smartphones and of course within browsers.",
"keywords": "esp32, esp8266, wasm, webassembly, interpreter, iot, edge computing",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Wasm3
version=0.4.5
version=0.4.8
author=Volodymyr Shymanskyy <vshymanskyi@gmail.com>, Steven Massey <soundandform@gmail.com>
license=MIT
maintainer=Volodymyr Shymanskyy <vshymanskyi@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion src/m3_api_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define m3ApiGetArg(TYPE, NAME) TYPE NAME = * ((TYPE *) (_sp++));
#define m3ApiGetArgMem(TYPE, NAME) TYPE NAME = (TYPE)m3ApiOffsetToPtr(* ((u32 *) (_sp++)));

#define m3ApiRawFunction(NAME) const void * NAME (IM3Runtime runtime, uint64_t * _sp, void * _mem)
#define m3ApiRawFunction(NAME) const void * NAME (IM3Runtime runtime, uint64_t * _sp, void * _mem, void * userdata)
#define m3ApiReturn(VALUE) { *raw_return = (VALUE); return m3Err_none; }
#define m3ApiTrap(VALUE) { return VALUE; }
#define m3ApiSuccess() { return m3Err_none; }
Expand Down
1 change: 0 additions & 1 deletion src/m3_api_libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ m3ApiRawFunction(m3_libc_memset)
m3ApiReturn(result);
}


m3ApiRawFunction(m3_libc_memmove)
{
m3ApiReturnType (int32_t)
Expand Down
Loading

0 comments on commit 66ca1a3

Please sign in to comment.