Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/glubs9/bytecodemacro
a python library that exposes the python bytecode to allow for run time modifications of python
https://github.com/glubs9/bytecodemacro
Last synced: about 2 months ago
JSON representation
a python library that exposes the python bytecode to allow for run time modifications of python
- Host: GitHub
- URL: https://github.com/glubs9/bytecodemacro
- Owner: Glubs9
- License: gpl-3.0
- Created: 2021-05-20T00:26:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-05T06:43:42.000Z (over 3 years ago)
- Last Synced: 2024-11-06T19:52:31.335Z (about 2 months ago)
- Language: Python
- Size: 367 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributinginformation.txt
- License: LICENSE
Awesome Lists containing this project
README
# 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.```python
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)
- 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
- add continuations to examples.py
- fix walrus in examples
- test and then handle encountering the extended arg instruction in the uncompile package
- i am also still lost on closures and co_freevars
- printing a string also prints the ""