Skip to main content

Python cross-version byte-code interpeter

Project description

TravisCI CircleCI

x-python

This is a C Python interpreter written Python.

You can use this to:

  • Learn about how the internals of CPython works since this models that

  • Use as a sandboxed environment inside a debugger for trying pieces of execution

  • Have one Python program that runs multiple versions of Python bytecode. For example running Python 2.5 or 2.6 bytecode from Python 3.7. No need to install Python 2.6!

The sandboxed environment in a debugger I find interesting. Since there is a separate execution, and traceback stack, inside a debugger you can try things out in the middle of a debug session without effecting the real execution. On the other hand if a sequence of executions works out, it is possible to copy this (under certain circumstances) back into CPython’s execution stack.

Going the other way, I may at some point hook in my debugger into this interpreter and then you’ll have a conventional pdb/gdb like debugger also with the ability to step bytecode instructions.

Status:

Currently only Python 2.5 - 2.7, and 3.2 - 3.5 bytecode is well understood. Other versions will start to appear with the help of xdis.

Whereas Byterun was a bit loose in accepting bytecode opcodes that is invalid for particular Python but may be valid for another; x-python is more stringent. This has pros and cons. On the plus side Byterun might run certain Python 3.4 bytecode because the opcode sets are similar. However starting with Python 3.5 and beyond the likelihood gets much less because, while the underlying opcode names may be the same, the semantics of the operation may change subtely. See for example https://github.com/nedbat/byterun/issues/34.

Internally Byterun needs the kind of overhaul we have here to be able to scale to support bytecode for more Pythons, and to be able to run bytecode across different versions of Python. Specifically, you can’t rely on Python’s dis module if you expect to expect to run a bytecode other than the bytecode that the interpreter is running.

In x-python there is a clear distinction between the version being interpreted and the version of Python that is running. There is tighter control of opcodes and an opcode’s implementation is kept for each Python version. So we’ll warn early when something is invalid. You can run 3.3 bytecode using Python 3.7 (largely).

The “largely” part is because the interpreter has always made use of Python builtins. When a Python version running the interperter matches a supported bytecode close enough, the interpreter can (and does) make use interpreter internals. For example, built-in functions like range() are supported this way.

However running 2.7 bytecode on 3.x is often not feasible since the runtime and internal libraries used like inspect are too different.

I would say this is more than a a simple toy interpreter, but it will never be as complete as CPython or PyPy.

History

This is a fork of Byterun. which is a pure-Python implementation of a Python bytecode execution virtual machine. Net Batchelder started it (based on work from Paul Swartz) to get a better understanding of bytecodes so he could fix branch coverage bugs in coverage.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

x-python-1.0.1.tar.gz (45.5 kB view details)

Uploaded Source

Built Distributions

x_python-1.0.1-py3.5.egg (66.4 kB view details)

Uploaded Egg

x_python-1.0.1-py3.4.egg (66.6 kB view details)

Uploaded Egg

x_python-1.0.1-py3.3.egg (67.4 kB view details)

Uploaded Egg

x_python-1.0.1-py3.2.egg (65.9 kB view details)

Uploaded Egg

x_python-1.0.1-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

x_python-1.0.1-py2.7.egg (65.1 kB view details)

Uploaded Egg

x_python-1.0.1-py2-none-any.whl (31.4 kB view details)

Uploaded Python 2

File details

Details for the file x-python-1.0.1.tar.gz.

File metadata

  • Download URL: x-python-1.0.1.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x-python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2b733a4402f40f7a1db585198811f78ab39861ecdabc6f6dd67921693f1785d5
MD5 c514cde6d40edec33a2d231536020d69
BLAKE2b-256 91e08f73bc239d966fccfbba7c365fe27f3d70d80dad41b54f7e94c5bd6b6dd8

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py3.5.egg.

File metadata

  • Download URL: x_python-1.0.1-py3.5.egg
  • Upload date:
  • Size: 66.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py3.5.egg
Algorithm Hash digest
SHA256 32d131adb03093cd911ac8708d8a657df34cacebbea2144d893ccb9e43087f9f
MD5 b39e7c7785e2d37b82efe06effc64342
BLAKE2b-256 d78cbead650e6fa44e0fa9da4f1c24b9d7a16c564beb4550ad6d6e4cdf95a6c6

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py3.4.egg.

File metadata

  • Download URL: x_python-1.0.1-py3.4.egg
  • Upload date:
  • Size: 66.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py3.4.egg
Algorithm Hash digest
SHA256 3d6cb02fdf68bbeb518c5fbff5fa1cb96ff0e00cbbfaa531457d0e3ccfe8efe1
MD5 1acfaf0652d988bd0356a38cfe53f6e4
BLAKE2b-256 1cf9df42e13fcbfb0bed6f78c3da325167a5c57eb0fe49c5bb0dcbe210a7ead0

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py3.3.egg.

File metadata

  • Download URL: x_python-1.0.1-py3.3.egg
  • Upload date:
  • Size: 67.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py3.3.egg
Algorithm Hash digest
SHA256 caef176537f8e19ada049db93bc1b4d5dd70cc25d6ebadb170ce6ddd18c613bc
MD5 4ffbc65b8ffeacf9034085a72d3623db
BLAKE2b-256 69fd08b1caca92bc4965da37f2ef2dcfbe1ddd9ed3d50e8f1b6d8116d92e3705

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py3.2.egg.

File metadata

  • Download URL: x_python-1.0.1-py3.2.egg
  • Upload date:
  • Size: 65.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py3.2.egg
Algorithm Hash digest
SHA256 70cefa84044772d1f8530a48b8534bdaa7db8c7dac7f62c2bb2d63e77562c855
MD5 ee79c051ae23014f3c784a9bcb23e7b8
BLAKE2b-256 d23174ed866236acd5deeb602147345912a928595e48a1094c73cdb877a25494

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: x_python-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a639cdbbeb01c5206fac019bf3e73cc26be9e326c1475a023e5e16cef75d7562
MD5 708609a08baf6c5ddadb807923cc5065
BLAKE2b-256 576060d2e69b03e3a327d03e6bf842f48298b52073101e6da3ee86949ba1843b

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py2.7.egg.

File metadata

  • Download URL: x_python-1.0.1-py2.7.egg
  • Upload date:
  • Size: 65.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py2.7.egg
Algorithm Hash digest
SHA256 dcec68a2beddbf21416aeac1d6c0241fb3074b769a3bc34df4bf1dd7b676b1c8
MD5 f62e44f4263419f0fef6d025e7fad773
BLAKE2b-256 e55bb1343a3b91edff9e144ad55d9ad729bc0c0f0d6577174f71b6b64322596f

See more details on using hashes here.

File details

Details for the file x_python-1.0.1-py2-none-any.whl.

File metadata

  • Download URL: x_python-1.0.1-py2-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.9

File hashes

Hashes for x_python-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 7df449c6083f48b2199b555c7443d1a35a4bd790db6d7206a6d8bd151e1b0063
MD5 6e5ec4f6fff7f9ae4241c4c0ae646b69
BLAKE2b-256 5ffe5330e48439cefaaebafe08dc024027d292518b8ade3c13112b2d63c9d6ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page