Commit 4dde3519 authored by Kevin Modzelewski's avatar Kevin Modzelewski

New approach for marking instances as always-nonzero

Set a flag on the class, rather than having to specify a whitelist.
Even though this is pretty annoying I think it's still worth it.
parent e18f82ad
......@@ -1282,6 +1282,7 @@ void setupList() {
sizeof(BoxedListIterator), false, "listiterator");
list_reverse_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedListIterator::gcHandler, 0, 0,
sizeof(BoxedListIterator), false, "listreverseiterator");
list_iterator_cls->instances_are_nonzero = list_reverse_iterator_cls->instances_are_nonzero = true;
list_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)listLen, BOXED_INT, 1)));
......
......@@ -2486,12 +2486,13 @@ extern "C" bool nonzero(Box* obj) {
rewriter.reset();
if (rtn == NULL) {
ASSERT(obj->cls->is_user_defined || obj->cls == classobj_cls || obj->cls == type_cls
|| isSubclass(obj->cls, Exception) || obj->cls == file_cls || obj->cls == traceback_cls
|| obj->cls == instancemethod_cls || obj->cls == module_cls || obj->cls == capifunc_cls
|| obj->cls == builtin_function_or_method_cls || obj->cls == method_cls || obj->cls == frame_cls
|| obj->cls == generator_cls || obj->cls == capi_getset_cls || obj->cls == pyston_getset_cls
|| obj->cls == wrapperdescr_cls || obj->cls == wrapperobject_cls,
ASSERT(obj->cls->is_user_defined || obj->cls->instances_are_nonzero || obj->cls == classobj_cls
|| obj->cls == type_cls || isSubclass(obj->cls, Exception) || obj->cls == file_cls
|| obj->cls == traceback_cls || obj->cls == instancemethod_cls || obj->cls == module_cls
|| obj->cls == capifunc_cls || obj->cls == builtin_function_or_method_cls
|| obj->cls == method_cls || obj->cls == frame_cls || obj->cls == generator_cls
|| obj->cls == capi_getset_cls || obj->cls == pyston_getset_cls || obj->cls == wrapperdescr_cls
|| obj->cls == wrapperobject_cls,
"%s.__nonzero__", getTypeName(obj)); // TODO
if (rewriter.get()) {
......
......@@ -235,6 +235,12 @@ public:
// that we can't rely on for extension classes.
bool is_pyston_class;
// Just for debugging: whether instances of this class should always be considered nonzero.
// This is the default for anything that doesn't define a __nonzero__ or __len__ method, but
// for builtin types we have the extra check that we opted into this behavior rather than
// just forgot to add nonzero/len.
bool instances_are_nonzero;
bool has___class__; // Has a custom __class__ attribute (ie different from object's __class__ descriptor)
bool has_instancecheck;
bool has_subclasscheck;
......
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