Author: Alexander Hesse <[email protected]>
Branch: split-rpython
Changeset: r59900:d2ee25531ada
Date: 2013-01-09 21:30 +0100
http://bitbucket.org/pypy/pypy/changeset/d2ee25531ada/
Log: Split up stdlib_opcode
diff --git a/pypy/interpreter/astcompiler/assemble.py
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -4,7 +4,7 @@
from pypy.interpreter.astcompiler import ast, symtable
from pypy.interpreter import pycode
-from rpython.tool import stdlib_opcode as ops
+from pypy.tool import stdlib_opcode as ops
from pypy.interpreter.error import OperationError
from rpython.rlib.objectmodel import we_are_translated
diff --git a/pypy/interpreter/astcompiler/codegen.py
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -10,7 +10,7 @@
from pypy.interpreter.astcompiler import ast, assemble, symtable, consts, misc
from pypy.interpreter.astcompiler import optimize # For side effects
from pypy.interpreter.pyparser.error import SyntaxError
-from rpython.tool import stdlib_opcode as ops
+from pypy.tool import stdlib_opcode as ops
from pypy.interpreter.error import OperationError
diff --git a/pypy/interpreter/astcompiler/optimize.py
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -2,7 +2,7 @@
import sys
from pypy.interpreter.astcompiler import ast, consts, misc
-from rpython.tool import stdlib_opcode as ops
+from pypy.tool import stdlib_opcode as ops
from pypy.interpreter.error import OperationError
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.runicode import MAXUNICODE
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -4,7 +4,7 @@
from pypy.interpreter.pyparser.test import expressions
from pypy.interpreter.pycode import PyCode
from pypy.interpreter.pyparser.error import SyntaxError, IndentationError
-from rpython.tool import stdlib_opcode as ops
+from pypy.tool import stdlib_opcode as ops
def compile_with_astcompiler(expr, mode, space):
p = pyparse.PythonParser(space)
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -13,11 +13,11 @@
from pypy.interpreter.astcompiler.consts import (
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
CO_GENERATOR, CO_CONTAINSGLOBALS)
+from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib import jit
from rpython.rlib.objectmodel import compute_hash
-from rpython.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
class BytecodeCorruption(Exception):
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -12,7 +12,7 @@
from rpython.rlib.debug import make_sure_not_resized, check_nonneg
from rpython.rlib.rarithmetic import intmask, r_uint
from rpython.rlib import jit
-from rpython.tool import stdlib_opcode
+from pypy.tool import stdlib_opcode
from rpython.tool.stdlib_opcode import host_bytecode_spec
# Define some opcodes used
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -15,7 +15,7 @@
from rpython.rlib.rarithmetic import r_uint, intmask
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.debug import check_nonneg
-from rpython.tool.stdlib_opcode import (bytecode_spec,
+from pypy.tool.stdlib_opcode import (bytecode_spec,
unrolling_all_opcode_descs)
def unaryoperation(operationname):
diff --git a/pypy/module/_continuation/interp_pickle.py
b/pypy/module/_continuation/interp_pickle.py
--- a/pypy/module/_continuation/interp_pickle.py
+++ b/pypy/module/_continuation/interp_pickle.py
@@ -1,4 +1,4 @@
-from rpython.tool import stdlib_opcode as pythonopcode
+from pypy.tool import stdlib_opcode as pythonopcode
from rpython.rlib import jit
from pypy.interpreter.error import OperationError
from pypy.interpreter.pyframe import PyFrame
diff --git a/pypy/module/pypyjit/interp_jit.py
b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -27,7 +27,7 @@
JUMP_ABSOLUTE = opmap['JUMP_ABSOLUTE']
def get_printable_location(next_instr, is_being_profiled, bytecode):
- from rpython.tool.stdlib_opcode import opcode_method_names
+ from pypy.tool.stdlib_opcode import opcode_method_names
name = opcode_method_names[ord(bytecode.co_code[next_instr])]
return '%s #%d %s' % (bytecode.get_repr(), next_instr, name)
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -106,7 +106,7 @@
space.w_None])
def exc_info_direct(space, frame):
- from rpython.tool import stdlib_opcode
+ from pypy.tool import stdlib_opcode
# In order to make the JIT happy, we try to return (exc, val, None)
# instead of (exc, val, tb). We can do that only if we recognize
# the following pattern in the bytecode:
diff --git a/pypy/tool/pydis.py b/pypy/tool/pydis.py
--- a/pypy/tool/pydis.py
+++ b/pypy/tool/pydis.py
@@ -7,8 +7,8 @@
import sys
-from rpython.tool import stdlib_opcode
-from rpython.tool.stdlib_opcode import *
+from pypy.tool import stdlib_opcode
+from pypy.tool.stdlib_opcode import *
__all__ = ["dis","pydisassemble","distb","disco"] + stdlib_opcode.__all__
diff --git a/rpython/tool/stdlib_opcode.py b/pypy/tool/stdlib_opcode.py
rename from rpython/tool/stdlib_opcode.py
rename to pypy/tool/stdlib_opcode.py
--- a/rpython/tool/stdlib_opcode.py
+++ b/pypy/tool/stdlib_opcode.py
@@ -10,97 +10,10 @@
'hasconst', 'hasname', 'hasjrel', 'hasjabs',
'haslocal', 'hascompare', 'hasfree', 'cmp_op']
-# ____________________________________________________________
-# RPython-friendly helpers and structures
-
-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__
-
-class _baseopcodedesc:
- """A namespace mapping OPCODE_NAME to _BaseOpcodeDescs."""
- pass
-
-
-class BytecodeSpec(object):
- """A bunch of mappings describing a bytecode instruction set."""
-
- 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__
-
-
# Initialization
from rpython.rlib.unroll import unrolling_iterable
+from rpython.tool.stdlib_opcode import BytecodeSpec, host_bytecode_spec
from opcode import (
opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT)
@@ -119,7 +32,6 @@
del load_pypy_opcode
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
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -1,8 +1,8 @@
"""
Bytecode handling classes and functions for use by the flow space.
"""
-from rpython.tool.stdlib_opcode import (host_bytecode_spec, EXTENDED_ARG,
- HAVE_ARGUMENT)
+from rpython.tool.stdlib_opcode import host_bytecode_spec
+from opcode import EXTENDED_ARG, HAVE_ARGUMENT
from rpython.flowspace.argument import Signature
from rpython.flowspace.flowcontext import BytecodeCorruption
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit