The Inner Compilers

  Some parts of this page/site are currently incomplete & will be updated asap
Other parts will change continually so use “Refresh” in your browser !!
  There is extensive use of “Tooltips” text to support learning which do not seem to render on a Smartphone. This site is best viewed via a computer’s HD monitor


The COLON Compiler is the most fundamental and important Forth compiler and is dealt with separately, along with the Semi-Colon Compiler…

The Inner Compilers

The Constant Compiler

Defining a constant value is an alternative to having the value compiled as an in-line numeric literal. When the constant definition is executed, it pushes its value onto the stack

Image#1 Fig 172. Source for the Constant Compiler, CONSTANT
Image: (Husband 2011), based on the Intel 8080 figForth model

More discussion of SMUDGE & the Smudge Bit

A discussion of CONSTANT’s run-time code, DOCON

A discussion of CREATE

The Variable Compiler

Defining a variable to hold a value that changes is often needed when using the stack for this purpose is not appropriate. When the variable definition is executed, it pushes its parameter field address, rather than its content, onto the stack

Note how VARIABLE is a very simple modification of CONSTANT

Image#2. Source for the Variable Compiler, VARIABLE
Image: (Husband 2011), based on the Intel 8080 figForth model

The use of VARIABLE does assume that the dictionary is in RAM; i.e. that DP, the dictionary pointer, is pointing to RAM…

A discussion of VARIABLE’s run-time code, DOVAR

The User Variable Compiler

Image#3. Source for the User Variable Compiler, USER
Image: (Husband 2011), based on the Intel 8080 figForth model

User Variables are very similar to variables. Compare Image#2 & Image#3; the compilers are virtually identical; VARIABLE compiles DOVAR as its run-time code and USER compiles DOUSE as its run-time code

DOUSE applies a fixed offset relative to the user area pointer UP to the address pushed onto the stack

A discussion of USER’s run-time code, DOUSE

The Vocabulary Compiler

VOCABULARY is a defining word used in the form: VOCABULARY cccc

where cccc is the name of the new vocabulary. The run-time code DOVOC is compiled into cccc

Image#3. The figForth Glossary definition of CONTEXT Image: (Husband 2011), based on the Intel 8080 figForth model

Executing cccc will make it the CONTEXT vocabulary which will be searched by the text interpreter first

In-line Data Compiler

In the parameter field of a colon definition there is normally a list of execution ad-dresses (code field addresses), which the address interpreter processes and executes… (Ting, 1986, p. 57; 1989, p. 30)

However, there are times when it is needed to embed other data such as literal numbers or strings of characters, or addresses for routing program flow144…

Literal Compiler

“If compiling, compile the stack value n as a 16-bit literal, which when later executed will leave n on the stack…” (Haydon 1982, p. 151)

Because the Address Interpreter will try to treat all values it encounters as execution addresses, in-line literal numbers in a colon definition must be preceded by run-time code called LIT which will push the contents of the next PFA onto the stack at execution time. LITERAL is responsible for compiling LIT when appropriate during compilation

These are 16-bit literal words… The equivalent 32-bit (“double”) words are: DLITERAL and D-LIT

The Text Compiler 1

Sometimes it is needed to output a string of text characters and this can be done using the word .” (“dot-quote”) .” uses WORD to read text from the input stream until delimiter “ is encountered and places it at the top of the dictionary starting at HERE. The first byte is the character count, then the text string, then two or more spaces. .” is “state-smart” so if it is compiling it compiles the run-time code (.”) and inserts the count & text in-line after (.”) . If the system is executing it outputs the text via TYPE

Image#4. Source for the Text Compiler, .” (“dot-quote”)
Image: (Husband 2011), based on the Intel 8080 figForth model

.” is an IMMEDIATE word

Control Structure Compiler

Forth allows a number of control structures to control the program flow based upon conditions but they all compile combinations of run-time code 0BRANCH and/or BRANCH

These are shown below. Ting has omitted the BEGIN … AGAIN structure

Compiled Control Structures

Image#5. Compiled Control Structures
Image: Based on Ting (1986, p. 140)

Defining New Defining Words

: …. ;CODE

Most of the High-Level Defining Words were created using the : …. ;CODE compiler, where ;CODE created run-time code in machine code. This method has portability issues when moving code to other processors as all the code following ;CODE would need to be rewritten for the new host

<BUILDS & DOES>

<BUILDS … DOES> allows the run-time code to be written in high-level Forth

References:

Brodie, L., 1981. Starting FORTH : an introduction to the FORTH language and operating system for beginners and professionals [online]. Englewood Cliffs, N.J: Prentice-Hall. Available from: https://www.forth.com/starting-forth/.

Haydon, G. B., 1982. All About Forth - An Annotated Forth Glossary [online]. Available from: Http://figforth.org.uk/library/All.About.Forth.pdf.

Husband, D., 2011. M.Sc in IT (Software Engineering). Master’s thesis. University of Liverpool.

Ting, C. H., 2013. Systems Guide to fig-Forth [online]. 3rd ed. San Mateo, CA 94402, USA: Offete Enterprises, Inc. Available from: http://figforth.org.uk/library/Systems.Guide.to.figForth.pdf.

  1. Not to be confused with parsing that compiles input text but in a totally different way… 


Updated: 13th February 2022 by David Husband
© 2021 David Husband, a.k.a. Baremetal Engineer Extraordinaire
All Rights Reserved – All Trademarks & Copyrights Acknowledged
All personal information is subject to the Data Protection Act 2018 & the UK GDPR
“ad auxilium aliis ad auxilium sibi”