Commit d14249f1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add function.__call__

parent 9c86cf20
...@@ -712,8 +712,6 @@ if _exists("fork"): ...@@ -712,8 +712,6 @@ if _exists("fork"):
return p.stdin, p.stdout return p.stdin, p.stdout
__all__.append("popen4") __all__.append("popen4")
# Pyston change: disable custom pickle-registration for now
"""
import copy_reg as _copy_reg import copy_reg as _copy_reg
def _make_stat_result(tup, dict): def _make_stat_result(tup, dict):
...@@ -740,4 +738,3 @@ try: ...@@ -740,4 +738,3 @@ try:
_make_statvfs_result) _make_statvfs_result)
except NameError: # statvfs_result may not exist except NameError: # statvfs_result may not exist
pass pass
"""
...@@ -280,15 +280,12 @@ def _subx(pattern, template): ...@@ -280,15 +280,12 @@ def _subx(pattern, template):
# register myself for pickling # register myself for pickling
# Pyston change: disable the pickle-registration for now
"""
import copy_reg import copy_reg
def _pickle(p): def _pickle(p):
return _compile, (p.pattern, p.flags) return _compile, (p.pattern, p.flags)
copy_reg.pickle(_pattern_type, _pickle, _compile) copy_reg.pickle(_pattern_type, _pickle, _compile)
"""
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# experimental stuff (see python-dev discussions for details) # experimental stuff (see python-dev discussions for details)
......
...@@ -386,6 +386,19 @@ static Box* functionGet(BoxedFunction* self, Box* inst, Box* owner) { ...@@ -386,6 +386,19 @@ static Box* functionGet(BoxedFunction* self, Box* inst, Box* owner) {
return boxInstanceMethod(inst, self); return boxInstanceMethod(inst, self);
} }
static Box* functionCall(BoxedFunction* self, Box* args, Box* kwargs) {
RELEASE_ASSERT(self->cls == function_cls, "%s", getTypeName(self)->c_str());
// This won't work if you subclass from function_cls, since runtimeCall will
// just call back into this function.
// Fortunately, CPython disallows subclassing FunctionType; we don't currently
// disallow it but it's good to know.
assert(args->cls == tuple_cls);
assert(kwargs->cls == dict_cls);
return runtimeCall(self, ArgPassSpec(0, 0, true, true), args, kwargs, NULL, NULL, NULL);
}
extern "C" { extern "C" {
Box* None = NULL; Box* None = NULL;
Box* NotImplemented = NULL; Box* NotImplemented = NULL;
...@@ -763,6 +776,8 @@ void setupRuntime() { ...@@ -763,6 +776,8 @@ void setupRuntime() {
function_cls->giveAttr("__module__", function_cls->giveAttr("__module__",
new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFunction, modname))); new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFunction, modname)));
function_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)functionGet, UNKNOWN, 3))); function_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)functionGet, UNKNOWN, 3)));
function_cls->giveAttr("__call__",
new BoxedFunction(boxRTFunction((void*)functionCall, UNKNOWN, 1, 0, true, true)));
function_cls->freeze(); function_cls->freeze();
instancemethod_cls->giveAttr("__name__", boxStrConstant("instancemethod")); instancemethod_cls->giveAttr("__name__", boxStrConstant("instancemethod"));
......
def f():
print "f"
return 2
print f.__call__()
def g():
print "g"
return 3
print type(f).__call__(f)
print type(f).__call__(g)
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