
A Dynamic Forth Compiler for WebAssembly - pjmlp
https://el-tramo.be/blog/waforth/
======
AstroJetson
I'm always impressed on the new ways and places that people get new versions
of FORTH installed and rolling. I know that eons ago I did one by coding it
into 8051 assembler. It was interesting to browse the Webassembly to see if I
could match up with what I remember.

Bonus for writing the core in Webassembly, but then writing some of the more
tedious parts in Racket.

I was really impressed with the speed metrics. I would have guessed that it
would be much faster than a JS version, but would have never guessed on those
low numbers.

Congrats on a very cool project!

~~~
sbjs
But forth is a very low level language isn’t it? Even though it’s interpreter,
it’s naturally going to be a lot faster than JS and even Java because it maps
very closely to the assembler instructions you would normally write by hand.
So it would be probably 3x slower than C assuming every Forth instruction
takes three C instructions to run (get opcode and arguments, do operation,
push on stack).

~~~
rwmj
I wrote jonesforth which is a simple threaded FORTH (in other words,
interpreted and certainly not a modern FORTH). Threaded interpreters produce
compact code. They are _not_ efficient on modern CPUs, because they interact
badly with branch prediction. For embedded cases where memory is at a premium
and you usually have a simple CPU like an Arduino, FORTH is a great fit still.

Modern FORTHs are all compiled (as indeed are modern Javascripts). In my view
FORTH is a pretty horrible language to write code in, and if you lose the
advantage of the compact code for the embedded case then you might as well use
a nice compiled language - whatever is your preference, but my preference
would not be FORTH if I had to write code all day long in it.

~~~
sbjs
I wonder if the same semantics that make Forth simple and fast can be used
with another (higher-level) syntax to make it easier to write in, kind of like
how C replaced Assembly. It could become a new family of languages that might
rival modern high-level languages in the same way CL Lisp tried to shake
things up by being both low-level and high-level at the same time.

~~~
vanderZwan
You might be interested in looking up _concatenative_ languages. There's a
wiki[0]. I really like Joy in the abstract sense.

Factor made a few waves a decade ago but has kind of lost steam[1]. It's still
being developed though[2]. Kitten looks promising but develops at a snail pace
because it's _one_ guy doing it[3]. Not a dig against him, mind you!

[0]
[http://concatenative.org/wiki/view/Front%20Page](http://concatenative.org/wiki/view/Front%20Page)

[1] [http://factorcode.org/](http://factorcode.org/)

[2] [https://github.com/factor/factor/](https://github.com/factor/factor/)

[3] [http://kittenlang.org/](http://kittenlang.org/)

------
s-macke
Looks like the code is handwritten in the webassembly assembler language [1].

[1]
[https://github.com/remko/waforth/blob/master/src/waforth.wat](https://github.com/remko/waforth/blob/master/src/waforth.wat)

~~~
pjmlp
Kind of, WebAssembly doesn't support macros.

He is using Racket.

------
jstewartmobile
Forth never got the traction or appreciation that it deserved. It's the only
REPL language I know of that can fit comfortably within the storage, CPU, and
power limitations of an embedded system.

If more EEs had experience with REPL languages, they'd know what they're
missing, and things probably would have turned out differently. His use of
Scheme was not a surprise.

Thank you for fighting the good fight Remko.

~~~
pjmlp
At least on my degree, CS and EE had common Prolog classes.

~~~
jstewartmobile
Our Prolog class was more like a drive-by math exercise than programming. I
don't recall if we actually ever _ran_ anything.

~~~
pjmlp
For that we used _Tarski 's World_ in introduction to logic classes.

Prolog classes were actual programming with SWI Prolog.

Additionally there are national competitions between universities in logic
programming, with Prolog as the official language.

------
wingi
Great!

