leastfixedpoint

JONESFORTH ported to PowerPC and Mac OS X

This page is a mirrored copy of an article originally posted on the (now sadly defunct) LShift blog; see the archive index here.

Thu, 4 October 2007

A couple of weeks ago, Richard W. M. Jones released JONESFORTH, which I thought was pretty exciting. Today I spent a few hours porting the assembly-language part to PowerPC on Mac OS X 10.3.9. It ended up being 600 non-comment lines of code in total, and took me about eleven hours in total to write and debug. It runs the standard JONESFORTH prelude, up to and including SEE.

You can download the code here: ppcforth.S.m4.

(It’s also available via darcs: darcs get http://www.eighty-twenty.org/~tonyg/Darcs/jonesforth.)

The assembler-macro tricks that the original i386 version uses are sadly unavailable with the default OS X assembler, so I’ve had to resort to using m4 instead; other than that, it’s more-or-less a direct translation of Richard’s original program. To compile it,

m4 ppcforth.S.m4 > ppcforth.S
gcc -nostdlib -o ppcforth ppcforth.S
rm ppcforth.S

To run it, download the JONESFORTH prelude (save it as jonesforth.f), and

$ cat jonesforth.f - | ./ppcforth 
JONESFORTH VERSION 14641 
OK 

Here’s an example session, decompiling the “ELSE” word:

SEE ELSE
: ELSE IMMEDIATE ‘ BRANCH , HERE @ 0 , SWAP DUP HERE @ SWAP - SWAP ! ;

I’d like to thank Richard for such an amazingly well-written program: not only is JONESFORTH itself a beautiful piece of software, it’s also an incredibly lucid essay that does a wonderful job of introducing the reader to the concepts and techniques involved in implementing a FORTH.

Comments

On 28 October, 2007 at 8:16 pm, Duane Bailey wrote:

Hey, thanks, I was just thinking of doing this myself!

On 29 October, 2007 at 10:22 am, tonyg wrote:

Note that I based my port at JONESFORTH version 38 - and Richard has been continuing development of the system. He’s now at version 45. If anyone updates the PPC code to track Richard’s x86 version, please post links to your darcs repositories below! (Or simply email me patches, if you prefer)

On 16 June, 2009 at 5:07 am, Felix Klock wrote:

FYI: I had to add -static to the gcc options to build ppcforth.S on my system (Mac OS X 10.5.7).

I do not know if that would break the build on older systems like 10.3, but it might be worth adding to the makefile…