examples/wasm/README.md
This folder contains the example WASM files which can be executed by the WasmEdge binary tools.
Most of the following examples are handwritten in WAT format. You can use WABT tool to compile it to the WASM format.
wat2wasm add.wat # This will generate add.wasm
wat2wasm fibonacci.wat # This will generate fibonacci.wasm
wat2wasm factorial.wat # This will generate factorial.wasm
The add.wat is a handwritten WebAssembly script to add two given numbers. It is compiled into WebAssembly using the WABT tool. The following example computes the result of (1+2).
$ wasmedge --reactor add.wasm add 1 2
3
The fibonacci.wat is a handwritten WebAssembly script to compute the Fibonacci sequence. It is compiled into WebAssembly using the WABT tool. The following example computes the 8th Fibonacci number.
$ wasmedge --reactor fibonacci.wasm fib 8
34
The factorial.wat is a handwritten WebAssembly script to compute factorial numbers. It is compiled into WebAssembly using the WABT tool. The following example computes 12!
$ wasmedge --reactor factorial.wasm fac 12
479001600
The hello.wasm example is a WebAssembly which compiled from a Rust application called hello, you can find it under the hello folder..
If you want to compile it, please install Rust toolchain. And then use the following commands in the hello folder:
cargo build --offline --release --target=wasm32-wasip1
# The hello.wasm will be located at `target/wasm32-wasip1/release/hello.wasm`
# Run it in the interpreter mode
$ wasmedge hello.wasm WasmEdge 1 2 3
hello
WasmEdge
1
2
3
# Run it in the AOT mode
$ wasmedge compile hello.wasm hello.aot.wasm
$ wasmedge hello.aot.wasm WasmEdge 1 2 3
hello
WasmEdge
1
2
3