Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.53 KB

README.md

File metadata and controls

61 lines (43 loc) · 1.53 KB

Reverse

Simple program that receives lines of strings via stdin and writes the string reverted to stdout.

for example:

echo "Hello" | ./bin/reverse

returns:

olleH

Options

Currently, the only option available is -v (verbose), this prints the output with the original word and an arrow to the reversed word ({original string} -> {reversed string}):

echo "Hello" | ./bin/reverse -v
Hello -> olleH

Build requirements.

You need zig installed to build this using the ./build.sh script.

./build.sh

This builds the ELF binary and the wasm32-wasi binary (in ./bin and ./wasm).

Running the WASI module

This can be run with any capable runtime available (Rust, Go, Node, etc), but I personally recommend using wasmtime, for example:

echo "Hello" | wasmtime ./wasm/reverse.wasm

also returns:

olleH

Test

I provide a list of words to reverse (97565 words, one per line in ./test-data/common-words.txt) so you can test it against a long list of words like this,

with the ELF binary:

cat ./test-data/common-words.txt | ./bin/reverse

and the wasm32-wasi binary:

cat ./test-data/common-words.txt | wasmtime ./wasm/reverse.wasm

Motivation

This is just a experiment to see how wasi behaves when there's backpressure involved and also to have a reference implementation of a simple algorithm in C trying to follow some POSIX conventions.