Scripting with WASM
Last updated
Last updated
WebAssembly (WASM) technology allows a program compiler to target a generic CPU. The program the runs the compiled code is called a web assembly run time. This technology is included in the IO app. Please note WebAssembly has nothing to do with the Web - its just where the origin of the technology came from.
Example wasm projects are available from the FreeWili Github:
Users can compile programs, store them in the Free Wil-i's file system and execute them. Either on demand or at power up.
Free Wil-i uses the WASM 3 run time. https://github.com/wasm3/wasm3
The Free Wil-i IO app implement APIs to control FW and provides them to the run time. These APIs are defined in a header file called "fwwasm.h"
The recommend toolset to compile for Free Wil-i wasm is the wasi sdk https://github.com/WebAssembly/wasi-sdk . For a development IDE visual studio code or CLion is recommended.
In the settings menu you can select a WASM file to run on start -up. This will run anytime Free Wil-i is powered on. Otherwise you can start WASM files from the serial menu.
Many tools compile binaries that use too many memory pages. FreeWili only supports 2 (128Kb). Ensure that the stack size of your binary is limited in this way. Please see the github examples for the necessary command line switches need to do this.
A good tool for trouble shooting WASM files is the web assembly explorer.