PF11 -- An ANS Forth Implementation for the 68HC11
Andrew Sterian
Padnos School of Engineering
Grand Valley State University
| Top-Level | Glossary
| Compiler Design | Rationale | Notes |
Version 1.0 |
| July 18, 2003 |
|
| Introduction | Dictionary | Code Space
| The User and Return Stacks | Primitives | Control
Structures | Defining Words | Miscellaneous |


: test IF word1 ELSE word2 THEN ;

: test ( n -- )The code space implementation of the test word is as follows, shown in Forth code rather than code space words, for brevity.
CASE
1 OF word1 ENDOF
2 OF word2 ENDOF
3 5 RANGEOF word3 ENDOF
word4
ENDCASE
;
: test ( n -- )The implementation of the CASE structure uses variables CASE-DEPTH and OF-DEPTH at compile time to expand the structure to its primitive components.
1 OVER = IF DROP ( OF )
word1
ELSE ( ENDOF )
2 OVER = IF DROP ( OF )
word2
ELSE ( ENDOF )
3 5 (RANGEOF?) IF DROP ( RANGEOF )
word3
ELSE ( ENDOF )
word4
DROP THEN THEN THEN ( ENDCASE )
;
: test BEGIN word1 AGAIN ;The code space implementation of the test word is as follows:

: test BEGIN word1 UNTIL ;The code space implementation is as follows:

: test BEGIN word1 WHILE word2 REPEAT ;The code space implementation is as follows:

VARIABLE testThe word test is added to the dictionary. Its code space implementation is as follows.

9 CONSTANT testThe word test is added to the dictionary. Its code space implementation is as follows.

9 VALUE testThe word test is added to the dictionary as an IMMEDIATE word. Its code space implementation is the same as that of CONSTANT described above, except the word called as part of the "body" (i.e., the word after ID_CREATE_P) is different. The body that is executed at run time is (after the address of the data cell, 0x0009 in this example, is pushed on the stack by ID_CREATE_P):
STATE @The TO Forth word simply changes the 4th word of the code space implementation from its current value to a new value.
IF
[compile] LITERAL
compile @
ELSE
@
THEN
DEFER testThe word test is added to the dictionary. Its code space implementation is as follows.

CREATE testThe word test is added to the dictionary. Its code space implementation is as follows.


: CONSTANT CREATE , DOES> @ ;The code space implementation of CONSTANT, therefore, is:

3 trace-level !
: CONSTANT CREATE , DOES> @ ;
( stack trace omitted )
Error in ffSemiColon - stack depth changed between : and ; . Probably unbalanced conditional
hex 5678 1234