swapforth

Форк
0
/
searchordertest.fth 
182 строки · 6.3 Кб
1
\ To test the ANS Forth search-order word set and search order extensions
2

3
\ This program was written by Gerry Jackson in 2006, with contributions from
4
\ others where indicated, and is in the public domain - it can be distributed
5
\ and/or modified in any way but please retain this notice.
6

7
\ This program is distributed in the hope that it will be useful,
8
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10

11
\ The tests are not claimed to be comprehensive or correct 
12

13
\ ------------------------------------------------------------------------------
14
\ Version 0.10 3 August 2014 Name changes to remove redefinition messages
15
\               "list" changed to "wordlist" in message for ORDER tests
16
\         0.5 1 April 2012  Tests placed in the public domain.
17
\         0.4 6 March 2009 { and } replaced with T{ and }T
18
\         0.3 20 April 2007 ANS Forth words changed to upper case
19
\         0.2 30 Oct 2006 updated following GForth tests to get
20
\             initial search order into a known state
21
\         0.1 Oct 2006 First version released
22

23
\ ------------------------------------------------------------------------------
24
\ The tests are based on John Hayes test program for the core word set
25
\ and requires those files to have been loaded
26

27
\ Words tested in this file are:
28
\     FORTH-WORDLIST GET-ORDER SET-ORDER ALSO ONLY FORTH GET-CURRENT
29
\     SET-CURRENT DEFINITIONS PREVIOUS SEARCH-WORDLIST WORDLIST FIND
30
\ Words not fully tested:
31
\     ORDER only tests that it executes, display is implementation
32
\           dependent and should be visually inspected
33

34
\ ------------------------------------------------------------------------------
35
\ Assumptions and dependencies:
36
\     - tester.fr or ttester.fs has been loaded prior to this file
37
\     - that ONLY FORTH DEFINITIONS will work at the start of the file
38
\       to ensure the search order is in a known state
39
\ ------------------------------------------------------------------------------
40

41
ONLY FORTH DEFINITIONS
42

43
TESTING Search-order word set
44

45
DECIMAL
46

47
VARIABLE WID1  VARIABLE WID2
48

49
: SAVE-ORDERLIST ( widn ... wid1 n -> ) DUP , 0 ?DO , LOOP ;
50

51
\ ------------------------------------------------------------------------------
52
TESTING FORTH-WORDLIST GET-ORDER SET-ORDER
53

54
T{ FORTH-WORDLIST WID1 ! -> }T
55

56
CREATE ORDER-LIST
57

58
T{ GET-ORDER SAVE-ORDERLIST -> }T
59

60
: GET-ORDERLIST  ( -- widn ... wid1 n )
61
   ORDER-LIST DUP @ CELLS  ( -- ad n )
