Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

walt-compiler

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

walt-compiler

Alternative syntax for WebAssembly text format

  • 0.10.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Walt Compiler

This is the main walt compiler package.

Install

npm install --save walt-compiler

API

Compile and run Walt code in browser:

import compileWalt from 'walt-compiler';

const buffer = compileWalt(`
  let counter: i32 = 0;
  export function count(): i32 {
    counter += 1;
    return counter;
  }
`);

WebAssembly.instantiate(buffer).then(result => {
  console.log(`First invocation: ${result.instance.exports.count()}`);
  console.log(`Second invocation: ${result.instance.exports.count()}`);
});

Compile and save a .wasm file via Node.js:

const compileWalt = require('walt-compiler').default;
const fs = require('fs');

const buffer = compileWalt(`
  let counter: i32 = 0;
  export function count(): i32 {
    counter += 1;
    return counter;
  }
`);

fs.writeFileSync('bin.wasm', new Uint8Array(buffer));
parse

Main parse step of the compiler. Returns a bare bones Abstract Syntax Tree without type information. This tree cannot be directly compiled without semantic analysis, but can be transformed easily.

import { parser } from 'walt-compiler';

const ast = parser(`
  type MyObjectType = { 'foo': i32, 'bar': f32 };
  export function test(): f32 {
    const obj: MyObjectType = 0;
    obj['foo'] = 2;
    obj['bar'] = 2.0;
    return obj['foo'] + obj['bar'];
  }
`);

console.log(ast); // { value: 'ROOT_NODE', Type: 'Program', range: [...], params: [...] .... }
prettyPrintNode

Provides a human readable output of the AST nodes. Returns a string, does not log to console.

semantics

Semantic Analyzer, takes a bare AST and returns a transformed version of the AST with semantics applied(type indexes etc.,).

generator

Intermediate code generator, takes an AST and returns a Program object.

emitter

Binary emitter, takes a Program and returns an OutputStream object. OutputStream.buffer() generates a "real" binary buffer.

debug

Used for debugging the buffer returned by emitter. Returns a string representation of the binary program.

Keywords

FAQs

Package last updated on 18 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc