Commit 7ca763c7 authored by Rudi Chen's avatar Rudi Chen

Move around some dict declarations.

parent 3d8398be
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
namespace pyston { namespace pyston {
BoxedClass* dict_iterator_cls = NULL;
BoxedClass* dict_keys_cls = NULL;
BoxedClass* dict_values_cls = NULL;
BoxedClass* dict_items_cls = NULL;
Box* dictRepr(BoxedDict* self) { Box* dictRepr(BoxedDict* self) {
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
...@@ -677,18 +682,16 @@ extern "C" Box* dictInit(BoxedDict* self, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -677,18 +682,16 @@ extern "C" Box* dictInit(BoxedDict* self, BoxedTuple* args, BoxedDict* kwargs) {
return None; return None;
} }
BoxedClass* dict_iterator_cls = NULL; static void BoxedDictIterator:::gcHandler(GCVisitor* v, Box* b) {
extern "C" void dictIteratorGCHandler(GCVisitor* v, Box* b) { assert(b->cls == dict_iterator_cls);
boxGCHandler(v, b); boxGCHandler(v, b);
BoxedDictIterator* it = static_cast<BoxedDictIterator*>(b); BoxedDictIterator* it = static_cast<BoxedDictIterator*>(b);
v->visit(it->d); v->visit(it->d);
} }
BoxedClass* dict_keys_cls = NULL; static void BoxedDictView::gcHandler(GCVisitor* v, Box* b) {
BoxedClass* dict_values_cls = NULL; assert(b->cls == dict_items_cls);
BoxedClass* dict_items_cls = NULL;
extern "C" void dictViewGCHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b); boxGCHandler(v, b);
BoxedDictView* view = static_cast<BoxedDictView*>(b); BoxedDictView* view = static_cast<BoxedDictView*>(b);
...@@ -717,14 +720,14 @@ static Box* dict_repr(PyObject* self) noexcept { ...@@ -717,14 +720,14 @@ static Box* dict_repr(PyObject* self) noexcept {
} }
void setupDict() { void setupDict() {
dict_iterator_cls = BoxedHeapClass::create(type_cls, object_cls, &dictIteratorGCHandler, 0, 0, dict_iterator_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictIterator::gcHandler, 0, 0,
sizeof(BoxedDictIterator), false, "dictionary-itemiterator"); sizeof(BoxedDictIterator), false, "dictionary-itemiterator");
dict_keys_cls = BoxedHeapClass::create(type_cls, object_cls, &dictViewGCHandler, 0, 0, sizeof(BoxedDictView), false, dict_keys_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictView::gcHandler, 0, 0, sizeof(BoxedDictView), false,
"dict_keys"); "dict_keys");
dict_values_cls = BoxedHeapClass::create(type_cls, object_cls, &dictViewGCHandler, 0, 0, sizeof(BoxedDictView), dict_values_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictView::gcHandler, 0, 0, sizeof(BoxedDictView),
false, "dict_values"); false, "dict_values");
dict_items_cls = BoxedHeapClass::create(type_cls, object_cls, &dictViewGCHandler, 0, 0, sizeof(BoxedDictView), dict_items_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictView::gcHandler, 0, 0, sizeof(BoxedDictView),
false, "dict_items"); false, "dict_items");
dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, BOXED_INT, 1))); dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, BOXED_INT, 1)));
......
...@@ -24,6 +24,7 @@ extern BoxedClass* dict_iterator_cls; ...@@ -24,6 +24,7 @@ extern BoxedClass* dict_iterator_cls;
extern BoxedClass* dict_keys_cls; extern BoxedClass* dict_keys_cls;
extern BoxedClass* dict_values_cls; extern BoxedClass* dict_values_cls;
extern BoxedClass* dict_items_cls; extern BoxedClass* dict_items_cls;
class BoxedDictIterator : public Box { class BoxedDictIterator : public Box {
public: public:
enum IteratorType { KeyIterator, ValueIterator, ItemIterator }; enum IteratorType { KeyIterator, ValueIterator, ItemIterator };
...@@ -36,6 +37,8 @@ public: ...@@ -36,6 +37,8 @@ public:
BoxedDictIterator(BoxedDict* d, IteratorType type); BoxedDictIterator(BoxedDict* d, IteratorType type);
DEFAULT_CLASS(dict_iterator_cls); DEFAULT_CLASS(dict_iterator_cls);
static void gcHandler(GCVisitor* v, Box* self);
}; };
Box* dictGetitem(BoxedDict* self, Box* k); Box* dictGetitem(BoxedDict* self, Box* k);
...@@ -52,6 +55,8 @@ class BoxedDictView : public Box { ...@@ -52,6 +55,8 @@ class BoxedDictView : public Box {
public: public:
BoxedDict* d; BoxedDict* d;
BoxedDictView(BoxedDict* d); BoxedDictView(BoxedDict* d);
static void gcHandler(GCVisitor* v, Box* self);
}; };
Box* dictViewKeysIter(Box* self); Box* dictViewKeysIter(Box* self);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment