[pypy-svn] r73485 - in pypy/branch/decouple-host-opcodes/pypy: interpreter module/__builtin__ objspace/std/test translator/goal
antoine at codespeak.net
antoine at codespeak.net
Wed Apr 7 01:57:00 CEST 2010
Author: antoine
Date: Wed Apr 7 01:56:58 2010
New Revision: 73485
Modified:
pypy/branch/decouple-host-opcodes/pypy/interpreter/pyframe.py
pypy/branch/decouple-host-opcodes/pypy/interpreter/pyopcode.py
pypy/branch/decouple-host-opcodes/pypy/module/__builtin__/app_inspect.py
pypy/branch/decouple-host-opcodes/pypy/objspace/std/test/test_obj.py
pypy/branch/decouple-host-opcodes/pypy/translator/goal/translate.py
Log:
Implement some 2.7 opcodes (enough to pass objspace tests untranslated)
Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/pyframe.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/pyframe.py Wed Apr 7 01:56:58 2010
@@ -239,6 +239,8 @@
self.pushvalue(w_value)
def peekvalue(self, index_from_top=0):
+ # NOTE: top of the stack is peekvalue(0).
+ # Contrast this with CPython where it's PEEK(-1).
index_from_top = hint(index_from_top, promote=True)
index = self.valuestackdepth + ~index_from_top
assert index >= 0, "peek past the bottom of the stack"
Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/pyopcode.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/pyopcode.py Wed Apr 7 01:56:58 2010
@@ -261,7 +261,22 @@
else: # when we are not translated, a list lookup is much faster
methodname = self.opcode_method_names[opcode]
- res = getattr(self, methodname)(oparg, next_instr)
+ try:
+ meth = getattr(self, methodname)
+ except AttributeError:
+ raise BytecodeCorruption("unimplemented opcode, ofs=%d, code=%d, name=%s" %
+ (self.last_instr, opcode, methodname))
+ try:
+ res = meth(oparg, next_instr)
+ except Exception:
+ if 0:
+ import dis, sys
+ print "*** %s at offset %d (%s)" % (sys.exc_info()[0], self.last_instr, methodname)
+ try:
+ dis.dis(co_code)
+ except:
+ pass
+ raise
if res is not None:
next_instr = res
@@ -997,7 +1012,7 @@
self.pushvalue(w_result)
def MISSING_OPCODE(self, oparg, next_instr):
- ofs = next_instr - 1
+ ofs = self.last_instr
c = self.pycode.co_code[ofs]
name = self.pycode.co_name
raise BytecodeCorruption("unknown opcode, ofs=%d, code=%d, name=%s" %
@@ -1007,6 +1022,9 @@
class __extend__(pyframe.PyPyFrame):
+ """
+ Execution of PyPy opcodes (mostly derived from Python 2.5.2).
+ """
bytecode_spec = bytecode_spec
opcode_method_names = bytecode_spec.method_names
opcodedesc = bytecode_spec.opcodedesc
@@ -1025,6 +1043,9 @@
host_version_info = sys.version_info
class __extend__(pyframe.HostPyFrame):
+ """
+ Execution of host (CPython) opcodes.
+ """
bytecode_spec = host_bytecode_spec
opcode_method_names = host_bytecode_spec.method_names
opcodedesc = host_bytecode_spec.opcodedesc
@@ -1051,6 +1072,40 @@
else:
raise BytecodeCorruption
+ def POP_JUMP_IF_FALSE(self, jumpto, next_instr):
+ w_cond = self.popvalue()
+ if not self.space.is_true(w_cond):
+ next_instr = jumpto
+ return next_instr
+
+ def POP_JUMP_IF_TRUE(self, jumpto, next_instr):
+ w_cond = self.popvalue()
+ if self.space.is_true(w_cond):
+ return jumpto
+ return next_instr
+
+ def JUMP_IF_FALSE_OR_POP(self, jumpto, next_instr):
+ w_cond = self.peekvalue()
+ if not self.space.is_true(w_cond):
+ return jumpto
+ self.popvalue()
+ return next_instr
+
+ def JUMP_IF_TRUE_OR_POP(self, jumpto, next_instr):
+ w_cond = self.peekvalue()
+ if self.space.is_true(w_cond):
+ return jumpto
+ self.popvalue()
+ return next_instr
+
+ def LIST_APPEND(self, oparg, next_instr):
+ w = self.popvalue()
+ if host_version_info < (2, 7):
+ v = self.popvalue()
+ else:
+ v = self.peekvalue(oparg - 1)
+ self.space.call_method(v, 'append', w)
+
### ____________________________________________________________ ###
Modified: pypy/branch/decouple-host-opcodes/pypy/module/__builtin__/app_inspect.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/module/__builtin__/app_inspect.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/module/__builtin__/app_inspect.py Wed Apr 7 01:56:58 2010
@@ -64,9 +64,7 @@
if isinstance(obj, types.ModuleType):
try:
- result = obj.__dict__.keys()
- if not isinstance(result, list):
- raise TypeError("expected __dict__.keys() to be a list")
+ result = list(obj.__dict__.keys())
result.sort()
return result
except AttributeError:
Modified: pypy/branch/decouple-host-opcodes/pypy/objspace/std/test/test_obj.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/objspace/std/test/test_obj.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/objspace/std/test/test_obj.py Wed Apr 7 01:56:58 2010
@@ -7,11 +7,14 @@
cpython_behavior = (not option.runappdirect
or not hasattr(sys, 'pypy_translation_info'))
- cls.w_cpython_behavior = cls.space.wrap(cpython_behavior)
+ cls.w_cpython_behavior = cls.space.wrap(cpython_behavior)
+ cls.w_cpython_version = cls.space.wrap(tuple(sys.version_info))
def test_hash_builtin(self):
if not self.cpython_behavior:
skip("on pypy-c id == hash is not guaranteed")
+ if self.cpython_version >= (2, 7):
+ skip("on CPython >= 2.7, id != hash")
import sys
o = object()
assert (hash(o) & sys.maxint) == (id(o) & sys.maxint)
@@ -33,7 +36,7 @@
class X(object):
pass
x = X()
- if self.cpython_behavior:
+ if self.cpython_behavior and self.cpython_version < (2, 7):
assert (hash(x) & sys.maxint) == (id(x) & sys.maxint)
assert hash(x) == object.__hash__(x)
Modified: pypy/branch/decouple-host-opcodes/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/translator/goal/translate.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/translator/goal/translate.py Wed Apr 7 01:56:58 2010
@@ -213,6 +213,14 @@
else:
prof = None
+ import gc
+ try:
+ # Reduce CPython GC pressure by raising the thresholds
+ a, b, c = gc.get_threshold()
+ gc.set_threshold(a * 2, b * 3, c * 15)
+ except (AttributeError, NotImplementedError):
+ pass
+
t = translator.TranslationContext(config=config)
pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands
More information about the Pypy-commit
mailing list