What a fun week and a half:
https://codeberg.org/kira/forth32/
This is an implementation of FORTH, following the jonesforth tutorial[1]. The original is written in x86 assembly, mine is in C.
It works! I'm so thrilled. I've bounced off of trying to implement this perhaps, say, 3 or 4 times? Each time I'd get stuck, and a couple of months later I'd have another go at it, and I'd grok the thing I had been stuck on the previous time.
And this time I made it to the end (of the main implementation).
The base system is 3900 bytes: that includes the stacks, string buffer, and all of the built-in words.
What a joy! It's so cool to finally understand how FORTH works from the ground up. It's complicated but elegant & simple.
[1] https://github.com/nornagon/jonesforth/blob/master/jonesforth.S
=> More informations about this toot | More toots from tty@sunbeam.city
What gets me is that, if someone unfamiliar with FORTH tries to read this or run it, they're going to have a terribly confusing time.
I haven't figured out yet how to present this in a way that's accessible. 🤔
=> More informations about this toot | More toots from tty@sunbeam.city
I wish I could explain how cool this is, how powerful it is!
FORTH can rewrite its own interpreter/compiler at runtime or compile-time (as you prefer). You can write words that run their own logic at compile-time (like Lisp macros). You can replace any built-in core function with your own. You can define IF...THEN yourself and any loop construct from with in FORTH itself. FORTH has full access to the same memory it runs in (including the dictionary of all words), so it can modify itself in any way.
You can even create new types of syntax for single- and multi-line comments from within FORTH!
🤯 🤯 🤯
=> More informations about this toot | More toots from tty@sunbeam.city
Adding multi-line comments to FORTH, in FORTH:
: (
KEY CHAR ) = 0BRANCH [ -20 , ]
;
There's more to be understood here re: [ and ] and , but that's the high level!
Now I can write comments like,
( hello world! this input is ignored! )
=> More informations about this toot | More toots from tty@sunbeam.city
Now I've written DO...WHILE loops in FORTH itself! giggles This is too fun.
=> More informations about this toot | More toots from tty@sunbeam.city This content has been proxied by September (3851b).Proxy Information
text/gemini