A Forth dialect implemented in C, Javascript, WebAssembly and compiled from C to asm.js and WebAssembly.
This project is based on the 1992 IOCCC entry buzzard.2 (design notes: buzzard.2.design), prettified and then compiled to:
- asmjs using emscripten
- WebAssembly using Binaryen
Also reimplemented by translating the C code into Javascript and WebAssebly.
To read the process of prettifying the C code follow the buzzard.c commits in chronological order.
Pre setup (I assume ubuntu or debian derivative, see here for instructions to build on windows):
sudo apt-get update sudo apt-get -y install build-essential cmake nodejs default-jre
git clone -b incoming --depth 1 https://github.com/kripken/emscripten-fastcomp llvm git clone -b incoming --depth 1 https://github.com/kripken/emscripten-fastcomp-clang llvm/tools/clang git clone -b incoming --depth 1 https://github.com/kripken/emscripten emsdk git clone --depth 1 https://github.com/WebAssembly/binaryen binaryen mkdir llvm/build mkdir binaryen/build cd llvm/build cmake .. -DCMAKE_INSTALL_PREFIX=.. \ -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;JSBackend" \ -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DLLVM_INCLUDE_EXAMPLES=OFF \ -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_EXAMPLES=OFF -DCLANG_INCLUDE_TESTS=OFF cmake --build . --target install --config Release cd ../../binaryen/build cmake .. -DCMAKE_INSTALL_PREFIX=.. -DBUILD_STATIC_LIB=ON cmake --build . --target install --config Release cd ../../ # this should go in a more permanent place like .bashrc or equivalent export PATH=$PATH:$PWD/llvm/bin/:$PWD/emsdk/:$PWD/binaryen/bin/ # Run the command so it generates basic configuration em++
Now edit emscripten configuration file:
edit $HOME/.emscripten
git clone https://github.com/qis/wasm wasm-example cd wasm-example em++ -Os -std=c++14 -s BINARYEN=1 -s "BINARYEN_METHOD='native-wasm'" \ --memory-init-file 1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s MODULARIZE=1 \ -s "EXPORT_NAME='main'" -s NO_EXIT_RUNTIME=1 -s USE_GLFW=3 main.cc -o main.js python -m SimpleHTTPServer firefox http://localhost:8000/
make all
- src/buzzard.c
- Prettified version of original buzzard.2.orig.c. Used to generate the native binary, asmjs and wasm versions.
- src/buzzard.js
- Translation of buzzard.c by hand to vanilla js
- src/first.wast
- Translation of buzzard.c by hand to WebAssembly text format
- src/clib.js
- JS implementations of c functions from buzzard.c too simulate i/o
- src/buzzard-emcc.html
- HTML page used to run the asmjs version, allows input in text area
- src/buzzard-emcc.pre.js
- Initialization code for buzzard-emcc.html
- src/buzzard-binaryen.html
- HTML page used to run the wasm version, allows input in text area
- test/index.html
- Unit tests for buzzard.js
- test/tests.js
- Unit tests for buzzard.js
- examples/demo1.1st
- Hello world program
- examples/min.1st
- Simplest program that runs to completion
- examples/third
- Implementation of the forth dialect bootstraping from minimal interpreter
- examples/demo[1-5].th
- 5 Demos that run on top of third (third must be provided as input before this examples)
- docs/*
- Documentation about buzzard from the IOCCC site, kept here too to have all the info in the repo
This files are generated during make all.
- bin/first
- binary from buzzard.c
- bin/first.wasm
- WebAssembly version of src/first.wast, compiled with wasm-as
- bin/buzzard-binaryen.*
- Files from c -> wasm translation
- bin/buzzard-emcc.*
- Files from c -> asmjs translation
Slides from a presentation I gave at StuttgartJS (August 10th, 2016) are available here: WebAssembly Presentation at StuttgartJS
- WebAssembly demos
- WebAssembly Explorer
- ast.run WebAssembly playground
- Prototype Spec in Markdown
- JS-like proposal from FF Nightly
- Wasm example and instructions to build on windows
- emscripten's emsdk/src/settings.js contains docs about the flags that can be passed to emcc
- Future of Binaryen in a stack machine world?
- Luke Wagner -on- WebAssembly: A New Compiler Target For The Web
- Ben Titzer @ VMSS16: A Little on V8 and WebAssembly
- Emscripten and WebAssembly by Alon Zakai / @kripken
- Build Your First Thing With WebAssembly
- A Particle System experiment designed to benchmark web technologies from a non trivial piece of code: ES6, Emscripten and Web Assembly
- SHA-3 (Keccak padding) in WebAssembly WAST
- Experimental programming language that compiles to both WebAssembly and JavaScript
- Oryol 3D Engine Demos in asm.js and wasm
- wast -> forth
- WASM Pilot Text Format Playground
- gh/drom wasm/wast related projects
- Clean, extract, reuse code from bin/*.html files
- Create some micro benchmarks and benchmark tooling to compare execution time
The following files are copyright Landon Curt Noll & Larry Bassel. See COPYRIGHT for more details:
- src/buzzard.c
- examples/*
- docs/*
All other files were created by Mariano Guerra, licensed under MIT License