How to Do Something with RPython Part 1

Ok, so here's how to set up a new independent codebase which you want to write in RPython using the C backend. I use this kind of set up when hacking on Safelisp, which is a language totally unrelated to Python which I am implementing in RPython.

This will take you through writing, translating, and running a program which prints "hello world" to standard out.

I'll assume you have an SVN checkout of pypy at ~/Projects/pypy/.

$ mkdir MyProjectInRPython
$ cd MyProjectInRPython
$ echo "This is my RPython-based project." > README
$ mkdir myproj
$ touch myproj/__init__.py
$ emacs myproj/myproj_target.py
And put the following code in the file:
# __________  Entry point  __________

def entry_point(argv):
print "hello world"
return 0

# _____ Define and setup target ___

def target(*args):
return entry_point, None

Now compile and run it.
$ ~/Projects/pypy/pypy/translator/goal/translate.py  --batch myproj/myproj_target.py
[Lots and lots of output]

$ ./myproj_target-c
hello world

That translate.py command is really long, so I generally put a symlink to it in my ~/bin named "pypy-translate". The --batch flag is meant to disable the interactive debugging facilities during translation -- if you leave it off, a very nice pygame viewer will pop up showing the annotated graph of your application, which is a great way to learn more. It'll also give you a Pdb debugger on the console.

I'll post further about actually writing some real RPython code. It ain't easy.

Pre-holiday braindump

Ok, here's a load of totally dissociated thoughts, technical ones last:

Woo Emma!

I am going back to Pittsburgh again for Christmas. I'll be gone from the 22nd to the 2nd.

Coldness is noticeable.

I saw Borat. I think it was pretty funny, but whenever I think about it all I can remember are the offensive bits. Which probably make up the majority of the movie, actually. I'm not a square or anything; I was laughing through most of them, but it was always a guilty laugh. Holy crap, that was so bad. Fortunately Emma, who had seen it already, was there to warn me: "This next scene is going to be REALLY GROSS".

I am reading Kafka on the Shore by Murakami Haruki. It is kind of silly but also awesome. It is FULL of (fairly explicit) literary reference, which really tickles me.

Speaking of Japanese stuff, I am only two classes away from completing my Level 1 Japanese language course. I definitely plan on going on to level two. It's amazing how little I know after two months of taking classes: it's such a different language that I only have a very basic grasp of the grammar and knowledge of maybe 50 nouns and a dozen or so verbs. For the last class, I'm going to have to write a big paragraph about myself in hiragana and read it aloud.

Efforts towards Twisted 2.5 are accelerating. Also, did you see the new web site?

Holy crap, what was I thinking with that last blog post? Porting CMUCL's readtable implementation to RPython would have been insane. I ended up just using Carl Bolz' BNF parser generator in pypy.rlib.parsing, and it was hella easy. I did it mostly while I was flying and hanging out in Pittsburgh during Thanksgiving.

That's probably enough for now.

I know what will kick your knickers, small child!