Skip to main content

a macro library that expoes the bytecode of python

Project description

bytecode macro lib

exposes (a slightly modified version of) the bytecode of a function to allow for run-time modification of python syntax.

how to use

for a description of how to use and install the program, please go to the docs folder on the github (https://github.com/Glubs9/bytecodemacro).

cool example to get you excited

this is a cool example to get you excited with what this library could do and the fun you can have doing it.

def goto(tups):
    ret = []
    for n in tups:
        inst, arg = n
        if inst == "LOAD_CONST" and len(arg) > 6 and arg[1:5] == "goto":
            ret.append(("JUMP_ABSOLUTE", arg[6:-1]))
        elif inst == "LOAD_CONST" and len(arg) > 2 and arg[-2] == ":":
            ret.append(("LABEL", arg[1:-2]))
        else:
            ret.append(n)
    return ret

@macro(goto)
def f():
    n = 0
    while n < 10:
        if n > 5:
            _ = "goto exit"
        print(n)
        n+=1
    _ = "exit:"
f() #prints 1 2 3 4 5 !

please have fun writing your own macros! or just have fun looking at the examples in docs/examples.py in the github

basic installation

please read through install.txt for requirements but if you just want to get it installed before looking through the library the comamnd is.

python3 -m pip install bytecodemacro

todo

- add error / semantics checking for the returned bytecode (maybe)
- add more examples
- order examples.py by ease of understanding
	- so the easy ones to read like constant and add_arg are at the top but the ones
		that are harder like cloop or join are at the bottom
- fix walrus.py
- test and then handle encountering the extended arg instruction in the uncompile package
- i am also still lost on closures and co_freevars

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

bytecodemacro-2.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

bytecodemacro-2.1.0-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file bytecodemacro-2.1.0.tar.gz.

File metadata

  • Download URL: bytecodemacro-2.1.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for bytecodemacro-2.1.0.tar.gz
Algorithm Hash digest
SHA256 b95ebcc861aa1cf3999418621a952fd5dee21daeacaf537508a7b141fc362279
MD5 ce6c2e8afa852a26062d34862a36bb19
BLAKE2b-256 f3c034dbcd0fec332ac7fe4afa6a3c5baa70f979da4e3f2d13fffa97af0f4a35

See more details on using hashes here.

File details

Details for the file bytecodemacro-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: bytecodemacro-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for bytecodemacro-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc07f261587c7a9130a6e71c1cc03bdcf003be7efc21a653476e4aa88a0334d
MD5 ce397a6d5cbc3fca7a578a4e25521aea
BLAKE2b-256 06be8472aabfd919150d0c33e8077e60e118a68d9cd459208fdda9536f1605a4

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