-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocals-test.fs
330 lines (285 loc) · 5.2 KB
/
locals-test.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
\ test gforth locals
\ Copyright (C) 1995,1996,1997,2000,2003,2007 Free Software Foundation, Inc.
\ This file is part of Gforth.
\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.
require glocals.fs
require debugs.fs
: localsinfo \ !! only debugging
." stack: " .s ." locals-size: " locals-size ? ." locals-list"
also locals words previous cr ;
." before foo" cr
: foo
{ c: a b c: c d: d }
a .
b .
d type
c . cr
;
." before" .s cr
lp@ . cr
1 2 3 s" xxx" foo
lp@ . cr
." after" .s cr
." xxx" cr
.s cr
depth . cr
." testing part 2" cr
: xxxx
[ ." starting xxxx" .s cr ]
{ f } f
if
{ a b }
b a
[ ." before else" .s cr ]
else
[ ." after else" .s cr ]
{ c d }
c d
then
[ ." locals-size after then:" locals-size @ . cr ]
~~ f ~~ drop
[ ." ending xxxx" .s cr ]
;
2 3 1 xxxx . . cr
2 3 0 xxxx . . cr
cr cr cr
: xxx3
begin
{ a }
until
a
;
." after xxx3" .s cr cr cr
: xxx2
[ ." start of xxx2" .s cr ]
begin
[ ." after begin" .s cr ]
{ a }
[ ." after { a }" .s cr ]
1 while
[ ." after while" .s cr ]
{ b }
a b
[ ." after a" .s cr ]
repeat
[ ." after repeat" .s cr
also locals words previous cr
]
a
[ ." end of xxx2" .s cr ]
;
: xxx4
[ ." before if" localsinfo ]
if
[ ." after if" localsinfo ]
{ a }
[ ." before begin" localsinfo ]
begin
[ ." after begin" localsinfo ]
[ 1 cs-roll ]
[ ." before then" localsinfo ]
then
{ b }
until
[ ." after until" localsinfo ]
;
: xxx5
{ a }
a drop
ahead
assume-live
begin
[ ." after begin" localsinfo ]
a drop
[ 1 cs-roll ]
then
[ ." after then" localsinfo ]
until
[ ." after until" localsinfo ]
;
." xxx6 coming up" cr
: xxx6
[ ." starting xxx6" localsinfo ]
if
{ x }
else
[ ." after else" localsinfo ]
ahead
begin
[ ." after begin" localsinfo ]
[ 2 CS-ROLL ] then
[ ." after then" localsinfo ]
until
then
[ ." ending xxx6" localsinfo ]
;
." xxx7 coming up" cr
: xxx7
{ b }
do
{ a }
[ ." before loop" localsinfo ]
loop
[ ." after loop" localsinfo ]
;
." xxx8 coming up" cr
: xxx8
{ b }
?do
{ a }
[ ." before loop" localsinfo ]
loop
[ ." after loop" localsinfo ]
;
." xxx9 coming up" cr
: xxx9
{ b }
do
{ c }
[ ." before ?leave" leave-sp ? leave-stack . cr ]
?leave
[ ." after ?leave" leave-sp ? cr ]
{ a }
[ ." before loop" localsinfo ]
loop
[ ." after loop" localsinfo ]
;
." strcmp coming up" cr
: strcmp { addr1 u1 addr2 u2 -- n }
addr1 addr2 u1 u2 min 0 ?do
{ s1 s2 }
s1 c@ s2 c@ - ?dup if
unloop exit
then
s1 char+ s2 char+
loop
2drop
u1 u2 - ;
: teststrcmp
." lp@:" lp@ . cr
s" xxx" s" yyy" strcmp . cr
." lp@:" lp@ . cr
s" xxx" s" xxx" strcmp . cr
." lp@:" lp@ . cr
s" xxx" s" xxxx" strcmp . cr
." lp@:" lp@ . cr
s" xxx3" s" xxx2" strcmp . cr
." lp@:" lp@ . cr
s" " s" " strcmp . cr
." lp@:" lp@ . cr
." lp@:" lp@ . cr
." stack:" .s cr
;
: findchar { c addr u -- i }
addr u 0 ?do
{ p }
p c@ c = if
p leave
then
p char+
loop
addr - ;
: testfindchar
." findcahr " cr
." lp@:" lp@ . cr
[char] a s" xxx" findchar . cr
." lp@:" lp@ . cr
[char] a s" " findchar . cr
." lp@:" lp@ . cr
[char] a s" wam" findchar . cr
." lp@:" lp@ . cr
[char] a s" wma" findchar . cr
." lp@:" lp@ . cr
[char] a s" awam" findchar . cr
." lp@:" lp@ . cr
." stack:" .s cr
;
." stack:" .s cr
teststrcmp
testfindchar
." hey you" cr
: xxx10
[ ." before if" localsinfo ]
if
[ ." after if" localsinfo ]
scope
[ ." after scope" localsinfo ]
{ a }
[ ." before endscope" localsinfo ]
endscope
[ ." before begin" localsinfo ]
begin
[ ." after begin" localsinfo ]
[ 1 cs-roll ]
[ ." before then" localsinfo ]
then
{ b }
until
[ ." after until" localsinfo ]
;
: xxx11
if
{ a }
exit
[ ." after xexit" localsinfo ]
else
{ b }
[ ." before xthen" localsinfo ]
then
[ ." after xthen" localsinfo ]
;
." strcmp1 coming up" cr
: strcmp1 { addr1 u1 addr2 u2 -- n }
u1 u2 min 0 ?do
addr1 c@ addr2 c@ - ?dup if
unloop exit
then
addr1 char+ TO addr1
addr2 char+ TO addr2
loop
u1 u2 - ;
: teststrcmp1
." lp@:" lp@ . cr
s" xxx" s" yyy" strcmp1 . cr
." lp@:" lp@ . cr
s" xxx" s" xxx" strcmp1 . cr
." lp@:" lp@ . cr
s" xxx" s" xxxx" strcmp1 . cr
." lp@:" lp@ . cr
s" xxx3" s" xxx2" strcmp1 . cr
." lp@:" lp@ . cr
s" " s" " strcmp1 . cr
." lp@:" lp@ . cr
." lp@:" lp@ . cr
." stack:" .s cr
;
teststrcmp1
." testing the abominable locals-ext wordset" cr
: puke locals| this read you can |
you read this can ;
1 2 3 4 puke . . . . cr
\ just some other stuff
: life1 { b0 b1 b23 old -- new }
b23 invert old b1 b0 xor and old invert b1 and b0 and or and ;
: life2 { b0 b1 b23 old -- new }
b0 b1 or old b0 xor b1 xor b23 or invert and ;
$5555 $3333 $0f0f $00ff life1 .
$5555 $3333 $0f0f $00ff life2 .
.s
cr
: test
1 { a } ." after }" cr
2 { b -- } ." after --" cr
;
test
.s cr
bye