Commit d0863da3 authored by Chris Ramstad's avatar Chris Ramstad

Merge branch 'master' of https://github.com/dropbox/pyston

Conflicts:
	src/runtime/dict.cpp
parents 81b55a8c 6081cc7a
...@@ -149,6 +149,18 @@ Box* dictSetdefault(BoxedDict* self, Box* k, Box* v) { ...@@ -149,6 +149,18 @@ Box* dictSetdefault(BoxedDict* self, Box* k, Box* v) {
Box* dictContains(BoxedDict* self, Box* k) { Box* dictContains(BoxedDict* self, Box* k) {
assert(self->cls == dict_cls); assert(self->cls == dict_cls);
return boxBool(self->d.count(k) != 0); return boxBool(self->d.count(k) != 0);
extern "C" Box* dictNew(Box* _cls) {
if (!isSubclass(_cls->cls, type_cls))
raiseExcHelper(TypeError, "dict.__new__(X): X is not a type object (%s)", getTypeName(_cls)->c_str());
BoxedClass* cls = static_cast<BoxedClass*>(_cls);
if (!isSubclass(cls, dict_cls))
raiseExcHelper(TypeError, "dict.__new__(%s): %s is not a subtype of dict", getNameOfClass(cls)->c_str(),
getNameOfClass(cls)->c_str());
RELEASE_ASSERT(cls == dict_cls, "");
return new BoxedDict();
} }
BoxedClass* dict_iterator_cls = NULL; BoxedClass* dict_iterator_cls = NULL;
...@@ -166,7 +178,7 @@ void setupDict() { ...@@ -166,7 +178,7 @@ void setupDict() {
dict_cls->giveAttr("__name__", boxStrConstant("dict")); dict_cls->giveAttr("__name__", boxStrConstant("dict"));
// dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, NULL, 1))); // dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, NULL, 1)));
// dict_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)dictGetitem, NULL, 2))); // dict_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)dictGetitem, NULL, 2)));
// dict_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)dictNew, NULL, 1))); dict_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)dictNew, UNKNOWN, 1)));
// dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NULL, 1))); // dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NULL, 1)));
dict_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)dictRepr, STR, 1))); dict_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)dictRepr, STR, 1)));
dict_cls->giveAttr("__str__", dict_cls->getattr("__repr__")); dict_cls->giveAttr("__str__", dict_cls->getattr("__repr__"));
......
...@@ -41,3 +41,8 @@ print d.setdefault(11, 9) ...@@ -41,3 +41,8 @@ print d.setdefault(11, 9)
print sorted(d.items()) print sorted(d.items())
print d.setdefault(11, 10) print d.setdefault(11, 10)
print sorted(d.items()) print sorted(d.items())
print dict()
d = dict()
d[1] = 2
print d
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