1 \
FLK compiler words
(host
versions)
3 \
Copyright (C) 1998 Lars Krueger
5 \
This file is
part of FLK.
7 \
FLK is
free software
; you
can redistribute
it and/or
8 \ modify
it under the
terms of the
GNU General Public License
9 \
as published by the
Free Software Foundation; either version
2
10 \
of the
License, or (at
your option) any later version
.
12 \
This program is
distributed in the
hope that
it will
be useful
,
13 \ but
WITHOUT ANY WARRANTY; without
even the
implied warranty
of
14 \
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 \
GNU General Public License for more
details.
17 \
You should have
received a copy
of the GNU General Public License
18 \ along
with this
program; if not
, write
to the Free Software
19 \
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 \ $
Id: flkhcomp
.fs
,v
1.16 1998/09/21 11:25:20 root
Exp $
22 \ $
Log: flkhcomp
.fs
,v $
23 \
Revision 1.16 1998/09/21 11:25:20 root
26 \
Revision 1.15 1998/09/13 15:42:04 root
27 \ introduced separate
control flow stack
29 \
Revision 1.14 1998/08/30 10:50:59 root
30 \
new optimizing algorithm
32 \
Revision 1.13 1998/07/18 10:49:59 root
35 \
Revision 1.12 1998/07/16 19:31:37 root
36 \ changed
to conditional
near jumps
38 \
Revision 1.11 1998/07/13 18:08:54 root
39 \ various
optimizations
41 \
Revision 1.10 1998/07/03 09:09:28 root
42 \ support
for level
2 optimizer
44 \
Revision 1.9 1998/06/08 22:14:51 root
45 \ literals
cache (preparation
to level
2 optimizer
)
47 \
Revision 1.8 1998/05/01 18:11:25 root
48 \
GNU license
text added
51 \
Revision 1.7 1998/04/30 09:42:25 root
54 \
Revision 1.6 1998/04/24 16:47:39 root
57 \
Revision 1.5 1998/04/16 18:43:39 root
58 \ flow
control improved
60 \
Revision 1.4 1998/04/16 14:09:25 root
61 \
IF ELSE THEN generates
faster code
63 \
Revision 1.3 1998/04/15 18:15:30 root
66 \
Revision 1.2 1998/04/09 11:35:03 root
67 \ all
words checked and OK
69 \
Revision 1.1 1998/04/07 20:10:33 root
74 \
Factor of AHEAD and IF.
76 CFT-orig
(new-cs
-item
)
79 fwd
-jmp
(curr
-cf
-item
) 3 CELLS + !
84 : IF ( flag
-- ) ( C: -- orig
)
93 : THEN ( -- ) ( C: orig -- )
96 CFT-orig (check-cs-item)
97 FALSE (curr-cf-item) CHAR+
99 (curr-cf-item) 3 CELLS + @
104 : ELSE ( -- ) ( C: orig1 -- orig2 )
108 [OSEM] THEN [PREVIOUS]
112 : BEGIN ( -- ) ( C: -- dest
)
115 CFT-dest
(new-cs
-item
)
116 (curr
-cf
-item
) CHAR+ allocator
-state
117 asm
-here
(curr
-cf
-item
) 3 CELLS + !
121 : UNTIL ( flag
-- ) ( C: dest
-- )
123 CFT-dest
(check
-cs
-item
)
128 TRUE (curr
-cf
-item
) CHAR+ allocator
-rebuild
129 (curr
-cf
-item
) 3 CELLS + @ \ jmp
-addr
137 : WHILE ( C: dest
-- orig dest
) ( flag
-- )
139 CFT-dest
(check
-cs
-item
)
144 ['] n-jz, (ahead) \ dest orig
149 : REPEAT ( C: orig dest -- ) ( -- )
151 CFT-dest (check-cs-item)
153 FALSE (curr-cf-item) CHAR+
154 allocator-rebuild \ C: orig dest
155 (curr-cf-item) 3 CELLS + @ \ jmp-addr / C: orig dest
156 (delete-cs-item) \ jmp-addr / C: orig
158 CFT-orig (check-cs-item)
159 (curr-cf-item) CHAR+ allocator-store
160 (curr-cf-item) 3 CELLS + @
161 (delete-cs-item) \ jmp-addr
165 \ Data format for CFT-do
168 \ 1 byte allocator state
169 \ 3 cells a1=addr. of inner code
170 \ 4 cells a3=fix-addr for ?DO
174 \ Set's up a new cf-stack item and copies the current allocator state to it.
175 : (prepare-do-cs-item) ( -- )
177 (curr-cf-item) CHAR+ allocator-state
178 asm-here (curr-cf-item) 3 CELLS + !
183 : DO ( lim start -- ) ( C: -- do-sys )
185 req-any \ tos0=start=ind=eax
186 req-any \ tos1=lim=ecx
187 $$ 80000000 ## tos1 add,
190 tos0 push, \ r: lim ind
193 0 (curr-cf-item) 4 CELLS + !
197 : ?DO ( lim start -- ) ( C: -- do-sys )
199 req-any \ tos0=start=ind=eax
200 req-any \ tos1=lim=ecx
202 ['] n
-je
, fwd
-jmp \
a3
203 $$
80000000 ## tos1 add,
206 tos0 push
, \
a3 / r
: cnt
ind
209 (curr
-cf
-item
) 4 CELLS + !
213 : LOOP ( -- ) ( C: do-sys
-- )
215 CFT-do (check
-cs
-item
)
222 TRUE (curr
-cf
-item
) CHAR+ allocator-rebuild
223 (curr
-cf
-item
) 3 CELLS + @ \ jmp
-addr
226 (curr
-cf
-item
) 4 CELLS + @ ?DUP IF
256 [CHAR] " PARSE \ addr len
257 2>R td-here CODE-SIZE +
258 (opt-add-r-const) 2R>
259 TUCK 2>R (opt-add-const)
264 ' CSEM >BODY @ SEARCH-WORDLIST
266 S" Can't find TYPE." error-exit
273 [COMMENTS] S" [PREVIOUS]
274 (type-xt) (opt-add-xt) ;
279 t-lastheader t->CFA t-@ >R
287 : CASE ( -- C: case-sys )
288 CFT-case (new-cs-item)
289 0 (curr-cf-item) CELL+ !
292 : OF ( case-sys -- orig case-sys / x -- )
293 CFT-case (check-cs-item)
294 1 (curr-cf-item) CELL+ +!
300 : ENDOF ( orig1 case -- orig2 case )
301 CFT-case (check-cs-item)
303 [OSEM] ELSE [PREVIOUS]
307 : ENDCASE ( orig1..orign case-sys -- )
308 CFT-case (check-cs-item)
309 (curr-cf-item) CELL+ @
310 (delete-cs-item) \ cnt
311 [OSEM] DROP [PREVIOUS]
313 [OSEM] THEN [PREVIOUS]