finally prop compiles too
[prop.git] / tests / test_gc18.pcc
blob5b19f3959acf65f1b599f7fe3fdc0b783d3cf0fb
1 #include <iostream.h>
2 #include <assert.h>
3 #include <AD/gc/gcobject.h>
4 #include <AD/strings/quark.h>
6 int traced = 0;
8 template <class T>
9    class base : public GCObject 
10    {
11    public:
12       base() {}
13       virtual void trace(GC *) { traced++; }
14    };
16 datatype Exp<T> : collectable public base<T> :: collectable =
17     OP(Quark, Exp<T>, Exp<T>)
18 |   OBJ(T) 
19 |   ID(Quark)
22 template <class T>
23    ostream& operator << (ostream& s, Exp<T> e)
24    {  match (e) of
25         OP(a,b,c):  { return s << '(' << b << ' ' << a << ' ' << c << ')'; }
26       | OBJ x:      { return s << x; }
27       | ID  x:      { return s << x; }
28       end match;
29    }
31 instantiate datatype Exp<int>;
33 int main()
35    GC::get_default_gc().set_initial_heap_size(1024*1024);
36    for (int i = 0; i < 100000; i++)
37    {
38       Exp<int> a = new classof ID<int>(#"a");
39       Exp<int> b = new classof ID<int>(#"b");
40       Exp<int> e1 = new classof OBJ<int>(0);
41       Exp<int> e = OP(#"+",a,OP(#"*",b,e1));
42       if (i % 10000 == 0) cout << i << ": " << e << '\n';
43    }
44    cout << "Finished: base class traced = " << traced << "\n";
45    assert(traced != 0);
46    return 0;