I’ve spent the last week working on a tinypy to C++ converter. Â It works! Â See the screenshot to the right – I’ve managed to port a pygame game over to C++.
Here’s how (and some of the catches):
- I require type annotation of all the functions and methods. Â “def test(x:str)->str: return x”
- I do two passes on each file, the first pass to catch all the function types and class members, and the second pass to generate the code.
- I generate C++ code that has automagic reference counting. Â So you have to code your script so it won’t have any cyclic references if you want garbage collected for you.
How is this different from shedskin (really cool project!)?
- Built-in reference counting, instead of using libgc.
- I require the user to type annotate everything.
- It only supports a subset of the tinypy subset of python. Â Shedskin supports a much larger subset of python.
So what’s the point?
- Well, I learned a lot about STL and C++.
- I know it will produce iPhone friendly code, I’m pretty sure libgc isn’t iPhone friendly? Â (At least, I haven’t found anything via a few searches…)
- Way less magic. Â Since everything is annotated, there are no surprises.
- Implementing C++ modules is pretty easy – the code can be inlined within the python code and it just works.
- This will make it easier for me to develop C++ games.
Anyway, if you’re super brave, you can check out svn://www.imitationpickles.org/tinypy/branches/tinypy2 .. I don’t have the elephants example in there, but the pygame.py that I include gives you a pretty good example of a complex module.
I’m going to chat with the tinypy folks to see if we’ll merge this into the tinypy trunk or have it as a separate project.  I’m not quite sure what makes sense to everyone else 🙂  The nice bit about merging this in is that I could unify the test suites nicely.  And tinypy would still function as normal, just better tested, and with function annotation parsing supported.  All that said, I should make a tinypy module for tinypyC++ so that I can do some code evals!