[pypy-svn] r35961 - in pypy/dist/pypy: interpreter objspace/std
mwh at codespeak.net
mwh at codespeak.net
Fri Dec 22 17:26:44 CET 2006
Author: mwh
Date: Fri Dec 22 17:26:43 2006
New Revision: 35961
Modified:
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/objspace/std/objspace.py
Log:
place a flow space friendly implementation of CALL_LIKELY_BUILTIN into
interpreter/pyopcode.py and move the optimized, stdobjspace-dependent
implementation into objspace/std, where it belongs.
thanks samuele for the prodding :-)
now to find why the co_code & friends attributes are moving up to
eval.Code...
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Fri Dec 22 17:26:43 2006
@@ -602,18 +602,20 @@
return
f.LOAD_GLOBAL(nameindex) # fall-back
- def LOAD_GLOBAL(f, nameindex, *ignored):
- w_varname = f.getname_w(nameindex)
+ def _load_global(f, w_varname):
w_value = f.space.finditem(f.w_globals, w_varname)
if w_value is None:
# not in the globals, now look in the built-ins
w_value = f.builtin.getdictvalue(f.space, w_varname)
if w_value is None:
- varname = f.getname_u(nameindex)
+ varname = f.space.str_w(w_varname)
message = "global name '%s' is not defined" % varname
raise OperationError(f.space.w_NameError,
f.space.wrap(message))
- f.valuestack.push(w_value)
+ return w_value
+
+ def LOAD_GLOBAL(f, nameindex, *ignored):
+ f.valuestack.push(f._load_global(f.getname_w(nameindex)))
def DELETE_FAST(f, varindex, *ignored):
if f.fastlocals_w[varindex] is None:
@@ -875,31 +877,13 @@
pass
def CALL_LIKELY_BUILTIN(f, oparg, *ignored):
- from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module
- from pypy.objspace.std.dictmultiobject import W_DictMultiObject
- w_globals = f.w_globals
- num = oparg >> 8
- assert isinstance(w_globals, W_DictMultiObject)
- w_value = w_globals.implementation.get_builtin_indexed(num)
- if w_value is None:
- w_builtins = f.builtin
- assert isinstance(w_builtins, Module)
- w_builtin_dict = w_builtins.w_dict
- assert isinstance(w_builtin_dict, W_DictMultiObject)
- w_value = w_builtin_dict.implementation.get_builtin_indexed(num)
-## if w_value is not None:
-## print "CALL_LIKELY_BUILTIN fast"
- if w_value is None:
- varname = OPTIMIZED_BUILTINS[num]
- message = "global name '%s' is not defined" % varname
- raise OperationError(f.space.w_NameError,
- f.space.wrap(message))
- nargs = oparg & 0xff
- w_function = w_value
+ # overridden by faster version in the standard object space.
+ from pypy.module.__builtin__ import OPTIMIZED_BUILTINS
+ w_varname = f.space.wrap(OPTIMIZED_BUILTINS[oparg >> 8])
+ w_function = f._load_global(w_varname)
+ nargs = oparg&0xFF
try:
w_result = f.space.call_valuestack(w_function, nargs, f.valuestack)
- # XXX XXX fix the problem of resume points!
- #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
finally:
f.valuestack.drop(nargs)
f.valuestack.push(w_result)
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Fri Dec 22 17:26:43 2006
@@ -36,6 +36,38 @@
assert issubclass(implcls, W_Object)
_registered_implementations[implcls] = True
+from pypy.interpreter import pyframe
+
+class StdObjSpaceFrame(pyframe.PyFrame):
+ def CALL_LIKELY_BUILTIN(f, oparg, *ignored):
+ from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module
+ from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+ w_globals = f.w_globals
+ num = oparg >> 8
+ assert isinstance(w_globals, W_DictMultiObject)
+ w_value = w_globals.implementation.get_builtin_indexed(num)
+ if w_value is None:
+ w_builtins = f.builtin
+ assert isinstance(w_builtins, Module)
+ w_builtin_dict = w_builtins.w_dict
+ assert isinstance(w_builtin_dict, W_DictMultiObject)
+ w_value = w_builtin_dict.implementation.get_builtin_indexed(num)
+## if w_value is not None:
+## print "CALL_LIKELY_BUILTIN fast"
+ if w_value is None:
+ varname = OPTIMIZED_BUILTINS[num]
+ message = "global name '%s' is not defined" % varname
+ raise OperationError(f.space.w_NameError,
+ f.space.wrap(message))
+ nargs = oparg & 0xff
+ w_function = w_value
+ try:
+ w_result = f.space.call_valuestack(w_function, nargs, f.valuestack)
+ # XXX XXX fix the problem of resume points!
+ #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
+ finally:
+ f.valuestack.drop(nargs)
+ f.valuestack.push(w_result)
##################################################################
@@ -233,7 +265,7 @@
if not we_are_translated() and isinstance(code, CPythonFakeCode):
return CPythonFakeFrame(self, code, w_globals)
else:
- return ObjSpace.createframe(self, code, w_globals, closure)
+ return StdObjSpaceFrame(self, code, w_globals, closure)
def gettypefor(self, cls):
return self.gettypeobject(cls.typedef)
More information about the Pypy-commit
mailing list