Wednesday, November 21, 2007

PyPy-Squeak Mini-Tutorial

A proper installation guide had been missing so far, here it comes.

How to install PyPy and generate a Squeak VM

Make sure you are running Python version 2.5 or higher, and checkout the project from subversion

> svn co pypy-dist
> cd pypy-dist

Now, lets generate some Squeak VMs. Switch to the translation goal folder and run the tool chain

> cd pypy/translator/goal
> ./ --gc=generation

This yields tons of output and ends in the debugger, just press ctrl-D to leave and run the generated VM as follows

> ./targetfibsmalltalk-c 25

If you browse the target's python file, you'll find some fixture code together with a function called entry_point(argv). The fixture code is executed before the tool chain takes over, it may use the full power of Python and is not restricted to RPython. Then, the tool chain is started up, taking the entry_point function and the fixture's result as an input, to generate the VM. Therefore, all code eventually called by the entry point must conform to RPython.

Other available goals for Smalltalk are

> ls *smalltalk*.py

For more options, please refer to the previous post Translating the Smalltalk interpreter to C, Java or .NET.

How to browse and test the source code

First, go back to the pypy root folder

> cd ../../../

Then, add py.test to your $PATH to run the tests, for example like this

> sudo ln -s py/bin/py.test /usr/bin

And now, switch to the Smalltalk folder and run the tests

> cd pypy/lang/smalltalk
> py.test

Browse the python files to read the source code - implements bytecodes and interpreter loop - implements primitives - implements image loading

For more information or questions, you may subscribe toor go to channel #pypy on

Thanks to Alexandre Bergel and Mathieu Suen for fighting through an earlier version of this tutorial, eliminiating my command line typos – akuhn


Anonymous said...

Where you do the sudo ln, you should provide the absolute path to py.test, since root might not be in the same dir as you.

adam said...

great! exactly what I was looking for. good tutorial and once I got my path's sorted out it all worked perfectly. - Adam