MCPcopy Index your code
hub / github.com/aspkg/ecmassembly

github.com/aspkg/ecmassembly @v0.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.1 ↗ · + Follow
38 symbols 84 edges 13 files 7 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ECMAssembly

Spec'd and/or common JavaScript APIs brought to AssemblyScript.

The name is a play on words: ECMAScript -> AssemblyScript -> ECMAssembly

Usage

Look at example/index.js to see how one would pass JavaScript-side requirements into the Wasm module via imports object, then look at example/assembly/index.ts to see how to import the APIs inside of AssemblyScript code.

First:

npm install ecmassembly

On the JavaScript side pass required glue code to the Wasm module via imports:

import {ECMAssembly} from 'ecmassembly/index.js'
import ASLoader from '@assemblyscript/loader'

const es = new ECMAssembly()

const imports = {
    ...es.wasmImports,
    /*...All your own imports...*/
}

ASLoader.instantiateStreaming(fetch('path/to/module.wasm'), imports).then(wasmModule => {
    // After the Wasm module is created, you need to pass the exports back to the lib:
    es.wasmExports = wasmModule.exports

    // Then finally, run anything from the module that depends on setTimeout, Promise, etc:
    wasmModule.exports.runMyApp()
})

In your AssemblyScript code import what you need an use it:

import {Promise, setTimeout, PromiseActions} from '../node_modules/ecmassembly/assembly/index'

export function runMyApp() {
    const actions: PromiseActions | null = null

    const promise = new Promise<boolean>(_actions => {
        // Temporary hack while AS does not yet support closures (no closing over variable except those that are at the top-level of the module).
        actions = _actions

        // resolve after 1 second
        setTimeout(() => {
            actions.resolve(true)
        }, 1000)
    })

    promise.then(result => {
        // `result` will be `true` here, this runs one second later.
    })
}

or

import {requestAnimationFrame} from '../node_modules/ecmassembly/assembly/index'

// This is out here because there is no closure support for non-top-level variables yet.
let loop: (time: f32) => void = (t: f32) => {}

export function runMyApp() {
    // Make an infinite game loop.

    loop = (time: f32) => {
        // ... render something based on the current elapsed time ...

        requestAnimationFrame(loop)
    }

    requestAnimationFrame(loop)
}

Finally, make sure when you compile your AS code you pass --exportTable --exportRuntime to the asc CLI. For example:

asc assembly/index.ts --target release --exportTable --exportRuntime

APIs so far

  • requestAnimationFrame/cancelAnimationFrame
  • setTimeout/clearTimeout
  • setInterval/clearInterval
  • Promise (rudimentary initial implementation, still lacking things like promise chaining and static methods, etc)

Core symbols most depended-on inside this repo

setTimeout
called by 12
assembly/setTimeout.ts
then
called by 7
assembly/Promise.ts
getFn
called by 5
index.js
resolve
called by 5
assembly/Promise.ts
requestAnimationFrame
called by 4
assembly/requestAnimationFrame.ts
deferWithArg
called by 4
assembly/defer.ts
catch
called by 4
assembly/Promise.ts
reject
called by 4
assembly/Promise.ts

Shape

Function 17
Method 15
Class 6

Languages

TypeScript100%

Modules by API surface

assembly/Promise.ts17 symbols
example/assembly/index.ts8 symbols
index.js4 symbols
example/index.js2 symbols
assembly/utils.ts2 symbols
assembly/defer.ts2 symbols
assembly/setTimeout.ts1 symbols
assembly/setInterval.ts1 symbols
assembly/requestAnimationFrame.ts1 symbols

For agents

$ claude mcp add ecmassembly \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page