from Hacker News

milliForth

by binarycrusader on 11/6/23, 3:03 AM with 83 comments

  • by tromp on 11/6/23, 7:51 AM

    > However, milliFORTH appears to be the smallest programming language implementation ever, beating out sectorLISP2, a mind-blowing 436 byte implementation of LISP, by 14 bytes.

    The sectorlambda implementation of Binary Lambda Calculus is shorter yet at 383 bytes [1].

    And the BLC self-interpreter is only 29 bytes [2].

    > A FORTH in 422 bytes — the smallest real programming language ever, as of yet.

    That may still be true, as BLC is an esoteric programming language.

    [1] https://justine.lol/lambda/

    [2] https://ioccc.org/2012/tromp/hint.html

  • by PaulHoule on 11/6/23, 3:46 PM

    When I was in high school I wrote a nice FORTH for the TRS-80 Color Computer using the OS-9 operating system which was a Unix-like multitasking OS that would fit on a 6809 microcomputer.

    I think it was around 2000 lines of assembly code to implement most of the FORTH-83 standard although mine was unusual in that it did not support the block-based I/O that was common on “language system” FORTHs but instead it had handle-based API for accessing files similar to Unix, C and MS-DOS in version 2 and up.

    The programming environment was a lot like Linux overall in that I’d use an ed or vi clone to edit files, then run something like an assembler or C compiler. I’d run my FORTH binary and it would present an interactive environment like most FORTHs.

  • by anotherhue on 11/6/23, 4:25 AM

    I love projects like these, reminds me of the magic within the machine, as opposed to the normal cacophony of the world that comes via the machine.
  • by rep_lodsb on 11/6/23, 9:59 PM

    You could save one byte by replacing "0=" with "0<>" (well, except for the name, maybe use "0#"?):

        pop ax
        neg ax     ;sets carry flag if nonzero
        sbb ax,ax
        push ax
    
    And another two bytes in DOCOL:

        ;add ax,4
        ;mov si,ax
        xchg ax,si
        lodsw
        lodsw
    
    Maybe even free up a word register to always hold the address of DOCOL, then you only need two bytes at each colon definition. If it's possible without adding any extra instructions, this should save 4 bytes in total (one stosw in COLON, the DOCOL.addr variable, one lodsw in the above version of DOCOL)
  • by lynx23 on 11/6/23, 7:38 AM

    Porting JonesFORTH to x86-64 was one of the most rewarding fun-project experiences lately. Forth is fun to play with.
  • by alexisread on 11/6/23, 3:07 PM

    Looking at the code, this looks remarkably similar to sectorforth? Thing is, with sectorforth and this, 2 of the primitives are not required so reducing the VM to 6ops, so you can probably go smaller. Looks as though Cesar was happy with fitting into a sector: https://github.com/cesarblum/sectorforth/issues
  • by jart on 11/7/23, 9:48 AM

    When SectorLISP claimed to be the tiniest programming language in the world, it included (1) a Turing machine program, (2) an implementation of SectorLISP written in SectorLISP, and (3) a proof that it could run software that had been written for the original LISP 1.5 system built by LISP's inventor. If milliForth is making the same claim, then it should hold itself to the same standard. Otherwise it's just a calculator written by an anonymous person. I filed an issue here: https://github.com/fuzzballcat/milliForth/issues/8
  • by mikewarot on 11/6/23, 8:29 AM

    I've always wondered how to boot a virtual machine from a single sector with no other OS... now I know, which is cool.
  • by badcppdev on 11/6/23, 9:18 AM

    Does anyone in the Forth community know if Charles Moore is still with us?
  • by tomcam on 11/6/23, 11:03 PM

    justine is probably working on a version so small it will trigger the singularity irrevocably
  • by LordShredda on 11/6/23, 4:59 AM

    Does the benefit of it being embeddable on a QR code outweigh the lack of quality of life features like subtraction? Nevertheless, truly an impressive feat that shows how simple computers can be without all these modern API layers.
  • by tomberek on 11/8/23, 4:10 AM

    Look at how much room you have for data! I wonder what we can fit in there.

    More seriously, a metacircular example to draw from would be: https://github.com/kragen/stoneknifeforth

  • by wkjagt on 11/8/23, 1:26 AM

    Would it be possible to do a similar thing in a similar size for, for example, the 6502? I would love to give that a try, even though I probably lack the skills to make it that small. Or maybe it's even impossible.
  • by H8crilA on 11/7/23, 11:29 AM

    How fast is the grabage collector? And is it web scale? I'm concerned by the lack of native JSON support.
  • by mikewarot on 11/7/23, 5:40 AM

    Has anyone figured out how to pipe input to the qemu vm under WSL 2? I've tried all sorts of things, and nothing seems to work.

    The included py_autotype.py takes forever, but nothing outputs in the qemu vm as it is running.

    WSL 2 does have an X server running (xeyes works).

    Update: running the script against gedit doesn't work either... it's not a qemu issue