| 1 |
""" |
| 2 |
Opcodes PyPy compiles Python source to. |
| 3 |
Also gives access to opcodes of the host Python PyPy was bootstrapped with |
| 4 |
(module attributes with the `host_` prefix). |
| 5 |
""" |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
__all__ = ['opmap', 'opname', 'HAVE_ARGUMENT', |
| 10 |
'hasconst', 'hasname', 'hasjrel', 'hasjabs', |
| 11 |
'haslocal', 'hascompare', 'hasfree', 'cmp_op'] |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from rpython.rlib.unroll import unrolling_iterable |
| 16 |
from rpython.tool.stdlib_opcode import BytecodeSpec, host_bytecode_spec |
| 17 |
|
| 18 |
from opcode import ( |
| 19 |
opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT) |
| 20 |
|
| 21 |
def load_pypy_opcode(): |
| 22 |
from pypy.tool.lib_pypy import LIB_PYTHON |
| 23 |
opcode_path = LIB_PYTHON.join('opcode.py') |
| 24 |
d = {} |
| 25 |
execfile(str(opcode_path), d) |
| 26 |
for name in __all__: |
| 27 |
if name in d: |
| 28 |
globals()[name] = d[name] |
| 29 |
return d |
| 30 |
|
| 31 |
load_pypy_opcode() |
| 32 |
del load_pypy_opcode |
| 33 |
|
| 34 |
bytecode_spec = BytecodeSpec('pypy', opmap, HAVE_ARGUMENT) |
| 35 |
bytecode_spec.to_globals(globals()) |
| 36 |
|
| 37 |
opcode_method_names = bytecode_spec.method_names |
| 38 |
opcodedesc = bytecode_spec.opcodedesc |
| 39 |
|
| 40 |
unrolling_all_opcode_descs = unrolling_iterable( |
| 41 |
bytecode_spec.ordered_opdescs + host_bytecode_spec.ordered_opdescs) |
| 42 |
unrolling_opcode_descs = unrolling_iterable( |
| 43 |
bytecode_spec.ordered_opdescs) |