yorkie / me

CV at Github and Notes based on Issues
71 stars 12 forks source link

WebAssembly: create a library to convert JavaScript code to WAT #23

Open yorkie opened 7 years ago

yorkie commented 7 years ago

To enable WebAssembly to be read and edited by humans, there is a textual representation of the wasm binary format.

The above sentences are from MDN's article: Understanding WebAssembly text format.

This way that we write the code runs on modern browsers is still not readable, this is the example that wasm text format project: https://github.com/mafintosh/blake2b-wasm/blob/master/blake2b.wat. I hardly read over 300 lines, even the whole source file contains 2800+ lines.

Improving this source would have the following 2 ways for now:

  1. split the big file into many modules in a structured place, that's play WAT better
  2. writing the same implementation in existing language that's friend to developers

I'll go for the latter, the former method may works, but with a hard learning curve. Obviously the existing language is the JavaScript itself. Aha, that we would do: write JavaScript and compile it to binary executable, and run in JavaScript VM. Interesting, right?

Having to say, this idea looks like what I was expecting in yorkie/lv, which gets AST via esprima, and generates Assembly source code for NASM. About the implementation of the new thoughts, we don't need esprima any more, because we can provide APIs by following WAT's specification, and generates WAT source directly.

If you have interested in this project, feel free to leave comments here :)

yorkie commented 7 years ago

In computing, s-expressions, sexprs or sexps (for "symbolic expression") are a notation for nested list (tree-structured) data, invented for and popularized by the programming language Lisp, which uses them for source code as well as data.

Oops, the WAT is using the S-expressions which is used as well by LISP, just curious why WebAssembly make this choose so far :)

yorkie commented 7 years ago

Created this library at https://github.com/yorkie/watjs :)