Commit 230eed7d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Oldstyle class __delitem__ support

parent c23a8bce
...@@ -269,6 +269,14 @@ Box* instanceSetitem(Box* _inst, Box* key, Box* value) { ...@@ -269,6 +269,14 @@ Box* instanceSetitem(Box* _inst, Box* key, Box* value) {
return runtimeCall(setitem_func, ArgPassSpec(2), key, value, NULL, NULL, NULL); return runtimeCall(setitem_func, ArgPassSpec(2), key, value, NULL, NULL, NULL);
} }
Box* instanceDelitem(Box* _inst, Box* key) {
RELEASE_ASSERT(_inst->cls == instance_cls, "");
BoxedInstance* inst = static_cast<BoxedInstance*>(_inst);
Box* delitem_func = _instanceGetattribute(inst, boxStrConstant("__delitem__"), true);
return runtimeCall(delitem_func, ArgPassSpec(1), key, NULL, NULL, NULL, NULL);
}
void setupClassobj() { void setupClassobj() {
classobj_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedClassobj::gcHandler, classobj_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedClassobj::gcHandler,
offsetof(BoxedClassobj, attrs), 0, sizeof(BoxedClassobj), false, "classobj"); offsetof(BoxedClassobj, attrs), 0, sizeof(BoxedClassobj), false, "classobj");
...@@ -295,6 +303,7 @@ void setupClassobj() { ...@@ -295,6 +303,7 @@ void setupClassobj() {
instance_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)instanceLen, UNKNOWN, 1))); instance_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)instanceLen, UNKNOWN, 1)));
instance_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)instanceGetitem, UNKNOWN, 2))); instance_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)instanceGetitem, UNKNOWN, 2)));
instance_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)instanceSetitem, UNKNOWN, 3))); instance_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)instanceSetitem, UNKNOWN, 3)));
instance_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)instanceDelitem, UNKNOWN, 2)));
instance_cls->freeze(); instance_cls->freeze();
} }
......
...@@ -126,3 +126,17 @@ print g.b ...@@ -126,3 +126,17 @@ print g.b
print g.__class__ print g.__class__
print g.__dict__.items() print g.__dict__.items()
print bool(g) print bool(g)
class MappingTest:
def __getitem__(self, key):
print "getitem", key
return 1
def __setitem__(self, key, value):
print "setitem", key, value
def __delitem__(self, key):
print "delitem", key
m = MappingTest()
m[1] = 2
del m[2]
print m[3]
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