a simple forth implementation
G/c trailing whitespace.
(UNPARSED) - return string as ( -- c-addr u )
forth_eval - implement for arm


browse log


This is a very simple Forth that uses dumb, honest to god indirect
threaded code.  The core is written entirely in assembler.  There are
only three environmental dependencies for now - printing one char
(EMIT), printing a buffer (TYPE) and reading an input line (ACCEPT).
Escape to C is also used for things like 64-bit division (rewriting
__divmoddi4 in asm from scratch is boring and kinda pointless).

Currently supported CPUs: arm, i386, powerpc, sh3.

The core of the interpreter for sh3 is 14 instructions (two of which
are nops in delay slots).  About 90 asm words tally up to about 500
instructions.  Nearly all of them are short trivial sequences, like
adding two numbers, etc.  I'd say that someone familiar with the
target ISA can port == write the asm core in two or three evenings.  I
wrote powerpc code in three evenings without any prior knowledge of
the ISA.  The ARM port was done on a branch with a lot of small
commits specifically to illustrate the process and can be used as a

The rest of the system is transpiled from the forth sources to MI
assembler sources.  That "compiled" assembler used to be handwritten
(and you can still find it on the "handwritten" branch), but as the
system grows it gets more inconvenient to maintain it in that form.

Generating assembler source is not the most convenient way to go about
making a forth system.  Still there are certain reasons that make the
tradeoffs worthwhile for me.  GNU assembler is single pass, so that
imposes certain limitations.  There's a strong temptation to throw M4
into the mix to fix that, but M4 introduces certain inconveniences of
its own and I'm still not desperate enough to accept them.