Git Product home page Git Product logo

wast-forth's Introduction

Build Status

wast-forth

WebAssembly AST ๐Ÿ‘‰ Forth

Usage

Install

npm i wast-forth

CLI

genforth test.wast > test.forth

As a library

var p = require('wast-praser').parse,
    g = require('wast-forth').genforth;

console.log(g(p('(module )')));
// =>

References

Portable Assembly Language (PAF)

wast-forth's People

Contributors

drom avatar

Stargazers

Quentin Carver avatar  avatar Dustin Van Tate Testa avatar Karsten Schmidt avatar onion avatar Pablo Hugo Reda avatar Chen, Chih Han avatar kuwze avatar 7rans avatar Simon Kirkby avatar  avatar  avatar Sean Jensen-Grey avatar Dylan Koji-Cheslin avatar Rick Carlino avatar Ben Tucker avatar Lars Brinkhoff avatar

Watchers

7rans avatar  avatar James Cloos avatar Ben Tucker avatar Sergey A. Shishkin avatar  avatar

Forkers

graunked rigidus

wast-forth's Issues

map stack manipulation words to the locals

WebAssembly has no notion of stacks. Forth has stack manipulation words like: dup swap over drop ... that has no direct equivalent in WebAssembly, and need to be mapped to the local values. Here are some ideas:

  1. Parameters stack is i32.
  2. All WebAssembly function parameters (fixed count) will be mapped in-order to the Forth parameter stack.
  3. All additional (temporal) parameter stack entries will be mapped to the WebAssembly tree leafs of local variables.
  4. Function will return (0/1) result on the parameter stack.
  5. Additional floating point stack assumed for f64

dup over

In general, dup and over words require temporal local variable in WebAssembly or explicit duplication of source.

: foo ( n -- x ) dup 0= if 1+ then ;
(func $foo (param i32) (result i32)
  (if
    (i32.eq (get_local $0) (i32.const 0))
    (set_local $0
      (i32.add (get_local $0) (i32.const 1))
    )
  )
  (return $0)  
)

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.