logoalt Hacker News

DonHopkinsyesterday at 9:50 AM0 repliesview on HN

Then you can have fun implementing Forth in Forth, with a metacompiler that compiles itself!

Here's some of Mitch Bradley'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, with or without headers, etc:

kernel.fth: https://github.com/MitchBradley/openfirmware/blob/master/for...

metacompile.fth: https://github.com/MitchBradley/openfirmware/blob/master/for...

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.