Author: Ronan Lamy <[email protected]>
Branch: annotator
Changeset: r68746:e18a718a0185
Date: 2014-01-17 18:41 +0000
http://bitbucket.org/pypy/pypy/changeset/e18a718a0185/
Log: move handling of call special cases to SimpleCall.eval()
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -579,7 +579,7 @@
def appcall(self, func, *args_w):
"""Call an app-level RPython function directly"""
w_func = const(func)
- return op.simple_call(w_func, *args_w).eval(self)
+ return self.do_op(op.simple_call(w_func, *args_w))
def BAD_OPCODE(self, _):
raise FlowingError("This operation is not RPython")
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -46,24 +46,12 @@
return self.call(w_func, args)
def call(self, w_callable, args):
- if isinstance(w_callable, Constant):
- fn = w_callable.value
- try:
- sc = SPECIAL_CASES[fn] # TypeError if 'fn' not hashable
- except (KeyError, TypeError):
- pass
- else:
- if args.keywords:
- raise FlowingError(
- "should not call %r with keyword arguments" % (fn,))
- return sc(self, *args.as_list())
-
if args.keywords or isinstance(args.w_stararg, Variable):
shape, args_w = args.flatten()
hlop = op.call_args(w_callable, Constant(shape), *args_w)
else:
hlop = op.simple_call(w_callable, *args.as_list())
- return self.frame.do_op(hlop)
+ return hlop.eval(self.frame)
def build_flow(func, space=FlowObjSpace()):
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -15,6 +15,7 @@
SpaceOperation)
from rpython.flowspace.specialcase import register_flow_sc
from rpython.annotator.model import SomeTuple
+from rpython.flowspace.specialcase import SPECIAL_CASES
NOT_REALLY_CONST = {
@@ -495,9 +496,36 @@
class SimpleCall(SingleDispatchMixin, CallOp):
opname = 'simple_call'
+ def eval(self, frame):
+ w_callable, args_w = self.args[0], self.args[1:]
+ if isinstance(w_callable, Constant):
+ fn = w_callable.value
+ try:
+ sc = SPECIAL_CASES[fn] # TypeError if 'fn' not hashable
+ except (KeyError, TypeError):
+ pass
+ else:
+ return sc(frame.space, *args_w)
+ return frame.do_op(self)
+
+
class CallArgs(SingleDispatchMixin, CallOp):
opname = 'call_args'
+ def eval(self, frame):
+ w_callable = self.args[0]
+ if isinstance(w_callable, Constant):
+ fn = w_callable.value
+ try:
+ sc = SPECIAL_CASES[fn] # TypeError if 'fn' not hashable
+ except (KeyError, TypeError):
+ pass
+ else:
+ raise FlowingError(
+ "should not call %r with keyword arguments" % (fn,))
+ return frame.do_op(self)
+
+
# Other functions that get directly translated to SpaceOperators
func2op[type] = op.type
func2op[operator.truth] = op.bool
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit