1 USING: accessors arrays compiler.units generic hashtables
2 stack-checker kernel kernel.private math prettyprint sequences
3 sbufs strings tools.test vectors words sequences.private
4 quotations classes classes.algebra classes.tuple.private
5 continuations growable namespaces hints alien.accessors
6 compiler.tree.builder compiler.tree.optimizer sequences.deep ;
9 GENERIC: xyz ( obj -- obj )
12 [ t ] [ \ xyz optimized>> ] unit-test
14 ! Test predicate inlining
17 dup integer? [ "integer" ] [ "nope" ] if
22 [ 1 "integer" ] [ 1 pred-test-1 ] unit-test
28 dup pred-test? [ "pred-test" ] [ "nope" ] if
33 [ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-2 ] unit-test
37 dup tuple? [ "pred-test" ] [ "nope" ] if
42 [ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-3 ] unit-test
47 [ t ] [ "nom" inline-test ] unit-test
48 [ f ] [ "shayin" inline-test ] unit-test
49 [ f ] [ 3 inline-test ] unit-test
51 : fixnum-declarations >fixnum 24 shift 1234 bitxor ;
53 [ ] [ 1000000 fixnum-declarations . ] unit-test
57 : literal-not-branch 0 not [ ] [ ] if ;
59 [ ] [ literal-not-branch ] unit-test
63 : bad-kill-1 ( a b -- c d e ) [ 3 f ] [ dup bad-kill-1 ] if ; inline
64 : bad-kill-2 bad-kill-1 drop ;
66 [ 3 ] [ t bad-kill-2 ] unit-test
69 : (the-test) ( x -- y ) dup 0 > [ 1- (the-test) ] when ; inline
70 : the-test ( -- x y ) 2 dup (the-test) ;
72 [ 2 0 ] [ the-test ] unit-test
75 : (double-recursion) ( start end -- )
77 6 1 (double-recursion)
78 3 2 (double-recursion)
81 : double-recursion ( -- ) 0 2 (double-recursion) ;
83 [ ] [ double-recursion ] unit-test
86 : double-label-1 ( a b c -- d )
87 [ f double-label-1 ] [ swap nth-unsafe ] if ; inline
89 : double-label-2 ( a -- b )
90 dup array? [ ] [ ] if 0 t double-label-1 ;
92 [ 0 ] [ 10 double-label-2 ] unit-test
95 GENERIC: void-generic ( obj -- * )
96 : breakage ( -- * ) "hi" void-generic ;
97 [ t ] [ \ breakage optimized>> ] unit-test
98 [ breakage ] must-fail
101 : branch-fold-regression-0 ( m -- n )
102 t [ ] [ 1+ branch-fold-regression-0 ] if ; inline
104 : branch-fold-regression-1 ( -- m )
105 10 branch-fold-regression-0 ;
107 [ 10 ] [ branch-fold-regression-1 ] unit-test
110 : constant-branch-fold-0 "hey" ; foldable
111 : constant-branch-fold-1 ( -- ? ) constant-branch-fold-0 "hey" = ; inline
112 [ 1 ] [ [ constant-branch-fold-1 [ 1 ] [ 2 ] if ] compile-call ] unit-test
116 : bar ( -- ? ) foo 4 4 = and ;
117 [ f ] [ bar ] unit-test
119 ! compiling <tuple> with a non-literal class failed
120 : <tuple>-regression ( class -- tuple ) <tuple> ;
122 [ t ] [ \ <tuple>-regression optimized>> ] unit-test
124 GENERIC: foozul ( a -- b )
130 reversed \ foozul specific-method
131 reversed \ foozul method
136 : constant-fold-2 f ; foldable
137 : constant-fold-3 4 ; foldable
140 [ constant-fold-2 constant-fold-3 4 = ] compile-call
143 : constant-fold-4 f ; foldable
144 : constant-fold-5 f ; foldable
147 [ constant-fold-4 constant-fold-5 or ] compile-call
150 [ 5 ] [ 5 [ 0 + ] compile-call ] unit-test
151 [ 5 ] [ 5 [ 0 swap + ] compile-call ] unit-test
153 [ 5 ] [ 5 [ 0 - ] compile-call ] unit-test
154 [ -5 ] [ 5 [ 0 swap - ] compile-call ] unit-test
155 [ 0 ] [ 5 [ dup - ] compile-call ] unit-test
157 [ 5 ] [ 5 [ 1 * ] compile-call ] unit-test
158 [ 5 ] [ 5 [ 1 swap * ] compile-call ] unit-test
159 [ 0 ] [ 5 [ 0 * ] compile-call ] unit-test
160 [ 0 ] [ 5 [ 0 swap * ] compile-call ] unit-test
161 [ -5 ] [ 5 [ -1 * ] compile-call ] unit-test
162 [ -5 ] [ 5 [ -1 swap * ] compile-call ] unit-test
164 [ 0 ] [ 5 [ 1 mod ] compile-call ] unit-test
165 [ 0 ] [ 5 [ 1 rem ] compile-call ] unit-test
167 [ 5 ] [ 5 [ -1 bitand ] compile-call ] unit-test
168 [ 0 ] [ 5 [ 0 bitand ] compile-call ] unit-test
169 [ 5 ] [ 5 [ -1 swap bitand ] compile-call ] unit-test
170 [ 0 ] [ 5 [ 0 swap bitand ] compile-call ] unit-test
171 [ 5 ] [ 5 [ dup bitand ] compile-call ] unit-test
173 [ 5 ] [ 5 [ 0 bitor ] compile-call ] unit-test
174 [ -1 ] [ 5 [ -1 bitor ] compile-call ] unit-test
175 [ 5 ] [ 5 [ 0 swap bitor ] compile-call ] unit-test
176 [ -1 ] [ 5 [ -1 swap bitor ] compile-call ] unit-test
177 [ 5 ] [ 5 [ dup bitor ] compile-call ] unit-test
179 [ 5 ] [ 5 [ 0 bitxor ] compile-call ] unit-test
180 [ 5 ] [ 5 [ 0 swap bitxor ] compile-call ] unit-test
181 [ -6 ] [ 5 [ -1 bitxor ] compile-call ] unit-test
182 [ -6 ] [ 5 [ -1 swap bitxor ] compile-call ] unit-test
183 [ 0 ] [ 5 [ dup bitxor ] compile-call ] unit-test
185 [ 0 ] [ 5 [ 0 swap shift ] compile-call ] unit-test
186 [ 5 ] [ 5 [ 0 shift ] compile-call ] unit-test
188 [ f ] [ 5 [ dup < ] compile-call ] unit-test
189 [ t ] [ 5 [ dup <= ] compile-call ] unit-test
190 [ f ] [ 5 [ dup > ] compile-call ] unit-test
191 [ t ] [ 5 [ dup >= ] compile-call ] unit-test
193 [ t ] [ 5 [ dup eq? ] compile-call ] unit-test
194 [ t ] [ 5 [ dup = ] compile-call ] unit-test
195 [ t ] [ 5 [ dup number= ] compile-call ] unit-test
196 [ t ] [ \ vector [ \ vector = ] compile-call ] unit-test
198 GENERIC: detect-number ( obj -- obj )
199 M: number detect-number ;
201 [ 10 f [ <array> 0 + detect-number ] compile-call ] must-fail
204 [ 4 [ + ] ] [ 2 2 [ [ + ] [ call ] keep ] compile-call ] unit-test
209 USE: binary-search.private
211 : old-binsearch ( elt quot seq -- elt quot i )
215 [ midpoint swap call ] 3keep roll dup zero?
216 [ drop dup from>> swap midpoint@ + ]
217 [ dup midpoint@ cut-slice old-binsearch ] if
221 10 20 >vector <flat-slice>
222 [ [ - ] swap old-binsearch ] compile-call 2nip
228 : node-successor-f-bug ( x -- * )
229 [ 3 throw ] [ empty-compound ] compose [ 3 throw ] if ;
231 [ t ] [ \ node-successor-f-bug optimized>> ] unit-test
233 [ ] [ [ new ] build-tree optimize-tree drop ] unit-test
235 [ ] [ [ <tuple> ] build-tree optimize-tree drop ] unit-test
238 : lift-throw-tail-regression ( obj -- obj str )
239 dup integer? [ "an integer" ] [
240 dup string? [ "a string" ] [
245 [ t ] [ \ lift-throw-tail-regression optimized>> ] unit-test
246 [ 3 "an integer" ] [ 3 lift-throw-tail-regression ] unit-test
247 [ "hi" "a string" ] [ "hi" lift-throw-tail-regression ] unit-test
249 : lift-loop-tail-test-1 ( a quot -- )
251 [ [ 3 - ] dip call ] keep lift-loop-tail-test-1
256 [ [ 2 - ] dip call ] keep lift-loop-tail-test-1
260 : lift-loop-tail-test-2
261 10 [ ] lift-loop-tail-test-1 1 2 3 ;
263 [ 1 2 3 ] [ lift-loop-tail-test-2 ] unit-test
265 ! Forgot a recursive inline check
266 : recursive-inline-hang ( a -- a )
267 dup array? [ recursive-inline-hang ] when ;
269 HINTS: recursive-inline-hang array ;
271 : recursive-inline-hang-1 ( -- a )
272 { } recursive-inline-hang ;
274 [ t ] [ \ recursive-inline-hang-1 optimized>> ] unit-test
276 DEFER: recursive-inline-hang-3
278 : recursive-inline-hang-2 ( a -- a )
279 dup array? [ recursive-inline-hang-3 ] when ;
281 HINTS: recursive-inline-hang-2 array ;
283 : recursive-inline-hang-3 ( a -- a )
284 dup array? [ recursive-inline-hang-2 ] when ;
286 HINTS: recursive-inline-hang-3 array ;
289 [ ] [ { 3append-as } compile ] unit-test
292 : counter-example ( a b c d -- a' b' c' d' )
293 dup 0 > [ 1 - [ rot 2 * ] dip counter-example ] when ; inline
295 : counter-example' ( -- a' b' c' d' )
296 1 2 3.0 3 counter-example ;
298 [ 2 4 6.0 0 ] [ counter-example' ] unit-test
300 : member-test ( obj -- ? ) { + - * / /i } member? ;
302 \ member-test must-infer
303 [ ] [ \ member-test build-tree-from-word optimize-tree 2drop ] unit-test
304 [ t ] [ \ + member-test ] unit-test
305 [ f ] [ \ append member-test ] unit-test
308 TUPLE: cons car cdr ;
310 UNION: improper-list cons POSTPONE: f ;
312 PREDICATE: list < improper-list
313 [ cdr>> list instance? ] [ t ] if* ;
316 T{ cons f 1 T{ cons f 2 T{ cons f 3 f } } }
317 [ list instance? ] compile-call
321 : interval-inference-bug ( obj -- obj x )
322 dup "a" get { array-capacity } declare >=
323 [ dup "b" get { array-capacity } declare >= [ 3 ] [ 4 ] if ] [ 5 ] if ;
325 \ interval-inference-bug must-infer
327 [ ] [ 1 "a" set 2 "b" set ] unit-test
328 [ 2 3 ] [ 2 interval-inference-bug ] unit-test
329 [ 1 4 ] [ 1 interval-inference-bug ] unit-test
330 [ 0 5 ] [ 0 interval-inference-bug ] unit-test
332 : aggressive-flush-regression ( a -- b )
333 f over [ <array> drop ] dip 1 + ;
335 [ 1.0 aggressive-flush-regression drop ] must-fail
337 [ 1 [ "hi" + drop ] compile-call ] must-fail
339 [ "hi" f [ <array> drop ] compile-call ] must-fail
341 TUPLE: some-tuple x ;
343 : allot-regression ( a -- b )
344 [ ] curry some-tuple boa ;
346 [ T{ some-tuple f [ 3 ] } ] [ 3 allot-regression ] unit-test
348 [ 1 ] [ B{ 0 0 0 0 } [ 0 alien-signed-4 1+ ] compile-call ] unit-test
349 [ 1 ] [ B{ 0 0 0 0 } [ 0 alien-unsigned-4 1+ ] compile-call ] unit-test
350 [ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-signed-8 1+ ] compile-call ] unit-test
351 [ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-unsigned-8 1+ ] compile-call ] unit-test
352 [ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-signed-cell 1+ ] compile-call ] unit-test
353 [ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-unsigned-cell 1+ ] compile-call ] unit-test
355 : deep-find-test ( seq -- ? ) [ 5 = ] deep-find ;
357 [ 5 ] [ { 1 2 { 3 { 4 5 } } } deep-find-test ] unit-test
358 [ f ] [ { 1 2 { 3 { 4 } } } deep-find-test ] unit-test
360 [ B{ 0 1 2 3 4 5 6 7 } ] [ [ 8 [ ] B{ } map-as ] compile-call ] unit-test
362 [ 0 ] [ 1234 [ { fixnum } declare -64 shift ] compile-call ] unit-test
364 ! Loop detection problem found by doublec
370 counter inc counter get 2 < [ loop-bbb ] when ; inline recursive
373 [ loop-aaa ] with-scope ; inline recursive
375 : loop-ccc ( -- ) loop-bbb ;
377 [ 0 ] [ 0 counter set loop-ccc counter get ] unit-test
379 ! Type inference issue
382 [ { bignum integer } declare [ shift ] keep 1+ ] compile-call