Merge remote branch 'master'
[prop.git] / tests / prop4.pcc
blob3d0ab10466c850f830ff49ba458979c885f57a72
1 //  Test -lno-implicit-template instantiation of polymorphic types
2 //  This is the same as prop3.pcc except that it is generated with
3 //  the options save_space and -O15.
5 #include <iostream.h>
7 datatype List<T> :: collectable printable rewrite 
8    = #[] | #[ T ... List<T> ]
9    ;
11 datatype Tree<T> :: collectable printable rewrite
12    = Empty | Leaf of T | Node of (Tree<T>, Tree<T>)
13    ;
15 datatype Foo :: collectable printable rewrite = FOO() | BAR();
17 instantiate extern datatype List<int>, Tree<List<int> >, Tree<int>, Foo;
19 Tree<int> flip(Tree<int> t)
20 {  match (t)
21    {  Node(a,b): { return Node(flip(b),flip(a)); }
22    |  t:         { return t; }
23    }
26 #define PROP_EXPLICIT_TEMPLATE_INSTANTIATION
27 instantiate datatype List<int>, Tree<List<int> >, Tree<int>, Foo;
29 int main()
30 {  List<int> a = #[1,2,3];
31    Tree<List<int> > empty = Empty; // fake it for now
32    Tree<List<int> > b = Node(Leaf(#[4]),Node(Leaf(#[5,6]),empty));
33    Tree<int> c = Node(Leaf(4),Node(Leaf(5),Leaf(6)));
34    for (int i = 0; i < 10000; i++)
35    {  Foo l = FOO(); }
36    cout << "a = " << a << endl;
37    cout << "b = " << b << endl;
38    cout << "c = " << c << endl;
39    return 0;