[pypy-commit] pypy less-stringly-ops: remove special cases in HLOperation.make_sc()
rlamy
noreply at buildbot.pypy.org
Sun Sep 22 21:24:49 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r67058:c5840ab6589e
Date: 2013-09-22 06:58 +0100
http://bitbucket.org/pypy/pypy/changeset/c5840ab6589e/
Log: remove special cases in HLOperation.make_sc()
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -47,14 +47,6 @@
@classmethod
def make_sc(cls):
def sc_operator(space, *args_w):
- if len(args_w) != cls.arity:
- if cls is op.pow and len(args_w) == 2:
- args_w = list(args_w) + [Constant(None)]
- elif cls 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" % (
- cls.opname, cls.arity))
return cls(*args_w).eval(space.frame)
return sc_operator
@@ -260,7 +252,6 @@
add_operator('div', 2, pure=True, ovf=True)
add_operator('mod', 2, pure=True, ovf=True)
add_operator('divmod', 2, pyfunc=divmod, pure=True)
-add_operator('pow', 3, pyfunc=pow, pure=True)
add_operator('lshift', 2, pure=True, ovf=True)
add_operator('rshift', 2, pure=True)
add_operator('and_', 2, pure=True)
@@ -298,6 +289,20 @@
add_operator('userdel', 1, pyfunc=userdel)
add_operator('buffer', 1, pyfunc=buffer, pure=True) # see buffer.py
+class Pow(PureOperation):
+ opname = 'pow'
+ arity = 3
+ can_overflow = False
+ canraise = []
+ pyfunc = pow
+
+ def __init__(self, w_base, w_exponent, w_mod=const(None)):
+ self.args = [w_base, w_exponent, w_mod]
+ self.result = Variable()
+ self.offset = -1
+op.pow = Pow
+
+
class Iter(HLOperation):
opname = 'iter'
arity = 1
@@ -372,6 +377,8 @@
# Other functions that get directly translated to SpaceOperators
func2op[type] = op.type
func2op[operator.truth] = op.bool
+func2op[pow] = op.pow
+func2op[operator.pow] = op.pow
func2op[__builtin__.iter] = op.iter
func2op[getattr] = op.getattr
func2op[__builtin__.next] = op.next
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -37,6 +37,14 @@
return space.frame.do_operation('simple_call', const(isinstance),
w_instance, w_type)
+ at register_flow_sc(getattr)
+def sc_getattr(space, w_obj, w_index, w_default=None):
+ if w_default is not None:
+ return space.frame.do_operation('simple_call', const(getattr), w_obj,
+ w_index, w_default)
+ else:
+ return space.getattr(w_obj, w_index)
+
# _________________________________________________________________________
# a simplified version of the basic printing routines, for RPython programs
class StdOutBuffer:
More information about the pypy-commit
mailing list