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) by JoeMerchant on Wednesday June 10 2020, @03:31AM (6 children)

    by JoeMerchant (3937) on Wednesday June 10 2020, @03:31AM (#1005633)

    1995-ish, we did a project with a bunch of 6811's - one team member insisted on using his "familiar" 8088 can also do 6502 "free" compiler, the rest of us used Cosmic C which had an actual, functioning 6502 optimizer. The difference in the assembly code produced was dramatic, the optimized code was 2-3x as fast, and 5-10x smaller in many cases.

    If I were tasked with writing an 8 bit OS, I'm pretty sure I'd do it in C, maybe even C++ in some rare places - check the assembly that the compiler produced, but even in 1995 the good optimizers were as good as, often better than, hand coded assembly.

    --
    🌻🌻 [google.com]
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 3, Insightful) by qzm on Wednesday June 10 2020, @04:36AM (5 children)

    by qzm (3260) on Wednesday June 10 2020, @04:36AM (#1005657)

    Did you actually READ the submission?

    His point is a self-hosting environment, which means you would need a C compiler... so be able to compile the environment on the environment (thats what self-hosting means).

    How exactly do you plan on fitting a C compiler in 5k?

    • (Score: 3, Touché) by maxwell demon on Wednesday June 10 2020, @06:52AM (2 children)

      by maxwell demon (1608) on Wednesday June 10 2020, @06:52AM (#1005703) Journal

      How exactly do you plan on fitting a C compiler in 5k?

      Maybe this way. [bellard.org]

      --
      The Tao of math: The numbers you can count are not the real numbers.
      • (Score: 1, Insightful) by Anonymous Coward on Wednesday June 10 2020, @10:45AM (1 child)

        by Anonymous Coward on Wednesday June 10 2020, @10:45AM (#1005743)

        Such a small subset of C, while very small (but also, depending on a multi-megabyte kernel), is much less useful one might think. You might find writing a self-hosting OS in this language very awkward.

        • (Score: 2) by maxwell demon on Thursday June 11 2020, @05:11AM

          by maxwell demon (1608) on Thursday June 11 2020, @05:11AM (#1006182) Journal

          but also, depending on a multi-megabyte kernel

          No. Those multi-megabyte kernels are the "compile everything in, just in case" distribution kernels. I strongly doubt a compiler would need anything that wasn't already in Linux 1.0 in its minimal configuration. Indeed, I suspect even the earliest released 0.x version had the ability to run a compiler.

          Unfortunately I couldn't find any data on the size of those early kernels. But then, even the earliest kernels had stuff that isn't strictly necessary for a compiler to run. For example, if you removed all the networking and multiuser code, I'm pretty sure you'd get a massive shrinkage of the kernel (it would no longer really be Linux, but the point is, it would still be able to run the compiler).

          --
          The Tao of math: The numbers you can count are not the real numbers.
    • (Score: 3, Insightful) by JoeMerchant on Wednesday June 10 2020, @11:49AM (1 child)

      by JoeMerchant (3937) on Wednesday June 10 2020, @11:49AM (#1005757)

      "Self hosting" is more than a little bit of a pointless exercise.

      Note: those 6811 compilers from 1995 were running on 1995 hardware, itself not too far removed from 8 bit capability, and with not too much effort a fully kitted 6811 (64K RAM, etc) could run a good C compiler with that 1995 level of compiler tech, but... what are you gaining?

      Sure, you can start with a Z80 chip and 5K of RAM and cobble up your Forth environment with nothing more than hand written assembly code on paper that you type in, or maybe dial in with a rotary dial system if you prefer that level of bootstrapping, but... at the end of the exercise... can you actually tell the difference between a primitive bootstrapped environment and one written on a modern PC, cross compiled with modern tools and downloaded into your 5K system? Assuming you're using a keyboard, monitor of some sort, and non-volatile storage media - where are the drivers for all that coming from? Do we also need to develop the graphics chip in a self-hosted Z80 environment? What's the RAM limit for the chip design software?

      --
      🌻🌻 [google.com]
      • (Score: 0) by Anonymous Coward on Wednesday June 10 2020, @11:54AM

        by Anonymous Coward on Wednesday June 10 2020, @11:54AM (#1005762)

        The idea is to have an OS that can still be deployed to another machine after the last modern computer dies.