Stories
Slash Boxes
Comments

SoylentNews is people

posted by Fnord666 on Wednesday June 10 2020, @02:57AM   Printer-friendly
from the a-new-OS-is-forth-coming dept.

It appears the leadership of Collapse OS have decided to switch from Z-80 to Forth. In this article, they explain their reasoning.

Collapse OS' first incarnation was written in Z80 assembler. One of the first feedbacks I had after it went viral was "why not Forth?". I briefly looked at it and it didn't seem such a great choice at first, so I first dismissed it. Then, I had what alcoholics refer to as a "Moment of clarity".

[...] The Z80 asm version of Collapse OS self-hosts on a RC2014 with a 5K shell on ROM, a 5K assembler binary loaded in RAM from SD card (but that could be in ROM, that's why I count it as ROM in my project's feature highlights) and 8K of RAM. That is, it can assemble itself from source within those resources.

[...] If I wanted to re-implement that assembler feature-for-feature in Forth, it would probably require much more resources to build. Even though higher level words are more compact, the base of the pyramid to get there couldn't compete with the straight assembler version. This was under this reasoning that I first dismissed Forth.

So, again, what makes Forth more compact than assembler? Simplicity. The particularity of Forth is that it begins "walking by itself", that is, implementing its own words from its base set, very, very early. This means that only a tiny part of it needs to be assembled into native code. This tiny part of native code requires much less tooling, and thus an assembler with much less features. This assembler requires less RAM.

What is more compact than something that doesn't exist? Even Z80 assembler can't beat the void.

That's how although Forth is not more compact that native code (duh!), a Forth Collapse OS achieves self-hosting with as much resources than its Z80 counterpart.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2, Insightful) by Anonymous Coward on Wednesday June 10 2020, @03:32AM (3 children)

    by Anonymous Coward on Wednesday June 10 2020, @03:32AM (#1005635)

    Forth seems popular with hobbyists who want to (re)invent a complete machine S/W architecture from the bottom up, with an interpreter running the whole show. Forth is a seductive choice because the language is SO SIMPLE. It's simple because there is not much distinction between the Forth "VM" (the guts of the interpreter) and the Forth language itself. Effectively, programming in Forth is programming in the "assembly language" of the Forth interpreter, a
      stack machine.

    If you don't write complicated software (example, you just write simple hardware access routines), this might be sufficient.
    For more complicated stuff, Forth doesn't scale at all. Forth also ties your code pretty hard to a fixed machine "word size" like 16 or 32 bits. Other intrepreted languages don't make you pick one wordsize nor do they even have a wordsize concept.

    Starting Score:    0  points
    Moderation   +2  
       Insightful=1, Interesting=1, Total=2
    Extra 'Insightful' Modifier   0  

    Total Score:   2  
  • (Score: 4, Informative) by istartedi on Wednesday June 10 2020, @06:42AM

    by istartedi (123) on Wednesday June 10 2020, @06:42AM (#1005699) Journal

    Forth has been taken higher up than you might think. People have even written object systems in it, and added lambdas and other things that you might not expect. It's an odd thing to do, but I'm quite confident that Forth is flexible enough to overcome the word size "restrictions" of which you speak. After all, words are just data, and Forth can handle any data you can throw at it.

    For an example of something that's sort of what Forth would be if you made it higher level, google around for concatenative languages [wikipedia.org] such as Joy. It's an interesting little niche in the programming world.

    --
    Appended to the end of comments you post. Max: 120 chars.
  • (Score: 1, Insightful) by Anonymous Coward on Wednesday June 10 2020, @07:17PM

    by Anonymous Coward on Wednesday June 10 2020, @07:17PM (#1005948)

    Hobbies are supposed to be fun.

    For some people, coding in Forth is fun. I always enjoyed it.

    Sometimes things aren't complicated.

  • (Score: 3, Interesting) by hendrikboom on Thursday June 11 2020, @02:07PM

    by hendrikboom (1125) Subscriber Badge on Thursday June 11 2020, @02:07PM (#1006285) Homepage Journal

    On the now static TUNES forum, where they discussed building a modern verified OS from scratch, using modern verification tools as early in the bootstrapping as feasible, opinion was fairly divided about whether they should start with a Forth dialect or a Lisp/Scheme dialect.

    They never got together enough to build anything much, but their archived site [tunes.org] is a gold mine of information about related issues.

    -- hendrik