I still think that’s an interesting idea, but I decided to try my hand at a much smaller and more fun problem: using the Python ast (abstract syntax tree) module to parse Python syntax, then recursively visit the AST nodes to turn them into another language. It’s obviously not portable, and Python’s data and memory model is much different and higher-level than the x86’s. I got onto this recently when I was doing some performance work on Python bytecode (a story for another day), and I wondered, “Hmmm, what if Python bytecode was just x86 code?” That is, why have a bytecode interpreter when you have a super-speedy native interpreter right there in your CPU? I’m sure that idea isn’t original with me, and it has probably been tried and found wanting. ![]() So why not borrow Python’s syntax – and its parser – for your own evil schemes? You can write an algorithm in pseudocode, and then a minute later realize you’ve just written valid Python. ![]() One of the reasons people like Python is because of its readable, low-punctuation syntax. It’s basically a toy, but it shows how easy it is to use the ast module to co-opt Python’s lovely syntax for your own ends. Summary: I used Python’s built-in AST module to parse a subset of Python syntax and turn it into an x86-64 assembly program. Compiling Python syntax to x86-64 assembly for fun and (zero) profit
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |