HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
openbios
openfirmware
Forth2017–2023
openbios / openfirmware

openfirmware

OpenFirmware as used on OLPC (and elsewhere)

3Distinct people
15Mentions
1Explicit recommenders
125GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

OpenFirmware as used on OLPC (and elsewhere)

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

I've frequently written about Mitch Bradley's Forthmacs / Sun Forth / CForth / OpenBoot / OpenFirmware on HN. I was his summer intern at Sun in 1987, and used his Forth systems…

DonHopkins used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:03:16 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year15 dated mentions

Observed mentions: 2017-10-13 20:46:18 UTC to 2023-12-18 22:27:33 UTC.

02462017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20172018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2023

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC101
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC202
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC606
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC303
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC202

What Hacker News says

15 sources
Mitch Bradley came up with a nice way to refactor the Forth compiler/interpreter and control structures, so that you could use them immediately at top level! Traditional FORTHs only let you use IF, DO, WHILE, etc in : definitions, but they work fine at top level in Mitch's Forths (including CForth and Open Firmware). I've written about it before on HN: https://news.ycombinator.com/item?id=29261810 Speaking of Forth experts -- there's Mitch Bradley, who created OpenFirmware: [...] Mitch Bradley's 68k forth lets you use interactive conditionals and loops in the top level outer interpreter! I think he wrote a paper about that feature, which I might be able to dig up ... Here's something related he wrote about refactoring the outer interpreter, but not what I'm thinking of: https://groups.google.com/forum/#!topic/comp.lang.forth/lKQj... [...]
Read the rest
I got a quick reply from Mitch Bradley! Yes I wrote a paper but I probably can't find it. The easiest place to look would be in the Open Firmware source. https://github.com/MitchBradley/openfirmware/blob/master/for... The magic is all in +level and -level. Search for those in kernel.fth to see other places they are used to achieve a similar effect, e.g. in abort" For an alternative but effectively equivalent formulation, see: https://github.com/MitchBradley/cforth/blob/master/src/cfort... and https://github.com/MitchBradley/cforth/blob/master/src/cfort... [...] https://news.ycombinator.com/item?id=29264309 In PostScript that would be: /PostScript Know? { Honk! } { /PostScript Learn! } ifelse FORTH doesn't have an IFELSE unless you define it yourself of course, but it would have no way of telling which part of your code was the conditional, part to do if true, or part to do if false, since white space and line breaks have no meaning to it, except for a few cases like \ comments. The IF comes between the conditional and the part to do if true, the ELSE comes between the part to do if true and the part to do if false, and the THEN comes at the end. The structure of PostScript code, conditionals, and flow control is homoiconic, made of nested arrays, like polymorphic JSON arrays, where FORTH code is flat untyped arrays of threaded pointers with relative branching. Forth has an "inner interpreter" called NEXT that threads from one pointer to the next (sometimes implemented as one machine language instruction, or just a few), and also an "outer interpreter" or compiler that translates text into threaded code for the inner interpreter. https://en.wikipedia.org/wiki/Polymorphism_(computer_science... https://en.wikipedia.org/wiki/Homoiconicity https://en.wikipedia.org/wiki/Threaded_code Here's Mitch Bradley's implementation of interactive control structures (IF, ELSE, THEN, BEGIN, UNTIL, AGAIN, REPEAT, WHILE, DO, LOOP, etc) in the outer interpreter of his FORTH system, which actually allows you to use conditionals and loops at the interactive top level of the interpreter, not just in compiled words (which solves a traditional and frustrating limitation of classic FORTH). https://github.com/MitchBradley/openfirmware/blob/master/for... Here is an alternative but equivalent implementation of interactive Forth control structures in his CForth (Forth implemented in C, of course): https://github.com/MitchBradley/cforth/blob/master/src/cfort... Here's some more of Mitch's beautiful code from OpenFirmware, his Forth kernel meta-compiler written in Forth, which supports 8, 16, 32, an 64 bit, big-endian and little-endian architectures, as well as direct, indirect, and token threaded code: https://github.com/MitchBradley/openfirmware/blob/master/for... https://en.wikipedia.org/wiki/Threaded_code#Direct_threading https://en.wikipedia.org/wiki/Threaded_code#Indirect_threadi... https://en.wikipedia.org/wiki/Threaded_code#Token_threading [...] https://news.ycombinator.com/item?id=29265144 Some FORTH systems even have a "metacompiler" that lets one FORTH system compile another FORTH system for the same or different CPU, word size, byte order, threading technique, with or without a built-in compiler, etc, from the same source code! OpenFirmware (the FORTH burnt into boot roms of SPARC, PowerPC, OLPC, and other systems) is a great highly refined example that supports many different architectures: openfirmware/forth/kernel/metacompile.fth https://github.com/openbios/openfirmware/blob/master/forth/k... openfirmware/forth/kernel/meta1.fth https://github.com/openbios/openfirmware/blob/master/forth/k... The OpenFirmware kernel is a Forth meta-compiler, which can compile itself on any architecture, and also cross-compile for different target architectures. It has cross-architecture extensions to FORTH (like \16 \32 comments and /n /n* generically typed words) that make it possible to write platform, word size, byte order, and threading independent code, and compile images (stripped or with headers) for embedded systems (like the OLPC boot ROMs) and new CPU architectures (like Sun's transition from 68K to SPARC), and share code with a more powerful development environments. https://en.wikipedia.org/wiki/Compiler-compiler#Forth_metaco... [...] https://news.ycombinator.com/item?id=29264489 [...] Here's some IBM-PC Forth for the CAM-6 cellular automata machine that was block based -- check out the unique idiosyncratic right-justified reverse-indentation style (starting with KGET), which is not standard Forth style, but sure looks cool and poetic, like E E CUMMINGS ON CAPS LOCK: https://donhopkins.com/home/code/tomt-cam-forth-scr.txt https://donhopkins.com/home/code/tomt-users-forth-scr.txt [...] https://news.ycombinator.com/item?id=29261868 Coco Conn and Paul Rother wrote this up about what they did with FORTH at HOMER & Assoc, who made some really classic music videos including Atomic Dog, and hired Charles Moore himself! Here's what Coco Conn posted about it, and some discussion and links about it that I'm including with her permission: [...] Forth & Charles Moore We hired Forth, Inc. and got Charles Moore, the inventor of FORTH to program the console host computer. I learned FORTH and worked with Charles. I programmed the 2K byte EPROM in each visual channel. On the Master Z80 system we ran PolyForth a multi tasking system in 32K bytes. We had an extra 16K RAM for buffers and things. If I remember right, the system ran four tasks, but that was 20 years ago, my memory may be hazy. Anyway, I learn not only FORTH from Charles Moore, but also how to factor code in to small reusable routines, WORDs they're called in FORTH. I learned Object Oriented Programming without knowing it. Also a lot of use of vectors. Its a cool language. Charles Moore was a great inspiration to me, and really taught me a great deal that they never taught me in computer programming school. [...]
In A Forth Vocabulary for Iteration
Mitch Bradley's CForth has an infinite while loop as the inner interpreter with a switch statement inside, that uses a macro "#define next continue" to jump to the next instruction in the infinite while loop, instead of break. https://github.com/MitchBradley/cforth/blob/master/src/cfort... Mitch's CForth is about as efficient (and well designed and refined) a Forth interpreter you can possibly implement in portable C. Mitch's OpenFirmware is a more traditional industrial strength Forth implementation, extremely advanced, feature rich, and well designed, that runs on many different processors and hardware, has assemblers for different CPUs, and a metacompiler that supports many different CPUs, word sizes, byte orders, threading techniques, top level interactive control structures, headerless code, machine independent bytecode, read-only fi
Read the rest
rmware, portable device drivers, hardware and driver configuration, and many hardware platforms. https://github.com/MitchBradley/openfirmware This is an implementation of Open Firmware, a processor-independent firmware design. Open Firmware is specified by IEEE 1275-1994, Standard for Boot (Initialization, Configuration) Firmware. The IEEE standard designation lapsed in 1999, when the Open Firmware working group declined to go through the rather time-consuming IEEE reaffirmation process, but the design lives on. This implementation was written primarily by Mitch Bradley, the original author of Open Firmware. The bulk of the recent development was done at Firmworks by Bradley and colleagues. It traces its roots back to the original Open Boot firmware implementation that Bradley developed at Sun Microsystems in the late 80s and early 90s. That in turn had roots in Forthmacs, a Forth programming language implementation developed and marketed during the early 80s by Bradley Forthware. And Forthmacs, in turn, owes a debt of gratitude to the public domain Forth implementations F83, developed by Michael Perry, and MVP Forth, by Glen Haydon. Lilian Walter wrote the USB stack. https://news.ycombinator.com/item?id=29279022 DonHopkins on Nov 19, 2021 | parent | context | favorite | on: Forth vs Lisp The inner interpreter of Mitch Bradley's portable and efficient CForth is simply implemented with a big switch statement, in the function called "inner_interpreter". The C compiler typically compiles that code with the big switch statement into an efficient jump table, behind the scenes. https://github.com/MitchBradley/cforth/blob/master/src/cfort... Properly speaking, that's a token threaded interpreter, since it switches on token numbers in the code field, instead of indirecting function through pointers to the C equivalent of "code" words. https://en.wikipedia.org/wiki/Threaded_code#Token_threading https://news.ycombinator.com/item?id=27484426 DonHopkins on June 12, 2021 | root | parent | next [–] From https://news.ycombinator.com/item?id=21823081 I wrote malloc.fth for Mitch Bradley's ForthMacs, which ended up in OpenFirmware: https://github.com/openbios/openfirmware/blob/master/ofw/cor... [...] https://news.ycombinator.com/item?id=21822840 DonHopkins on Dec 18, 2019 | parent | context | favorite | on: Thoughts on Forth Programming Here's the interview with Mitch Bradley saved on archive.org: https://web.archive.org/web/20120118132847/http://howsoftwar... I've previously posted some stuff about Mitch Bradley -- I have used various versions of his ForthMacs / CForth / OpenFirmware systems, and I was his summer intern at Sun in '87! Mitch is an EXTREMELY productive FORTH programmer! He explains that FORTH is a "Glass Box": you just have to memorize its relatively simple set of standard words, and then you can have a complete understanding and full visibility into exactly how every part of the system works: there is no mysterious "magic", you can grok and extend every part of the system all the way down to the metal. It's especially nice when you have a good decompiler / dissassembler ("SEE") like ForthMacs, CForth, and OpenFirmware do. https://news.ycombinator.com/item?id=9271644 [...]
In My history with Forth and stack machines (2010)
I also love your comments, this and others! Of course OpenFirmware has some code for paging! ;) purpose: Set up page tables and turn on paging https://github.com/openbios/openfirmware/blob/master/cpu/x86... start-assembling protected-mode \ RAM is on and mem-info-pa tells the memory layout label entry \ Initialize virtual page table \ Initialize linear=physical page table (redundant page table entries) \ Enable paging (note that page fault handler is not in place yet) [ifdef] notdef \ clear page tables ax ax xor /ptab /l / # cx mov pt-pa # di mov rep ax stos [then]
In Thinking Forth (1984)
Yes indeed, but even more so: Forth is vastly more powerful than a mere macro assembler, because you have the full power of Forth to write arbitrary functions and mini-compilers to assemble code, no just simple macros! It comes with structured control flow constructs, and you can even write your own. Not only is the assembler itself written in Forth, but you can seamlessly extend and build on top of the it too, building high level interfaces and domain specific languages on top of low level assembly code and hardware. Check out the amazingly powerful x86 assembler in OpenFirmware, which is deeply integrated with the hardware, operating system, bootstrapping, debugging, tracing, breakpointing, disassembling, cross assembling, meta compiling, and calling back and forth with C code: purpose: x86 assembler https://github.com/openbios/openfirm
Read the rest
ware/tree/master/cpu/x86 purpose: From Forth, call the C subroutine whose address is on the stack https://github.com/openbios/openfirmware/blob/master/cpu/x86... purpose: Tools for creating disembodied assembly code sequences https://github.com/openbios/openfirmware/blob/master/cpu/x86... purpose: Forth access words for special 386 registers https://github.com/openbios/openfirmware/blob/master/cpu/x86... purpose: After a breakpoint, displays a backtrace of C stack frames. https://github.com/openbios/openfirmware/blob/master/cpu/x86... purpose: 386 disassembler. https://github.com/openbios/openfirmware/blob/master/cpu/x86... purpose: Access to I/O ports and physical addresses under Linux https://github.com/openbios/openfirmware/blob/master/cpu/x86... https://github.com/openbios/openfirmware/blob/master/cpu/x86... \ One of the very best features of FORTH assemblers is the ability \ to use structured conditionals instead of branching to nonsense \ labels. : IF >MARK swap long-offsets @ if dup h# eb = if drop h# e9 asm8, else prefix-0f h# 10 + asm8, then real? if 0 asm16, else 0 asm32, then else ASM8, 0 asm8, then ; : THEN >RESOLVE ; : BEGIN <MARK ; : UNTIL <RESOLVE ; : AHEAD 0EB IF ; : ELSE AHEAD BUT THEN ; : AGAIN 0EB UNTIL ; : WHILE IF BUT ; : REPEAT AGAIN THEN ; \ These conditional test words leave the opcodes of conditional \ branches to be used by the structured conditional words. \ For example, \ 5 # ECX CMP 0< IF EAX EBX ADD ELSE EAX EBX SUB THEN \ begin dx al in tbe # al and 0<> until https://github.com/openbios/openfirmware/blob/master/cpu/x86... \ Some x86 assembler macros to make it easier to write x86 early \ startup code. There are macros to set MSRs to specific values, \ to set and clear individual MSR bits, to read and write PCI \ configuration registers with the common CF8/CFC mechanism, \ and to read and write I/O ports. \ The code keeps the MSR register number in %ecx, the low 32 bits \ of the value in %eax, and the high 32 bits in %edx, consistent \ with the way the rdmsr and wrmsr machine instructions work. \ The bitset and bitclr operations work on %eax, and the -hi versions \ work on %edx. \ The I/O port operations also leave the data in %eax, so you can \ use bitset and bitclr with them too.
In Thinking Forth (1984)
DonHopkins·Nov 20, 2022Recommendation phrase
I've frequently written about Mitch Bradley's Forthmacs / Sun Forth / CForth / OpenBoot / OpenFirmware on HN. I was his summer intern at Sun in 1987, and used his Forth systems in many projects! https://github.com/openbios https://wiki.laptop.org/go/FORTH https://news.ycombinator.com/item?id=29261810 Speaking of Forth experts -- there's Mitch Bradley, who created OpenFirmware: https://news.ycombinator.com/item?id=21822840 Here's the interview with Mitch Bradley saved on archive.org: https://web.archive.org/web/20120118132847/http://howsoftwar... [...] https://news.ycombinator.com/item?id=27484426 I wrote malloc.fth for Mitch Bradley's ForthMacs, which ended up in OpenFirmware: https://github.com/openbios/openfirmware/blob/master/ofw/cor... [...] https://news.ycombinator.com/item?id=26892629 In a lot of FORTH implementations, constant numb
Read the rest
ers like 0, 1, -1 and others are hard coded, not just for speed but also for space: a call to a code word only takes one cell, instead of using two cells with a LIT [value]. Here's some Breshenham line code I first wrote in FORTH (Mitch Bradley's SunForth on a 68k Sun-2 with cg2 graphics board), then translated to 68k code (using the rpn FORTH assembler) -- the FORTH code is commented out before the corresponding assembly code: https://donhopkins.com/home/archive/forth/cg/line.f [...] https://news.ycombinator.com/item?id=17480298 Cool! Does it include a FORTH 6502 assembler written in FORTH? I love writing assembly code in RPN with Forth macros! You can write FORTH code with loops and conditionals and any kind of logic and parameters, that dynamically assembles machine code! Much better than your typical macro assembler. Here's some 6502 assembler for an Apple ][ SUPDUP terminal emulator that does ram card bank switching: http://www.donhopkins.com/home/archive/forth/supdup.f [...] https://news.ycombinator.com/item?id=22456471 In what way is PostScript worse than Forth? Please answer with specific details, and provide links to code if you can. I programmed a lot of Forth code before learning and moving on to programming a lot of PostScript code, so I've used each of them extensively, and much prefer PostScript, and I'm happy to show you why and explain by showing you code. [...] https://news.ycombinator.com/item?id=21968175 Kragen is right that PostScript is a lot more like Lisp or Smalltalk than Forth, especially when you use Owen Densmore's object oriented PostScript programming system (which NeWS was based on). PostScript is semantically very different and much higher level that Forth, and syntactically similar to Forth but uses totally different names (exch instead of swap, pop instead of drop, etc). [...]
In Thinking Forth (1984)
NeWS didn't use FORTH. But HyperTIES used both FORTH and NeWS because there were a lot of things that FORTH could do that NeWS couldn't, like link and call C code directly. The FORTH I used was Mitch Bradley's "Sun Forth", aka "Forthmacs" (with the Jove ersatz Emacs editor by Jonathan Payne built in), which eventually evolved into OpenFirmware, and which was once defined by an IEEE standard, "IEEE 1275-1994", but it was withdrawn because the standard was not reaffirmed: https://en.wikipedia.org/wiki/Open_Firmware >Open Firmware is described by IEEE standard IEEE 1275-1994, which was not reaffirmed by the Open Firmware Working Group (OFWG) since 1998 and has therefore been officially withdrawn by IEEE. It's still alive and maintained and used for many things. Here's the source code, called OpenBIOS, as well as some other implementations an
Read the rest
In Hypertext '87 (1988) [pdf]
https://news.ycombinator.com/item?id=26913281 (edited and expanded) DonHopkins 6 months ago | parent | context | favorite | on: Moving Forth (1993) >Some FORTH systems even have a "metacompiler" that lets one FORTH system compile another FORTH system for the same or different CPU, word size, byte order, threading technique, with or without a built-in compiler, etc, from the same source code! >OpenFirmware (the FORTH burnt into boot roms of SPARC, PowerPC, OLPC, and other systems) is a great highly refined example that supports many different architectures: >openfirmware/forth/kernel/metacompile.fth https://github.com/openbios/openfirmware/blob/master/forth/k... >openfirmware/forth/kernel/meta1.fth https://github.com/openbios/openfirmware/blob/master/forth/k... The OpenFirmware kernel is a Forth meta-compiler, which can compile itself on a
Read the rest
ny architecture, and also cross-compile for different target architectures. It has cross-architecture extensions to FORTH (like \16 \32 comments and /n /n* generically typed words) that make it possible to write platform, word size, byte order, and threading independent code, and compile images (stripped or with headers) for embedded systems (like the OLPC boot ROMs) and new CPU architectures (like Sun's transition from 68K to SPARC), and share code with a more powerful development environments. https://en.wikipedia.org/wiki/Compiler-compiler#Forth_metaco... >Many advocates of the language Forth call the process of creating a new implementation of Forth a meta-compilation and that it constitutes a metacompiler. The Forth definition of metacompiler is: >"A metacompiler is a compiler which processes its own source code, resulting in an executable version of itself." >This Forth use of the term metacompiler is disputed in mainstream computer science. See Forth (programming language) and History of compiler construction. The actual Forth process of compiling itself is a combination of a Forth being a self-hosting extensible programming language and sometimes cross compilation, long established terminology in computer science. Metacompilers are a general compiler writing system. Besides the Forth metacompiler concept being indistinguishable from self-hosting and extensible language. The actual process acts at a lower level defining a minimum subset of forth words, that can be used to define additional forth words, A full Forth implementation can then be defined from the base set. This sounds like a bootstrap process. The problem is that almost every general purpose language compiler also fits the Forth metacompiler description. >When (self-hosting compiler) X processes its own source code, resulting in an executable version of itself, X is a metacompiler. >Just replace X with any common language, C, C++, Pascal, COBOL, Fortran, Ada, Modula-2, etc. And X would be a metacompiler according to the Forth usage of metacompiler. A metacompiler operates at an abstraction level above the compiler it compiles. It only operates at the same (self-hosting compiler) level when compiling itself. One has to see the problem with this definition of metacompiler. It can be applied to most any language. >However, on examining the concept of programming in Forth, adding new words to the dictionary, extending the language in this way is metaprogramming. It is this metaprogramming in Forth that makes it a metacompiler. >Programming in Forth is adding new words to the language. Changing the language in this way is metaprogramming. Forth is a metacompiler because Forth is a language specifically designed for metaprogramming. Programming in Forth is extending Forth adding words to the Forth vocabulary creates a new Forth dialect. Forth is a specialized metacompiler for Forth language dialects. Mitch's OpenFirmware code is one end of the readability spectrum. But for shock value, here are some beautiful but inscrutable FORTH code excerpts that define cellular automata rules with lots of deeply nested conditionals around mysterious but exquisitely indented BEEPS and BOOPS and line noise that makes Perl look clean and elegant. ;) https://donhopkins.com/home/code/tomt-users-forth-scr.txt ( A-BOMB) 24 LOAD : KN C0 X0 Y0 Z0 + + + C1 X1 Y1 Z1 + + + * 0> ; : KC C0 C1 * X0 X1 * Y0 Y1 * Z0 Z1 * + + + 0> ; : EXPL X1 Y1 + X1 Y1 * - ; : RULE0 C0 KN IF DROP 0 THEN KC IF DROP 0 THEN C0 C1 * 1 = IF DROP 1 THEN ; : RULE1 Z1 KN IF DROP EXPL THEN KC IF DROP 0 THEN C0 C1 * 1 = IF DROP 1 THEN ; ( CASEN ) FORGET TASK : TASK ; : NSUM NORTH SOUTH EAST WEST N.WEST N.EAST S.WEST S.EAST CENTER + + + + + + + + ; : CASEN NSUM 0 = IF 0 ELSE NSUM 1 = IF 0 ELSE NSUM 2 = IF 1 ELSE NSUM 3 = IF 0 ELSE NSUM 4 = IF 0 ELSE NSUM 5 = IF 0 ELSE NSUM 6 = IF 0 ELSE NSUM 7 = IF 0 ELSE NSUM 8 = IF 0 ELSE NSUM 9 = IF 0 ELSE THEN THEN THEN THEN THEN THEN THEN THEN THEN THEN ; <T> ( BRAIN ) 36 LOAD : CENTERS CENTER1 2 * CENTER + ; : FEEP CENTERS 0 = IF 1 ELSE CENTERS 1 = IF 0 ELSE CENTERS 2 = IF 0 ELSE CENTERS 3 = IF 0 ELSE THEN THEN THEN THEN ; : RULE CASEN FEEP AND ; <T> f1 BBM01 ( READY ) FORGET TASK : TASK ; : CENTERS CENTER1 2 * CENTER + ; : READY CENTERS 0 = IF 1 ELSE CENTERS 1 = IF 0 ELSE CENTERS 2 = IF 0 ELSE CENTERS 3 = IF 0 ELSE THEN THEN THEN THEN ; <T> ( PUCCIO1) 24 LOAD : K7 C0 C1 * X0 X1 * Y0 Y1 * Z0 Z1 * + + + 0<> ; : K71 C0 C1 X0 1 X1 Y0 Y1 Z0 Z1 + + + + + * * * 1 = ; : K72 X0 X1 Z0 1 C0 C1 Y0 Y1 Z1 + + + + + * * * 1 = ; : K73 Z0 Z1 Y0 1 Y1 C0 C1 X0 X1 + + + + + * * * 1 = ; : K74 Y0 Y1 C0 1 C1 X0 X1 Z0 Z1 + + + + + * * * 1 = ; : K81 X0 X1 Y0 1 C0 C1 Z0 Z1 Y1 + + + + + * * * 1 = ; : K82 Z0 Z1 C0 1 X0 X1 Y0 Y1 C1 + + + + + * * * 1 = ; : K83 Y0 Y1 X0 1 Z0 Z1 C0 C1 X1 + + + + + * * * 1 = ; : K84 C0 C1 Z0 1 Y0 Y1 X0 X1 Z1 + + + + + * * * 1 = ; --> : RULE0 Y1 ( X1 Z1 + Z1 Y1 + Y1 C1 + * * 1 = IF DROP C1 THEN ) K7 IF DROP Z0 THEN K71 IF DROP 0 THEN K72 IF DROP 1 THEN K73 IF DROP 0 THEN K74 IF DROP 1 THEN K81 IF DROP 0 THEN K82 IF DROP 1 THEN K83 IF DROP 1 THEN K84 IF DROP 0 THEN ; ( DOUBLE GAS etoile on P0 and P1) 24 LOAD : KK C0 X0 Y0 Z0 + + + 1+ C1 X1 Y1 Z1 + + + 1+ * 5 = ; ( rotate right/left w/collisions ) : RULE0 KC0 IF C0 ELSE T0 0= IF Y0 ELSE X0 THEN THEN KK IF DROP C1 THEN ; ( diagonal gas, w/collisions) : RULE1 KC1 IF X1 ELSE Z1 THEN KK IF DROP C0 THEN ; BBM01 https://donhopkins.com/home/code/tomt-cam-forth-scr.txt ( MENU of keys ) VARIABLE UNFLG : ?UNDEF UNFLG @ IF OUT @ SWAP $. OUT @ - 6 + SPACES ." is undefined" ELSE DROP THEN ; : K. ( string.addr --) FIND IF OUT @ OVER >NAME .NAME OUT @ - 6 + SPACES >BODY BEGIN DUP @ ['] ;S <> WHILE DUP @ >NAME .NAME 2+ REPEAT DROP ELSE ?UNDEF THEN ; ( == creates fast code words for picking out bits of variable X) VARIABLE X CODE X! AX POP X , AX MOV NEXT, END-CODE CODE X@ AX, X MOV AX PUSH NEXT, END-CODE CREATE ZPUSH ASSEMBLER 1$ JNZ AX, # 0 MOV AX PUSH NEXT, 1$: AX, # 1 MOV AX PUSH NEXT, : X? ( mask byt#-) ASSEMBLER AL, X + MOV AL, # TEST ZPUSH JMP ; 0 CARRAY 2^N 1 C, 2 C, 4 C, 8 C, 10 C, 20 C, 40 C, 80 C, : == ( bit# --) ( ---- name ) >R [COMPILE] CODE R> 8 /MOD SWAP 2^N C@ SWAP X? ASSEMBLER [COMPILE] END-CODE ; 1 == NORTH 3 == WEST 5 == N.WEST 7 == S.WEST 9 == CENTER1 2 == SOUTH 4 == EAST 6 == N.EAST 8 == S.EAST 0 == CENTER ( eg. NORTH will return bit #1 of X when executed ) --> : #DX! ASSEMBLER DX, # MOV ; : #AL! ASSEMBLER AL, # MOV ; : AL.IN ASSEMBLER AL, DX IN ; : AL.OUT ASSEMBLER DX, AL OUT ; : SRCE BEGIN ?STEPPING @ (?TERMINAL) NOT AND WHILE STEPPING REPEAT (?TERMINAL) DLAST @ AND DNUM @ 0= OR SRCE.SEG SPOINT @ @L 0= OR IF SAVE.INPUT KSAV ELSE SRCE.SEG SPOINT GET DUP KPUT DUP DLAST C! THEN ;
In Forth vs Lisp
Forth is an interesting case. It's really unproductive to build complex systems with. If you try, you will probably be frustrated. Instead it forces you to try really hard to find a cheating short-cut to solve the problem as few moving parts as possible. Just one simple example. The 'struct' language feature is 1500 LOC in Lisp but only 10 LOC in FORTH (see below.) Are they equivalent? No, the Lisp one has lots of bells and whistles, while the FORTH one is minimalist in the extreme. If you tried to write the feature-complete Lisp version in FORTH you would probably find it very difficult and unproductive. So you wouldn't do that. And this to me is what FORTH's peculiar brand of efficiency is all about. If FORTH were a bar the only drink on the menu would be tap water. That bar would be extremely efficient to run. Lisp: https://github.com/
Read the rest
In What to Learn
From https://news.ycombinator.com/item?id=21823081 I wrote malloc.fth for Mitch Bradley's ForthMacs, which ended up in OpenFirmware: https://github.com/openbios/openfirmware/blob/master/ofw/cor... \ Forth dynamic storage managment. \ \ By Don Hopkins, University of Maryland \ Modified by Mitch Bradley, Bradley Forthware \ Public Domain \ \ First fit storage allocation of blocks of varying size. \ Blocks are prefixed with a usage flag and a length count. \ Free blocks are collapsed downwards during free-memory and while \ searching during allocate-memory. Based on the algorithm described \ in Knuth's _An_Introduction_To_Data_Structures_With_Applications_, \ sections 5-6.2 and 5-6.3, pp. 501-511. Forth systems running on C libraries can also call back to the native malloc/free implementation
Read the rest
, but it's nice to have a pure FORTH implementation for embedded applications.
In Fitting a FORTH in 512 bytes
Some FORTH systems even have a "metacompiler" that lets one FORTH system compile another FORTH system for the same or different CPU, word size, byte order, threading technique, with or without a built-in compiler, etc, from the same source code! OpenFirmware (the FORTH burnt into boot roms of SPARC, PowerPC, OLPC, and other systems) is a great highly refined example that supports many different architectures: openfirmware/forth/kernel/metacompile.fth https://github.com/openbios/openfirmware/blob/d5cc657ce81c0f... openfirmware/forth/kernel/meta1.fth https://github.com/openbios/openfirmware/blob/d5cc657ce81c0f...
In Moving Forth (1993)
I wrote malloc.fth for Mitch Bradley's ForthMacs, which ended up in OpenFirmware: https://github.com/openbios/openfirmware/blob/d5cc657ce81c0f... \ Forth dynamic storage managment. \ \ By Don Hopkins, University of Maryland \ Modified by Mitch Bradley, Bradley Forthware \ Public Domain \ \ First fit storage allocation of blocks of varying size. \ Blocks are prefixed with a usage flag and a length count. \ Free blocks are collapsed downwards during free-memory and while \ searching during allocate-memory. Based on the algorithm described \ in Knuth's _An_Introduction_To_Data_Structures_With_Applications_, \ sections 5-6.2 and 5-6.3, pp. 501-511. Forth systems running on C libraries can also call back to the native malloc/free implementation, but it's nice to have a pure FORTH implementation
Read the rest
for embedded applications.
In Thoughts on Forth Programming
Speaking of Lisp and Forth, I was really stunned when I noticed that adding syntactic support for "structs" in the language is about 10 lines in Forth (https://github.com/openbios/openfirmware/blob/master/forth/l...) and about 2000 lines in Lisp (https://github.com/sbcl/sbcl/blob/master/src/code/defstruct....). Mitch Bradley wrote up an explanation of the Forth library, and lots of other cool bits of Openfirmware, at http://wiki.laptop.org/go/Forth_Lesson_18.
In The Oforth Programming Language

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.