News for hackers. Stuff that matters.
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Sunday September 27, 2020 @01:44AM (#24604482)
Author here! This was a super fun project that consumed over a month of evenings and weekends. In the past couple of days I finished the examples, and I'm glad to finally put it out there.

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...

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by schoen on Sunday September 27, 2020 @02:30AM (#24604655)
This is a cool project! You might also like

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by jart on Sunday September 27, 2020 @10:46PM (#24612470)
> a non-exhaustive list of projects that create super-minimal interpreters

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Monday September 28, 2020 @01:31AM (#24613272)
> 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 :)

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by jart on Monday September 28, 2020 @04:53AM (#24614497)
Here's the follow-up to our email efforts: https://justine.storage.googleapis.com/forth.mp4 It works!
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by pabs3 on Monday September 28, 2020 @08:47PM (#24622972)
This just appears to be a copy of the bootstrappable wiki:

https://bootstrappable.org/ https://bootstrapping.miraheze.org/

Any idea why it was copy-pasted to the Golang News blog without attribution?

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by schoen on Wednesday September 30, 2020 @10:23PM (#24646606)
No, sorry for linking to a source that wasn't original!
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by nathell on Monday September 28, 2020 @06:13AM (#24615019)
I'd really like to revive https://github.com/nathell/lithium sometime. It can't bootstrap itself yet, but "no dependencies, runnable on bare metal" was a goal from the start.
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by rwmj on Monday September 28, 2020 @07:54AM (#24615633)
Here's my "one line" (very long) command to run it:

  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.
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by breckinloggins on Sunday September 27, 2020 @07:56PM (#24611314)
I tried to do something “interesting” with my own little lisp based on the “Maxwell’s Equations of Software” paper. I don’t know if I succeeded exactly (and like most such projects I left it in a somewhat unfinished state), but I did achieve the same “now we’ve defined comments!” kind of mystical experience as the author of the linked article.

Have fun! https://github.com/breckinloggins/vau

(Check out the prelude for satisfying doses of meta)

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by RodgerTheGreat on Sunday September 27, 2020 @09:07PM (#24611819)
It's a very different kind of simplicity and self-hosting. Vau uses rich features of a managed programming language in order to achieve lispiness.

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by breckinloggins on Sunday September 27, 2020 @09:48PM (#24612120)
Yep. I was definitely cheating, and it’s more like “syntactical self hosting”. I’ve wanted to try my hand at a Forth like this but so far I haven’t started anything.
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by stevekemp on Monday September 28, 2020 @01:20AM (#24613227)
I also recently hacked up a simple FORTH-like system, but mine just emulates the effects making IF/ELSE/THEN and DO/LOOP be built-in primitives.

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:

https://github.com/skx/foth/

Nice to see more FORTH stuff posted here!

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Monday September 28, 2020 @01:29AM (#24613265)
I actually came across your project yesterday :) Great work!
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by vitiral on Sunday September 27, 2020 @10:16PM (#24612297)
This is awesome! I've had a similar history very recently and am trying to write a forth with a type system (I think I've found a way to do it with nearly zero overhead) for Civboot.org I have a few notes about it on the github page, and I've just made it through the jobesforth tutorial. Learning asm ain't easy!
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by unixhero on Monday September 28, 2020 @03:18AM (#24613849)
Very cool! Does it have any games yet?
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by rwmj on Monday September 28, 2020 @07:57AM (#24615656)
This guy has written a bunch of boot sector games, although not boot sector games in forth ... https://github.com/nanochess/Invaders
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by parkertomatoes on Monday September 28, 2020 @12:00AM (#24612834)
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Monday September 28, 2020 @01:27AM (#24613260)
Awesome!
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by RodgerTheGreat on Sunday September 27, 2020 @06:29PM (#24610692)
Leaving out numeric literals is an interesting choice to simplify your Forth kernel. Not many languages have sufficiently flexible naming rules to permit something like ": 3 1 2 + ;"

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by samatman on Sunday September 27, 2020 @06:35PM (#24610740)
Related advice would be to annotate every stack effect with a comment, no exceptions.

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by dfischer on Sunday September 27, 2020 @07:42PM (#24611192)
Have you seen Factor? https://factorcode.org/
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by TapamN on Sunday September 27, 2020 @06:52PM (#24610841)
That's actually been done. It's called StrongForth.

http://www.arestlessmind.org/2009/02/03/intro.html

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by MaxBarraclough on Monday September 28, 2020 @04:32AM (#24614346)
You beat me to it. See also this other page on StrongForth: https://www.stephan-becher.de/strongforth/

See also the Kitten programming language, which does something similar: https://kittenlang.org/

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Sunday September 27, 2020 @10:46PM (#24612468)
Yep, annotating the examples with stack effects is in my plans :)
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by cblum on Sunday September 27, 2020 @10:46PM (#24612472)
Oh, interesting. I feel like I've gotten used to reasoning with rot and -rot. Didn't know there was advice out there not to use it.
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by loa_in_ on Sunday September 27, 2020 @11:15PM (#24612624)
It's not any more or less intuitive to me than nip and over.

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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by fao_ on Sunday September 27, 2020 @10:42PM (#24612443)
Heh, I was thinking about this idea literally last week, nice to see someone's done it :)
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by scottyelich on Sunday September 27, 2020 @07:22PM (#24611072)
Now all we need is a networking layer and we'll be all set. evil grin
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by 082349872349872 on Monday September 28, 2020 @01:01AM (#24613132)
Best[1] I could do was a non-networked forth that easily fit in a jumbo frame. Maybe one day I'll think of a trick to fit it in a normal MTU, but it's more likely that networking will widen in the meantime.

[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.

Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by tinus_hn on Monday September 28, 2020 @08:24AM (#24615845)
The old Sun workstations had a firmware in Forth that could run networking (very basic for bootp/tftp)
Re:Sectorforth: A 16-bit x86 Forth that fits in a boot sector by mikewarot on Tuesday September 29, 2020 @10:39PM (#24635197)
STOICAL does networking, and a whole lot more... but it looks like it hasn't been touched since 2002. 8(

http://stoical.sourceforge.net/documentation.php