From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

Forth is a heavily stack-oriented self-compiling procedural programming language that fist appeared in 1970. Forth interpreters can be written to run on bare metal or on top of a general purpose operating system. Forth code is self-compiling in real-time even when run from bare metal on top of simple machine language primitives. Thus, somewhat like defining a new compiler target in C, Forth is sometimes used to bootstrap entirely new hardware. Forth programs are divided up into "words" (subroutines). Embedded Forth interpreters are typically written in assembly language and built from Forth-words that call machine language primitives. Forth interpreters built for server use typically are written in C and built from Forth-words that call OS primitives.

Forth is infamous for requiring all mathematical operations be written in postfix notation. That is, 5+2 is written as 5 2 +. Needless to say, this syntax takes some getting used to.

Forth code runs on the most minimal of virtual machines, requiring only two CPU registers and a stack to function. Forth has been ported to extremely low spec processors, even to 8 and 16-bit CPU's that can make a difficult C compiler target. Forth applications are built on top of Forth interpreters; that is, the base Forth interpreter essentially becomes the application over the course of development. Consequently, Forth lacks a concept of C-style linking. This makes embedded versions of Forth extremely useful for time-critical embedded applications and even firmware development.

Forth on Gentoo

Gentoo has support for the following Forth interpreters: