9 ms·
Fitting a FORTH in 512 bytes
- deleted 5y ago[deleted]
- stcredzero 5y ago"To compile a kernel, you need a running kernel." Why? I guess it depends on how you define "kernel." But to be able to do a batch process like compilation, you can get away with a little.
- spicybright 5y agoI'm guessing by kernel he meant any program that can host other programs in some way. Can you clarify what batch process means in this case? I /think/ the authors definition of a kernel is a program that can host other programs in some way. A video game on a boot sector can't do that (even though it likely would have it's own kernel to function), but some kind of input loop to write memory could.
- stcredzero 5y agoThe old Apple II+ I had as a kid only did one process at a time. For an OS, it basically had what amounted to a REPL for Microsoft BASIC. You don't need to host another program to compile something. All you need to do is to read data off disk, then write other data back.
- Someone 5y agoAnd what would do that “read data off disk, then write other data back”, if not a program? Even if you use a monitor (https://en.wikipedia.org/wiki/Machine_code_monitor https://en.wikipedia.org/wiki/Machine_code_monitor) to write a program, that’s still a program. The only way to avoid that is to hand-punch a tape or something like that (with lots of practice and patience, it may be possible to program a small PROM or write an early floppy by hand)
- ronsor 5y agoI'm reminded of the manually-inputted Microsoft BASIC bootloader for the ALTAIR 8800: https://just8bits.blogspot.com/2017/03/doing-it-in-less-than-bill-gates.html https://just8bits.blogspot.com/2017/03/doing-it-in-less-than...
- SAI_Peregrinus 5y agoI've compiled some simple C (microcontroller blinky) by hand. Then assembled and linked the output, and written the machine code into a HEX (Intel format) file. Then tested it on the micro. It's a rather fun exercise (Type 2 fun).
- Something1234 5y agoWhat is type 2 fun?
- deleted 5y ago[deleted]
- kstrauser 5y agoOn a Commodore 64, the kernal [sic] was similar to the BIOS on a PC, with display and keyboard handlers, IO routines, etc. When you first turned on the machine, something had to say "** COMMODORE 64 BASIC V2 **", and that something was the kernal.
- edgyquant 5y agoI always kind of thought the kernel was, at its core, the thing that handles processes and hardware io. Even if you use one of those tiny micro kernels it has to handle processes and present an api through which to communicate with devices (even if it doesn’t handle the devices itself.) I think it’s true you need a kernel to compile a kernel in this sense.
- NieDzejkob 5y agoWorkarounds exist, like for every other example I mentioned. I am mostly referring to the commonly used dependency graph.
- musicale 5y agoAs the article demonstrates, all you really need is a boot loader. On early machines (large and small) with front panel hardware, you could use switches to manually enter the boot loader into memory and then start it.
- stan_rogers 5y ago...and the EDSAC crew decided that that sort of thing was a mug's game as far back as 1949, so they added what amounts to a machine to do that for you (the Initial Orders unit). (No, I don't really miss the Altair, no matter how ecstatic I was about it in high school. Toogle-booting is fun maybe twice.)
- dng88 5y agoTechnically not true. As all computer starts with hardware and only that so e input process is needed. Of course, it really depends on howto define kennel. But you do not need very high level. Some feedback is better. Otherwise just input something, computer can take on. The “software” on the hardware need not be complete.
- astrobe_ 5y agoThat's precisely the joke. "Kernel" here means the minimal feature set that let you compile a kernel. The sentence is tautological, except perhaps for the definition of "minimal", because there are various flavors of "minimal" (e.g. absolute minimum, practical minimum, ergonomic minimum...).
- hyperhopper 5y agoI find it amusing how often trying to do complex tasks with simple constraints, always ends up back at stack based languages. Probably why the stack based turing machine is academically important.
- q-big 5y ago> Probably why the stack based turing machine is academically important. A Turing machine is not stack-based, but tape-based. A pushdown automaton (PDA) is stack-based.
- NieDzejkob 5y agoI suppose that prior art influences things. In my case, I went "a separate text editor won't fit, I need a REPL", and that basically filtered to just Forth and Lisp. It would be interesting to see what subset of Lisp would fit in a bootsector, but I wouldn't get my hopes up.
- na85 5y agoThere's sectorlisp that appears to fit into two sectors but is yet shy of their single-sector goal: https://github.com/jart/sectorlisp https://github.com/jart/sectorlisp
- jart 5y agosectorlisp right now is 800 bytes but it implements LISP well enough that you can use its built-in LISP IDE to implement your own LISP engine on top of sectorlisp using high-level functional programming techniques. https://youtu.be/hvTHZ6E0Abo https://youtu.be/hvTHZ6E0Abo If we can trim down the code size another 250 bytes then all this will fit in the master boot record.
- cblum 5y agoGonna plug my own sectorforth here: https://github.com/cesarblum/sectorforth https://github.com/cesarblum/sectorforth The linked post is really impressive. The author went way beyond what I did. I'm especially impressed by the I/O stuff.
- na85 5y agoMan, Forth is such a cool language. It really captures (what I perceive to be) the "hacker mentality" of powerful but simple tools, without much overt concern for polish/slick interfaces. I mean I know a lot of foundational code of yesteryear was hacked together in C, but C lacks a certain ineffable cachet in my view. A cachet that Forth definitely has.
- deleted 5y ago[deleted]
- kabdib 5y agoFORTH is a fun little class of languages. These are easy to implement; in a few KB you can have a working development environment, with a screen editor, debugger and whatnot. In my experience, FORTH doesn't really scale to big projects, or things that need a lot of dynamic allocation. It's great at low-level stuff like hardware bringup (we used it on the Atari ST, back in the day, and even the hardware engineers were writing code to exercise their designs), but doing anything at scale is going to be tough. You probably don't want to write a modern web server platform in it, for instance. But it's probably great on an Arduino with a serial port. There were a lot of games started at Atari in FORTH ("Hey, this is simple! Who needs to hire expensive assembly language programmers?") but the only project that shipped was the pinball machine "Four by Four". I saw a bunch of expensive disasters and mostly steered away from it.
- NieDzejkob 5y agoThis reminds me of this video on a text processing example with Forth: https://www.youtube.com/watch?v=mvrE2ZGe-rs https://www.youtube.com/watch?v=mvrE2ZGe-rs
- bluedino 5y agoWeren’t some 7800 games written in Forth?
- kabdib 5y agoLooks like a few were: https://atariage.com/forums/topic/155951-games-written-in-forth/ https://atariage.com/forums/topic/155951-games-written-in-fo... These were written by third parties and published by Atari. Atari did not have any game programmers on the payroll at that point (all the software folks were working on the ST and related things). There might have been some contracting going on, but the days of an Atari employee coming up with a new game idea and shipping a new cartridge were gone.
- dingosity 5y agopeople talking about how cool FORTH is. @cblum made his own sector forth. this is my tribe. i honestly thought there were no stack fans left in the world, thanks for proving me wrong.
- musicale 5y agoOpenBoot/Open Firmware[1] also used Forth. Although the standard was withdrawn in 2000, it continued to be used by PowerPC Macs until Apple moved to x86 and EFI/UEFI. Open Firmware is now actually open source as OpenBIOS (and OpenBoot is also available under a BSD license.) Apparently it can be used as a qemu boot rom for Linux, BSD, Solaris, and PowerPC versions of Mac OS 9 and OS X.[2] [1] https://en.wikipedia.org/wiki/Open_Firmware https://en.wikipedia.org/wiki/Open_Firmware [2] https://www.openfirmware.info/OpenBIOS https://www.openfirmware.info/OpenBIOS
- sarak12070 5y agoGet beautiful glowing face using papaya mask Step by step guide http://healthwithbeauty.xyz/2021/06/11/papaya-yogurt-mask-step-by-step-guide/ http://healthwithbeauty.xyz/2021/06/11/papaya-yogurt-mask-st... most dangerous bridge in the world https://www.interestingnews.club/2021/06/most-dangerous-bridge-in-world.html https://www.interestingnews.club/2021/06/most-dangerous-brid... Norwegian man dead hangs for 16 minutes to break world record https://www.interestingnews.club/2021/06/norwegian-man-dead-hangs-for-16-minutes.html https://www.interestingnews.club/2021/06/norwegian-man-dead-...
- timonoko 5y agoThere must be lots of ole-school fixed-width machines, which have stack machine built-in. Especially if you decide that top-of-stack means contents of the accumulator(s). To make it a "forth", you need separate string space, where machine words are linked to symbols. 1+ for example is just INC.
- int_19h 5y agoMany modern RISC architectures have pre-increment and post-decrement addressing modes for all their general-purpose registers, so it's very easy and convenient to maintain multiple stacks and implement "NEXT".
- throwaway81523 5y agoSeems painful. I liked this approach better: https://github.com/nineties/planckforth https://github.com/nineties/planckforth You start with a very tiny address or bytecode interpreter, much smaller than 512 bytes. Then you load several levels of bootstrap interpreters into it until you have a fairly featureful Forth. So that occupies ram but not program space on the target computer. You would load the non-initial stuff from a remote computer that didn't have tiny memory constraints.
- 1vuio0pswjnm7 5y agoWill this run in Bochs.