radixvinni / astricks

:cool: Metaprogramming tools for ast manipulation, creating rewritable functions, that are aware of their :one: functional equivalence, :two: computability, :three: asymptotic complexity and :four: problems being solved

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

metafunc.py

Function wrapper for decompiling and ast manipulation of wrapped function. Can be used as decorator with any python function or lambda.

>>> Mf(lambda x:x+1)
#-5599708371849146885
def f(x):
    return (x + 1)

rewrite_rules.py

Defines NodeTransformers to modify ast

>>> b=Mf(lambda y:y+1)
>>> RewriteNames({'y':'x'}).visit(b.ast)
<_ast.FunctionDef object at 0x7f5e03f5f350>
>>> b
#-5599708371849146885
def f(x):
    return (x + 1)
>>> b==a
True

About

:cool: Metaprogramming tools for ast manipulation, creating rewritable functions, that are aware of their :one: functional equivalence, :two: computability, :three: asymptotic complexity and :four: problems being solved


Languages

Language:Python 100.0%