Permalink
Browse files

Added StableNode::init(RichNode) and UnstableNode::copy(RichNode).

Unfortunately, this required to move the whole definition of
RichNode before the ones of StableNode and UnstableNode. This is
why the commit looks so big for such a small change.
  • Loading branch information...
1 parent b861180 commit 62adfe1828e01bdec073c4549142167fc28e39a0 @sjrd committed Apr 4, 2012
Showing with 96 additions and 86 deletions.
  1. +88 −86 vm/main/store-decl.hh
  2. +8 −0 vm/main/store.hh
View
@@ -85,6 +85,92 @@ private:
Node saved;
};
+template <class T>
+class TypedRichNode {
+};
+
+/**
+ * A rich node is a node with an accompanying unstable origin
+ * The important invariant of this class is that following a chain of
+ * references starting at the origin eventually reaches the node.
+ */
+struct RichNode {
+private:
+ RichNode(Node* node, UnstableNode& origin) : _node(node), _origin(&origin) {}
+public:
+ __attribute__((always_inline))
+ inline
+ RichNode(UnstableNode& origin);
+
+ const Type* type() {
+ return _node->type;
+ }
+
+ UnstableNode& origin() {
+ return *_origin;
+ }
+
+ template <class T>
+ TypedRichNode<T> as() {
+ assert(type() == T::type());
+ return TypedRichNode<T>(*this);
+ }
+
+ __attribute__((always_inline))
+ inline
+ StableNode* getStableRef(VM vm);
+
+ inline
+ void update();
+
+ inline void reinit(VM vm, StableNode& from);
+ inline void reinit(VM vm, UnstableNode& from);
+ inline void reinit(VM vm, RichNode from);
+
+ template<class T, class... Args>
+ void remake(VM vm, Args... args) {
+ _node->make<T>(vm, args...);
+ }
+
+ NodeBackup makeBackup() {
+ return NodeBackup(_node);
+ }
+
+ bool isSameNode(RichNode right) {
+ return _node == right._node;
+ }
+
+ inline
+ std::string toDebugString();
+private:
+ inline
+ static Node* dereference(Node* node);
+
+ __attribute__((noinline))
+ inline
+ static Node* dereferenceLoop(Node* node);
+
+ inline
+ static StableNode* getStableRefFor(VM vm, UnstableNode& node);
+
+ __attribute__((noinline))
+ inline
+ static StableNode* getStableRefForLoop(StableNode* node);
+
+ inline
+ static StableNode* destOf(Node* node);
+private:
+ template <class T>
+ friend class BaseSelf;
+
+ MemWord value() {
+ return _node->value;
+ }
+private:
+ Node* _node;
+ UnstableNode* _origin;
+};
+
/**
* Stable node, which is guaranteed never to change
*/
@@ -98,6 +184,7 @@ public:
inline void init(VM vm, StableNode& from);
inline void init(VM vm, UnstableNode& from);
+ inline void init(VM vm, RichNode from);
template<class T, class... Args>
void make(VM vm, Args... args) {
@@ -160,6 +247,7 @@ public:
inline void copy(VM vm, StableNode& from);
inline void copy(VM vm, UnstableNode& from);
+ inline void copy(VM vm, RichNode from);
inline void swap(UnstableNode& from);
inline void reset(VM vm);
@@ -211,92 +299,6 @@ private:
};
};
-template <class T>
-class TypedRichNode {
-};
-
-/**
- * A rich node is a node with an accompanying unstable origin
- * The important invariant of this class is that following a chain of
- * references starting at the origin eventually reaches the node.
- */
-struct RichNode {
-private:
- RichNode(Node* node, UnstableNode& origin) : _node(node), _origin(&origin) {}
-public:
- __attribute__((always_inline))
- inline
- RichNode(UnstableNode& origin);
-
- const Type* type() {
- return _node->type;
- }
-
- UnstableNode& origin() {
- return *_origin;
- }
-
- template <class T>
- TypedRichNode<T> as() {
- assert(type() == T::type());
- return TypedRichNode<T>(*this);
- }
-
- __attribute__((always_inline))
- inline
- StableNode* getStableRef(VM vm);
-
- inline
- void update();
-
- inline void reinit(VM vm, StableNode& from);
- inline void reinit(VM vm, UnstableNode& from);
- inline void reinit(VM vm, RichNode from);
-
- template<class T, class... Args>
- void remake(VM vm, Args... args) {
- _node->make<T>(vm, args...);
- }
-
- NodeBackup makeBackup() {
- return NodeBackup(_node);
- }
-
- bool isSameNode(RichNode right) {
- return _node == right._node;
- }
-
- inline
- std::string toDebugString();
-private:
- inline
- static Node* dereference(Node* node);
-
- __attribute__((noinline))
- inline
- static Node* dereferenceLoop(Node* node);
-
- inline
- static StableNode* getStableRefFor(VM vm, UnstableNode& node);
-
- __attribute__((noinline))
- inline
- static StableNode* getStableRefForLoop(StableNode* node);
-
- inline
- static StableNode* destOf(Node* node);
-private:
- template <class T>
- friend class BaseSelf;
-
- MemWord value() {
- return _node->value;
- }
-private:
- Node* _node;
- UnstableNode* _origin;
-};
-
/**
* Base class for Self types
*/
View
@@ -57,6 +57,10 @@ void StableNode::init(VM vm, UnstableNode& from) {
from.make<Reference>(vm, this);
}
+void StableNode::init(VM vm, RichNode from) {
+ init(vm, from.origin());
+}
+
void UnstableNode::copy(VM vm, StableNode& from) {
if (from.node.type->isCopiable())
node = from.node;
@@ -75,6 +79,10 @@ void UnstableNode::copy(VM vm, UnstableNode& from) {
}
}
+void UnstableNode::copy(VM vm, RichNode from) {
+ copy(vm, from.origin());
+}
+
void UnstableNode::reset(VM vm) {
node.reset(vm);
}

0 comments on commit 62adfe1

Please sign in to comment.