Basically these ecosystems treat ES5 Javascript like the 'byte code'
of the Java world!!
(btw, Espruino team found that ES5 source code is more compact than
the byte-code created by any Javascript engine, so there are
surprising tradeoffs in memory constrained devices!).
To play in that ecosystem, you basically need:
1) to emit and consume ES5 compliant Javascript.
2) implement perfect JSON parsing and stringification.
3) support http and websocket protocols.
4) support the CommonJS module standard which NodeJS uses.
Optionally:
6) a babel plugin to support real-time transpilation to other js
flavors (e.g. ES-6, or Typescript).
7) a webpack plugin to support 'hot redeploy', remote debugging, and
other niceties of that platform.
Incredibly useful advice, thank you.
Btw, you mention Espruino, I think it’s a very interesting contrast
between Jerryscript. You look at Espruino’s compiler, and it was
clearly written in a swashbuckling style:
https://github.com/espruino/Espruino/blob/master/src/jsparse.c
With parsing and lexing going straight to three address code and even
executing while being parsed. While the coding style may not be ours,
this is a very efficient way to write things if you want to compile on
the device, and he’s clearly lived & breathed this stuff for 4 years.
As opposed to Jerryscript, which has a standard two-stage compilation
process (parse tree->tac). They have also written a good compiler, and
clearly have experience.
https://github.com/Samsung/jerryscript/tree/master/jerry-core/parser/js
but it is not optimized to compile on these small environments. It’s
VM however, is very optimized:
https://github.com/Samsung/jerryscript/tree/master/jerry-core/vm
So, you could easily take this, and pre-compile just byte-code to run on
the device. While the byte-code might take more flash than ES5 source
code, it will certainly take drastically less RAM to run (precious.)
I think the compiler that will win here will depend on what is the
broadest use-case. If you can afford to compile prior to running on the
device, than the Jerryscript compiler has the advantage of being simpler
and more complete. If you need to parse & run on the device (or you
want to), then the Espruino compiler is highly optimized for that. The
only use-case I can currently think of for such a thing is a Javascript
console on the device, but you could always compile that in for debug
mode only with Jerryscript.
The other, being that you want to dynamically recompile Javascript on a
device over a WebSocket. But when that happens, I’ll know it’s time
to leave embedded for some other line of work. :-)
Sterling