All Projects → almarklein → wasmfun

almarklein / wasmfun

Licence: BSD-2-Clause license
Getting the hang of WASM - generate WASM from Python

Programming Languages

HTML
75241 projects
python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects

Labels

Projects that are alternatives of or similar to wasmfun

bounce
The uncomplicated Yew State management library
Stars: ✭ 43 (+26.47%)
Mutual labels:  wasm
jupiter
Wasm smart contract networks powered by Substrate FRAME Contracts pallet in Polkadot ecosystem.
Stars: ✭ 49 (+44.12%)
Mutual labels:  wasm
wasm.cljc
Spec compliant WebAssembly compiler, decompiler, and generator
Stars: ✭ 178 (+423.53%)
Mutual labels:  wasm
boids
🦢 The boids flocking simulation in Wasm using Ebiten!
Stars: ✭ 56 (+64.71%)
Mutual labels:  wasm
rabin-wasm
Rabin fingerprinting implemented in WASM
Stars: ✭ 26 (-23.53%)
Mutual labels:  wasm
AheuiJIT
Aheui JIT compiler for PC and web
Stars: ✭ 27 (-20.59%)
Mutual labels:  wasm
wasp
🐝 Wasp : Wasm programming (language)
Stars: ✭ 93 (+173.53%)
Mutual labels:  wasm
web logger
Rust Logger for Web Browsers
Stars: ✭ 19 (-44.12%)
Mutual labels:  wasm
epick
Color picker for creating harmonic color palettes that works on Linux, Windows, macOS and web.
Stars: ✭ 89 (+161.76%)
Mutual labels:  wasm
webp-wasm
Webp image convertor (webassembly, works offline in browser)
Stars: ✭ 18 (-47.06%)
Mutual labels:  wasm
tiny-secp256k1
A tiny secp256k1 native/JS wrapper
Stars: ✭ 41 (+20.59%)
Mutual labels:  wasm
matchbox
Painless peer-to-peer WebRTC networking for rust wasm
Stars: ✭ 276 (+711.76%)
Mutual labels:  wasm
WebAssembly-in-Action
Source code for the book "WebAssembly in Action" (https://www.manning.com/books/webassembly-in-action)
Stars: ✭ 44 (+29.41%)
Mutual labels:  wasm
fastlike
Run Fastly Compute@Edge Wasm programs on your own computer, powered by wasmtime
Stars: ✭ 36 (+5.88%)
Mutual labels:  wasm
swaplink
Site to perform peer to peer atomic swaps on the Algorand blockchain
Stars: ✭ 15 (-55.88%)
Mutual labels:  wasm
rotation master
Provide conversion between the major representations of 3D rotation and visualize the orientation of a rigid body
Stars: ✭ 157 (+361.76%)
Mutual labels:  wasm
pigmnts
🎨 Color palette generator from an image using WebAssesmbly and Rust
Stars: ✭ 38 (+11.76%)
Mutual labels:  wasm
SkyEmu
Game Boy, Game Boy Color, and Game Boy Advanced Emulator
Stars: ✭ 59 (+73.53%)
Mutual labels:  wasm
n2t-wasm
Emulator for the Hack CPU.
Stars: ✭ 41 (+20.59%)
Mutual labels:  wasm
rust-wasm-loader
Webpack loader for Rust
Stars: ✭ 81 (+138.24%)
Mutual labels:  wasm

wasmfun

Getting the hang of WASM

The repository provides a (pure) Python library to generate WASM, and scripts that use it in various ways. The purpose of this code is for me to play with WASM, to get a feel for it and seeing if/how I can put it to actual use.

How to use this code

You can browse the code on Github, the readme's of most subdirs have links to html pages that show a piece of code, run the WASM that was produced from it, and show the output.

To play with this yourself, clone the repository and add the root directory to your PYTHONPATH. Needs Python 3.x, and nothing more. The (limited) docs are here.

What is WASM?

WASM, short for WebAssembly, is a low level description of a program. It is an intermediate representation (IR) that programs can be compiled to, and subsequently be translated to native instuctions by a WASM virual machine, like the browser. It is not dissimilar from LLVM IR, but is targeted to be able to run in browsers.

Check out the links down below for (much) more info.

WASM comes with a text and binary format. The x.wasm extension is for the binary format, x.wat is the text format. The browser can only read the binary.

There ought to be a 1-to-1 relationship between the WASM text format and the binary format. However, it looks like there are currently multiple variants of the text format floating around in the web. Perhaps its still under change. Also, the relation is not so direct that you can map "fields" 1-on-1; there is some compilation/interpretation needed. This is why this code only works with the binary format.

WASM is pretty darn cool

WASM is primarily made to allow programs written in C/C++ to be run on the web. They already could, sort of, via ASM.js, but WASM makes this much more well-defined and faster (in terms of load time and run-time performance).

But that's not why I find it so interesting. I'm looking at WASM as a compilation target for dynamic languages, like Python, or perhaps new languages. Because WASM must be able to run in the browser, it has some interesting features w.r.t. ease of distribution, safety, etc.

It's important to realize that although WASM is designed to be able to run in the browser, it has no dependencies on anything "web". Running on the desktop, or mobile devices, or other is an equally important goal of WASM. This means that any language compiled to WASM can basically run anywhere. This means that any language compiled to WASM can basically run anywhere. I intentionally repeated that sentence because its really a big thing! Most modern browsers already support WASM, and there are already projects that can run it on desktop too, or e.g. in the JVM.

WASM is inherently safe and has no way (by itself) to e.g. access the file system. Functionality like this is provided by the host environment via an import mechanism, the same that is used to dynamically link multiple WASM modules together. This makes a clear separation. E.g. code on the web can access the DOM, code on desktop can access the file system. Also, new programming languages can piggy back on the host environment by letting it provide functionality for e.g. logging, math, regexp, etc.

Another nice feature (observed by Rasmus Andersson) is that WASM can also be interpreted/emulated instead of being compiled to machince code. Although it will be much slower, it allows for awesome debugging capabilities. Basically, debug like you do with Python, with a language that's nearly as fast as C.

In this repo

wasmfun: I (partly) implemented an internal representation of (binary) WASM that can be exported to a .wasm file. One can write WASM directly (in Python) using the classes of this internal representation. Or one can use it as a compilation target (i.e. use it as the target AST) for new/toy languages.

play_manual: Using the above tool, you can manually write apps in "raw WASM". A bit tedious, but it works!

play_calc: Implementation of a real simple "programming language" that basically acts like a calculator, which is compiled to WASM.

brainfuck A compiler of brainfuck to WASM.

simplepy: A compiler for a very-strict-subset of Python to WASM.

zoof: An experimental language with a very friendly syntax that compiles to WASM. The parsing and compiling is implemented in Python, but it could eventually be self-hosting, which is when it will start to be come real interesting ...

Links

Official and most generally useful:

Some posts that I found useful:

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].