You could recompile python bytecode, then you can keep python syntax. i.e. language frontend as it is. If you wanted great improvement, you may have to change libpython.
Look at pyastra and pymite projects, they do a subset of python and native execution.
Cython can be useful as half-way between python and compilation.
On the larger scale, look at PyPy, Psyco and Unladen Swallow.
Answer from Dima Tisnek on Stack Overflowcompiler construction - What thing I will need for creating a front end for Python based on LLVM architecture? - Stack Overflow
Mapping Python to LLVM
Interest in Python frontend targetting PDL
Writing a toy language compiler in Python with LLVM—feasible?
Videos
Hi everyone!
A while ago, I started writing a C compiler in C—for learning and fun. Now I'm thinking it could be fun to write a compiler for a toy language of my own as well.
The thing is, unlike C, the syntax and structure of this toy language will evolve as I go, so I want to be able to iterate quickly. Writing another compiler entirely in C might not be the best option for this kind of rapid experimentation.
So I'm considering writing the frontend in Python, and then using LLVM via its C API, called from Python, to handle code generation. My questions:
-
Does this sound feasible?
-
Has anyone here done something similar?
-
Are there better approaches or tools you’d recommend for experimenting with toy languages and compiling them down to native code?
Thanks in advance—curious to hear your thoughts and experiences!