[C++-sig] Shed Skin Python-to-C++ Compiler

Mark Dufour mark.dufour at gmail.com
Mon Jul 3 23:28:13 CEST 2006


Hello all,

Having just released version 0.0.11 of my optimizing Python-to-C++
compiler, I thought why not ask around here if there is any interest
in helping out. For those that do not know it, Shed Skin accepts pure,
but implicitly statically typed, Python programs and converts them
into optimized C++ code. See this page for more information:

http://mark.dufour.googlepages.com

Besides being quite experimental in that the type inference is quite
academic and it sometimes has non-termination issues, especially with
recursive datastructures (I am quite sure both problems can be handled
successfully), integration with especially the standard library is the
other major problem.

Shed Skin currently supports several commonly-used standard library
calls, and it is often simple, but some work, to add support for other
calls.

For example, suppose we want to support random.random. First, a 'type
model' of this function must be provided in the file 'random_.py',
e.g.: def random(): return 1.0. This way, the global type analysis
understands what is going on externally. Second, a C++ implementation
or glue layer needs to be provided with the files 'random_.?pp'. A
glue layer can use the Python C API to call the real standard library.

Now, as  the C API is rather cumbersome (I've added support for some
Pygame functionality and it didn't really help my RSI..), I am
thinking about using boost.Python to quickly add support for many
standard library and other modules.  Trying to use it, I get this
error however:

scart at akemi ~/projects/shedskin $ g++ -I/usr/include/python2.4
-lpython2.4 pb.cpp
/tmp/ccqUfrVQ.o: In function `main':
pb.cpp:(.text+0x151): undefined reference to
`boost::python::api::object::object(boost::python::handle<_object>
const&)'
/tmp/ccqUfrVQ.o: In function `_object*
boost::python::expect_non_null<_object>(_object*)':
pb.cpp:(.gnu.linkonce.t._ZN5boost6python15expect_non_nullI7_objectEEPT_S4_+0xd):
undefined reference to `boost::python::throw_error_already_set()'
collect2: ld returned 1 exit status

Where I'm trying to compile the simple embedding example:

#include <boost/python.hpp>
using namespace boost::python;

int main() {
    Py_Initialize();
    object main_module((handle<>(borrowed(PyImport_AddModule("__main__")))));
    Py_Finalize();
}

Am I missing something simple? (I am using Python-2.4.3, boost 1.33.1,
GCC 3.4.6 under Gentoo Linux.)

Well, in any case,  I would be very interested to hear your thoughts
about the approach of using boost.Python to make Shed Skin more
broadly applicable. I would also be very happy to receive help in
implementing several commonly used modules, such as 're' and pygame..
:-)


Thanks,
Mark Dufour.
-- 
if vars: self.output('; '.join([self.type(var)+' '+name for (name,var)
in vars.items()])+';')



More information about the Cplusplus-sig mailing list