Commit 063f08fe authored by Kevin Modzelewski's avatar Kevin Modzelewski

capifunc_cls.__name__, PyNumber_Invert

parent 358610b9
......@@ -1621,8 +1621,12 @@ extern "C" PyObject* PyNumber_Absolute(PyObject* o) noexcept {
}
extern "C" PyObject* PyNumber_Invert(PyObject* o) noexcept {
fatalOrError(PyExc_NotImplementedError, "unimplemented");
return nullptr;
try {
return unaryop(o, AST_TYPE::Invert);
} catch (ExcInfo e) {
setCAPIException(e);
return nullptr;
}
}
extern "C" PyObject* PyNumber_Lshift(PyObject* lhs, PyObject* rhs) noexcept {
......
......@@ -89,6 +89,14 @@ public:
return rtn;
}
static Box* getname(Box* b, void*) {
RELEASE_ASSERT(b->cls == capifunc_cls, "");
const char* s = static_cast<BoxedCApiFunction*>(b)->name;
if (s)
return boxStrConstant(s);
return None;
}
static Box* callInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1,
Box* arg2, Box* arg3, Box** args, const std::vector<const std::string*>* keyword_names);
};
......
......@@ -1392,6 +1392,8 @@ void setupCAPI() {
auto capi_call = new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__call__, UNKNOWN, 1, 0, true, true));
capi_call->f->internal_callable = BoxedCApiFunction::callInternal;
capifunc_cls->giveAttr("__call__", capi_call);
capifunc_cls->giveAttr("__name__",
new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCApiFunction::getname, NULL, NULL));
capifunc_cls->freeze();
......
......@@ -18,3 +18,5 @@ print min(range(5))
for x in [float("inf"), math.pi]:
print x, math.isinf(x), math.fabs(x), math.ceil(x), math.log(x), math.log10(x)
print math.sqrt.__name__
# expected: fail
import operator
for op in sorted(dir(operator)):
if op.startswith("_"):
continue
print getattr(operator, op).__name__
......@@ -16,3 +16,7 @@ f = operator.attrgetter("count")
print f(["a", "a"])("a")
print f("ababa")("a")
for op in sorted(dir(operator)):
if op.startswith("_"):
continue
print getattr(operator, op).__name__
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