{"id":233,"date":"2009-12-01T16:18:38","date_gmt":"2009-12-01T22:18:38","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=233"},"modified":"2009-12-01T16:18:38","modified_gmt":"2009-12-01T22:18:38","slug":"restricted-tinypy-to-c-compiler","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2009\/12\/01\/restricted-tinypy-to-c-compiler\/","title":{"rendered":"Restricted tinypy to C++ compiler"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-234\" title=\"elephant1\" src=\"https:\/\/www.philhassey.com\/blog\/wp-content\/uploads\/2009\/12\/elephant1-288x300.png\" alt=\"elephant1\" width=\"288\" height=\"300\" srcset=\"https:\/\/www.philhassey.com\/blog\/wp-content\/uploads\/2009\/12\/elephant1-288x300.png 288w, https:\/\/www.philhassey.com\/blog\/wp-content\/uploads\/2009\/12\/elephant1.png 488w\" sizes=\"auto, (max-width: 288px) 100vw, 288px\" \/>I&#8217;ve spent the last week working on a tinypy to C++ converter. \u00a0It works! \u00a0See the screenshot to the right &#8211; I&#8217;ve managed to port a pygame game over to C++.<\/p>\n<p>Here&#8217;s how (and some of the catches):<\/p>\n<ul>\n<li>I require type annotation of all the functions and methods. \u00a0&#8220;def test(x:str)-&gt;str: return x&#8221;<\/li>\n<li>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.<\/li>\n<li>I generate C++ code that has automagic reference counting. \u00a0So you have to code your script so it won&#8217;t have any cyclic references if you want garbage collected for you.<\/li>\n<\/ul>\n<p>How is this different from shedskin (really cool project!)?<\/p>\n<ul>\n<li>Built-in reference counting, instead of using libgc.<\/li>\n<li>I require the user to type annotate everything.<\/li>\n<li>It only supports a subset of the tinypy subset of python. \u00a0Shedskin supports a much larger subset of python.<\/li>\n<\/ul>\n<p>So what&#8217;s the point?<\/p>\n<ul>\n<li>Well, I learned a lot about STL and C++.<\/li>\n<li>I know it will produce iPhone friendly code, I&#8217;m pretty sure libgc isn&#8217;t iPhone friendly? \u00a0(At least, I haven&#8217;t found anything via a few searches&#8230;)<\/li>\n<li>Way less magic. \u00a0Since everything is annotated, there are no surprises.<\/li>\n<li>Implementing C++ modules is pretty easy &#8211; the code can be inlined within the python code and it just works.<\/li>\n<li>This will make it easier for me to develop C++ games.<\/li>\n<\/ul>\n<p>Anyway, if you&#8217;re super brave, you can check out svn:\/\/www.imitationpickles.org\/tinypy\/branches\/tinypy2 .. I don&#8217;t have the elephants example in there, but the pygame.py that I include gives you a pretty good example of a complex module.<\/p>\n<p>I&#8217;m going to chat with the tinypy folks to see if we&#8217;ll merge this into the tinypy trunk or have it as a separate project. \u00a0I&#8217;m not quite sure what makes sense to everyone else \ud83d\ude42 \u00a0The nice bit about merging this in is that I could unify the test suites nicely. \u00a0And tinypy would still function as normal, just better tested, and with function annotation parsing supported. \u00a0All that said, I should make a tinypy module for tinypyC++ so that I can do some code evals!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve spent the last week working on a tinypy to C++ converter. \u00a0It works! \u00a0See the screenshot to the right &#8211; I&#8217;ve managed to port a pygame game over to C++. Here&#8217;s how (and some of the catches): I require type annotation of all the functions and methods. \u00a0&#8220;def test(x:str)-&gt;str: return x&#8221; I do two [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,6,3,2,32],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-c","category-development","category-pygame","category-python","category-tinypy"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":2,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":236,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/233\/revisions\/236"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}