Phil Hassey - game dev blog
Phil Hassey as Rambo
".. I've been there,
I know what it's like,
and I'll do it again if I have to."

tinypy 64k – now with built in garbage collection

Yay – I got incremental garbage collection added into tinypy. It took a good deal of troubleshooting, but thanks to valgrind (and thanks to the people who pointed me to it) after some work I got all the memory leaks and crashes worked out. This is a nice step forward, since it enabled me to eliminate the libgc dependency.

tinypy is slightly larger than 64k, but I have vague hopes that will be remedied* at some point. In the meantime, I’m going to take a bit of a break from it. On Feb. 23rd, the Ludum Dare community is having a “warm-up” compo, and I shall give tinypy a real try at that point. After that I will probably put out the 1.0 release.

All that said, its been quite a learning experience for me. I learned how to tokenize, parse, generate byte code, build a virtual machine, and do garbage collection. I’m hoping this will make looking at the innards of other languages seem less intimidating in the future.

* if you’re a clever C / python coder and feel like taking a look at the tinypy code and give me ideas on how to compact the code a bit, I’d sure appreciate it. It’s 4k too big right now, and I’d really like to fix that. I’m cool with any suggestions though I won’t implement anything unless it leaves the code just as (if not more) readable. Please examine the README.txt to find out how I calculate the code size first.

svn://www.imitationpickles.org/tinypy/trunk or tinypy.zip for the brave. I’ve managed to compile it under mingw32 (Minimalist GCC for windows) as well as using GCC under MacOSX. Perhaps for the 1.0 release I’ll include binaries 🙂

7 Responses to “tinypy 64k – now with built in garbage collection”

  1. Omar Gómez Says:

    Hi Phill,

    Congrats on your achievement. I’ve been quitely following your work on this 64k implementation of Python VM. For some time now I wanted to do the same for the also beatifull language Io (http://www.iolanguage.com/). Have you any plans to document a detailed history of your experience designing tinypy 64k?. Some of us out here would benefit for your experience.

    //omar

  2. Dave Says:

    Looks like you have enjoyed the process. I have enjoyed reading about it. I love the banners ate the top of your site.

  3. philhassey Says:

    Omar – I think you’ve been reading it 🙂 Though I’d be glad to answer any questions about stuff I haven’t talked about… Good luck with your project!

  4. A.B.Leal Says:

    Congratulations, this looks fun.

    I’ve looked at the zip. I cannot compile (no SDL),
    but to reduce size you may want to play with these,
    if you have not already:

    a) Use “gcc -Os” instead of “gcc -O2”. Perhaps it will
    not affect performance significantly.

    b) Strip the binary (“strip tinypy”). Goodbye debug 😉

    c) Check strings in the binary (“strings tinypy”).
    You may want to make some global to avoid repeats
    (I don’t know if gcc is smart about that).

  5. philhassey Says:

    Leal – thanks. I’m actually trying to reduce the code size, not the binary size though 🙂

  6. A.B.Leal Says:

    > I’m actually trying to reduce the code size, not the binary size

    Duh (smacking forehead), the _source_ code – yeah, that’s
    what it says in the boot.py and NOTES.txt that I speed-read …
    (was also wondering how all the linked stuff was going to fit).
    My apologies.

    Well, what about changing the motto to
    “Tinypy – around Python in 80k” ?

    Cheers.

  7. philhassey Says:

    That doesn’t have quite as nice a ring to it .. and it’s nice to have the code be so short that anyone can read through it all in a couple hours. Though at this point, I’m not sure I can trim it down much …