]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/builder/builder-tests.factor
optimize fixnum*fast and fixnum-shift-fast
[factor.git] / basis / compiler / cfg / builder / builder-tests.factor
1 IN: compiler.cfg.builder.tests
2 USING: tools.test kernel sequences
3 words sequences.private fry prettyprint alien alien.accessors
4 math.private compiler.tree.builder compiler.tree.optimizer
5 compiler.cfg.builder compiler.cfg.debugger arrays locals byte-arrays
6 kernel.private math ;
7
8 ! Just ensure that various CFGs build correctly.
9 : unit-test-cfg ( quot -- ) '[ _ test-cfg drop ] [ ] swap unit-test ;
10
11 {
12     [ ]
13     [ dup ]
14     [ swap ]
15     [ [ ] dip ]
16     [ fixnum+ ]
17     [ fixnum+fast ]
18     [ 3 fixnum+fast ]
19     [ fixnum*fast ]
20     [ 3 fixnum*fast ]
21     [ 3 swap fixnum*fast ]
22     [ fixnum-shift-fast ]
23     [ 10 fixnum-shift-fast ]
24     [ -10 fixnum-shift-fast ]
25     [ 0 fixnum-shift-fast ]
26     [ 10 swap fixnum-shift-fast ]
27     [ -10 swap fixnum-shift-fast ]
28     [ 0 swap fixnum-shift-fast ]
29     [ fixnum-bitnot ]
30     [ eq? ]
31     [ "hi" eq? ]
32     [ fixnum< ]
33     [ 5 fixnum< ]
34     [ float+ ]
35     [ 3.0 float+ ]
36     [ float<= ]
37     [ fixnum>bignum ]
38     [ bignum>fixnum ]
39     [ fixnum>float ]
40     [ float>fixnum ]
41     [ 3 f <array> ]
42     [ [ 1 ] [ 2 ] if ]
43     [ fixnum< [ 1 ] [ 2 ] if ]
44     [ float+ [ 2.0 float* ] [ 3.0 float* ] bi float/f ]
45     [ { [ 1 ] [ 2 ] [ 3 ] } dispatch ]
46     [ [ t ] loop ]
47     [ [ dup ] loop ]
48     [ [ 2 ] [ 3 throw ] if 4 ]
49     [ "int" f "malloc" { "int" } alien-invoke ]
50     [ "int" { "int" } "cdecl" alien-indirect ]
51     [ "int" { "int" } "cdecl" [ ] alien-callback ]
52 } [
53     unit-test-cfg
54 ] each
55
56 : test-1 ( -- ) test-1 ;
57 : test-2 ( -- ) 3 . test-2 ;
58 : test-3 ( a -- b ) dup [ test-3 ] when ;
59
60 {
61     test-1
62     test-2
63     test-3
64 } [ unit-test-cfg ] each
65
66 {
67     byte-array
68     simple-alien
69     alien
70     POSTPONE: f
71 } [| class |
72     {
73         alien-signed-1
74         alien-signed-2
75         alien-signed-4
76         alien-unsigned-1
77         alien-unsigned-2
78         alien-unsigned-4
79         alien-cell
80         alien-float
81         alien-double
82     } [| word |
83         { class } word '[ _ declare 10 _ execute ] unit-test-cfg
84         { class fixnum } word '[ _ declare _ execute ] unit-test-cfg
85     ] each
86     
87     {
88         set-alien-signed-1
89         set-alien-signed-2
90         set-alien-signed-4
91         set-alien-unsigned-1
92         set-alien-unsigned-2
93         set-alien-unsigned-4
94     } [| word |
95         { fixnum class } word '[ _ declare 10 _ execute ] unit-test-cfg
96         { fixnum class fixnum } word '[ _ declare _ execute ] unit-test-cfg
97     ] each
98     
99     { float class } \ set-alien-float '[ _ declare 10 _ execute ] unit-test-cfg
100     { float class fixnum } \ set-alien-float '[ _ declare _ execute ] unit-test-cfg
101     
102     { float class } \ set-alien-double '[ _ declare 10 _ execute ] unit-test-cfg
103     { float class fixnum } \ set-alien-double '[ _ declare _ execute ] unit-test-cfg
104     
105     { pinned-c-ptr class } \ set-alien-cell '[ _ declare 10 _ execute ] unit-test-cfg
106     { pinned-c-ptr class fixnum } \ set-alien-cell '[ _ declare _ execute ] unit-test-cfg
107 ] each