rodrigodd/chasm-rs

A very simple compile-to-WebAssembly language

My implementation loosely follow his online demo

chasm

You can play with chasm online.

This is a rewrite in Rust of the compiler for the language chasm. chasm is a very simple programming language with a two-fold purpose:

  1. Introduce the basic building blocks of compilers - and show that they aren't that scary or difficult!
  2. Reveal some of the inner workings of WebAssembly.

chasm was first created by Colin Eberhardt to accompany a talk at FullStack Conference NYC. You can see the original implementation of the compiler here. My implementation loosely follow his blog post. His implementation uses an AST, but mine is a single-pass compiler.

Example

Below is an example of a Mandelbrot fractal renderer. Other examples can be found in the ./examples folder. You can also test these examples in the online demo.

var y = 0
while (y < 100)
  var x  = 0
  while (x < 100)
    var cr = ((y / 50) - 1.5)
    var ci = ((x / 50) - 1)

    var i = 0
    var j = 0
    var iter = 0

    while ((((i * i) + (j * j)) < 4) && (iter < 255))
      var ni = (((i * i) - (j * j)) + cr)
      j = (((2 * i) * j) + ci)
      i = ni
      iter = (iter + 1)
    endwhile
    setpixel (x, y, iter)
    x = (x + 1)
  endwhile
  y = (y + 1)
endwhile

Build and Run

CLI

You can pass a file as an argument to the CLI to run and render chasm code in the file. For example, to render the Julia set in ./examples/julia.chasm, you can run the command (assuming you are in the repo root):

cargo run -- examples/julia.chasm

If you pass any second argument it will render in the terminal as ASCII, and if you pass no argument it will run a bad REPL.

WebAssembly

To build the compiler for WebAssembly, you need to use wasm-pack:

cd chasm-wasm
wasm-pack build --release --target web

This will output a folder ./chasm-wasm/pkg with the files chasm_wasm.js and chasm_wasm_bg.wasm (and some others). You can then move these two files to ./docs to test them on the web page ./docs/index.html.

Information - Updated Aug 01, 2022

Stars: 10
Forks: 0
Issues: 0

LVGL Rust to WASM

Example of LVGL in Rust compiling to WASM

LVGL Rust to WASM

This is a minimal example of the gcode-rs crate with web assembly

1) Install Rust, wasm-pack, and &quot;rollup&quot;

This is a minimal example of the gcode-rs crate with web assembly

WASM / Rust / D3 example

Fetch data with Rust + WASM and show it with JS + D3

WASM / Rust / D3 example

Envoy proxy WASM filter with gRPC unary call (rust-sdk)

In this example, envoy WASM filter makes gRPC unary calls to an external gRPC service from both request path and response path

Envoy proxy WASM filter with gRPC unary call (rust-sdk)

A WASM binding for eciesrs

A WASM binding for this example for how to use it in browsers

A WASM binding for eciesrs

Rust WASM Web Worker Examples

This repository contains four different examples of using web workers in conjunction with WASM in

Rust WASM Web Worker Examples

jupyterlab-wasm-example

This repository is meant to be used as an example for extending JupyterLab with WebAssembly modules

jupyterlab-wasm-example

WebCam DOM Stream over WASM

You can build the example locally with:

WebCam DOM Stream over WASM

wasmCloud Examples

Example actors, capability providers, and other demonstrations

wasmCloud Examples

Modor is a modular and kind of object-oriented game engine

Web: cargo run-wasm --example &lt;name&gt; --release

Modor is a modular and kind of object-oriented game engine

wasmer-rust-embed-wasm

Example code to load a wasm file, add

wasmer-rust-embed-wasm
Facebook Instagram Twitter GitHub Dribbble
Privacy