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
11 ! Don't leak extra roots if error is thrown
12 [ ] [ 1000 [ [ 3 throw ] ignore-errors ] times ] unit-test
14 [ ] [ 1000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
16 ! Make sure we report the correct error on stack underflow
18 ${ "kernel-error" ERROR-DATASTACK-UNDERFLOW f f } =
24 3 [ { } set-retainstack ] dip ]
25 [ ${ "kernel-error" ERROR-RETAINSTACK-UNDERFLOW f f } =
30 : overflow-d ( -- ) 3 overflow-d ;
32 : (overflow-d-alt) ( -- n ) 3 ;
34 : overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
36 : overflow-r ( -- ) 3 load-local overflow-r ;
39 { overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
40 [ t "no-compile" set-word-prop ] each
44 ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
50 ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
53 [ ] [ [ :c ] with-string-writer drop ] unit-test
56 ${ "kernel-error" ERROR-RETAINSTACK-OVERFLOW f f } =
61 : overflow-c ( -- ) overflow-c overflow-c ;
63 ! The VM cannot recover from callstack overflow on Windows,
64 ! because no facility exists to run memory protection
65 ! fault handlers on an alternate callstack.
68 ${ "kernel-error" ERROR-CALLSTACK-OVERFLOW f f } =
72 [ -7 <byte-array> ] must-fail
74 [ 3 ] [ t 3 and ] unit-test
75 [ f ] [ f 3 and ] unit-test
76 [ f ] [ 3 f and ] unit-test
77 [ 4 ] [ 4 6 or ] unit-test
78 [ 6 ] [ f 6 or ] unit-test
79 [ f ] [ 1 2 xor ] unit-test
80 [ 1 ] [ 1 f xor ] unit-test
81 [ 2 ] [ f 2 xor ] unit-test
82 [ f ] [ f f xor ] unit-test
87 [ 1 [ call ] dip ] must-fail
90 [ 1 2 [ call ] dip ] must-fail
93 [ 5 ] [ 1 [ 2 2 + ] dip + ] unit-test
95 [ [ ] keep ] must-fail
97 [ 6 ] [ 2 [ sq ] keep + ] unit-test
99 [ [ ] 2keep ] must-fail
100 [ 1 [ ] 2keep ] must-fail
101 [ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
103 [ 0 ] [ f [ sq ] [ 0 ] if* ] unit-test
104 [ 4 ] [ 2 [ sq ] [ 0 ] if* ] unit-test
106 [ 0 ] [ f [ 0 ] unless* ] unit-test
107 [ t ] [ t [ "Hello" ] unless* ] unit-test
109 [ "2\n" ] [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
110 [ "9\n" ] [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
112 [ f ] [ f (clone) ] unit-test
113 [ -123 ] [ -123 (clone) ] unit-test
115 [ 6 2 ] [ 1 2 [ 5 + ] dip ] unit-test
117 [ ] [ callstack set-callstack ] unit-test
119 [ 3drop datastack ] must-fail
122 ! Doesn't compile; important
125 << \ foo t "no-compile" set-word-prop >>
127 [ drop foo ] must-fail
131 : (loop) ( a b c d -- )
132 [ pick ] dip swap [ pick ] dip swap
133 < [ [ 1 + ] 3dip (loop) ] [ 4drop ] if ; inline recursive
136 H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
140 ! Discovered on Windows
141 : total-failure-1 ( -- a ) "" [ ] map unimplemented ;
143 [ total-failure-1 ] must-fail
145 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
146 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
147 [ [ sq ] tri@ ] must-infer
149 [ 4 ] [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
151 ! Test traceback accuracy
152 : last-frame ( -- pair )
153 error-continuation get call>> callstack>array 6 head* 3 tail* ;
156 { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
158 [ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
163 { [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
165 [ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
170 { [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
172 [ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
177 { [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
179 [ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
184 { [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
186 [ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
190 [ 10 2 3 4 5 ] [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
192 [ 3 -1 5/6 ] [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
194 [ { 1 2 } { 3 4 } { 5 6 } ] [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
196 [ t ] [ { } identity-hashcode fixnum? ] unit-test
197 [ 123 ] [ 123 identity-hashcode ] unit-test
198 [ t ] [ f identity-hashcode fixnum? ] unit-test
200 ! Make sure memory protection faults work
201 [ f 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
202 [ 1 <alien> 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
204 { 1 2 3 1 2 3 } [ 1 2 3 3dup ] unit-test
205 { 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4dup ] unit-test