1 USING: arrays byte-arrays kernel kernel.private literals math
2 memory namespaces sequences tools.test math.private quotations
3 continuations prettyprint io.streams.string debugger assocs
4 sequences.private accessors locals.backend grouping words
5 system alien alien.accessors kernel.private ;
8 [ 0 ] [ f size ] unit-test
9 [ t ] [ [ \ = \ = ] all-equal? ] unit-test
24 ] [ 1 2 10 iota [ 3array ] 2with map ] unit-test
26 ! Don't leak extra roots if error is thrown
27 [ ] [ 1000 [ [ 3 throw ] ignore-errors ] times ] unit-test
29 [ ] [ 1000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
31 ! Make sure we report the correct error on stack underflow
33 ${ "kernel-error" ERROR-DATASTACK-UNDERFLOW f f } =
39 3 [ { } set-retainstack ] dip ]
40 [ ${ "kernel-error" ERROR-RETAINSTACK-UNDERFLOW f f } =
45 : overflow-d ( -- ) 3 overflow-d ;
47 : (overflow-d-alt) ( -- n ) 3 ;
49 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
51 : overflow-r ( -- ) 3 load-local overflow-r ;
54 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
55 [ t "no-compile" set-word-prop ] each
59 ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
65 ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
68 [ ] [ [ :c ] with-string-writer drop ] unit-test
71 ${ "kernel-error" ERROR-RETAINSTACK-OVERFLOW f f } =
76 : overflow-c ( -- ) overflow-c overflow-c ;
78 ! The VM cannot recover from callstack overflow on Windows,
79 ! because no facility exists to run memory protection
80 ! fault handlers on an alternate callstack.
83 ${ "kernel-error" ERROR-CALLSTACK-OVERFLOW f f } =
87 [ -7 <byte-array> ] must-fail
89 [ 3 ] [ t 3 and ] unit-test
90 [ f ] [ f 3 and ] unit-test
91 [ f ] [ 3 f and ] unit-test
92 [ 4 ] [ 4 6 or ] unit-test
93 [ 6 ] [ f 6 or ] unit-test
94 [ f ] [ 1 2 xor ] unit-test
95 [ 1 ] [ 1 f xor ] unit-test
96 [ 2 ] [ f 2 xor ] unit-test
97 [ f ] [ f f xor ] unit-test
102 [ 1 [ call ] dip ] must-fail
105 [ 1 2 [ call ] dip ] must-fail
108 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
110 [ [ ] keep ] must-fail
112 [ 6 ] [ 2 [ sq ] keep + ] unit-test
114 [ [ ] 2keep ] must-fail
115 [ 1 [ ] 2keep ] must-fail
116 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
118 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
119 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
121 [ 0 ] [ f [ 0 ] unless* ] unit-test
122 [ t ] [ t [ "Hello" ] unless* ] unit-test
124 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
125 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
127 [ f ] [ f (clone) ] unit-test
128 [ -123 ] [ -123 (clone) ] unit-test
130 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
132 [ ] [ callstack set-callstack ] unit-test
134 [ 3drop datastack ] must-fail
137 ! Doesn't compile; important
140 << \ foo t "no-compile" set-word-prop >>
142 [ drop foo ] must-fail
146 : (loop) ( a b c d -- )
147 [ pick ] dip swap [ pick ] dip swap
148 < [ [ 1 + ] 3dip (loop) ] [ 4drop ] if ; inline recursive
151 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
155 ! Discovered on Windows
156 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
158 [ total-failure-1 ] must-fail
160 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
161 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
162 [ [ sq ] tri@ ] must-infer
164 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
166 ! Test traceback accuracy
167 : last-frame ( -- pair )
168 error-continuation get call>> callstack>array 6 head* 3 tail* ;
171 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
173 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
178 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
180 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
185 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
187 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
192 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
194 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
199 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
201 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
205 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
207 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
209 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
211 [ t ] [ { } identity-hashcode fixnum? ] unit-test
212 [ 123 ] [ 123 identity-hashcode ] unit-test
213 [ t ] [ f identity-hashcode fixnum? ] unit-test
215 ! Make sure memory protection faults work
216 [ f 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
217 [ 1 <alien> 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
219 { 1 2 3 1 2 3 } [ 1 2 3 3dup ] unit-test
220 { 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4dup ] unit-test