4 ms·
Interesting extension of this exercise would be to replace your custom AST with the AST exposed by Python, then use the compile() builtin to compile said AST in
by thomaslee 13y ago
Interesting extension of this exercise would be to replace your custom AST with the AST exposed by Python, then use the compile() builtin to compile said AST into a PyCodeObject ready for direct execution by the Python VM. :)
Something along these lines: https://github.com/thomaslee/viking-poc/blob/master/viking#L334 https://github.com/thomaslee/viking-poc/blob/master/viking#L...
(Disclaimer: I wrote the Python-AST-to-PyObject transformation code for Python 2.6 that made this sort of stuff possible -- fun hack!)