Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a how-to-write-a-FORTH tutorial that I wrote a few years ago. It's particularly nice that you get to see how various control structures are implemented, like IF, CASE and even comments!

Part 1: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth...

Part 2: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth...

(github mirror: https://github.com/AlexandreAbreu/jonesforth/blob/master/jon... https://github.com/AlexandreAbreu/jonesforth/blob/master/jon...)

Previous HN comments: https://news.ycombinator.com/item?id=10187248



Working through Jones Forth got me up to speed on both understanding how Forth works and getting my hands dirty with some practical assembly coding.

Once I got a better idea of Forth, I also realized that Jones stays in assembly for rather long. He builds up the entire interpreter from raw assembly words, because you need the interpreter to start parsing textual Forth source. But you if you could somehow write Forth before the interpreter is put together, it would be quite natural to switch to Forth much earlier. And it turns out you can do that. Jones even defines the `defword` macro. But for some reason he makes very little use of it. Rewriting most of the code leading up to INTERPRET using defword was a fun exercise.

The next step would've been making the whole system bootstrapping by rewriting the assembler in Forth, but x86 machine code generation is hairy enough that I bailed out at this point.


All fair points. I was reading over it again today thinking that it would have been better to write more of it in FORTH. At the time I was prematurely optimizing I think.


Have you ever considered a revisit?


I've used jonesforth in the past few weeks as a basis for implementing my own Forth, but for RISC-V (and soon, maybe Xtensa).

It's an excellent codebase; thank you very much! I've changed the design a slight bit so far -- but the vague signature of jonesforth is really still there, I think!


It's donated into the public domain -- please change it, redesign it, and otherwise do whatever you want with it!


Thanks, I've loved that piece for a while. I had written a couple of subroutine-threaded forths before that, but you helped me cross the border into indirect threading.


This is one of my favorite pieces of code, and absolutely the coolest having to do with Forth.

Thanks!


This is amazing. Thank you so much for sharing this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: