PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/tool/stdlib_opcode.py

https://bitbucket.org/pypy/pypy/
Python | 43 lines | 26 code | 10 blank | 7 comment | 2 complexity | a14036606abc49c5c17d6e0208b43fe3 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  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. # load opcode.py as pythonopcode from our own lib
  7. __all__ = ['opmap', 'opname', 'HAVE_ARGUMENT',
  8. 'hasconst', 'hasname', 'hasjrel', 'hasjabs',
  9. 'haslocal', 'hascompare', 'hasfree', 'cmp_op']
  10. # Initialization
  11. from rpython.rlib.unroll import unrolling_iterable
  12. from rpython.tool.stdlib_opcode import BytecodeSpec, host_bytecode_spec
  13. from opcode import (
  14. opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT)
  15. def load_pypy_opcode():
  16. from pypy.tool.lib_pypy import LIB_PYTHON
  17. opcode_path = LIB_PYTHON.join('opcode.py')
  18. d = {}
  19. execfile(str(opcode_path), d)
  20. for name in __all__:
  21. if name in d:
  22. globals()[name] = d[name]
  23. return d
  24. load_pypy_opcode()
  25. del load_pypy_opcode
  26. bytecode_spec = BytecodeSpec('pypy', opmap, HAVE_ARGUMENT)
  27. bytecode_spec.to_globals(globals())
  28. opcode_method_names = bytecode_spec.method_names
  29. opcodedesc = bytecode_spec.opcodedesc
  30. unrolling_all_opcode_descs = unrolling_iterable(
  31. bytecode_spec.ordered_opdescs + host_bytecode_spec.ordered_opdescs)
  32. unrolling_opcode_descs = unrolling_iterable(
  33. bytecode_spec.ordered_opdescs)