Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r67062:2e89f6de1470
Date: 2013-09-22 19:14 +0100
http://bitbucket.org/pypy/pypy/changeset/2e89f6de1470/

Log:    Add op.simple_call and op.call_args

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -933,7 +933,7 @@
         arguments = self.popvalues(n_arguments)
         args = CallSpec(arguments, keywords, w_star, w_starstar)
         w_function = self.popvalue()
-        w_result = self.space.call_args(w_function, args)
+        w_result = self.space.call(w_function, args)
         self.pushvalue(w_result)
 
     def CALL_FUNCTION(self, oparg):
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -21,15 +21,6 @@
 from rpython.rlib import rstackovf
 
 
-# built-ins that can always raise exceptions
-builtins_exceptions = {
-    int: [ValueError],
-    float: [ValueError],
-    chr: [ValueError],
-    unichr: [ValueError],
-    unicode: [UnicodeDecodeError],
-}
-
 
 def _assert_rpythonic(func):
     """Raise ValueError if ``func`` is obviously not RPython"""
@@ -203,14 +194,14 @@
 
     def call_function(self, w_func, *args_w):
         args = CallSpec(list(args_w))
-        return self.call_args(w_func, args)
+        return self.call(w_func, args)
 
     def appcall(self, func, *args_w):
         """Call an app-level RPython function directly"""
         w_func = const(func)
         return self.frame.do_operation('simple_call', w_func, *args_w)
 
-    def call_args(self, w_callable, args):
+    def call(self, w_callable, args):
         if isinstance(w_callable, Constant):
             fn = w_callable.value
             if hasattr(fn, "_flowspace_rewrite_directly_as_"):
@@ -228,25 +219,10 @@
 
         if args.keywords or isinstance(args.w_stararg, Variable):
             shape, args_w = args.flatten()
-            w_res = self.frame.do_operation('call_args', w_callable,
-                    Constant(shape), *args_w)
+            hlop = op.call_args(w_callable, Constant(shape), *args_w)
         else:
-            w_res = self.frame.do_operation(
-                    'simple_call', w_callable, *args.as_list())
-        self.frame.guessexception(self._callable_exceptions(w_callable))
-        return w_res
-
-    def _callable_exceptions(self, w_callable):
-        if isinstance(w_callable, Constant):
-            c = w_callable.value
-            if (isinstance(c, (types.BuiltinFunctionType,
-                               types.BuiltinMethodType,
-                               types.ClassType,
-                               types.TypeType)) and
-                  c.__module__ in ['__builtin__', 'exceptions']):
-                return builtins_exceptions.get(c, [])
-        # *any* exception for non-builtins
-        return [Exception]
+            hlop = op.simple_call(w_callable, *args.as_list())
+        return self.frame.do_op(hlop)
 
     def find_global(self, w_globals, varname):
         try:
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -7,6 +7,7 @@
 import __future__
 import operator
 import sys
+import types
 from rpython.rlib.unroll import unrolling_iterable, _unroller
 from rpython.tool.sourcetools import compile2
 from rpython.flowspace.model import (Constant, WrapException, const, Variable,
@@ -28,6 +29,13 @@
     }
 }
 
+# built-ins that can always raise exceptions
+builtins_exceptions = {
+    chr: [ValueError],
+    unichr: [ValueError],
+    unicode: [UnicodeDecodeError],
+}
+
 
 class _OpHolder(object): pass
 op = _OpHolder()
@@ -38,8 +46,6 @@
     pure = False
 
     def __init__(self, *args):
-        if len(args) != self.arity:
-            raise TypeError(self.opname + " got the wrong number of arguments")
         self.args = list(args)
         self.result = Variable()
         self.offset = -1
@@ -372,7 +378,29 @@
                 pass
 op.getattr = GetAttr
 
+class CallOp(HLOperation):
+    @property
+    def canraise(self):
+        w_callable = self.args[0]
+        if isinstance(w_callable, Constant):
+            c = w_callable.value
+            if (isinstance(c, (types.BuiltinFunctionType,
+                               types.BuiltinMethodType,
+                               types.ClassType,
+                               types.TypeType)) and
+                  c.__module__ in ['__builtin__', 'exceptions']):
+                return builtins_exceptions.get(c, [])
+        # *any* exception for non-builtins
+        return [Exception]
 
+class SimpleCall(CallOp):
+    opname = 'simple_call'
+op.simple_call = SimpleCall
+
+
+class CallArgs(CallOp):
+    opname = 'call_args'
+op.call_args = CallArgs
 
 # Other functions that get directly translated to SpaceOperators
 func2op[type] = op.type
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to