Stefan Behnel <stefan...@behnel.de> writes: >> C is pretty poor as a compiler target: how would you translate Python >> generators into C, for example? > Depends. If you have CPython available, that'd be a straight forward > extension type.
Calling CPython hardly counts as compiling Python into C. > For the yielding, you can use labels and goto. Given that you generate > the code, that's pretty straight forward as well. You're going to compile the whole Python program into a single C function so that you can do gotos inside of it? What happens if the program imports a generator? >> How would you handle garbage collection? > CPython does it automatically for us at least. You mean you're going to have all the same INCREF/DECREF stuff on every operation in compiled data? Ugh. > Lacking that, you'd use one of the available garbage collection > implementations, What implementations would those be? There's the Boehm GC which is useful for some purposes but not really suitable at large scale, from what I can tell. Is there something else? > or provide none at all. You're going to let the program just leak memory until it crashes?? > you shouldn't expect too much of a performance gain from what the > platform gives you for the underlying implementation. It can optimise > the emulator, but it won't see enough of the Python code to make > anything efficient out of it. Jython is an example for that. Compare that to the performance gain of LuaJIT and it starts to look like something is wrong with that approach, or maybe some issue inherent in Python itself. > You can get pretty far with static code analysis, optimistic > optimisations and code specialisation. It seems very hard to do reasonable optimizations in the presence of standard Python techniques like dynamically poking class instance attributes. I guess some optimizations are still possible, like storing attributes named as literals in the program in fixed slots, saving some dictionary lookups even though the slot contents would have to still be mutable. -- http://mail.python.org/mailman/listinfo/python-list