]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/builder/builder-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[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     [ fixnum-shift-fast ]
22     [ 10 fixnum-shift-fast ]
23     [ -10 fixnum-shift-fast ]
24     [ 0 fixnum-shift-fast ]
25     [ fixnum-bitnot ]
26     [ eq? ]
27     [ "hi" eq? ]
28     [ fixnum< ]
29     [ 5 fixnum< ]
30     [ float+ ]
31     [ 3.0 float+ ]
32     [ float<= ]
33     [ fixnum>bignum ]
34     [ bignum>fixnum ]
35     [ fixnum>float ]
36     [ float>fixnum ]
37     [ 3 f <array> ]
38     [ [ 1 ] [ 2 ] if ]
39     [ fixnum< [ 1 ] [ 2 ] if ]
40     [ float+ [ 2.0 float* ] [ 3.0 float* ] bi float/f ]
41     [ { [ 1 ] [ 2 ] [ 3 ] } dispatch ]
42     [ [ t ] loop ]
43     [ [ dup ] loop ]
44     [ [ 2 ] [ 3 throw ] if 4 ]
45     [ "int" f "malloc" { "int" } alien-invoke ]
46     [ "int" { "int" } "cdecl" alien-indirect ]
47     [ "int" { "int" } "cdecl" [ ] alien-callback ]
48 } [
49     unit-test-cfg
50 ] each
51
52 : test-1 ( -- ) test-1 ;
53 : test-2 ( -- ) 3 . test-2 ;
54 : test-3 ( a -- b ) dup [ test-3 ] when ;
55
56 {
57     test-1
58     test-2
59     test-3
60 } [ unit-test-cfg ] each
61
62 {
63     byte-array
64     simple-alien
65     alien
66     POSTPONE: f
67 } [| class |
68     {
69         alien-signed-1
70         alien-signed-2
71         alien-signed-4
72         alien-unsigned-1
73         alien-unsigned-2
74         alien-unsigned-4
75         alien-cell
76         alien-float
77         alien-double
78     } [| word |
79         { class } word '[ _ declare 10 _ execute ] unit-test-cfg
80         { class fixnum } word '[ _ declare _ execute ] unit-test-cfg
81     ] each
82     
83     {
84         set-alien-signed-1
85         set-alien-signed-2
86         set-alien-signed-4
87         set-alien-unsigned-1
88         set-alien-unsigned-2
89         set-alien-unsigned-4
90     } [| word |
91         { fixnum class } word '[ _ declare 10 _ execute ] unit-test-cfg
92         { fixnum class fixnum } word '[ _ declare _ execute ] unit-test-cfg
93     ] each
94     
95     { float class } \ set-alien-float '[ _ declare 10 _ execute ] unit-test-cfg
96     { float class fixnum } \ set-alien-float '[ _ declare _ execute ] unit-test-cfg
97     
98     { float class } \ set-alien-double '[ _ declare 10 _ execute ] unit-test-cfg
99     { float class fixnum } \ set-alien-double '[ _ declare _ execute ] unit-test-cfg
100     
101     { pinned-c-ptr class } \ set-alien-cell '[ _ declare 10 _ execute ] unit-test-cfg
102     { pinned-c-ptr class fixnum } \ set-alien-cell '[ _ declare _ execute ] unit-test-cfg
103 ] each