Skip to content

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

Notifications You must be signed in to change notification settings

sespinosa/reverse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published