All Projects → marianoguerra → ricardo-forth

marianoguerra / ricardo-forth

Licence: other
Forth dialect implemented in C, Javascript, WebAssembly and compiled from C to asm.js and WebAssembly.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to ricardo-forth

koder
QR/bar code scanner for the Browser
Stars: ✭ 73 (+180.77%)
Mutual labels:  webassembly
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (+15.38%)
Mutual labels:  webassembly
rustwasmc
Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.
Stars: ✭ 97 (+273.08%)
Mutual labels:  webassembly
image-hub
Image Hub is a sample application for exploring WebAssembly modules used as Envoy filters.
Stars: ✭ 56 (+115.38%)
Mutual labels:  webassembly
brainfuck2wasm
A brainfuck-to-WebAssembly compiler
Stars: ✭ 36 (+38.46%)
Mutual labels:  webassembly
yew-router
Router extension to yew
Stars: ✭ 27 (+3.85%)
Mutual labels:  webassembly
cat-o-licious
Cat game written in Go
Stars: ✭ 100 (+284.62%)
Mutual labels:  webassembly
libOpenDRIVE
Small, lightweight C++ library for handling OpenDRIVE files
Stars: ✭ 104 (+300%)
Mutual labels:  webassembly
samlang
Sam's Programming Language
Stars: ✭ 22 (-15.38%)
Mutual labels:  webassembly
WasmEdge-go
The GO language SDK and API for WasmEdge
Stars: ✭ 62 (+138.46%)
Mutual labels:  webassembly
Sharpen
(Demo) A v-dom "diff" engine based on WebAssembly, aim to build efficient and fluent web apps.
Stars: ✭ 20 (-23.08%)
Mutual labels:  webassembly
node-wasi
WASI for Node.js
Stars: ✭ 64 (+146.15%)
Mutual labels:  webassembly
shorelark
Simulation of life & evolution
Stars: ✭ 109 (+319.23%)
Mutual labels:  webassembly
widgets playground
Showcase example for https://github.com/therecipe/qt
Stars: ✭ 50 (+92.31%)
Mutual labels:  webassembly
warpy
WebAssembly interpreter in RPython
Stars: ✭ 54 (+107.69%)
Mutual labels:  webassembly
Uno.Themes
This library is designed to help you use the material design system with the Uno Platform
Stars: ✭ 112 (+330.77%)
Mutual labels:  webassembly
fast-base64
Fastest base64 on the web, with Wasm + SIMD
Stars: ✭ 23 (-11.54%)
Mutual labels:  webassembly
go-wasm-examples
Some small examples of using Go and WebAssembly
Stars: ✭ 22 (-15.38%)
Mutual labels:  webassembly
kotlin-gradle-templates
Quick start kotlin gradle DSL
Stars: ✭ 50 (+92.31%)
Mutual labels:  webassembly
block-aligner
SIMD-accelerated library for computing global and X-drop affine gap penalty sequence-to-sequence or sequence-to-profile alignments using an adaptive block-based algorithm.
Stars: ✭ 58 (+123.08%)
Mutual labels:  webassembly

Ricardo Forth

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:

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.

Setup Dev Environment

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

Try one example

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/

Build

make all

Files

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

Files on the build folder

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

Presentation

Slides from a presentation I gave at StuttgartJS (August 10th, 2016) are available here: WebAssembly Presentation at StuttgartJS

Resources

TODO

  • Clean, extract, reuse code from bin/*.html files
  • Create some micro benchmarks and benchmark tooling to compare execution time

Copyright Notice

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].