Giter VIP home page Giter VIP logo

chasm's Introduction


chasm logo

badge badge badge badge badge badge


Chasm is an experimental WebAssembly runtime built on Kotlin Multiplatform.

The runtime targets the latest wasm specification and supports all instructions with the exception of VectorInstructions.

Additionally, the runtime supports the following Stage 4 proposals

  • Tail Call
  • Extended Constant Expressions
  • Typed Function References
  • Wasm GC

Setup

dependencies {
    implementation("io.github.charlietap.chasm:chasm:0.6.0")
}

Usage

Invoking functions

Webassembly compilations output a Module encoded as either a .wasm or .wat file, currently chasm supports decoding only .wasm binaries

val wasmFileAsByteArray = ...
val result = module(wasmFileAsByteArray)

Once a module has been decoded you'll need to instantiate it, and for that you'll need also need a store

val store = store()
val result = instance(store, module)

Instances allow you to invoke functions that are exported from the module

val result = invoke(store, instance, "fibonacci")

Imports

Modules often depend on imports, which come in two flavours, either:

  • Host functions
  • Exported functions from other wasm modules

Both are represented by ExternalValue's and can be imported at instantiation time

val import = Import(
    "import module name",
    "import entity name",
    externalValue,
)
val result = instance(store, module, listOf(import))

Host functions

Host functions are kotlin functions that can be called by wasm programs at runtime. The majority of host functions represent system calls, WASI for example is intended to be integrated as imports of host functions.

Allocation of a host function requires a FunctionType

The function type describes the inputs and outputs of your function so the runtime can call it and use its results

Once you have function type you can allocate the host function like so

val functionType = FunctionType(ResultType(emptyList()), ResultType(emptyList()))
val hostFunction: HostFunction = {
    println("Hello world")
    emptyList()
}

val result = function(store, funcType, hostFunction)

License

This project is dual-licensed under both the MIT and Apache 2.0 licenses. You can choose which one you want to use the software under.

  • For details on the MIT license, please see the LICENSE-MIT file.
  • For details on the Apache 2.0 license, please see the LICENSE-APACHE file.

chasm's People

Contributors

charlietap avatar illarionov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.