Skip to main content

Generate Python code objects by

Project description

peak.util.assembler is a simple bytecode assembler module that handles most low-level bytecode generation details like jump offsets, stack size tracking, line number table generation, constant and variable name index tracking, etc. That way, you can focus your attention on the desired semantics of your bytecode instead of on these mechanical issues.

In addition to a low-level opcode-oriented API for directly generating specific bytecodes, this module also offers an extensible mini-AST framework for generating code from high-level specifications. This framework does most of the work needed to transform tree-like structures into linear bytecode instructions, and includes the ability to do compile-time constant folding.

Changes since version 0.1:

  • Constant handling has been fixed so that it doesn’t confuse equal values of differing types (e.g. 1.0 and True), or equal unhashable objects (e.g. two empty lists).

  • Removed nil, ast_curry() and folding_curry(), replacing them with the nodetype() decorator and fold_args(); please see the docs for more details.

  • Added stack tracking across jumps, globally verifying stack level prediction consistency and automatically rejecting attempts to generate dead code. It should now be virtually impossible to accidentally generate bytecode that can crash the interpreter. (If you find a way, let me know!)

Changes since version 0.0.1:

  • Added massive quantities of new documentation and examples

  • Full block, loop, and closure support

  • High-level functional code generation from trees, with smart labels and blocks, constant folding, extensibility, smart local variable names, etc.

  • The .label() method was renamed to .here() to distinguish it from the new smart Label objects.

  • Docs and tests were moved to README.txt instead of assembler.txt

  • Added a demo that implements a “switch”-like statement template that shows how to extend the code generation system and how to abuse END_FINALLY to implement a “computed goto” in bytecode.

  • Various bug fixes

There are a few features that aren’t tested yet, and not all opcodes may be fully supported. Notably, the following features are still NOT reliably supported yet:

  • Wide jump addressing (for generated bytecode>64K in size)

  • The dis() module in Python 2.3 has a bug that makes it show incorrect line numbers when the difference between two adjacent line numbers is greater than 255. This causes two shallow failures in the current test suite when it’s run under Python 2.3.

If you find any other issues, please let me know.

Please also keep in mind that this is a work in progress, and the API may change if I come up with a better way to do something.

Questions and discussion regarding this software should be directed to the PEAK Mailing List.

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

BytecodeAssembler-0.2.zip (33.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

BytecodeAssembler-0.2-py2.4.egg (20.1 kB view details)

Uploaded Egg

BytecodeAssembler-0.2-py2.3.egg (63.1 kB view details)

Uploaded Egg

File details

Details for the file BytecodeAssembler-0.2.zip.

File metadata

  • Download URL: BytecodeAssembler-0.2.zip
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for BytecodeAssembler-0.2.zip
Algorithm Hash digest
SHA256 b50cd83a7c958023cddd618acb8f52fa901704f1fbc5adaa4dec465039f0d359
MD5 edba545f392cde743fe6bcb53f8825d6
BLAKE2b-256 4741e4528a7be607a241505ee8867111bb355674a17679f8757c8300fdd31bd2

See more details on using hashes here.

File details

Details for the file BytecodeAssembler-0.2-py2.4.egg.

File metadata

File hashes

Hashes for BytecodeAssembler-0.2-py2.4.egg
Algorithm Hash digest
SHA256 73453a3c80187ef8b9dd3db21c4bcf3b21ee6a28699b8a1d68e638596a141fc0
MD5 3003958a0af24527988d243e8e91c786
BLAKE2b-256 f3d9a6c7e2683a07a5dffbd06c173114991e84d83391b348bf162e95ebff5d17

See more details on using hashes here.

File details

Details for the file BytecodeAssembler-0.2-py2.3.egg.

File metadata

File hashes

Hashes for BytecodeAssembler-0.2-py2.3.egg
Algorithm Hash digest
SHA256 a199e9a58fd87ec2852b4c3a7168da6f93085cccb20d33b048ef4057851ca63b
MD5 1136578a85e89bf293b03bdaf0048c13
BLAKE2b-256 92b4ce7b130406304bf8771c998375ffe92986c68df46bcf76e28a41877814a9

See more details on using hashes here.

Supported by

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