[pypy-svn] r73471 - in pypy/branch/decouple-host-opcodes/pypy: interpreter tool translator/goal
antoine at codespeak.net
antoine at codespeak.net
Tue Apr 6 23:35:36 CEST 2010
Author: antoine
Date: Tue Apr 6 23:35:35 2010
New Revision: 73471
Modified:
pypy/branch/decouple-host-opcodes/pypy/interpreter/pyopcode.py
pypy/branch/decouple-host-opcodes/pypy/tool/stdlib_opcode.py
pypy/branch/decouple-host-opcodes/pypy/translator/goal/translate.py
Log:
Translation finally works (after much bothering with unrolling_iterable's children)
Next step would be to add 2.7 support (which will probably unveil the bugs :-()
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 Tue Apr 6 23:35:35 2010
@@ -14,9 +14,8 @@
from pypy.rlib import jit, rstackovf
from pypy.rlib.rarithmetic import r_uint, intmask
from pypy.rlib.unroll import unrolling_iterable
-from pypy.tool.stdlib_opcode import (unrolling_opcode_descs,
- HAVE_ARGUMENT, host_HAVE_ARGUMENT, opcodedesc, host_opcodedesc,
- opcode_method_names, host_opcode_method_names, )
+from pypy.tool.stdlib_opcode import (
+ bytecode_spec, host_bytecode_spec, unrolling_all_opcode_descs, opmap, host_opmap)
def unaryoperation(operationname):
"""NOT_RPYTHON"""
@@ -164,6 +163,9 @@
@jit.unroll_safe
def dispatch_bytecode(self, co_code, next_instr, ec):
space = self.space
+ cls = self.__class__
+ # PyFrame is really an abstract class
+ assert self.__class__ is not pyframe.PyFrame
while True:
self.last_instr = intmask(next_instr)
if not jit.we_are_jitted():
@@ -228,15 +230,19 @@
if opcode == self.opcodedesc.JUMP_ABSOLUTE.index:
return self.jump_absolute(oparg, next_instr, ec)
- if we_are_translated():
+ if 1 or we_are_translated():
from pypy.rlib import rstack # for resume points
- for opdesc in unrolling_opcode_descs:
+ for opdesc in unrolling_all_opcode_descs:
# static checks to skip this whole case if necessary
+ if opdesc.bytecode_spec is not self.bytecode_spec:
+ continue
if not opdesc.is_enabled(space):
continue
- if not hasattr(pyframe.PyFrame, opdesc.methodname):
- continue # e.g. for JUMP_ABSOLUTE, implemented above
+ if opdesc.methodname in (
+ 'EXTENDED_ARG', 'RETURN_VALUE', 'YIELD_VALUE',
+ 'END_FINALLY', 'JUMP_ABSOLUTE'):
+ continue # opcodes implemented above
if opcode == opdesc.index:
# dispatch to the opcode method
@@ -1001,9 +1007,11 @@
class __extend__(pyframe.PyPyFrame):
- opcode_method_names = opcode_method_names
- opcodedesc = opcodedesc
- HAVE_ARGUMENT = HAVE_ARGUMENT
+ bytecode_spec = bytecode_spec
+ opcode_method_names = bytecode_spec.method_names
+ opcodedesc = bytecode_spec.opcodedesc
+ opdescmap = bytecode_spec.opdescmap
+ HAVE_ARGUMENT = bytecode_spec.HAVE_ARGUMENT
def BUILD_MAP(self, itemcount, next_instr):
if itemcount != 0:
@@ -1017,9 +1025,11 @@
host_version_info = sys.version_info
class __extend__(pyframe.HostPyFrame):
- opcode_method_names = host_opcode_method_names
- opcodedesc = host_opcodedesc
- HAVE_ARGUMENT = host_HAVE_ARGUMENT
+ bytecode_spec = host_bytecode_spec
+ opcode_method_names = host_bytecode_spec.method_names
+ opcodedesc = host_bytecode_spec.opcodedesc
+ opdescmap = host_bytecode_spec.opdescmap
+ HAVE_ARGUMENT = host_bytecode_spec.HAVE_ARGUMENT
def BUILD_MAP(self, itemcount, next_instr):
if host_version_info >= (2, 6):
Modified: pypy/branch/decouple-host-opcodes/pypy/tool/stdlib_opcode.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/tool/stdlib_opcode.py (original)
+++ pypy/branch/decouple-host-opcodes/pypy/tool/stdlib_opcode.py Tue Apr 6 23:35:35 2010
@@ -1,108 +1,131 @@
+"""
+Opcodes PyPy compiles Python source to.
+Also gives access to opcodes of the host Python PyPy was bootstrapped with
+(module attributes with the `host_` prefix).
+"""
+
# load opcode.py as pythonopcode from our own lib
__all__ = ['opmap', 'opname', 'HAVE_ARGUMENT',
'hasconst', 'hasname', 'hasjrel', 'hasjabs',
'haslocal', 'hascompare', 'hasfree', 'cmp_op']
-from opcode import (
- opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT)
-
-def load_opcode():
- import py
- opcode_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib-python/modified-2.5.2/opcode.py')
- d = {}
- execfile(str(opcode_path), d)
- return d
-
-opcode_dict = load_opcode()
-del load_opcode
-
-# copy some stuff from opcode.py directly into our globals
-for name in __all__:
- if name in opcode_dict:
- globals()[name] = opcode_dict[name]
-globals().update(opmap)
-SLICE = opmap["SLICE+0"]
-STORE_SLICE = opmap["STORE_SLICE+0"]
-DELETE_SLICE = opmap["DELETE_SLICE+0"]
-
-def make_method_names(opmap):
- tbl = ['MISSING_OPCODE'] * 256
- for name, index in opmap.items():
- tbl[index] = name.replace('+', '_')
- return tbl
-
-opcode_method_names = make_method_names(opmap)
-host_opcode_method_names = make_method_names(host_opmap)
-#print (
- #set(enumerate(opcode_method_names)) ^ set(enumerate(host_opcode_method_names))
-#)
-del make_method_names
-
# ____________________________________________________________
# RPython-friendly helpers and structures
-from pypy.rlib.unroll import unrolling_iterable
+class _BaseOpcodeDesc(object):
+ def __init__(self, bytecode_spec, name, index, methodname):
+ self.bytecode_spec = bytecode_spec
+ self.name = name
+ self.methodname = methodname
+ self.index = index
+ self.hasarg = index >= self.HAVE_ARGUMENT
+
+ def _freeze_(self):
+ return True
+
+ def is_enabled(self, space):
+ """Check if the opcode should be enabled in the space's configuration.
+ (Returns True for all standard opcodes.)"""
+ opt = space.config.objspace.opcodes
+ return getattr(opt, self.name, True)
+ is_enabled._annspecialcase_ = 'specialize:memo'
+
+ # for predictable results, we try to order opcodes most-used-first
+ opcodeorder = [124, 125, 100, 105, 1, 131, 116, 111, 106, 83, 23, 93, 113, 25, 95, 64, 112, 66, 102, 110, 60, 92, 62, 120, 68, 87, 32, 136, 4, 103, 24, 63, 18, 65, 15, 55, 121, 3, 101, 22, 12, 80, 86, 135, 126, 90, 140, 104, 2, 33, 20, 108, 107, 31, 134, 132, 88, 30, 133, 130, 137, 141, 61, 122, 11, 40, 74, 73, 51, 96, 21, 42, 56, 85, 82, 89, 142, 77, 78, 79, 91, 76, 97, 57, 19, 43, 84, 50, 41, 99, 53, 26]
+
+ def sortkey(self):
+ try:
+ i = self.opcodeorder.index(self.index)
+ except ValueError:
+ i = 1000000
+ return i, self.index
+
+ def __cmp__(self, other):
+ return (cmp(self.__class__, other.__class__) or
+ cmp(self.sortkey(), other.sortkey()))
+
+ def __str__(self):
+ return "<OpcodeDesc code=%d name=%s at %x>" % (self.index, self.name, id(self))
+
+ __repr__ = __str__
-def make_opcode_desc(HAVE_ARGUMENT):
- class OpcodeDesc(object):
- def __init__(self, name, index):
- self.name = name
- self.methodname = opcode_method_names[index]
- self.index = index
- self.hasarg = index >= HAVE_ARGUMENT
-
- def _freeze_(self):
- return True
-
- def is_enabled(self, space):
- """Check if the opcode should be enabled in the space's configuration.
- (Returns True for all standard opcodes.)"""
- opt = space.config.objspace.opcodes
- return getattr(opt, self.name, True)
- is_enabled._annspecialcase_ = 'specialize:memo'
-
- # for predictable results, we try to order opcodes most-used-first
- opcodeorder = [124, 125, 100, 105, 1, 131, 116, 111, 106, 83, 23, 93, 113, 25, 95, 64, 112, 66, 102, 110, 60, 92, 62, 120, 68, 87, 32, 136, 4, 103, 24, 63, 18, 65, 15, 55, 121, 3, 101, 22, 12, 80, 86, 135, 126, 90, 140, 104, 2, 33, 20, 108, 107, 31, 134, 132, 88, 30, 133, 130, 137, 141, 61, 122, 11, 40, 74, 73, 51, 96, 21, 42, 56, 85, 82, 89, 142, 77, 78, 79, 91, 76, 97, 57, 19, 43, 84, 50, 41, 99, 53, 26]
-
- def sortkey(self):
- try:
- i = self.opcodeorder.index(self.index)
- except ValueError:
- i = 1000000
- return i, self.index
-
- def __cmp__(self, other):
- return (cmp(self.__class__, other.__class__) or
- cmp(self.sortkey(), other.sortkey()))
+class _baseopcodedesc:
+ """A namespace mapping OPCODE_NAME to _BaseOpcodeDescs."""
+ pass
- return OpcodeDesc
-OpcodeDesc = make_opcode_desc(HAVE_ARGUMENT)
-HostOpcodeDesc = make_opcode_desc(host_HAVE_ARGUMENT)
+class BytecodeSpec(object):
+ """A bunch of mappings describing a bytecode instruction set."""
-opdescmap = {}
+ def __init__(self, name, opmap, HAVE_ARGUMENT):
+ """NOT_RPYTHON."""
+ class OpcodeDesc(_BaseOpcodeDesc):
+ HAVE_ARGUMENT = HAVE_ARGUMENT
+ class opcodedesc(_baseopcodedesc):
+ """A namespace mapping OPCODE_NAME to OpcodeDescs."""
+
+ self.name = name
+ self.OpcodeDesc = OpcodeDesc
+ self.opcodedesc = opcodedesc
+ self.HAVE_ARGUMENT = HAVE_ARGUMENT
+ # opname -> opcode
+ self.opmap = opmap
+ # opcode -> method name
+ self.method_names = tbl = ['MISSING_OPCODE'] * 256
+ # opcode -> opdesc
+ self.opdescmap = {}
+ for name, index in opmap.items():
+ tbl[index] = methodname = name.replace('+', '_')
+ desc = OpcodeDesc(self, name, index, methodname)
+ setattr(self.opcodedesc, name, desc)
+ self.opdescmap[index] = desc
+ # fill the ordered opdesc list
+ self.ordered_opdescs = lst = self.opdescmap.values()
+ lst.sort()
+
+ def to_globals(self):
+ """NOT_RPYTHON. Add individual opcodes to the module constants."""
+ g = globals()
+ g.update(self.opmap)
+ g['SLICE'] = self.opmap["SLICE+0"]
+ g['STORE_SLICE'] = self.opmap["STORE_SLICE+0"]
+ g['DELETE_SLICE'] = self.opmap["DELETE_SLICE+0"]
+
+ def __str__(self):
+ return "<%s bytecode>" % (self.name,)
+
+ __repr__ = __str__
-class _baseopcodedesc:
- pass
-class opcodedesc(_baseopcodedesc):
- """A namespace mapping OPCODE_NAME to OpcodeDescs."""
+# Initialization
-class host_opcodedesc(_baseopcodedesc):
- """A namespace mapping OPCODE_NAME to HostOpcodeDescs."""
+from pypy.rlib.unroll import unrolling_iterable
+
+from opcode import (
+ opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT)
+
+def load_pypy_opcode():
+ import py
+ opcode_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib-python/modified-2.5.2/opcode.py')
+ d = {}
+ execfile(str(opcode_path), d)
+ for name in __all__:
+ if name in d:
+ globals()[name] = d[name]
+ return d
-for name, index in opmap.items():
- desc = OpcodeDesc(name, index)
- setattr(opcodedesc, name, desc)
- opdescmap[index] = desc
-
-for name, index in host_opmap.items():
- desc = HostOpcodeDesc(name, index)
- setattr(host_opcodedesc, name, desc)
-
-lst = opdescmap.values()
-lst.sort()
-unrolling_opcode_descs = unrolling_iterable(lst)
+load_pypy_opcode()
+del load_pypy_opcode
-del name, index, desc, lst
+bytecode_spec = BytecodeSpec('pypy', opmap, HAVE_ARGUMENT)
+host_bytecode_spec = BytecodeSpec('host', host_opmap, host_HAVE_ARGUMENT)
+bytecode_spec.to_globals()
+
+opcode_method_names = bytecode_spec.method_names
+opcodedesc = bytecode_spec.opcodedesc
+
+unrolling_all_opcode_descs = unrolling_iterable(
+ bytecode_spec.ordered_opdescs + host_bytecode_spec.ordered_opdescs)
+unrolling_opcode_descs = unrolling_iterable(
+ bytecode_spec.ordered_opdescs)
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 Tue Apr 6 23:35:35 2010
@@ -213,6 +213,10 @@
else:
prof = None
+ import gc
+ a, b, c = gc.get_threshold()
+ gc.set_threshold(a * 2, b * 2, c * 8)
+
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