[pypy-svn] r56906 - in pypy/branch/garden-call-code/pypy: interpreter interpreter/test module/operator
pedronis at codespeak.net
pedronis at codespeak.net
Sat Aug 2 00:55:37 CEST 2008
Author: pedronis
Date: Sat Aug 2 00:55:35 2008
New Revision: 56906
Modified:
pypy/branch/garden-call-code/pypy/interpreter/eval.py
pypy/branch/garden-call-code/pypy/interpreter/function.py
pypy/branch/garden-call-code/pypy/interpreter/gateway.py
pypy/branch/garden-call-code/pypy/interpreter/pycode.py
pypy/branch/garden-call-code/pypy/interpreter/test/test_function.py
pypy/branch/garden-call-code/pypy/module/operator/interp_operator.py
Log:
first cleanup: avoid the strange interface checking whether the result is None for fastcall_# methods
slightly nicer code, no relavant perf impact for better or worse
Modified: pypy/branch/garden-call-code/pypy/interpreter/eval.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/interpreter/eval.py (original)
+++ pypy/branch/garden-call-code/pypy/interpreter/eval.py Sat Aug 2 00:55:35 2008
@@ -11,6 +11,8 @@
Abstract base class."""
hidden_applevel = False
+ fast_natural_arity = -1
+
def __init__(self, co_name):
self.co_name = co_name
@@ -58,15 +60,15 @@
# a performance hack (see gateway.BuiltinCode1/2/3 and pycode.PyCode)
def fastcall_0(self, space, func):
- return None
+ raise NotImplementedError
def fastcall_1(self, space, func, w1):
- return None
+ raise NotImplementedError
def fastcall_2(self, space, func, w1, w2):
- return None
+ raise NotImplementedError
def fastcall_3(self, space, func, w1, w2, w3):
- return None
+ raise NotImplementedError
def fastcall_4(self, space, func, w1, w2, w3, w4):
- return None
+ raise NotImplementedError
class Frame(Wrappable):
"""A frame is an environment supporting the execution of a code object.
Modified: pypy/branch/garden-call-code/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/interpreter/function.py (original)
+++ pypy/branch/garden-call-code/pypy/interpreter/function.py Sat Aug 2 00:55:35 2008
@@ -40,56 +40,39 @@
def funccall(self, *args_w): # speed hack
code = self.getcode() # hook for the jit
- if len(args_w) == 0:
- w_res = code.fastcall_0(self.space, self)
- if w_res is not None:
- return w_res
- elif len(args_w) == 1:
- w_res = code.fastcall_1(self.space, self, args_w[0])
- if w_res is not None:
- return w_res
- elif len(args_w) == 2:
- w_res = code.fastcall_2(self.space, self, args_w[0], args_w[1])
- if w_res is not None:
- return w_res
- elif len(args_w) == 3:
- w_res = code.fastcall_3(self.space, self, args_w[0],
- args_w[1], args_w[2])
- if w_res is not None:
- return w_res
- elif len(args_w) == 4:
- w_res = code.fastcall_4(self.space, self, args_w[0],
- args_w[1], args_w[2], args_w[3])
- if w_res is not None:
- return w_res
+ nargs = len(args_w)
+ if nargs == code.fast_natural_arity:
+ if nargs == 0:
+ return code.fastcall_0(self.space, self)
+ elif nargs == 1:
+ return code.fastcall_1(self.space, self, args_w[0])
+ elif nargs == 2:
+ return code.fastcall_2(self.space, self, args_w[0], args_w[1])
+ elif nargs == 3:
+ return code.fastcall_3(self.space, self, args_w[0],
+ args_w[1], args_w[2])
+ elif nargs == 4:
+ return code.fastcall_4(self.space, self, args_w[0],
+ args_w[1], args_w[2], args_w[3])
return self.call_args(Arguments(self.space, list(args_w)))
def funccall_valuestack(self, nargs, frame): # speed hack
code = self.getcode() # hook for the jit
- if nargs == 0:
- w_res = code.fastcall_0(self.space, self)
- if w_res is not None:
- return w_res
- elif nargs == 1:
- w_res = code.fastcall_1(self.space, self, frame.peekvalue(0))
- if w_res is not None:
- return w_res
- elif nargs == 2:
- w_res = code.fastcall_2(self.space, self, frame.peekvalue(1),
- frame.peekvalue(0))
- if w_res is not None:
- return w_res
- elif nargs == 3:
- w_res = code.fastcall_3(self.space, self, frame.peekvalue(2),
+ if nargs == code.fast_natural_arity:
+ if nargs == 0:
+ return code.fastcall_0(self.space, self)
+ elif nargs == 1:
+ return code.fastcall_1(self.space, self, frame.peekvalue(0))
+ elif nargs == 2:
+ return code.fastcall_2(self.space, self, frame.peekvalue(1),
+ frame.peekvalue(0))
+ elif nargs == 3:
+ return code.fastcall_3(self.space, self, frame.peekvalue(2),
frame.peekvalue(1), frame.peekvalue(0))
- if w_res is not None:
- return w_res
- elif nargs == 4:
- w_res = code.fastcall_4(self.space, self, frame.peekvalue(3),
- frame.peekvalue(2), frame.peekvalue(1),
- frame.peekvalue(0))
- if w_res is not None:
- return w_res
+ elif nargs == 4:
+ return code.fastcall_4(self.space, self, frame.peekvalue(3),
+ frame.peekvalue(2), frame.peekvalue(1),
+ frame.peekvalue(0))
args = frame.make_arguments(nargs)
try:
return self.call_args(args)
@@ -99,24 +82,21 @@
def funccall_obj_valuestack(self, w_obj, nargs, frame): # speed hack
code = self.getcode() # hook for the jit
- if nargs == 0:
- w_res = code.fastcall_1(self.space, self, w_obj)
- if w_res is not None:
- return w_res
- elif nargs == 1:
- w_res = code.fastcall_2(self.space, self, w_obj, frame.peekvalue(0))
- if w_res is not None:
- return w_res
- elif nargs == 2:
- w_res = code.fastcall_3(self.space, self, w_obj, frame.peekvalue(1),
- frame.peekvalue(0))
- if w_res is not None:
- return w_res
- elif nargs == 3:
- w_res = code.fastcall_4(self.space, self, w_obj, frame.peekvalue(2),
- frame.peekvalue(1), frame.peekvalue(0))
- if w_res is not None:
- return w_res
+ if nargs+1 == code.fast_natural_arity:
+ if nargs == 0:
+ return code.fastcall_1(self.space, self, w_obj)
+ elif nargs == 1:
+ return code.fastcall_2(self.space, self, w_obj,
+ frame.peekvalue(0))
+ elif nargs == 2:
+ return code.fastcall_3(self.space, self, w_obj,
+ frame.peekvalue(1),
+ frame.peekvalue(0))
+ elif nargs == 3:
+ return code.fastcall_4(self.space, self, w_obj,
+ frame.peekvalue(2),
+ frame.peekvalue(1),
+ frame.peekvalue(0))
stkargs = frame.make_arguments(nargs)
args = stkargs.prepend(w_obj)
try:
Modified: pypy/branch/garden-call-code/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/interpreter/gateway.py (original)
+++ pypy/branch/garden-call-code/pypy/interpreter/gateway.py Sat Aug 2 00:55:35 2008
@@ -559,6 +559,8 @@
return w_result
class BuiltinCode0(BuiltinCode):
+ fast_natural_arity = 0
+
def fastcall_0(self, space, w_func):
self = hint(self, deepfreeze=True)
try:
@@ -575,6 +577,8 @@
return w_result
class BuiltinCode1(BuiltinCode):
+ fast_natural_arity = 1
+
def fastcall_1(self, space, w_func, w1):
self = hint(self, deepfreeze=True)
try:
@@ -598,6 +602,8 @@
return w_result
class BuiltinCode2(BuiltinCode):
+ fast_natural_arity = 2
+
def fastcall_2(self, space, w_func, w1, w2):
self = hint(self, deepfreeze=True)
try:
@@ -621,6 +627,8 @@
return w_result
class BuiltinCode3(BuiltinCode):
+ fast_natural_arity = 3
+
def fastcall_3(self, space, func, w1, w2, w3):
self = hint(self, deepfreeze=True)
try:
@@ -644,6 +652,8 @@
return w_result
class BuiltinCode4(BuiltinCode):
+ fast_natural_arity = 4
+
def fastcall_4(self, space, func, w1, w2, w3, w4):
self = hint(self, deepfreeze=True)
try:
Modified: pypy/branch/garden-call-code/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/interpreter/pycode.py (original)
+++ pypy/branch/garden-call-code/pypy/interpreter/pycode.py Sat Aug 2 00:55:35 2008
@@ -162,7 +162,7 @@
def _compute_fastcall(self):
# Speed hack!
- self.do_fastcall = -1
+ self.fast_natural_arity = -1
if not (0 <= self.co_argcount <= 4):
return
if self.co_flags & (CO_VARARGS | CO_VARKEYWORDS):
@@ -170,52 +170,42 @@
if len(self._args_as_cellvars) > 0:
return
- self.do_fastcall = self.co_argcount
+ self.fast_natural_arity = self.co_argcount
def fastcall_0(self, space, w_func):
- if self.do_fastcall == 0:
- frame = space.createframe(self, w_func.w_func_globals,
+ frame = space.createframe(self, w_func.w_func_globals,
w_func.closure)
- return frame.run()
- return None
+ return frame.run()
def fastcall_1(self, space, w_func, w_arg):
- if self.do_fastcall == 1:
- frame = space.createframe(self, w_func.w_func_globals,
- w_func.closure)
- frame.fastlocals_w[0] = w_arg # frame.setfastscope([w_arg])
- return frame.run()
- return None
+ frame = space.createframe(self, w_func.w_func_globals,
+ w_func.closure)
+ frame.fastlocals_w[0] = w_arg # frame.setfastscope([w_arg])
+ return frame.run()
def fastcall_2(self, space, w_func, w_arg1, w_arg2):
- if self.do_fastcall == 2:
- frame = space.createframe(self, w_func.w_func_globals,
- w_func.closure)
- frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
- frame.fastlocals_w[1] = w_arg2
- return frame.run()
- return None
+ frame = space.createframe(self, w_func.w_func_globals,
+ w_func.closure)
+ frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
+ frame.fastlocals_w[1] = w_arg2
+ return frame.run()
def fastcall_3(self, space, w_func, w_arg1, w_arg2, w_arg3):
- if self.do_fastcall == 3:
- frame = space.createframe(self, w_func.w_func_globals,
- w_func.closure)
- frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
- frame.fastlocals_w[1] = w_arg2
- frame.fastlocals_w[2] = w_arg3
- return frame.run()
- return None
+ frame = space.createframe(self, w_func.w_func_globals,
+ w_func.closure)
+ frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
+ frame.fastlocals_w[1] = w_arg2
+ frame.fastlocals_w[2] = w_arg3
+ return frame.run()
def fastcall_4(self, space, w_func, w_arg1, w_arg2, w_arg3, w_arg4):
- if self.do_fastcall == 4:
- frame = space.createframe(self, w_func.w_func_globals,
- w_func.closure)
- frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
- frame.fastlocals_w[1] = w_arg2
- frame.fastlocals_w[2] = w_arg3
- frame.fastlocals_w[3] = w_arg4
- return frame.run()
- return None
+ frame = space.createframe(self, w_func.w_func_globals,
+ w_func.closure)
+ frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
+ frame.fastlocals_w[1] = w_arg2
+ frame.fastlocals_w[2] = w_arg3
+ frame.fastlocals_w[3] = w_arg4
+ return frame.run()
def funcrun(self, func, args):
frame = self.space.createframe(self, func.w_func_globals,
Modified: pypy/branch/garden-call-code/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/interpreter/test/test_function.py (original)
+++ pypy/branch/garden-call-code/pypy/interpreter/test/test_function.py Sat Aug 2 00:55:35 2008
@@ -351,7 +351,7 @@
code = PyCode._from_code(self.space, f.func_code)
fn = Function(self.space, code, self.space.newdict())
- assert fn.code.do_fastcall == 1
+ assert fn.code.fast_natural_arity == 1
called = []
fastcall_1 = fn.code.fastcall_1
@@ -384,7 +384,7 @@
code = PyCode._from_code(self.space, f.func_code)
fn = Function(self.space, code, self.space.newdict())
- assert fn.code.do_fastcall == 2
+ assert fn.code.fast_natural_arity == 2
called = []
fastcall_2 = fn.code.fastcall_2
Modified: pypy/branch/garden-call-code/pypy/module/operator/interp_operator.py
==============================================================================
--- pypy/branch/garden-call-code/pypy/module/operator/interp_operator.py (original)
+++ pypy/branch/garden-call-code/pypy/module/operator/interp_operator.py Sat Aug 2 00:55:35 2008
@@ -173,6 +173,8 @@
class SimpleClosureCode(eval.Code):
+ fast_natural_arity = 1
+
sig = (['obj'], None, None)
def __init__(self, co_name, is_attrgetter):
More information about the Pypy-commit
mailing list