Commit 5341455f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Some minor improvements

parent 79b7ab49
......@@ -1731,17 +1731,16 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
}
// TODO patch these cases
if (rewrite_args) {
assert(rewrite_args->out_success == false);
rewrite_args = NULL;
}
std::string rop_name = getReverseOpName(op_type);
Box* rattr_func = getattr_internal(rhs->cls, rop_name, false, false, NULL, NULL);
if (rattr_func) {
Box* rtn = runtimeCall2(rattr_func, 2, rhs, lhs);
if (rtn != NotImplemented) {
return rtn;
}
} else {
// printf("rfunc doesn't exist\n");
}
Box* rrtn = callattrInternal1(rhs, &rop_name, CLASS_ONLY, NULL, 1, lhs);
if (rrtn != NULL && rrtn != NotImplemented)
return rrtn;
llvm::StringRef op_sym = getOpSymbol(op_type);
const char* op_sym_suffix = "";
......@@ -1762,7 +1761,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
fprintf(stderr, "%s has %s, but returned NotImplemented\n", getTypeName(lhs)->c_str(), op_name.c_str());
else
fprintf(stderr, "%s does not have %s\n", getTypeName(lhs)->c_str(), op_name.c_str());
if (rattr_func)
if (rrtn)
fprintf(stderr, "%s has %s, but returned NotImplemented\n", getTypeName(rhs)->c_str(), rop_name.c_str());
else
fprintf(stderr, "%s does not have %s\n", getTypeName(rhs)->c_str(), rop_name.c_str());
......@@ -1877,7 +1876,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
ASSERT(isUserDefined(rhs->cls), "%s should probably have a __contains__", getTypeName(rhs)->c_str());
RELEASE_ASSERT(iter == NULL, "need to try iterating");
Box* getitem = getattr_internal(rhs, "__getitem__", false, false, NULL, NULL);
Box* getitem = typeLookup(rhs->cls, "__getitem__", NULL, NULL);
if (getitem)
ASSERT(isUserDefined(rhs->cls), "%s should probably have a __contains__", getTypeName(rhs)->c_str());
RELEASE_ASSERT(getitem == NULL, "need to try old iteration protocol");
......@@ -1930,24 +1929,18 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
} else {
}
std::string rop_name = getReverseOpName(op_type);
Box* rattr_func = getattr_internal(rhs->cls, rop_name, false, false, NULL, NULL);
if (rattr_func) {
Box* rtn = runtimeCall2(rattr_func, 2, rhs, lhs);
if (rtn != NotImplemented) {
////printf("rfunc returned NotImplemented\n");
////bool can_patchpoint = lhs->cls->is_constant && (lattr_func == NULL || (lattr;
// bool can_patchpoint = !isUserDefined(lhs->cls) && lhs->cls->is_constant;
// if (can_patchpoint && rhs->cls->is_constant && rattr_func->cls == function_cls) {
// void* rtn_addr = __builtin_extract_return_addr(__builtin_return_address(0));
//_repatchBinExp(rtn_addr, true, lhs, rhs, rattr_func);
//}
return rtn;
}
} else {
// printf("rfunc doesn't exist\n");
// TODO patch these cases
if (rewrite_args) {
assert(rewrite_args->out_success == false);
rewrite_args = NULL;
}
std::string rop_name = getReverseOpName(op_type);
Box* rrtn = callattrInternal1(rhs, &rop_name, CLASS_ONLY, NULL, 1, lhs);
if (rrtn != NULL && rrtn != NotImplemented)
return rrtn;
if (op_type == AST_TYPE::Eq)
return boxBool(lhs == rhs);
......
# expected: fail
# - descriptors not implemented yet
# Make sure that we guard in a getattr IC to make sure that
# we don't subsequently get an object with a __get__ defined.
class D(object):
pass
class C(object):
d = D()
c = C()
def print_d(c):
print c.d
print_d(c)
def get(self, obj, cls):
print self, obj, cls
return 1
D.__get__ = get
print_d(c)
# And also the other way around:
del D.__get__
print_d(c)
class E(object):
def __get__(self, obj, cls):
print "E.__get__"
return 2
C.d = E()
# Or if we switch out the object entirely:
print_d(c)
# expected: fail
# - descriptors
# Descriptors get processed when fetched as part of a dunder lookup
class D(object):
def __get__(self, obj, cls):
print "__get__()", obj is None
def desc():
print "desc()"
return 1
return desc
def __call__(self):
print "D.call"
return 2
class C(object):
__hash__ = D()
c = C()
print C.__hash__()
print c.__hash__()
print hash(c)
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