emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to implement a new WebAssembly major-mode


From: Etienne Prud’homme
Subject: How to implement a new WebAssembly major-mode
Date: Wed, 10 Jan 2018 11:56:56 -0500

Hi,

It’s been a time I thought it could be nice to implement a WebAssembly
major-mode.

WebAssembly is new web standard that specifies a binary format
(bytecode) and a corresponding assembly-like text format.  It is like
assembly in the sense of almost 1 to 1 correspondence between the text
format and the binary format.

WebAssembly is a portable stack machine.  It is designed to be a fast
and portable instruction set that will complement JavaScript to speed-up
performance-critical parts.  We could call it the JVM for web
applications.

As for now, it is mostly used in game development, but might get broader
adoption since it is much faster than JavaScript.  While WebAssembly was
primarily designed to support compilation from higher-level languages
such C/C++, the simplicity of the text representation makes it suitable
to be edited in a text-editor.

What might be interesting is its use of S-expressions.  While I would
not consider it to be Lisp at all, the representation makes it easier to
implement an AST (abstract syntax tree) and parse its syntax.

Sadly, current support for editing wast (WebAssembly text
representation) is mostly lacking from editors I know.  There’s not even
a common practice on how indentation should look like.

I think it’s a fantastic opportunity for GNU Emacs.  Since Emacs is the
editor for S-expressions (Lisp or not), it would not require much work
to make a parser for Emacs.  Furthermore, it might promote GNU Emacs for
web development.  The current trend is to use text-editors such as VS
Code, Atom or Sublime.

I now come to the project proposal.  I think it would be beneficial to
add WebAssembly support in Emacs.  By that, I mean support for the
bytecode in Emacs.  It’s in no way my intention to replace the current
bytecode architecture.  `bytecode.el` implements features such as cons
cells that we have no way to support efficiently in wasm.

Instead, the implementation would allow debugging the interpreted
bytecode.  The language implementations don’t yet include a debugger for
neither the binary nor text format.  While making an AST parser for
wasm, I don’t think it would be a difficult task to add an interpreter
given the simplicity of wasm instructions.

I started making a `major-mode` prototype, but I don’t see anywhere I
could start given its S-exp syntax, but no Lisp support.  I also noticed
there are many ways to make the parser (I can count 5 at least) and I’m
not sure what would be the best choice for maintainability.  I.E. I can
make my own parsing functions, use Bison/Wisent, or use Semantic, etc.
Not to even count the syntax-table.

What would be the steps to implement such a parser and major-mode?

--
Etienne



reply via email to

[Prev in Thread] Current Thread [Next in Thread]