The support library contains an implementation6 of a conservative garbage collector using two algorithms: one using a mostly copying scheme[Bar88, Bar89] and one using mark-sweep.
A datatype can be defined to be garbage collectable with the
qualifier collectable . In the following example, the datatype
Exp is will be allocated from the a garbage collected heap instead
of the default heap. Since it references another
user defined garbage collectable object
SymbolTable, the pointer to that symbol table is also marked
as collectable.
// SymbolTable is collectable
class SymbolTable: public GCObject
{
public:
class Id : public GCObject { ... };
...
};
datatype Exp :: collectable
= INT int
| VAR (collectable SymbolTable::Id, collectable SymbolTable *)
| ADD Exp, Exp
| SUB Exp, Exp
| MUL Exp, Exp
| DIV Exp, Exp
;
The corresponding instantiate datatype statement for Exp will generate the appropriate tracing methods for garbage collection.
Please see appendix A for more details concerning garbage collection.