Tiny Forth Could Be The Smallest

When you think of a programming language, you probably think of a hefty compiler or interpreter. Maybe its on a bunch of floppies, a CD, or even an EEPROM. But what about a language that fits in a single disk sector? A language like that would — in theory — be used to help bootstrap a computer system and that was the idea behind Sector Forth and, later, Sector Lisp. However, there’s a new game in town: milliForth, which claims to be the smallest ever at 422 380 bytes.

Why would you want such a thing? Well, first of all, why not? Even as a form of code golf, packing a functioning language into a tiny space seems interesting. However, you could also presumably use something like this to boot a small system or on a system with limited storage.

As you might expect, there are compromises. There are only a few keywords but since Forth can define new words, that might not be a problem The input system is a little different than you might expect, but you are unlikely to want to use this as an interactive interpreter, anyway.

Of course, this implies a challenge: Can you write more with less? If you want to try, there’s no need to actually boot a system. Virtualization software makes it easy to spin up a virtual machine to try things like this out.

SectorLisp is a little larger, but not much. Forth is a great candidate for putting on small computers.

28 thoughts on “Tiny Forth Could Be The Smallest

    1. You know you don’t have to use python, right? You can use perfectly capable languages like C or even asm.

      Besides, this doesn’t seem to be aimed at microcontrollers, so it’s not really relevant.

        1. *yawn* be free to choose whatever language you want to write code in, and champion it all you want, but give other people the same courtesy. I can’t think of anything I want to know about less than what things you have kneejerk negative reactions to.

        2. I agree compleely with you. I mostly use ASM, and sometimes C on microcontrollers, but I do see uses for something like a small forth on MCUs…or maybe even a small ‘bash’.

  1. Shorter code is less readable and the readability is a key feature of a programming/scripting language. Otherwise you would use binary metalanguage written in hexadecimal numbers.

    1. Short code might be less readable in today’s vastly wasted resource architectures. I work in environments requiring much greater efficiency and reduced code footprints are daily goals. Forth probably not viable around here but very intriguing when looking at what was accomplished.

  2. FORTH was designed for this, originally to control a telescope with an 8-bit microcomputer. Its threaded interpretation model is fascinating and lightning fast. It doesn’t use calls anywhere and so the stack is clean and the overheads are minimal. Of course it does still suffer from cache inefficiency like any language that uses lots of simple routines but, on this scale, or any likely program, the whole thing will be cached anyway.

    1. Actually it’s quite the opposite – what it was written for would not be small until 25 years later, and 40-50 years later would it be a small microprocessor.

      “Moore joined Mohasco Industries in Amsterdam, NY, in 1968. Here he developed computer graphics programs for an IBM 1130 minicomputer with a 2250 graphic display. This computer had a 16-bit CPU, 8k RAM, his first disk, keyboard, printer, card reader/punch”

      It just turned out to be quite suited to minicomputers and also microprocessors, and in particular to a single person implementing the whole programming tool. It has become obsolete largely because open source C compilers mean that no one person has to write and debug a whole compiler any more.

  3. I believe MilliForth can be made a few bytes shorter by deleting the 0= word.
    It is redundant. It function is to set all the bits of the Top of Stack to one iff all
    the bits were originally zero, zero otherwise. It is possible to do this with the other words already included in the minimal word list. (I mentioned this in the sectorforth comment area also.) The method is to repeatedly shift and OR the bits left (using the + and NAND words) the swap the upper and lower bytes of the word (@, ! and @SP words ). it is a little lengthy for a small operator, but possible.

  4. Suggestions:

    1 Write FORTH assembler [C,] in transparent portable gcc c.
    2 Make FORTH gcc c words interactively testable from Ubuntu.
    3 Make FORTH boot directly onto micro/nano computer using OS services

    a write to screen
    b read from terminal
    c read and write to disk file
    d clock functions
    int 21 OS or extensions.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.