Sectorforth: A 16-bit x86 Forth that fits in a boot sector
github.com
github.com
I don't quite remember how I fell into the Forth rabbit hole, but I think I first heard about Collapse OS. Then I read yosefk's "My history with Forth & stack machines" [0], which is actually very critical of Forth. But when I saw if/then/else being defined in Forth itself, I was hooked.
I've always been fascinated by the idea of having a minimal kernel of primitives from which "everything" can be built. Before Forth, I had only seen that in the form of Lisp's "Maxwell equations of software", which is cool, but always left me a little disappointed because it is too abstract to build something that you can actually interact with - you can't break out of its esoteric nature. The same applies to brainf*ck and other extremely small environments.
With Forth, however, you can start from almost nothing, and start adding things like ifs, loops, strings, etc., things that look more like your day-to-day programming. I find that there's a lot of beauty in that.
Anyways, I hope the examples in the repository do not look too awful to experienced Forth programmers :D
[0] https://yosefk.com/blog/my-history-with-forth-stack-machines...
https://golangnews.org/2020/09/bootstrapping/
... a non-exhaustive list of projects that create super-minimal interpreters, compilers, or maybe operating systems with very few dependencies or prerequisites.
One of the items on that page is described as "25k lines of asm". That's the problem with 'tiny'. It means different things to different people. This FORTH thing however appears to be an exception. You know you're playing the game at a different level when your entire app can be statically linked with all its dependencies and still be small enough to fit inside the master boot record of a floppy disk (i.e. less than 512 bytes). I just wish I could figure out how to use the thing.
We've talked over email. Hope my pointers were enough to get you unblocked :)
https://bootstrappable.org/ https://bootstrapping.miraheze.org/
Any idea why it was copy-pasted to the Golang News blog without attribution?
nbdkit -U - data base64='6h54UAAAAAFAW/8363YFdwEhW48H620OdwNzcEBU62QXdwNycEBV61sgdwIwPViFwA+VwEiYUOtLKXcBK1tYAdhQ60A5dwRuYW5kW1gh2PfQUOswRHcEZXhpdIflXofl6yJUdwN0aWJqAOsYYncFc3RhdGVoABDrC2x3Az5pbmgCEOsArf/geXcEaGVyZWiTd+vxAHmHdwZsYXRlc3Roo3fr4f53lXcDa2V5tADNFlDr0qV3BGVtaXRY6CIB68WydwE66LcAVon+iz6Td6Gjd4k+o3eriMgMQKrzpLj/Jqu4/HeriT6Td8YGABABXuuUh+VWh+WDwASJxuuI8He/d4E7ix6jd4BnAr/GBgAQALhbd4s+k3eriT6Td+lm//wODg4fBxfrC7ghCbsEALkCAM0Qvf52vP7/sAC5BBC/AADzqug4AIseo3eF23Taid6trIjCqEB1DiQfOMh1CFFX86ZfWXQEix/r4Inwvnt4gOKAChYAEP7KdJn/4EJ4iz4CELn//7Ag865PgD0AdBC5///yrk+JPgIQ99FJKc/DsA3oPACwCug3AL8AALQAzRY8DXQdPAh0BuglAKrr7oP/AHTpT+gZALggCrkBAM0Q69u4IACr6AgAxwYCEAAA655QtwC0A80QWLQOswfNEDwIdQyE0nUItAKyT/7OzRDDVao=' --run 'qemu-system-i386 -hda $nbd'
Although HN breaks the lines awkwardly if you copy and paste it should work.Have fun! https://github.com/breckinloggins/vau
(Check out the prelude for satisfying doses of meta)
The true beauty of something like SectorForth is its mechanical empathy. It relies only on the machine code of the system, and while it has quirks and shortcomings to fit in 512 bytes, it has everything you would need to bootstrap into a fully-productive Forth.
Of course, if Oscar Toledo feels inclined to step in and furnish a 512 byte extensible Lisp that runs on an 8080, I won't be upset.
In short I let you define words, and work in a FORTH-like manner, but without the real extensibility of an actual FORTH system. That will be something I tackle next:
Nice to see more FORTH stuff posted here!
Stylistically, one of the main suggestions I took to heart early in my career with Forth was to outright ignore "rot" and "-rot"; they make the stack tricky to follow. I see that helloworld.f defines "rot", but it's only used in one place.
Back when I was into Forth, I had this wild notion of adding a stack checker, defining two additional comment words which would be aware of the stack effect of all core words, and require a stack effect to be defined for every new piece of vocabulary.
Never did anything with it, don't write Forth anymore, doubt I will again. I still think it's a good idea though, so I like to put it out there.
See also the Kitten programming language, which does something similar: https://kittenlang.org/
Where there's three or more items to be manipulated there's always at least ambiguity which way rot is supposed to rotate according to codebase author. With more than three items it's easy to see what can be done but no unambiguous and meaningful names. The only consistent stack word names that work 4 items deep are 2dup and 2drop.
[1] I chose the constraint that CODE words were fine, but the kernel had to already contain the dictionary implementation: no "magic numbers" known to both the forth and kernel source. The motivation for that constraint was the "three instruction forth" which I would call a "monitor program" instead.