1 ! Black box testing of templater optimization
3 USING: arrays compiler kernel kernel.private math
4 hashtables.private math.private math.ratios.private namespaces
5 sequences sequences.private tools.test namespaces.private
6 slots.private combinators.private ;
10 [ 5000 ] [ [ 5000 ] compile-1 ] unit-test
11 [ "hi" ] [ [ "hi" ] compile-1 ] unit-test
13 [ 1 2 3 4 ] [ [ 1 2 3 4 ] compile-1 ] unit-test
15 [ 1 1 ] [ 1 [ dup ] compile-1 ] unit-test
16 [ 0 ] [ 3 [ tag ] compile-1 ] unit-test
17 [ 0 3 ] [ 3 [ [ tag ] keep ] compile-1 ] unit-test
19 [ 2 3 ] [ 3 [ 2 swap ] compile-1 ] unit-test
21 [ 2 1 3 4 ] [ 1 2 [ swap 3 4 ] compile-1 ] unit-test
23 [ 2 3 4 ] [ 3 [ 2 swap 4 ] compile-1 ] unit-test
25 [ { 1 2 3 } { 1 4 3 } 3 3 ]
26 [ { 1 2 3 } { 1 4 3 } [ over tag over tag ] compile-1 ]
29 [ { 1 2 3 } { 1 4 3 } 8 8 ]
30 [ { 1 2 3 } { 1 4 3 } [ over type over type ] compile-1 ]
33 ! Test literals in either side of a shuffle
34 [ 4 1 ] [ 1 [ [ 3 fixnum+ ] keep ] compile-1 ] unit-test
36 [ 2 ] [ 1 2 [ swap fixnum/i ] compile-1 ] unit-test
41 [ 1/2 [ tag [ foo ] keep ] compile-1 ]
45 [ 1/2 [ dup 1 slot swap 2 slot [ foo ] keep ] compile-1 ]
52 2dup 2>fraction >r * swap r> * swap
53 + -rot denominator swap denominator
66 [ >fraction ] 2apply swapd
67 >r 2array swap r> 2array swap
73 [ { 1 2 } { 1 1 } ] [ 1 >bignum 1/2 jxyz ] unit-test
77 global [ 3 \ foo set ] bind
78 \ foo [ global >n get ndrop ] compile-1
85 global [ 3 \ foo set ] bind
86 \ foo [ global [ get ] swap blech call ] compile-1
91 global [ 3 \ foo set ] bind
92 \ foo [ global [ get ] swap >n call ndrop ] compile-1
97 global [ 3 \ foo set ] bind
98 \ foo [ global [ get ] bind ] compile-1
102 -12 -13 [ [ 0 swap fixnum-fast ] 2apply ] compile-1
105 [ -1 2 ] [ 1 2 [ >r 0 swap fixnum- r> ] compile-1 ] unit-test
108 -12 -13 [ [ 0 swap fixnum- ] 2apply ] compile-1
112 SBUF" " [ 2 slot 2 [ slot ] keep ] compile-1 nip
116 [ 3 1 2 3 4 5 6 7 8 9 ] [
118 [ >r >r >r >r >r >r >r >r >r 3 r> r> r> r> r> r> r> r> r> ]
122 [ 2 2 2 2 2 2 2 2 2 2 1 ] [
124 [ swap >r dup dup dup dup dup dup dup dup dup r> ] compile-1
127 [ ] [ [ 9 [ ] times ] compile-1 ] unit-test
131 [ 200 dup [ 200 3array ] curry map drop ] times
136 ! Test how dispatch handles the end of a basic block
137 : try-breaking-dispatch
138 float+ swap { [ "hey" ] [ "bye" ] } dispatch ;
140 : try-breaking-dispatch-2
141 1 1.0 2.5 try-breaking-dispatch "bye" = >r 3.5 = r> and ;
144 10000000 [ drop try-breaking-dispatch-2 ] all?
148 : (broken) ( x -- y ) ;
150 [ 2.0 { 2.0 0.0 } ] [
152 [ float/f 0.0 [ drop (broken) ] 2keep 2array ] compile-1
156 : hellish-bug-1 2drop ;
158 : hellish-bug-2 ( i array x -- x )
159 2dup 1 slot eq? [ 2drop ] [
160 2dup array-nth tombstone? [
162 [ array-nth ] 2keep >r 1 fixnum+fast r> array-nth
163 pick 2dup hellish-bug-1 3drop
165 ] unless >r 2 fixnum+fast r> hellish-bug-2
168 : hellish-bug-3 ( hash array -- )
169 0 swap hellish-bug-2 drop ;
172 H{ { 1 2 } { 3 4 } } dup hash-array
173 [ 0 swap hellish-bug-2 drop ] compile-1
179 [ drop 3 ] [ dup tuple? [ drop 4 ] [ drop 5 ] if ] if ;
181 [ 3 ] [ f foox ] unit-test
185 [ 4 ] [ T{ my-tuple } foox ] unit-test
187 [ 5 ] [ "hi" foox ] unit-test