tinypy 1.0 – MIT License and swell OpenGL demo :)
Its been a long two months getting this project to the 1.0 state. Here it is:
tinypy1.zip | tinypy.tgz | svn://www.imitationpickles.org/tinypy/tags/1.0.0
$ python build.py
$ ./tinypy-sdl julia.py *
$ ./tinypy your-program-goes-here.py
The win32.zip includes the tinypy.exe and tinypy-sdl.exe binaries, so you can skip the building process.
Features include the ability to parse and compile to bytecode a pretty decent subset of python code. Its got a pretty simple API, incremental garbage collection, and a handful of builtin functions. The vm supports strings, dicts, lists, numbers, functions, methods, and custom data types. tinypy even has exotic features like list comprehensions, variable and named function arguments, inheritance, and exceptions with tracebacks. All this in just 64k** of code!!
I also had some fun this past weekend testing tinypy “in the field” making an OpenGL tetris knock-off. My apologies to Alexey Pajitnov for my misguided contribution of tinypy to the open source stack. win32.zip | svn://www.imitationpickles.org/ld105/trunk
I hope you enjoy checking out tinypy – I’ve had a pretty wild ride building it.
*julia.py included is a low-res “realtime” jula fractal demo. I felt like rendering a mandelbrot for this article.
**See README.txt for my definition of 64k. It’s close enough.
February 28th, 2008 at 5:58 am
hi phil,
congratulations on getting to 0.1!
February 28th, 2008 at 5:58 am
that was not meant as a bad joke – of course I meant 1.0! 🙂
February 28th, 2008 at 8:11 am
Big pat on the back man!
February 28th, 2008 at 10:57 am
Rock on! This is great!
February 28th, 2008 at 12:28 pm
Good job! This is awesome.
February 28th, 2008 at 12:44 pm
Thanks 🙂
February 28th, 2008 at 1:05 pm
Phil – how can i run sdl programs directly on the vm? i tried:
$ ./vm py2bc.tpc julia.py julia.tpc
$ ./vm julia.tpc
320 240
File “julia.py”, line 26, in ?
set_mode(SW,SH)
Exception:
tp_get: KeyError: set_mode
February 28th, 2008 at 1:10 pm
Ido – you’d have to build a vm with the SDL functions built in. Take tinypy-sdl.c and tweak the main function to be more like the main function from vmmain.c. Doing it that way would be useful for distributing a game where you don’t want to support any in-game scripting, or in a case where you really don’t want all that bytecode in memory for some reason.
February 28th, 2008 at 1:20 pm
Thanks.
Does that mean that if I use ‘eval’ in my python program i have to provide the tinypy compiler as well as the vm?
February 28th, 2008 at 1:21 pm
Nice, a nod to “Top Down Operator Precedence” in your parser 🙂
February 28th, 2008 at 1:24 pm
Ido: Yeah, to use eval or similar stuff the compiler must be included so it can dynamically compile the code.
shaurz: Indeed – http://javascript.crockford.com/tdop/tdop.html – was what got me through 🙂 I tried some other approaches, but TDOP really suited me.
February 28th, 2008 at 1:31 pm
Ido: just to clarify, tinypy includes the VM, so you don’t have to have both “vm.exe” and “tinypy.exe” available for things to work.
February 29th, 2008 at 8:51 pm
Nice piece of work 🙂
March 1st, 2008 at 11:22 am
Wow, that’s pretty cool. I can get the VM executable down to about 17k (-Os + strip + upx).
I’m thinking of a few things I can add to this, the first thing that comes it mind is transparent .zip file access via zziplib (http://zziplib.sourceforge.net/zzip-file.html) so a project can be distributed as vm + (compiled) code.zip
I’m also pondering an implementation of tasklets/channels/io ala Stackless Python, abusing libevent as a kernel.
Also – where can I send patches in?
March 1st, 2008 at 11:26 am
Harry – Cool stuff, I’d love to see some interesting stuff done with this. Patches can be sent to my name as one word @ gmail.com … Sometime soon I should set up some kind of “project” thing for this. But I haven’t gotten around to it yet.
March 1st, 2008 at 1:40 pm
[…] recently stumbled across TinyPy by Phil Hassey, what an amazing little project – a Python compiler & virtual machine that weighs in […]
March 4th, 2008 at 9:08 pm
Damn… I get a funk error when attemptng to build on OS X:
gcc -Wall -g vmmain.c -lm -o vm
/usr/bin/ld: /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libm.dylib unknown flags (type) of section 6 (__TEXT,__literal16) in load command 0
/usr/bin/ld: /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libSystem.dylib unknown flags (type) of section 6 (__TEXT,__literal16) in load command 0
collect2: ld returned 1 exit status
exit 256
March 4th, 2008 at 9:24 pm
Hmmn. I just tried tinypy on my OSX system and didn’t have any trouble. I’m not really sure what that error means, but if you figure it out, please tell me 🙂
May 6th, 2008 at 7:53 am
Sorry for what I am sure in a noob question but how do I go about outputing to the console as it seems to output to file by default?
May 6th, 2008 at 8:55 am
John – check out the latest svn, there is a fix for windows that fixes that.
May 27th, 2008 at 2:00 pm
@Mike Cantelon: I got this same error because I had upgraded to 10.5 from 10.4 (Ocelot or whatever it was called) without upgrading XCode. Once I installed the latest XCode (v3 I believe) from the Leopard install disc, I no longer got the error “libSystem.dylib unknown flags (type) of section 6 (__TEXT,__literal16) in load command 0”.
HTH