Author: Ronan Lamy <[email protected]>
Branch: flowoperators
Changeset: r65226:697a17c9d3a1
Date: 2013-07-05 18:19 +0200
http://bitbucket.org/pypy/pypy/changeset/697a17c9d3a1/
Log: Turn make_sc() into a method of SpaceOperator
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -8,6 +8,7 @@
import operator
from rpython.tool.sourcetools import compile2
from rpython.rlib.rarithmetic import ovfcheck
+from rpython.flowspace.model import Constant
class _OpHolder(object): pass
op = _OpHolder()
@@ -24,6 +25,22 @@
self.pure = pure
self.can_overflow = can_overflow
+ def make_sc(self):
+ def sc_operator(space, args_w):
+ if len(args_w) != self.arity:
+ if self is op.pow and len(args_w) == 2:
+ args_w = args_w + [Constant(None)]
+ elif self is op.getattr and len(args_w) == 3:
+ return space.frame.do_operation('simple_call',
Constant(getattr), *args_w)
+ else:
+ raise Exception("should call %r with exactly %d arguments"
% (
+ self.name, self.arity))
+ # completely replace the call with the underlying
+ # operation and its limited implicit exceptions semantic
+ return getattr(space, self.name)(*args_w)
+ return sc_operator
+
+
def add_operator(name, arity, symbol, pyfunc=None, pure=False, ovf=False):
operator_func = getattr(operator, name, None)
oper = SpaceOperator(name, arity, symbol, pyfunc, pure, can_overflow=ovf)
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -8,21 +8,6 @@
args = [space.unwrap(arg) for arg in args_w]
return space.import_name(*args)
-def make_sc(oper):
- def sc_operator(space, args_w):
- if len(args_w) != oper.arity:
- if oper is op.pow and len(args_w) == 2:
- args_w = args_w + [Constant(None)]
- elif oper is op.getattr and len(args_w) == 3:
- return space.frame.do_operation('simple_call',
Constant(getattr), *args_w)
- else:
- raise Exception("should call %r with exactly %d arguments" % (
- oper.name, oper.arity))
- # completely replace the call with the underlying
- # operation and its limited implicit exceptions semantic
- return getattr(space, oper.name)(*args_w)
- return sc_operator
-
# _________________________________________________________________________
# a simplified version of the basic printing routines, for RPython programs
class StdOutBuffer:
@@ -73,4 +58,4 @@
we_are_translated: sc_we_are_translated,
locals: sc_locals}
for fn, oper in func2op.items():
- SPECIAL_CASES[fn] = make_sc(oper)
+ SPECIAL_CASES[fn] = oper.make_sc()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit