8000 GitHub - putoutjs/ishvara
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

putoutjs/ishvara

Repository files navigation

Ishvara

ishvara

Compile JavaScript to WASM.

Install

npm i ishvara -g

Example

Let's suppose we have absolutely valid JavaScript file with types, which we can run with node v24.

import {create} from '#ishvara';

export const stack = [];

export const imports = [
    ['console', 'log', function log() {
        return i32;
    }],
];

const {
    i32,
    local,
    call,
} = create({
    stack,
    imports,
});

export function x(a: i32, b: i32): i32 {
    i32.add(local.get(a), local.get(b));
    call('log');
}

Compiled with ishvara 1.wast.ts to 1.wast:

(module
    (import "console" "log" (func $log (param $message i32) (result i32)))
    (func $x (export "x") (param $a i32) (param $b i32) (result i32)
        (i32.add (local.get $a) (local.get $b))
        (call $log)
    )
)

With:

import {compile} from 'ishvara';

const wast = compile(wastts);
const binary = await translate(wast);

const {x} = run(binary, {
    console: {
        log: (a) => {
            console.log(a);
            return a;
        },
    },
});

x(1, 2);
// outputs
3;

License

MIT

0