62
   OVER +                  ( -- ad ad' )
63
   ?DO I @ -1 CELLS +LOOP  ( -- )
64
;
65

66
T{ GET-ORDER OVER -> GET-ORDER WID1 @ }T \ Forth wordlist at top
67
T{ GET-ORDER SET-ORDER -> }T             \ Effectively noop
68
T{ GET-ORDER -> GET-ORDERLIST }T         \ Check nothing changed
69
T{ GET-ORDERLIST DROP GET-ORDERLIST 2* SET-ORDER -> }T
70
T{ GET-ORDER -> GET-ORDERLIST DROP GET-ORDERLIST 2* }T
71
T{ GET-ORDERLIST SET-ORDER GET-ORDER -> GET-ORDERLIST }T
72

73
\ ------------------------------------------------------------------------------
74
TESTING ALSO ONLY FORTH
75

76
T{ ALSO GET-ORDER -> GET-ORDERLIST OVER SWAP 1+ }T
77
T{ ONLY FORTH GET-ORDER -> GET-ORDERLIST }T    \ See assumptions above
78

79
\ ------------------------------------------------------------------------------
80
TESTING GET-CURRENT SET-CURRENT WORDLIST (simple)
81

82
T{ GET-CURRENT -> WID1 @ }T        \ See assumptions above
83
T{ WORDLIST WID2 ! -> }T
84
T{ WID2 @ SET-CURRENT -> }T
85
T{ GET-CURRENT -> WID2 @ }T
86
T{ WID1 @ SET-CURRENT -> }T
87

88
\ ------------------------------------------------------------------------------
89
TESTING minimum search order list contains FORTH-WORDLIST and SET-ORDER
90

91
: SO1 SET-ORDER ;    \ In case it is unavailable in the forth wordlist
92

93
T{ ONLY FORTH-WORDLIST 1 SET-ORDER GET-ORDERLIST SO1 -> }T
94
T{ GET-ORDER -> GET-ORDERLIST }T
95

96
\ ------------------------------------------------------------------------------
97
TESTING GET-ORDER SET-ORDER with 0 and -1 number of wids argument
98

99
: SO2A GET-ORDER GET-ORDERLIST SET-ORDER ; \  To recover search order
100
: SO2 0 SET-ORDER SO2A ;
101

102
T{ SO2 -> 0 }T         \ 0 set-order leaves an empty search order
103

104
: SO3 -1 SET-ORDER SO2A ;
105
: SO4 ONLY SO2A ;
106

107
T{ SO3 -> SO4 }T       \ -1 SET-ORDER = ONLY
108

109
\ ------------------------------------------------------------------------------
110
TESTING DEFINITIONS PREVIOUS
111

112
T{ ONLY FORTH DEFINITIONS -> }T
113
T{ GET-CURRENT -> FORTH-WORDLIST }T
114
T{ GET-ORDER WID2 @ SWAP 1+ SET-ORDER DEFINITIONS GET-CURRENT -> WID2 @ }T
115
T{ GET-ORDER -> GET-ORDERLIST WID2 @ SWAP 1+ }T
116
T{ PREVIOUS GET-ORDER -> GET-ORDERLIST }T
117
T{ DEFINITIONS GET-CURRENT -> FORTH-WORDLIST }T
118

119
\ ------------------------------------------------------------------------------
120
TESTING SEARCH-WORDLIST WORDLIST FIND
121

122
ONLY FORTH DEFINITIONS
123
VARIABLE XT  ' DUP XT !
124
VARIABLE XTI ' .( XTI !    \ Immediate word
125

126
T{ S" DUP" WID1 @ SEARCH-WORDLIST -> XT  @ -1 }T
127
T{ S" .("  WID1 @ SEARCH-WORDLIST -> XTI @  1 }T
128
T{ S" DUP" WID2 @ SEARCH-WORDLIST ->        0 }T
129

130
: C"DUP" C" DUP" ;
131
: C".("  C" .(" ;
132
: C"X" C" UNKNOWN WORD"  ;
133

134
T{ C"DUP" FIND -> XT  @ -1 }T
135
T{ C".("  FIND -> XTI @  1 }T
136
T{ C"X"   FIND -> C"X"   0 }T
137

138
\ ------------------------------------------------------------------------------
139
TESTING new definitions are put into the correct wordlist
140

141
: ALSOWID2 ALSO GET-ORDER WID2 @ ROT DROP SWAP SET-ORDER ;
142
ALSOWID2
143
: W2 1234  ;
144
DEFINITIONS
145
: W2 -9876 ; IMMEDIATE
146

147
ONLY FORTH
148
T{ W2 -> 1234 }T
149
DEFINITIONS
150
T{ W2 -> 1234 }T
151
ALSOWID2
152
T{ W2 -> -9876 }T
153
DEFINITIONS
154
T{ W2 -> -9876 }T
155

156
ONLY FORTH DEFINITIONS
157

158
: SO5  DUP IF SWAP EXECUTE THEN ;
159

160
T{ S" W2" WID1 @ SEARCH-WORDLIST SO5 -> -1  1234 }T
161
T{ S" W2" WID2 @ SEARCH-WORDLIST SO5 ->  1 -9876 }T
162

163
: C"W2" C" W2" ;
164
T{ ALSOWID2 C"W2" FIND SO5 ->  1 -9876 }T
165
T{ PREVIOUS C"W2" FIND SO5 -> -1  1234 }T
166

167
\ ------------------------------------------------------------------------------
168
TESTING ORDER  \ Should display search order and compilation wordlist
169

170
CR .( ONLY FORTH DEFINITIONS search order and compilation wordlist) CR
171
T{ ONLY FORTH DEFINITIONS ORDER -> }T
172

173
CR .( Plus another unnamed wordlist at the head of the search order) CR
174
T{ ALSOWID2 DEFINITIONS ORDER -> }T
175

176
\ ------------------------------------------------------------------------------
177

178
SEARCHORDER-ERRORS SET-ERROR-COUNT
179

180
CR .( End of Search Order word tests) CR
181

182
ONLY FORTH DEFINITIONS		\ Leave search order in the standard state
183

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.