annotate examples_forth/meta09.4 @ 191:d0f5894e9b3a default tip

some how load: confilicts in gmake
author kono
date Thu, 07 Dec 2023 09:37:15 +0900
parents 2088fd998865
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 \ CROSS COMPILER FOR THE MOTORAOLA 6809 PROCESSOR
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 \ created 1995 by L.C. Benschop.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 \ copyleft (c) 1995-2014 by the sbc09 team, see AUTHORS for more details.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 \ license: GNU General Public License version 2, see LICENSE for more details.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 \ This serves as an introduction to Forth cross compiling, so it is excessively
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 \ commented.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 \ This cross compiler can be run on any ANS Forth with the necessary
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 \ extension wordset that is at least 16-bit, including Motorola 6809 Forth.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 \ It creates the memory image of a new Forth system that is to be run
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 \ by the Motorola 6809 processor.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 \ The cross compiler (or meta compiler or target compiler) is similar
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 \ to a regular Forth compiler, except that it builds definitions in
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 \ a dictionary in the memory image of a different Forth system.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 \ We call this the target dictionary in the target space of the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 \ target system.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 \ As the new definitions are for a different Forth system, the cross
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 \ compiler cannot EXECUTE them. Neither can it easily find the new
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 \ definitions in the target dictionary. Hence a shadow definition
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 \ for each target definition is made in the normal Forth dictionary.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 \
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 \ The names of the new definitions overlap with the names of existing
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 \ elementary. Forth words. Therefore they need to be in a wordlist
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 \ different from the normal Forth wordlist.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 \ PART 1: THE VOCABULARIES.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 VOCABULARY TARGET
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 \ This vocabulary will hold shadow definitions for all words that are in
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 \ the target dictionary. When a shadow definition is executed, it
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 \ performs the compile action in the target dictionary.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 VOCABULARY TRANSIENT
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 \ This vocabulary will hold definitions that must be executed by the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 \ host system ( the system on which the cross compiler runs) and that
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 \ compile to the target system.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 \ Expl: The word IF occurs in all three vocabularies. The word IF in the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 \ FORTH vocabulary is run by the host system and is used when
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 \ compiling host definitions. A different version is in the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 \ TRANSIENT vocabulary. This one runs on the host system and
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 \ is used when compiling target definitions. The version in the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 \ TARGET vocabulary is the version that will run on the target
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 \ system.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 \ : \D ; \ Uncomment one of these. If uncommented, display debug info.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 : \D POSTPONE \ ; IMMEDIATE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 \ PART 2: THE TARGET DICTIONARY SPACE.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 \ Next we need to define the target space and the words to access it.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 1024 CONSTANT ORIGIN \ Start address of Forth image.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 8192 CONSTANT IMAGE_SIZE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 CREATE IMAGE IMAGE_SIZE CHARS ALLOT \ This space contains the target image.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 IMAGE IMAGE_SIZE 0 FILL \ Initialize it to zero.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 \ Fetch and store characters in the target space.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 : C@-T ( t-addr --- c) ORIGIN - CHARS IMAGE + C@ ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 : C!-T ( c t-addr ---) ORIGIN - CHARS IMAGE + C! ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 \ Fetch and store cells in the target space.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 \ M6809 is big endian 32 bit so store explicitly big-endian.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 : @-T ( t-addr --- x)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 ORIGIN - CHARS IMAGE + DUP C@ 8 LSHIFT SWAP 1 CHARS + C@ + ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 : !-T ( x t-addr ---)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 ORIGIN - CHARS IMAGE + OVER 8 RSHIFT OVER C! 1 CHARS + C! ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 \ A dictionary is constructed in the target space. Here are the primitives
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 \ to maintain the dictionary pointer and to reserve space.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 VARIABLE DP-T \ Dictionary pointer for target dictionary.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 ORIGIN DP-T ! \ Initialize it to origin.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 : THERE ( --- t-addr) DP-T @ ; \ Equivalent of HERE in target space.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 : ALLOT-T ( n --- ) DP-T +! ; \ Reserve n bytes in the dictionary.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 : CHARS-T ( n1 --- n2 ) ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 : CELLS-T ( n1 --- n2 ) 1 LSHIFT ; \ Cells are 2 chars.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 : ALIGN-T ; \ No alignment used.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 : ALIGNED-T ( n1 --- n2 ) ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 : C,-T ( c --- ) THERE C!-T 1 CHARS ALLOT-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 : ,-T ( x --- ) THERE !-T 1 CELLS-T ALLOT-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 : PLACE-T ( c-addr len t-addr --- ) \ Move counted string to target space.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 OVER OVER C!-T 1+ CHARS ORIGIN - IMAGE + SWAP CHARS CMOVE ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 \ 6809 cross assembler already loaded, configure it for cross assembly.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 FORTH ' ,-T ASSEMBLER IS ,
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 FORTH ' C,-T ASSEMBLER IS C,
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 FORTH ' !-T ASSEMBLER IS V!
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 FORTH ' @-T ASSEMBLER IS V@
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 FORTH ' C!-T ASSEMBLER IS VC!
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 FORTH ' C@-T ASSEMBLER IS VC@
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 FORTH ' THERE ASSEMBLER IS HERE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 FORTH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 \ PART 3: CREATING NEW DEFINITIONS IN THE TARGET SYSTEM.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 \ These words create new target definitions, both the shadow definition
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 \ and the header in the target dictionary. The layout of target headers
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 \ can be changed but FIND in the target system must be changed accordingly.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 \ All definitions are linked together in a number of threads. Each word
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 \ is linked in only one thread. Which thread the word is linked to, can be
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 \ determined from the name by a 'hash' code. To find a word, one can compute
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 \ the hash code and then one can search just one thread that contains a
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 \ small fraction of the words.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 4 CONSTANT #THREADS \ Number of threads
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 CREATE TLINKS #THREADS CELLS ALLOT \ This array points to the names
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 \ of the last definition in each thread.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 TLINKS #THREADS CELLS 0 FILL
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 VARIABLE LAST-T \ Address of last definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 : HASH ( c-addr u #threads --- n)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 >R OVER C@ 1 LSHIFT OVER 1 > IF ROT CHAR+ C@ 2 LSHIFT XOR ELSE ROT DROP
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 THEN XOR
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 R> 1- AND
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 : "HEADER >IN @ CREATE >IN ! \ Create the shadow definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 BL WORD
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 DUP COUNT #THREADS HASH >R \ Compute the hash code.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 ALIGN-T TLINKS R@ CELLS + @ ,-T \ Lay out the link field.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 \D DUP COUNT CR ." Creating: " TYPE ." Hash:" R@ .
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 COUNT DUP >R THERE PLACE-T \ Place name in target dictionary.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 THERE TLINKS R> R> SWAP >R CELLS + !
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 THERE LAST-T !
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 THERE C@-T 128 OR THERE C!-T R> 1+ ALLOT-T ALIGN-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 \ Set bit 7 of count byte as a marker.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 \ : "HEADER CREATE ALIGN-T ; \ Alternative for "HEADER in case the target system
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 \ is just an application without headers.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 ALSO TRANSIENT DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 : IMMEDIATE LAST-T @ DUP C@-T 64 OR SWAP C!-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 \ Set the IMMEDIATE bit of last name.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 PREVIOUS DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 \ PART 4: FORWARD REFERENCES
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 \ Some definitions are referenced before they are defined. A definition
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 \ in the TRANSIENT voc is created for each forward referenced definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 \ This links all addresses together where the forward reference is used.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 \ The word RESOLVE stores the real address everywhere it is needed.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 : FORWARD
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 CREATE 0 , \ Store head of list in the definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 DOES>
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 DUP @ ,-T THERE 1 CELLS-T - SWAP ! \ Reserve a cell in the dictionary
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 \ where the call to the forward definition must come.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 \ As the call address is unknown, store link to next
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 \ reference instead.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 : RESOLVE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 ALSO TARGET >IN @ ' >BODY @ >R >IN ! \ Find the resolving word in the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 \ target voc. and take the CFA out of the definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 \D >IN @ BL WORD COUNT CR ." Resolving: " TYPE >IN !
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 TRANSIENT ' >BODY @ \ Find the forward ref word in the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 \ TRANSIENT VOC and take list head.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 BEGIN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 DUP \ Traverse all the links until end.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 WHILE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 DUP @-T \ Take address of next link from dict.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 R@ ROT !-T \ Set resolved address in dict.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 REPEAT DROP R> DROP PREVIOUS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 \ PART 5: CODE GENERATION
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 \ Motorola 6809 Forth is a direct threaded Forth. It uses the following
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 \ registers: S for stack pointer, Y for return stack pointer, U for
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 \ instruction pointer. NEXT is the single instruction PULU PC.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 \ THe code field of a definition contains a JSR instruction.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 : JSR, [ HEX ] BD C,-T [ DECIMAL ] ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 VARIABLE STATE-T 0 STATE-T ! \ State variable for cross compiler.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 : T] 1 STATE-T ! ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 : T[ 0 STATE-T ! ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 VARIABLE CSP \ Stack pointer checking between : and ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 : !CSP DEPTH CSP ! ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 : ?CSP DEPTH CSP @ - ABORT" Incomplete control structure" ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 TRANSIENT DEFINITIONS FORTH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 FORWARD LIT
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 FORWARD DOCOL
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 FORWARD DOCON
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 FORWARD DOVAR
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 FORWARD UNNEST
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 FORWARD BRANCH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 FORWARD ?BRANCH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 FORTH DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 : LITERAL-T ( n --- )
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 \D DUP ." Literal:" . CR
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 [ TRANSIENT ] LIT [ FORTH ] ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 TRANSIENT DEFINITIONS FORTH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 \ Now define the words that do compile code.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 : : !CSP "HEADER THERE , JSR, [ TRANSIENT ] DOCOL [ FORTH ] T]
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 DOES> @ ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 : ; [ TRANSIENT ] UNNEST [ FORTH ] \ Compile the unnest primitive.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 T[ ?CSP \ Quit compilation state.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 : CODE "HEADER ASSEMBLE THERE ,
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 DOES> @ ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 : END-CODE [ ASSEMBLER ] ENDASM [ FORTH ] ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 : LABEL THERE CONSTANT ASSEMBLE ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 FORTH DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 \ PART 6: DEFINING WORDS.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 TRANSIENT DEFINITIONS FORTH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 : VARIABLE "HEADER THERE , JSR, [ TRANSIENT ] DOVAR [ FORTH ] 0 ,-T
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 \ Create a variable.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 DOES> @ ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 : CONSTANT "HEADER THERE , JSR, [ TRANSIENT ] DOCON [ FORTH ]
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 ,-T
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 DOES> @ ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 FORTH DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 : T' ( --- t-addr) \ Find the execution token of a target definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 ALSO TARGET '
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 \D ." T' shadow address, target address " DUP . DUP >BODY @ .
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 >BODY @ \ Get the address from the shadow definition.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 PREVIOUS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 : >BODY-T ( t-addr1 --- t-addr2 ) \ Convert executing token to param address.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 3 + ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 \ PART 7: COMPILING WORDS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 TRANSIENT DEFINITIONS FORTH
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 \ The TRANSIENT definitions for IF, THEN etc. compile the
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 \ branch primitives BRAMCH and ?BRANCH.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 : BEGIN THERE ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 : UNTIL [ TRANSIENT ] ?BRANCH [ FORTH ] ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 : IF [ TRANSIENT ] ?BRANCH [ FORTH ] THERE 1 CELLS-T ALLOT-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 : THEN THERE SWAP !-T ; TARGET
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 : ELSE [ TRANSIENT ] BRANCH THERE 1 CELLS-T ALLOT-T SWAP THEN [ FORTH ] ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 : WHILE [ TRANSIENT ] IF [ FORTH ] SWAP ; TARGET
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 : REPEAT [ TRANSIENT ] BRANCH ,-T THEN [ FORTH ] ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 FORWARD (DO)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 FORWARD (LOOP)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 FORWARD (.")
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 FORWARD (POSTPONE)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 : DO [ TRANSIENT ] (DO) [ FORTH ] THERE ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 : LOOP [ TRANSIENT ] (LOOP) [ FORTH ] ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 : ." [ TRANSIENT ] (.") [ FORTH ] 34 WORD COUNT DUP 1+ >R
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 THERE PLACE-T R> ALLOT-T ALIGN-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 : POSTPONE [ TRANSIENT ] (POSTPONE) [ FORTH ] T' ,-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 : \ POSTPONE \ ; IMMEDIATE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 : \G POSTPONE \ ; IMMEDIATE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 : ( POSTPONE ( ; IMMEDIATE \ Move duplicates of comment words to TRANSIENT
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 : CHARS-T CHARS-T ; \ Also words that must be executed while cross compiling.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 : CELLS-T CELLS-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 : ALLOT-T ALLOT-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 : ['] T' LITERAL-T ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 FORTH DEFINITIONS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 \ PART 8: THE CROSS COMPILER ITSELF.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 VARIABLE DPL
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 : NUMBER? ( c-addr ---- d f)
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 -1 DPL !
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 BASE @ >R
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 COUNT
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 OVER C@ 45 = DUP >R IF 1 - SWAP 1 + SWAP THEN \ Get any - sign
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 OVER C@ 36 = IF 16 BASE ! 1 - SWAP 1 + SWAP THEN \ $ sign for hex.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 OVER C@ 35 = IF 10 BASE ! 1 - SWAP 1 + SWAP THEN \ # sign for decimal
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 DUP 0 > 0= IF R> DROP R> BASE ! 0 EXIT THEN \ Length 0 or less?
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 >R >R 0 0 R> R>
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 BEGIN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 >NUMBER
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 DUP IF OVER C@ 46 = IF 1 - DUP DPL ! SWAP 1 + SWAP ELSE \ handle point.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 R> DROP R> BASE ! 0 EXIT THEN \ Error if anything but point
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 DUP 0= UNTIL DROP DROP R> IF DNEGATE THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 R> BASE ! -1
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 : CROSS-COMPILE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 ONLY TARGET DEFINITIONS ALSO TRANSIENT \ Restrict search order.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 BEGIN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 BL WORD
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 \D CR DUP COUNT TYPE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 DUP C@ 0= IF \ Get new word
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 DROP REFILL DROP \ If empty, get new line.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 ELSE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 DUP COUNT S" END-CROSS" COMPARE 0= \ Exit cross compiler on END-CROSS
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 IF
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 ONLY FORTH ALSO DEFINITIONS \ Normal search order again.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 DROP EXIT
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 FIND IF \ Execute if found.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 EXECUTE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 ELSE
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 NUMBER? 0= ABORT" Undefined word" DROP
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 STATE-T @ IF \ Parse it as a number.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 LITERAL-T \ If compiling then compile as a literal.
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 THEN
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 0 UNTIL
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 ;
2088fd998865 sbc09 directry clean up
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337