On Tue, Feb 29, 2000 at 10:41:35PM -0500, CLASSICCMP(a)trailing-edge.com wrote:
That's one way of doing it, but the most
traditional (and still most
popular, at least from what I see) way of doing it is to compile
straight to threaded machine code.
I've never understood this. Evidently most/all of the FIG FORTHs produced
threaded code, but I haven't found a single peep about it in the FIST standards
that say it's an inherent part of the language. I've written FORTHs that did
it both ways, very simple-minded in each case but I think it would be pretty
easy to write a FORTH that at least pruned out most of the superfluous stack
use (stuff that gets pushed and then popped right off) and could produce
semi-decent machine code.
Note that even though threaded code is usually most
commonly associated
with Forth and other "non-traditional" languages, the technique
is applicable to old-line languages as well.
Totally. When I ported Small-C to the IBM 370, I had it produce threaded
code, just because my head started to hurt whenever I thought about how to
automate the allocation of base registers. Yeeccchh...
My PDP-11 emulator has several different interpreters inside it for both
threaded code (for the device bootstraps, and for composing complicated
strings for log files) and tokenized code (for the keyboard script language),
they come in really handy. Funny how this stuff seems to be dying out these
days, but then again, if C is really bad at something, it's considered to
be that something's fault, no big surprise I guess. It's a really great
tool for cases where you're willing to lose a little speed to save a lot of
space.
John Wilson
D Bit