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 MyProjectInRPythonAnd put the following code in the file:
$ cd MyProjectInRPython
$ echo "This is my RPython-based project." > README
$ mkdir myproj
$ touch myproj/__init__.py
$ emacs myproj/myproj_target.py
# __________ 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.