[pypy-commit] pypy flowoperators: Remove fn argument from 'special cases'
rlamy
noreply at buildbot.pypy.org
Fri Jul 5 19:42:26 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: flowoperators
Changeset: r65225:b54330f38c8d
Date: 2013-05-19 16:42 +0200
http://bitbucket.org/pypy/pypy/changeset/b54330f38c8d/
Log: Remove fn argument from 'special cases'
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -352,7 +352,7 @@
args_w = args.arguments_w + self.unpackiterable(args.w_stararg)
else:
args_w = args.arguments_w
- return sc(self, fn, args_w)
+ return sc(self, args_w)
if args.keywords or isinstance(args.w_stararg, Variable):
shape, args_w = args.flatten()
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -3,24 +3,25 @@
from rpython.rlib.rarithmetic import r_uint
from rpython.rlib.objectmodel import we_are_translated
-def sc_import(space, fn, args_w):
+def sc_import(space, args_w):
assert len(args_w) > 0 and len(args_w) <= 5, 'import needs 1 to 5 arguments'
args = [space.unwrap(arg) for arg in args_w]
return space.import_name(*args)
-def sc_operator(space, fn, args_w):
- oper = func2op[fn]
- 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" % (
- fn, oper.arity))
- # completely replace the call with the underlying
- # operation and its limited implicit exceptions semantic
- return getattr(space, oper.name)(*args_w)
+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
@@ -47,7 +48,7 @@
# _________________________________________________________________________
-def sc_r_uint(space, r_uint, args_w):
+def sc_r_uint(space, args_w):
# special case to constant-fold r_uint(32-bit-constant)
# (normally, the 32-bit constant is a long, and is not allowed to
# show up in the flow graphs at all)
@@ -56,10 +57,10 @@
return Constant(r_uint(w_value.value))
return space.frame.do_operation('simple_call', space.wrap(r_uint), w_value)
-def sc_we_are_translated(space, we_are_translated, args_w):
+def sc_we_are_translated(space, args_w):
return Constant(True)
-def sc_locals(space, locals, args):
+def sc_locals(space, args):
raise Exception(
"A function calling locals() is not RPython. "
"Note that if you're translating code outside the PyPy "
@@ -71,5 +72,5 @@
SPECIAL_CASES = {__import__: sc_import, r_uint: sc_r_uint,
we_are_translated: sc_we_are_translated,
locals: sc_locals}
-for fn in func2op:
- SPECIAL_CASES[fn] = sc_operator
+for fn, oper in func2op.items():
+ SPECIAL_CASES[fn] = make_sc(oper)
More information about the pypy-commit
mailing list