All Projects → mbasso → watpl

mbasso / watpl

Licence: MIT license
Create WebAssembly modules using template strings

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to watpl

Cranelift
Cranelift code generator
Stars: ✭ 2,485 (+17650%)
Mutual labels:  wasm
Rust Yew Realworld Example App
Exemplary real world app built with Rust + Yew + WebAssembly
Stars: ✭ 249 (+1678.57%)
Mutual labels:  wasm
hash-wasm
Lightning fast hash functions using hand-tuned WebAssembly binaries
Stars: ✭ 382 (+2628.57%)
Mutual labels:  wasm
Rhino3dm
Libraries based on OpenNURBS with a RhinoCommon style
Stars: ✭ 232 (+1557.14%)
Mutual labels:  wasm
Wasmtime Go
Go WebAssembly runtime powered by Wasmtime
Stars: ✭ 239 (+1607.14%)
Mutual labels:  wasm
Lightbeam
Lightbeam has moved and now lives in the Wasmtime repository!
Stars: ✭ 253 (+1707.14%)
Mutual labels:  wasm
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+18500%)
Mutual labels:  wasm
aWsm
WebAssembly ahead-of-time compiler and runtime. Focuses on generating fast code, simplicity, and portability.
Stars: ✭ 177 (+1164.29%)
Mutual labels:  wasm
Wasmer Postgres
💽🕸 Postgres library to run WebAssembly binaries.
Stars: ✭ 245 (+1650%)
Mutual labels:  wasm
python-wasm
Build scripts and configuration for building CPython for Emscripten
Stars: ✭ 606 (+4228.57%)
Mutual labels:  wasm
Awesome Wasm Langs
😎 A curated list of languages that compile directly to or have their VMs in WebAssembly
Stars: ✭ 2,966 (+21085.71%)
Mutual labels:  wasm
Moonzoon
Rust Fullstack Framework
Stars: ✭ 244 (+1642.86%)
Mutual labels:  wasm
Tfjs
A WebGL accelerated JavaScript library for training and deploying ML models.
Stars: ✭ 15,834 (+113000%)
Mutual labels:  wasm
Wasm
WebAssembly decoder & disassembler library
Stars: ✭ 230 (+1542.86%)
Mutual labels:  wasm
glicol
(Audio) graph-oriented live coding language and music DSP library written in Rust
Stars: ✭ 853 (+5992.86%)
Mutual labels:  wasm
Wasm By Example
Wasm By Example is a website with a set of hands-on introduction examples and tutorials for WebAssembly (Wasm)
Stars: ✭ 226 (+1514.29%)
Mutual labels:  wasm
Prism
Build frontend web apps with Ruby and WebAssembly
Stars: ✭ 251 (+1692.86%)
Mutual labels:  wasm
emscripten-webxr
WebXR library for use with Emscripten.
Stars: ✭ 21 (+50%)
Mutual labels:  wasm
vgg runtime
VGG Runtime for loading and running designs as apps.
Stars: ✭ 19 (+35.71%)
Mutual labels:  wasm
Yew
Yew is a modern Rust framework for creating multi-threaded front-end web apps with WebAssembly.
Stars: ✭ 18,243 (+130207.14%)
Mutual labels:  wasm

watpl

Build Status npm version npm downloads Coverage Status MIT Donate

Create WebAssembly modules using template strings

Installation

You can install watpl using npm:

npm install --save watpl

If you aren't using npm in your project, you can include watpl using UMD build in the dist folder with <script> tag.

Usage

Once you have installed watpl, supposing a CommonJS environment, you can import and use it in this way:

import watpl from "watpl";

(async () => {
  // create a template
  const createAddModule = watpl`
    (module
      (func (param $lhs i32) (param $rhs i32) (result i32)
        get_local $lhs
        i32.const ${options => options.number}
        i32.add)
      (export "run" (func 0))
    )
  `;

  // create a module that adds 2
  const add2 = createAddModule({
    number: 2
  });

  // instantiate and run the module
  const instance = await add2.instantiate();
  instance.exports.run(3); // 5 = 3 + 2
})();

API

type WasmModule = {
  // created module as string
  string: string,
  // created module as buffer
  buffer: ArrayBuffer,
  // created WebAssembly module
  module: Promise<WebAssembly.Module>,
  // instantiate the module with the given importObject
  instantiate: (importObject: Object) => Promise<WebAssembly.Instance>,
  // cleanup the module
  destroy: () => void,
  toString: () => string
};

watpl`
  wat code
`: (options: any) => WasmModule

Browser support

watpl uses WebAssembly APIs, they are broadly supported by major browser engines but you would like to polyfill them to support old versions.

if (typeof WebAssembly === 'undefined') {
  ...
} else {
  ...
}

Inspiration

This project is inspired by this tweet of @rhmoller.

Change Log

This project adheres to Semantic Versioning.
Every release, along with the migration instructions, is documented on the Github Releases page.

Authors

Matteo Basso

Copyright and License

Copyright (c) 2019, Matteo Basso.

watpl source code is licensed under the 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].