Commit d6d38a4d authored by Kevin Modzelewski's avatar Kevin Modzelewski

attrwrapper.pop

parent 050fe962
...@@ -1153,9 +1153,7 @@ public: ...@@ -1153,9 +1153,7 @@ public:
DEFAULT_CLASS(attrwrapper_cls); DEFAULT_CLASS(attrwrapper_cls);
Box* getUnderlying() { Box* getUnderlying() { return b; }
return b;
}
static void gcHandler(GCVisitor* v, Box* b) { static void gcHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b); boxGCHandler(v, b);
...@@ -1219,6 +1217,25 @@ public: ...@@ -1219,6 +1217,25 @@ public:
return r; return r;
} }
static Box* pop(Box* _self, Box* _key, Box* default_) {
RELEASE_ASSERT(_self->cls == attrwrapper_cls, "");
AttrWrapper* self = static_cast<AttrWrapper*>(_self);
_key = coerceUnicodeToStr(_key);
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s);
if (r) {
self->b->delattr(key->s, NULL);
return r;
} else {
if (default_)
return default_;
raiseExcHelper(KeyError, "'%s'", key->data());
}
}
static Box* delitem(Box* _self, Box* _key) { static Box* delitem(Box* _self, Box* _key) {
RELEASE_ASSERT(_self->cls == attrwrapper_cls, ""); RELEASE_ASSERT(_self->cls == attrwrapper_cls, "");
AttrWrapper* self = static_cast<AttrWrapper*>(_self); AttrWrapper* self = static_cast<AttrWrapper*>(_self);
...@@ -2210,6 +2227,8 @@ void setupRuntime() { ...@@ -2210,6 +2227,8 @@ void setupRuntime() {
slice_cls->freeze(); slice_cls->freeze();
attrwrapper_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::setitem, UNKNOWN, 3))); attrwrapper_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::setitem, UNKNOWN, 3)));
attrwrapper_cls->giveAttr(
"pop", new BoxedFunction(boxRTFunction((void*)AttrWrapper::pop, UNKNOWN, 3, 1, false, false), { NULL }));
attrwrapper_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::getitem, UNKNOWN, 2))); attrwrapper_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::getitem, UNKNOWN, 2)));
attrwrapper_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::delitem, UNKNOWN, 2))); attrwrapper_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::delitem, UNKNOWN, 2)));
attrwrapper_cls->giveAttr("setdefault", attrwrapper_cls->giveAttr("setdefault",
......
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