Permalink
Browse files

Add two methods gCollect() in Type, for garbage-collecting.

These methods are responsible for garbage-collecting a node of this type.
One method g-collects to a StableNode, the other one g-collects to an Unstable
node.

They are generated by the generator, but currently are not implemented.
  • Loading branch information...
1 parent 1bd2b9c commit c01d12466dcdd3f7522d3a7287392c30bf8872dc @sjrd committed Feb 16, 2012
Showing with 48 additions and 1 deletion.
  1. +34 −0 generator/main/implementations.cc
  2. +3 −0 vm/main/core-forward-decl.hh
  3. +8 −1 vm/main/store.hh
  4. +3 −0 vm/main/type.hh
@@ -34,6 +34,7 @@ struct ImplementationDef {
transient = false;
storage = "";
base = "Type";
+ autoGCollect = true;
}
void makeOutputDecl(llvm::raw_fd_ostream& to);
@@ -44,6 +45,9 @@ struct ImplementationDef {
bool transient;
std::string storage;
std::string base;
+ bool autoGCollect;
+private:
+ void makeContentsOfAutoGCollect(llvm::raw_fd_ostream& to);
};
void handleImplementation(const SpecDecl* ND) {
@@ -68,6 +72,8 @@ void handleImplementation(const SpecDecl* ND) {
getTypeParamAsString(marker) + ">";
} else if (markerLabel == "BasedOn") {
definition.base = getTypeParamAsString(marker);
+ } else if (markerLabel == "NoAutoGCollect") {
+ definition.autoGCollect = false;
} else {}
}
@@ -96,6 +102,8 @@ void ImplementationDef::makeOutputDecl(llvm::raw_fd_ostream& to) {
}
to << "class " << name << ": public " << base << " {\n";
+ to << "private:\n";
+ to << " typedef SelfType<" << name << ">::Self Self;\n";
to << "public:\n";
to << " " << name << "() : " << base << "(\"" << name << "\", "
<< b2s(copiable) << ", " << b2s(transient) <<") {}\n";
@@ -104,8 +112,34 @@ void ImplementationDef::makeOutputDecl(llvm::raw_fd_ostream& to) {
to << " static const " << name << " rawType;\n";
to << " return &rawType;\n";
to << " }\n";
+
+ if (autoGCollect) {
+ to << "\n";
+ to << " inline\n";
+ to << " void gCollect(GC gc, Node& from, StableNode& to) const;\n";
+ to << "\n";
+ to << " inline\n";
+ to << " void gCollect(GC gc, Node& from, UnstableNode& to) const;\n";
+ }
+
to << "};\n";
}
void ImplementationDef::makeOutput(llvm::raw_fd_ostream& to) {
+ if (autoGCollect) {
+ to << "void " << name
+ << "::gCollect(GC gc, Node& from, StableNode& to) const {\n";
+ makeContentsOfAutoGCollect(to);
+ to << "}\n\n";
+
+ to << "void " << name
+ << "::gCollect(GC gc, Node& from, UnstableNode& to) const {\n";
+ makeContentsOfAutoGCollect(to);
+ to << "}\n";
+ }
+}
+
+void ImplementationDef::makeContentsOfAutoGCollect(llvm::raw_fd_ostream& to) {
+ // TODO
+ to << " // TODO\n";
}
@@ -37,6 +37,9 @@ class UnstableNode;
class VirtualMachine;
typedef VirtualMachine* VM;
+class GarbageCollector;
+typedef GarbageCollector* GC;
+
inline
void* operator new (size_t size, VM vm);
View
@@ -337,6 +337,14 @@ public:
return &rawType;
}
+ void gCollect(GC gc, Node& from, StableNode& to) const {
+ // TODO
+ }
+
+ void gCollect(GC gc, Node& from, UnstableNode& to) const {
+ // TODO
+ }
+
// This is optimized for the 0- and 1-dereference paths
// Normally it would have been only a while loop
static Node& dereference(Node& node) {
@@ -402,7 +410,6 @@ private:
return node;
}
-
};
/////////////////////////
View
@@ -44,6 +44,9 @@ public:
bool isCopiable() const { return _copiable; }
bool isTransient() const { return _transient; }
+
+ virtual void gCollect(GC gc, Node& from, StableNode& to) const = 0;
+ virtual void gCollect(GC gc, Node& from, UnstableNode& to) const = 0;
private:
const string _name;

0 comments on commit c01d124

Please sign in to comment.