1 \
FLK control
flow stack
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: flkcfstack
.fs
,v
1.3 1998/09/13 21:28:56 root
Exp $
22 \ $
Log: flkcfstack
.fs
,v $
23 \
Revision 1.3 1998/09/13 21:28:56 root
24 \ fixed cf stackk bugs
26 \
Revision 1.2 1998/09/13 16:14:56 root
27 \ fixed cf stack item description
29 \
Revision 1.1 1998/09/13 15:42:04 root
33 \
Structure of one
control flow stack item
36 \
1 byte
type dependent
data
38 \
Possible types of CF stack items
44 5 CONSTANT CFT-callback
46 \
Data format
for CFT-orig
49 \
1 byte
allocator state
50 \
3 cells
addr of jump distance
52 \
Data format
for CFT-dest
55 \
1 byte
allocator state
56 \
3 cells
addr of jump target
58 \
Data format
for CFT-do
61 \
1 byte
last allocator state
62 \
3 cells
a1=addr. of inner code
63 \
4 cells
a3=fix
-addr for ?DO
66 \
Data format
for CFT-case
71 \
LEAVEs are stored
as linked lists
starting at
last-leave
(the global
74 \
Data format
for CFT-colon
(host
)
77 \
3 cells
header address
80 \
Data format
for CFT-colon
(target
)
83 \
3 cells
header address
85 \
Data format
for CFT-callback
88 \
3 cells
header address
91 \
Total size of one
CF stack item
: 6 CELLS
93 \
Create the stack itself
.
94 CREATE cf
-stack
6 CELLS CF-ITEMS * ALLOT
99 \
Find the n-th top
of control flow stack item
.
100 : (#-top-cf-item) ( n -- addr )
102 cf
-sp
@ SWAP - \ offs
103 DUP 0< IF -22 THROW THEN \ offs
104 6 CELLS * cf
-stack + \
addr
107 : .cf
-type ( type -- )
109 CFT-orig
OF ." orig " ENDOF
110 CFT-dest
OF ." dest " ENDOF
111 CFT-do OF ." do-sys " ENDOF
112 CFT-colon
OF ." colon-sys " ENDOF
113 CFT-case
OF ." case " ENDOF
114 CFT-callback
OF ." callback " ENDOF
115 DUP ." unknown (" . ." ) "
118 \
Print the CF-stack.
121 cf
-sp
@ -1 = IF ." CF stack empty." CR EXIT THEN
123 I (#-top-cf-item) DUP \ addr addr
125 \
CHAR+ DUP C@ DUP . ." regs: " \
addr #regs
127 \
CHAR+ DUP C@ \
addr vreg
129 \
VREG-EAX OF ." eax " ENDOF
130 \
VREG-EBX OF ." ebx " ENDOF
131 \
VREG-ECX OF ." ecx " ENDOF
132 \
VREG-EDX OF ." edx " ENDOF
133 \
VREG-ESI OF ." esi " ENDOF
134 \
VREG-EDI OF ." edi " ENDOF
135 \
DUP ." unknown(" . ." ) "
142 \
Return the current cf
-item
.
143 : (curr
-cf
-item
) ( -- addr )
144 cf
-sp
@ 6 CELLS * cf
-stack + ;
146 \
Allocate a new item
.
147 : (new-cs
-item
) ( type -- )
149 cf
-sp
@ CF-ITEMS = IF .CS -52 THROW THEN
152 \
Delete the current item.
153 : (delete
-cs
-item) ( -- )
156 \
Check if the current item is
of correct
type.
157 : (check
-cs
-item) ( type -- )
158 (curr
-cf
-item) C@ 2DUP <> IF
159 .cf
-type ." found, " .cf
-type ." expected." CR
168 (#-top-cf-item) \ addr
169 0 (new-cs
-item) \
addr
170 (curr
-cf
-item) \ from
to
177 \ cu
cu-1 cu-2 ... c0
-- cu-1 cu-2 ... c0
cu
178 DUP (CS-PICK) \ u
/ cu cu-1 ... c0
cu
179 DUP (#-top-cf-item) \ u addr-u-1(=from)
180 OVER 1+ (#-top-cf-item) \ u from addr-u(=to)
181 ROT 1+ 6 CELLS * MOVE