All Projects → darmie → cabasa

darmie / cabasa

Licence: MIT License
Haxe Framework for WebAssembly

Programming Languages

haxe
709 projects

Projects that are alternatives of or similar to cabasa

Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (+1533.33%)
Mutual labels:  virtual-machine, webassembly, wasm
Wasmtime Go
Go WebAssembly runtime powered by Wasmtime
Stars: ✭ 239 (+696.67%)
Mutual labels:  runtime, webassembly, wasm
Lunatic
Lunatic is an Erlang-inspired runtime for WebAssembly
Stars: ✭ 2,074 (+6813.33%)
Mutual labels:  runtime, webassembly, wasm
Wasm3
🚀 The fastest WebAssembly interpreter, and the most universal runtime
Stars: ✭ 4,375 (+14483.33%)
Mutual labels:  virtual-machine, webassembly, wasm
Lam
🚀 a lightweight, universal actor-model vm for writing scalable and reliable applications that run natively and on WebAssembly
Stars: ✭ 176 (+486.67%)
Mutual labels:  virtual-machine, webassembly, wasm
Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+21276.67%)
Mutual labels:  runtime, webassembly, wasm
Wasm Micro Runtime
WebAssembly Micro Runtime (WAMR)
Stars: ✭ 2,440 (+8033.33%)
Mutual labels:  runtime, webassembly, wasm
wasm-joey
Serverless Wasm - A lightweight Node.js application for deploying and executing WebAssembly(Wasm) binary-code via HTTP
Stars: ✭ 48 (+60%)
Mutual labels:  runtime, virtual-machine
ugo-compiler-book
📚 µGo语言实现(从头开发一个迷你Go语言编译器)[Go版本+Rust版本]
Stars: ✭ 996 (+3220%)
Mutual labels:  webassembly, wasm
koder
QR/bar code scanner for the Browser
Stars: ✭ 73 (+143.33%)
Mutual labels:  webassembly, wasm
jasper
🧳 Single-binary packaging for Ruby applications that supports native and Wasm targets
Stars: ✭ 29 (-3.33%)
Mutual labels:  webassembly, wasm
TWVM
A tiny, lightweight and efficient WebAssembly virtual machine.
Stars: ✭ 105 (+250%)
Mutual labels:  runtime, virtual-machine
openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,973 (+9810%)
Mutual labels:  runtime, virtual-machine
vrcpu
Code, documentation, schematics, notes for my Ben Eater inspired breadboard computer and emulator
Stars: ✭ 98 (+226.67%)
Mutual labels:  webassembly, wasm
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+9240%)
Mutual labels:  runtime, virtual-machine
wasm-ops
Chart of WebAssembly Instructions
Stars: ✭ 46 (+53.33%)
Mutual labels:  webassembly, wasm
wasmsign2
PoC implementation of the WebAssembly Modules Signatures proposal.
Stars: ✭ 18 (-40%)
Mutual labels:  webassembly, wasm
wasm-linker-js
A simple WebAssembly Linker in JavaScript
Stars: ✭ 14 (-53.33%)
Mutual labels:  webassembly, wasm
vmrp
mrp emulator, virtual machine, mrp模拟器
Stars: ✭ 126 (+320%)
Mutual labels:  webassembly, wasm
imgalign
Webapplication for image stitching and aligning
Stars: ✭ 162 (+440%)
Mutual labels:  webassembly, wasm

Cābāsā

Cābāsā is a haxe framework for WebAssembly which includes a fast and secure WebAssembly VM (which is a haxe port of Life VM).

[Status: Not Ready For Use!]

Features

  • Fast - Includes a fast interpreter and an AOT compiler
  • Secure - Executed code is fully sandboxed, wasm modules do not have access to host resources unless explicitly given.
  • Portable - Does not rely on native dependencies and can redistribute wasm in AOT mode as normal haxe code.
  • Cross-Platform - Cābāsā aims to take full advantage of Haxe's cross platform capabilities, therefore wasm module can go anywhere Haxe goes.

Getting Started

Install package manager

npm i -g lix

Use latest Haxe version

lix use haxe 4.0.0-rc.5

Download dependencies

lix download

Executing WebAssembly Modules

Pass a wasm bytcode into a newly instantiated VM

import cabasa.exec.*;

...
var config:VMConfig = {...};
var resolver:ImportResolver = new MyImportResolver(); // handle function and global imports

var vm = new VM(code, config, resolver);

Look up an exported funtion from wasm code by its name, it will return its ID to be used to call the function later

var funcID = vm.getFunctionExport("main"); // could be the name of any exported function

Now call the function by its ID

var data = vm.run(funcID);
if(data.err != null){
    // do something with error
}
Sys.println('return value ${data.result}');

Implementing an Import Resolver

Assume a code compiled to wasm calls an virtual (or native) function __graphics_drawCirle(radius, color), we need to resolve for this function in the host application.

We create an ImportResolver class:

import cabasa.exec.*;

class MyImportResolver implements ImportResolver {
    ...
    public function resolveFunc(module:String, field:String):FunctionImport {
        return switch module {
            case 'env':{
                switch field:{
                    case '__graphics_drawCirle': function(vm:VM):I64 {
                            // get the local variables or function params
                            var radius:U32 = vm.getCurrentFrame().locals[0]; 
                            var color:U32 = vm.getCurrentFrame().locals[1]; 

                            // call the equivalent of the function in the host app
                            myhost.app.Graphics.drawCircle(cast radius, cast color); 

                            return 0;
                        };
                    }
                    default: throw 'cannot find field $field in module $module';
                }
            }
            default: throw 'module $module not found in host';
        }
    }
    // just like resolveFunc but returns the ID of the global export
    public function resolveGlobal(module:String, field:String):I64 {
        throw "not implemented for now"; 
    }
}

Now use this resolver in a VM instance

var vm = new VM(code, {...}, new MyImportResolver());

Run Test

#compile
haxe build.hxml

#run jar output
java -jar build/java/Test-Debug.jar

#run exe output
build/cs/bin/Test-Debug.exe

Why Cābāsā ?

I personally found other haxe embedded scripting interfaces quite limiting. CPPIA only works in C++ targets, HL only work in Hashlink VM just like Neko runs only in its VM. hscript is nice, it's crossplatform but it is a stripped down version of haxe, taking away useful features like types, OOP and modular imports (I honestly tried to fix this with hxComposer), it is at best just for expressions.

WebAssembly shows promise, apart from its much advertise use of redistributing native libraries to the web, it has drawn the attention of server side developers who feel the need to run self contained apps with all the advantages promised by WebAssembly. The WebAssembly specification describes a stack based immediate language with promise of a faster load time, smaller and portable binary format, and memory-safe execution environment.

Haxe + WebAssembly = , a combined force that will benefit all cross platform software engineers. With Haxe's cross platform abilities and wasm, software distribution accross platforms should be more fluid by reducing the need for platform specific glue code, which makes for a more portable software without compromise on quality and performance.

Dependencies

Supported Targets

  • C++
  • Java
  • C#

To-Do

  • Support runtime and AOT compilation for HashLink binary
  • Support runtime and AOT compilation for Neko binary
  • Support runtime and AOT compilation for CPPIA binary
  • Command Line Interface for running wasm module from terminal, disassemble wasm or compile wasm to Haxe AOT
  • Validate wasm binary
  • Extension framwork for distributing wasm modules as Haxe libraries
  • Examples
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].