Skip to content

Commit 6cd2bf6

Browse files
Patch v0.2.3 (#142)
* Refactor: remove prefix in when not debugging * Fix: splitting of spec tests in run_spec_tests.py Only first module was kept. New script creates module and asserts files for all modules in a source spec test file. * Update ignore.txt * Fix/upload (#139) * Fix upload for modules without main * Add INIT mode to disable dbg msg during loading of modules * Only print Ack after successful module update * simplify smart lamp example (#72) * Simplify example code * Fix: add missing build.sh script to examples * Update WAT examples * Fix: update boilerplate code in rust example * Fix example compilation --------- Co-authored-by: tolauwae <[email protected]> * Update README.md (#141) * Feat/invoke (#140) * Add argument values to invoke function * Add option to cli * Fix: module needs to be loaded to get parameters for invoked function Removes the `--file` option Fix wrong number of arguments check * Fix: `--paused` option always false * Fix: wrong magic number in spec tests Adds `--test` option * Add `interruptINVOKE` Move readArgs code from Proxy to util.cpp * Fix: IDF compilation error on print format * Fix: out of range fidx in invoke message * Fix: use LEB128 encoding in invoke debug message * VM waits when no `main` function is found * Fix: wrong program state during debug invoke Invoke from debugger now dumps the stack at the end * Fix: only first argument is copied to stack in `invoke` * Fix: trailing comma in stack dump * Fix: clang format * Add reset interrupt * Fix: off-by-one error in dump stack Missing comma in JSON. * Fix: splitting of spec tests in run_spec_tests.py Only first module was kept. New script creates module and asserts files for all modules in a source spec test file. * Fix: wrong arg types in invoke from main * Fix: print floating points as hexstrings * Fix: do not use LEB for floats * Clang format * Fix: print floats as strings * Remove upload.h from version control * Define VERSION in Cmake + bump to 0.2.3 --------- Co-authored-by: Robbert Gurdeep Singh <[email protected]>
1 parent 5ac7419 commit 6cd2bf6

File tree

27 files changed

+323
-97
lines changed

27 files changed

+323
-97
lines changed

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ option(BUILD_ESP "Build for esp" OFF)
55
option(BUILD_EMULATOR "Build for emulator" OFF)
66
option(BUILD_UNITTEST "Build for testing" OFF)
77

8+
if (ESP_PLATFORM)
9+
set(BUILD_ESP ON)
10+
endif()
811

912
if (NOT BUILD_ESP AND NOT BUILD_EMULATOR AND NOT BUILD_UNITTEST)
1013
message(WARNING "No build target set. Nothing to do.")
@@ -20,10 +23,13 @@ if (BUILD_ESP)
2023

2124
set(EXTRA_COMPONENT_DIRS "platforms/ESP-IDF")
2225

23-
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
26+
include($ENV{IDF_PATH}/tools/cmake/project.cmake "${PROJECT_BINARY_DIR}/../include")
2427
endif (BUILD_ESP)
2528

26-
project(WARDuino)
29+
project(WARDuino VERSION 0.2.3)
30+
31+
set(WARDUINO_VERSION_STRING "${PROJECT_VERSION}")
32+
configure_file(src/config.h.in include/warduino/config.h)
2733

2834
# Build the emulator version of WARDuino
2935
if (BUILD_EMULATOR)
@@ -67,7 +73,7 @@ if (BUILD_EMULATOR)
6773
# WARDuino CLI
6874
add_executable(wdcli platforms/CLI-Emulator/main.cpp ${SOURCE_FILES} ${TEST_FRAMEWORK})
6975
target_link_libraries(wdcli PRIVATE Threads::Threads)
70-
target_include_directories(wdcli PRIVATE ${EXTERNAL_LIB_HEADERS})
76+
target_include_directories(wdcli PRIVATE ${EXTERNAL_LIB_HEADERS} "${PROJECT_BINARY_DIR}/include")
7177
endif (BUILD_EMULATOR)
7278

7379
if(BUILD_UNITTEST)
@@ -124,7 +130,7 @@ if(BUILD_UNITTEST)
124130
message(DEBUG "Add executable for " ${TEST_FILE})
125131
add_executable(${TEST_NAME} ${TEST_FILE} ${SOURCE_FILES})
126132
target_link_libraries(${TEST_NAME} gtest_main)
127-
target_include_directories(${TEST_NAME} PRIVATE ${EXTERNAL_LIB_HEADERS})
133+
target_include_directories(${TEST_NAME} PRIVATE ${EXTERNAL_LIB_HEADERS} "${PROJECT_BINARY_DIR}/include")
128134
add_test(${TEST_NAME} ${TEST_NAME})
129135
endforeach()
130136
endif(BUILD_UNITTEST)

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
1-
<h1 align="center">WARDuino</h1>
1+
<div align="center">
2+
<h1>WARDuino</h1>
23

3-
<p align="center">
4-
<a href="https://github.com/TOPLLab/WARDuino/actions/workflows/compile.yml"><img src="https://github.com/TOPLLab/WARDuino/actions/workflows/compile.yml/badge.svg"></a>
5-
<a href="https://github.com/TOPLLab/WARDuino/actions/workflows/test.yml"><img src="https://github.com/TOPLLab/WARDuino/actions/workflows/test.yml/badge.svg"></a>
6-
<a href="https://github.com/TOPLLab/WARDuino/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MPL_2.0-blue.svg"></a>
7-
</p>
4+
<p>
5+
<strong>Wasm virtual machine for ESP32 / Arduino</strong>
6+
</p>
7+
8+
<p>
9+
<a href="https://github.com/TOPLLab/WARDuino/actions/workflows/compile.yml"><img src="https://github.com/TOPLLab/WARDuino/actions/workflows/compile.yml/badge.svg"></a>
10+
<a href="https://github.com/TOPLLab/WARDuino/actions/workflows/test.yml"><img src="https://github.com/TOPLLab/WARDuino/actions/workflows/test.yml/badge.svg"></a>
11+
<a href="https://github.com/TOPLLab/WARDuino/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MPL_2.0-blue.svg"></a>
12+
</p>
13+
14+
<h4>
15+
<a href="./README.md#build-and-development-instructions">Installation</a>
16+
<span> | </span>
17+
<a href="./examples/">Examples</a>
18+
<span> | </span>
19+
<a href="./README.md#webassembly-specification-tests">Run Specification tests</a>
20+
<span> | </span>
21+
<a href="./documentation/">Documentation</a>
22+
</h4>
23+
24+
</div>
25+
26+
## About
827

928
This project is released under the Mozilla Public License 2.0, and is being developed as part of an active research project at the University of Ghent's [TOPL Lab](https://github.com/TOPLLab).
1029

11-
The WARDuino virtual machine is a WebAssembly runtime for microcontrollers, which runs both under the Arduino and ESP-IDF toolchains.
12-
The WARDuino project also includes a [VS Code extension](https://github.com/TOPLLab/WARDuino-VSCode) to use both the remote debugging and the out-of-place debugging facilities offered by the virtual machine.
30+
+ The WARDuino virtual machine is a WebAssembly runtime for microcontrollers, which runs both under the Arduino and ESP-IDF toolchains.
31+
+ The WARDuino virtual machine features an extensive debugger with novel techniques such as out-of-place debugging.
32+
+ The virtual machine allows developers to implement their own primitives in C++, which are callable from Wasm.
33+
+ The WARDuino project also includes a [VS Code extension](https://github.com/TOPLLab/WARDuino-VSCode) to use both the remote debugging and the out-of-place debugging facilities offered by the virtual machine.
1334

14-
<p align="center">
15-
<a href="./README.md#build-and-development-instructions">Installation</a> | <a href="./examples/">Examples</a> | <a href="./README.md#webassembly-specification-tests">Run Specification tests</a> | <a href="./documentation/">Documentation</a>
16-
</p>
35+
*Note: WARDuino is not 1.0, since this is an active research project. Expect possible bugs or performance issues.*
1736

1837
## Build and Development Instructions
1938

examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
sdkconfig
22
*.wasm
33
*.wasm.h
4+
5+
!build.sh

examples/assemblyscript/main/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ set(SOURCE_FILES
22
../../../src/Memory/mem.cpp
33
../../../src/Utils/util.cpp
44
../../../src/Utils/util_arduino.cpp
5+
../../../src/Utils/sockets.cpp
56
../../../src/Debug/debugger.cpp
7+
../../../src/Edward/proxy.cpp
8+
../../../src/Edward/proxy_supervisor.cpp
9+
../../../src/Edward/RFC.cpp
610
../../../src/Utils/macros.cpp
711
../../../src/WARDuino/WARDuino.cpp
812
../../../src/Primitives/emulated.cpp
913
../../../src/Interpreter/instructions.cpp
1014
../../../src/WARDuino/CallbackHandler.cpp
1115
)
1216

13-
idf_component_register(SRCS "main.cpp" ${SOURCE_FILES} INCLUDE_DIRS "" REQUIRES driver)
17+
idf_component_register(SRCS "main.cpp" ${SOURCE_FILES} INCLUDE_DIRS ../../../lib/json/single_include/ REQUIRES driver)
1418

1519
add_definitions(-DESP=1)
1620

examples/assemblyscript/main/main.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,28 @@ extern "C" {
2222
extern void app_main(void);
2323
}
2424

25-
WARDuino wac;
2625
Module* m;
2726

2827
void startDebuggerStd(void* pvParameter) {
2928
int valread;
3029
uint8_t buffer[1024] = {0};
31-
wac.debugger->socket = fileno(stdout);
30+
Channel* duplex = new Duplex(stdin, stdout);
31+
WARDuino::instance()->debugger->channel = duplex;
3232
while (true) {
3333
taskYIELD();
3434
vTaskDelay(1000 / portTICK_PERIOD_MS);
3535

36-
while ((valread = read(fileno(stdin), buffer, 1024)) != -1) {
37-
write(fileno(stdout), "got a message ... \n", 19);
38-
wac.handleInterrupt(valread - 1, buffer);
39-
write(fileno(stdout), buffer, valread);
40-
fflush(stdout);
36+
while ((valread = duplex->read(buffer, 1024)) != -1) {
37+
WARDuino::instance()->handleInterrupt(valread, buffer);
4138
}
4239
}
4340
}
4441

4542
void app_main(void) {
46-
m = wac.load_module(src_wasm, src_wasm_len, {});
43+
m = WARDuino::instance()->load_module(src_wasm, src_wasm_len, {});
4744
xTaskCreate(startDebuggerStd, "Debug Thread", 5000, NULL, 1, NULL);
4845
printf("START\n\n");
49-
wac.run_module(m);
46+
WARDuino::instance()->run_module(m);
5047
printf("END\n\n");
51-
wac.unload_module(m);
48+
WARDuino::instance()->unload_module(m);
5249
}

examples/assemblyscript/main/smartlamp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function main(): void {
5151
wd.mqtt_init("192.168.0.24", 1883);
5252
until_connected(
5353
() => { wd.mqtt_connect(CLIENT_ID); wd.mqtt_loop(); },
54-
() => { return wd.mqtt_connected(); },
54+
wd.mqtt_connected,
5555
() => { return true; });
5656

5757
// Subscribe to MQTT topic and turn on LED
@@ -60,11 +60,11 @@ export function main(): void {
6060

6161
// Subscribe to button interrupt
6262
wd.interrupt_on(BUTTON, wd.CHANGED, toggle_led);
63-
63+
6464
while (true) {
6565
until_connected(
6666
() => { wd.mqtt_connect(CLIENT_ID); wd.mqtt_loop(); },
67-
() => { return wd.mqtt_connected(); },
67+
wd.mqtt_connected,
6868
() => { return true; });
6969

7070
wd.sleep(5); // Sleep for 5 seconds

examples/rust/main/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ set(SOURCE_FILES
22
../../../src/Memory/mem.cpp
33
../../../src/Utils/util.cpp
44
../../../src/Utils/util_arduino.cpp
5+
../../../src/Utils/sockets.cpp
56
../../../src/Debug/debugger.cpp
7+
../../../src/Edward/proxy.cpp
8+
../../../src/Edward/proxy_supervisor.cpp
9+
../../../src/Edward/RFC.cpp
610
../../../src/Utils/macros.cpp
711
../../../src/WARDuino/WARDuino.cpp
812
../../../src/Primitives/emulated.cpp
913
../../../src/Interpreter/instructions.cpp
1014
../../../src/WARDuino/CallbackHandler.cpp
1115
)
1216

13-
idf_component_register(SRCS "main.cpp" ${SOURCE_FILES} INCLUDE_DIRS "" REQUIRES driver)
17+
idf_component_register(SRCS "main.cpp" ${SOURCE_FILES} INCLUDE_DIRS ../../../lib/json/single_include/ REQUIRES driver)
1418

1519
add_definitions(-DESP=1)
1620

examples/rust/main/main.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,30 @@ extern "C" {
2222
extern void app_main(void);
2323
}
2424

25-
WARDuino wac;
2625
Module* m;
2726

2827
void startDebuggerStd(void* pvParameter) {
28+
Channel* duplex = new Duplex(stdin, stdout);
29+
WARDuino::instance()->debugger->setChannel(duplex);
30+
duplex->open();
31+
2932
int valread;
3033
uint8_t buffer[1024] = {0};
31-
wac.debugger->socket = fileno(stdout);
3234
while (true) {
3335
taskYIELD();
3436
vTaskDelay(1000 / portTICK_PERIOD_MS);
3537

36-
while ((valread = read(fileno(stdin), buffer, 1024)) != -1) {
37-
write(fileno(stdout), "got a message ... \n", 19);
38-
wac.handleInterrupt(valread - 1, buffer);
39-
write(fileno(stdout), buffer, valread);
40-
fflush(stdout);
38+
while ((valread = duplex->read(buffer, 1024)) != -1) {
39+
WARDuino::instance()->handleInterrupt(valread - 1, buffer);
4140
}
4241
}
4342
}
4443

4544
void app_main(void) {
46-
m = wac.load_module(src_wasm, src_wasm_len, {});
45+
m = WARDuino::instance()->load_module(src_wasm, src_wasm_len, {});
4746
xTaskCreate(startDebuggerStd, "Debug Thread", 5000, NULL, 1, NULL);
4847
printf("START\n\n");
49-
wac.run_module(m);
48+
WARDuino::instance()->run_module(m);
5049
printf("END\n\n");
51-
wac.unload_module(m);
50+
WARDuino::instance()->unload_module(m);
5251
}

examples/wat/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
cmake_minimum_required(VERSION 3.5)
22

3+
if (NOT EXISTS $ENV{IDF_PATH}/tools/cmake/project.cmake)
4+
message(FATAL_ERROR
5+
"Cannot find global project.cmake file. Make sure ESP-IDF is installed.")
6+
endif ()
7+
38
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4-
project(blink)
9+
project(wat)
510

examples/wat/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Blink in WAT
1+
# Examples in Textual WebAssembly
22

3-
This example implements the traditional "blinking LED" example for microcontrollers in WebAssembly Text Format (WAT).
3+
The `main` folder contains example programs written in textual WebAssembly.
4+
5+
## Compiling and Running the Examples
46

57
To compile and flash to an ESP32 with the ESP-IDF toolchain simply run the build script:
68

@@ -10,3 +12,17 @@ bash ./build.sh blink
1012

1113
The script takes the name of a wat file from the main folder as argument (without extension).
1214

15+
## Blink example
16+
17+
The `blink.wat` file implements the traditional "blinking LED" example for microcontrollers in WebAssembly Text Format (WAT).
18+
19+
## Factorial example
20+
21+
The `fac.wat` file implements the traditional wasm example. The program prints `5!` to the serial port in an infinite loop.
22+
23+
This is also an interesting example to run with the commandline interface:
24+
25+
```bash
26+
wdcli fac.wasm --invoke fac 10
27+
```
28+

0 commit comments

Comments
 (0)