Socket
Book a DemoInstallSign in
Socket

@wapc/widl-codegen

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wapc/widl-codegen

Flexible code generation using WIDL

latest
Source
npmnpm
Version
0.0.11
Version published
Weekly downloads
191
7.91%
Maintainers
3
Weekly downloads
 
Created
Source

WIDL Code Generation

This library works in tandem with wapc/widl-js to generate waPC module code in Rust, AssemblyScript, and TinyGo.

Installation

$ npm install @wapc/widl
$ npm install @wapc/widl-codegen

Usage (node)

const widl = require("@wapc/widl");
const ast = require("@wapc/widl/ast");
const assemblyscript = require("@wapc/widl-codegen/assemblyscript");

const schema = `
namespace "mandelbrot"

interface {
  update(width: u32, height: u32, limit: u32): [u16]
}`;

const context = new ast.Context({});

const doc = widl.parse(schema, { noLocation: true });
const writer = new ast.Writer();
const visitor = new assemblyscript.ScaffoldVisitor(writer);
doc.accept(context, visitor);
let source = writer.string();

console.log(source);

Usage (browser)

<html>
  <head>
    <script src="https://unpkg.com/prettier@2.2.1/standalone.js"></script>
    <script src="https://unpkg.com/prettier@2.2.1/parser-typescript.js"></script>
    <script src="https://unpkg.com/@wapc/widl/dist/standalone.min.js"></script>
    <script src="https://unpkg.com/@wapc/widl-codegen/dist/standalone.min.js"></script>
  </head>
  <body>
    <pre><code id="generated"></code></pre>
  </body>
  <script type="text/javascript">

const doc = widl.parse(`namespace "mandelbrot"

interface {
    update(width: u32, height: u32, limit: u32): [u16]
}`);
const context = new widl.ast.Context({});

const writer = new widl.ast.Writer();
const visitor = new widl.codegen.assemblyscript.ScaffoldVisitor(writer);
doc.accept(context, visitor);
let source = writer.string();

source = prettier.format(source, {
  parser: "typescript",
  plugins: prettierPlugins,
});

document.getElementById("generated").innerHTML = source;

  </script>
</html>

License

Apache License 2.0

Keywords

webassembly

FAQs

Package last updated on 15 Jul 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.