unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to implement a new WebAssembly major-mode
@ 2018-01-10 16:56 Etienne Prud’homme
  2018-01-11 14:04 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Etienne Prud’homme @ 2018-01-10 16:56 UTC (permalink / raw)
  To: Emacs Devel

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to implement a new WebAssembly major-mode
  2018-01-10 16:56 How to implement a new WebAssembly major-mode Etienne Prud’homme
@ 2018-01-11 14:04 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2018-01-11 14:04 UTC (permalink / raw)
  To: emacs-devel

> I now come to the project proposal.  I think it would be beneficial to
> add WebAssembly support in Emacs.

I'd welcome a webassembly package into GNU ELPA, indeed.

> 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.

Not sure exactly what you mean here.  What have you tried that didn't work?

> 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.

For the parsing needed for indentation and such, I think syntax-tables
should work just fine (with maybe a bit of syntax-propertize for (;...;)
comments).

As for real parsing for subsequent processing such as interpretation,
I'd try to just use `read` with some pre/post processing to handle the
few incompatibilities.


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-11 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10 16:56 How to implement a new WebAssembly major-mode Etienne Prud’homme
2018-01-11 14:04 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).