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 http://codespeak.net/svn/pypy/dist 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
> ./translate.py --gc=generation targetfibsmalltalk.py

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

targetfibsmalltalk.py
targettinybenchsmalltalk.py
targetimageloadingsmalltalk.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

classtable.py
constants.py
error.py
interpreter.py - implements bytecodes and interpreter loop
model.py
objtable.py
primitives.py - implements primitives
shadow.py
squeakimage.py - implements image loading
utility.py
test/test_classtable.py
test/test_interpreter.py
test/test_miniimage.py
test/test_model.py
test/test_primitives.py
test/test_shadow.py
test/test_squeakimage.py
tool/analyseimage.py
tool/autopath.py
tool/bitmanipulation.py
tool/test_bitmanipulation.py

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

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

2 comments:

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