larsbrinkhoff / lbForth

Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
GNU General Public License v3.0
418 stars 112 forks source link

Port asm.js target to more engines #36

Open larsbrinkhoff opened 7 years ago

larsbrinkhoff commented 7 years ago

I have no idea how the various JS engines interface to the operating system. Or how to run this in a browser.

larsbrinkhoff commented 7 years ago

What are the major engines?

pipcet commented 7 years ago

I don't know too much about the non-SpiderMonkey engines, but the current code should work under IonMonkey, the Baseline compiler, and the SpiderMonkey JS interpreter, though I say that without having tested it. Node.js has its own OS interface, which makes it hard to read input synchronously; V8 has a shell with a minimal OS interface similar to what SpiderMonkey offers.

I think the interesting target is the browser environment, ideally using only W3C APIs, but there is at least one obstacle: asynchronous APIs (and they all are) require control to pass back and forth between the Forth interpreter and the JavaScript top level. Nothing too hard to do, but a bit fiddly.

I've got a very WIP WebAssembly backend displaying "ok". (This is literally the first version that passes my sophisticated "3 4 * ." test.) Ideally, this should share some code with the asm.js backend. (Code at https://github.com/pipcet/lbForth/tree/wasm).

pipcet commented 7 years ago

Nothing too hard to do, but a bit fiddly.

Okay, I've got something working with nodejs at https://github.com/pipcet/lbForth/tree/asynchronous-js. I'll try to turn that into "official" nodejs support next.