Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
▗▄▖ ▗▄ ▗▖
█▀▜ ▟█ ▐▌ ▐▌
▟██▖ █▟█▌▐█▙█▖▐▌▄▖ ▐▘█ ▐███ ▐▙██▖
▘▄▟▌ █▘ ▐▌█▐▌▐█▀█▖▗▛ █ ▐▌ ▐▛ ▐▌
▗█▀▜▌ █ ▐▌█▐▌▐▌ ▐▌▐███▌ ▐▌ ▐▌ ▐▌
▐▙▄█▌ █ ▐▌█▐▌▝█▄█▘ █ ▐▙▄ ▐▌ ▐▌
▀▀▝▘ ▀ ▝▘▀▝▘ ▝▀▘ ▀ ▀▀ ▝▘ ▝▘
A Forth interpreter for Apple Silicon, bootstrapped from arm64 assembly. This
is a 64 bit, indirect-threaded Forth which runs on recent macOS versions.
It implements most common Forth words, but doesn't include everything. Mostly
of interest if you're curious how Forth works or how to write arm64 assembly,
but this is not a production system.
There are no external dependencies, but you'll need the usual Apple toolchain
(i.e. clang) to build it.
# build the executable
make
# run tests
make test
# execute a file
./forth demo.f
# start a REPL from stdin
./forth
See `demo.f` for a tiny crash course on Forth and the syntax supported by the
implementation.
ACKNOWLEDGEMENTS
This is my first experience with writing Forth, and I used several sources to
learn and draw inspiration:
1. Dave Gauer's blog post on Forth and its history and magic is the initial
inspiration behind this project. It's a great read for understanding the
why behind the `0 1 > IF 1 ELSE 0 THEN` of it all.
https://ratfactor.com/forth/the_programming_language_that_writes_itself
2. Jonesforth is an extremely well documented Forth written in x86 assembly
which is surprisingly readable and understandable. Several of the design
decisions in this system (e.g. indirect threading) came from exposure to
Jonesforth early on.
http://git.annexia.org/?p=jonesforth.git
3. Planckforth is a Forth system which starts with 1024 bytes of executable
machine code, just enough for basic stack manipulations, and the initial
Forth primitive functions to peek and poke memory. From there it spirals
into a fully-fledged Forth environment, despite beginning at essentially
nothing.
It's worth reading the source code of this implementation, it's very fun
watching a recognizable Forth slowly start to form out of the aether.
https://github.com/nineties/planckforth
LICENSE
Good luck, have fun.