First release of Shed Skin, a Python-to-C++ compiler.

M

Mark Dufour

First the good news: ShedSkin (SS) more or less works on Windows. After
patching gc6.5 for MinGW, building it, and testing it on WinXP with
some succuess, and after patching my local copy of SS, I can get the
test.py to compile from Python to C++, and it seems that I can get
almost all the unit tests in unit.py to pass.

Thank you so much for your efforts! I will try to download your
patches this afternoon on a roommate's Windows computer, and try to
see if I can fix the remaining tests.
Moreover, and since the GC system you used only works in "recent
versions of Windows", it follows that this solution will not work in
all versions. I tested it on Win98 and both GC tests and SS's unit.py
tests crash; although SS can still seem to compile the tests to C++.

Thanks!! Since adding GC support took about 10 lines of C++ code, I
guess it won't be hard to switch to a different system.. I'll try and
see if I can add support for a version that works with Win98..

BTW if anyone is interested in running Shed Skin under OSX.. I got
this comment on my blog (http://shed-skin.blogspot.com)

(why doesn't everybody just run Gentoo? :p)
Wow, very cool. Congratulations!

Here's what I had to do to get it working on the Mac (OS X 10.4):

1. Install the garbage collector from
http://www.hpl.hp.com/personal/Hans_Boehm/gc/

2. Add #include <cmath> above #include <vector> in builtin_.hpp

3. Change makelib to: g++ -dynamiclib -o libss.dylib builtin_.cpp
sets_.cpp >random_.cpp math_.cpp copy_.cpp -lgc -lm
4. Edit ss to use the appropriate path

5. Use python 2.4 instead of the version 2.2 or 2.3 that comes with
OS X (in my >case, I just had to put /usr/local at the start of my
path)
6. Run ./ss test.py

7. Compile the resulting cpp file with: g++ -L. test.cpp -lss -lgc

8. Run ./a.out and watch in awe.


thanks!
mark.
 
A

A.B., Khalid

Mark said:
Thank you so much for your efforts!


Don't mention it.
I will try to download your patches this afternoon on a roommate's Windows
computer, and try to see if I can fix the remaining tests.


Okay. An update.

- Test (124, 'small factorization program by Rohit Krishna Kumar') now
passes on Windows. My mistake in my patching of SS header files. The
patch is now updated. Please download again if you have an earlier
copy.

- Test (122, 'neural network simulator XXX later: recursive
customization, plus some small fixes') was not really failing, it was
just not passing. :)

You see the Python version calls random like so:
self.weight = (random()-0.5)/2 # [float]

And testing output for random generated values is not going to make the
test pass. So if we change that line to a random value generated by
Python in the same way like so:
self.weight = (0.88996634365870131-0.5) # [float]

We have then output from Python like so:
[[0.97483328216510368], [0.50575070454495774], [0.50047176765739709],
[0.93429133063585856], [0.50083898389362214], [0.98098364981984132],
[0.5033858371718114], [0.94838636704849744], [0.50002510730868799],
[0.50910910041727786], [0.5128172933740105], [0.50010155471769424]]


and from the compiled SS generated C++ files like so:
[[0.974833], [0.505751], [0.500472], [0.934291], [0.500839],
[0.980984], [0.503386], [0.948386], [0.500025], [0.509109], [0.512817],
[0.500102]]

Which is okay I guess, wouldn't you agree?

- On to Test (85, 'ifa: mixing strings and lists of strings in the same
list'). It is still failing. It is crashing in the compiled C++
generated from SS. But did you know that the test in pure Python is
crashing as well?

"""
#test03.py
#('ifa: mixing strings and lists of strings in the same list', '''
def row_perm_rec():
hoppa_row = 'impossible' # [str]
hoppa_row = [] # [list(str)]

a = hoppa_row # [pyobj]
hoppa_row.extend(a) # []
hoppa_row.append('u') # []

return hoppa_row # [pyobj]

a = [[7]] # [list(list(int))]
s = row_perm_rec() # [pyobj]
puzzleboard = [['']] # [list(list(str))]
puzzleboard[1][1] = s[1] # [str]
#''', '''
#check('s', ['pyobj'])
#check('a', ['list(list(int))'])
#check('puzzleboard', ['list(list(str))'])
#output()
"""



Running that file produces this error in all Python versions I have.:
Traceback (most recent call last):
File "test03.py", line 15, in ?
puzzleboard[1][1] = s[1] # [str]
IndexError: list index out of range



- Finally Test (60, '__class__ and __name__ attributes') needs
patience. :) In Python it outputs the following:
__main__.evert
evert
<type 'instance'>
instance
equal str!


In the compiled C++ generated by SS it outputs the following:
class evert
evert
class evert
evert
equal!
[Big nasty crash]



So there. :)


Regards,
Khalid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top