Special variables: Difference between revisions
Content deleted Content added
Line 575: | Line 575: | ||
===Common Practice=== |
===Common Practice=== |
||
Although not mandated in the Forth language specification, traditionally the language implements system variables as what are called USER variables. The name dates back to the a time when FORTH was used as a multi-user O/S and therefore each user needed a set of variables to control the state of their instance of the system. The user variables exist in a memory block called the USER AREA and are replicated for each task. On a context switch the system assigns a system VARIABLE called 'UP' (user pointer) to point to the new USER AREA. UP is commonly held in a CPU register on machines that have larger register sets. |
Although not mandated in the Forth language specification, traditionally the language implements system variables as what are called USER variables. The name dates back to the a time when FORTH was used as a multi-user O/S and therefore each user needed a set of variables to control the state of their instance of the system. The user variables exist in a memory block called the USER AREA and are replicated for each task. When used for embedded systems, Forth is still commonly implemented as a multi-tasking system, so this architecture is still relevant today. On a context switch the system assigns a system VARIABLE called 'UP' (user pointer) to point to the new USER AREA. UP is commonly held in a CPU register on machines that have larger register sets. |
||
This following list is |
This following list is an example of a set of USER variables in a small system. Consult the implementation documents for details on the USER variables in a specific FORTH system. |
||
<pre>Name Type Description |
<pre>Name Type Description |
||
--------------------------------------------- |
--------------------------------------------- |
||
TIB integer Terminal Input Buffer address |
TIB integer Terminal Input Buffer address |
||
U0 integer current user area address |
U0 integer current user area address |
||
>IN integer holds offset into TIB |
>IN integer holds offset into TIB, used for parsing |
||
BASE integer holds conversion radix |
BASE integer holds number conversion radix |
||
STATE integer holds compiler state (true=compiling, false=interpreting) |
STATE integer holds compiler state (true=compiling, false=interpreting) |
||
DP integer holds dictionary pointer |
DP integer holds dictionary memory pointer |
||
'SOURCE double contains length and address of input source |
'SOURCE double contains length and address of input source |
||
LATEST integer last word |
LATEST integer address of last word added to dictionary |
||
HP integer HOLD pointer, used for number formatting |
HP integer HOLD pointer, used for number formatting routines |
||
LP integer leave-stack pointer, used by do loops |
LP integer leave-stack pointer, used by do loops |
||
S0 integer end of parameter stack |
S0 integer end of parameter stack |
||
PAD chars[80] Generic buffer. (size is implementation |
PAD chars[80] Generic buffer. (size is implementation dependent) |
||
L0 integer bottom of leave stack |
L0 integer bottom of leave stack |
||
R0 integer end of return stack</pre> |
R0 integer end of return stack</pre> |