This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Translators/parsing Python



This was my feeling as well.  Compiled Python byte-code executes as a
neat, easy to implement stack language.  You'll want to look at the
marshalling facility for python.  (python/marshall.c)  A .pyc is just a
marshalled code object.  I've started porting it to Guile, but since
this is the first bit of Scheme I've ever coded, I'm not sure I'm doing
it properly, or in an idiosyncratic way.  This is compounded by the fact
that there is almost no documentation available.  What has me stumped is
how to represent python dictionaries; one could of course simply port
the python dictionary from C, but it seems there should be some way to
expose the namespace facility of Guile.  Since I don't understand the
namespace facility, and since again the documentation is scant, I'd
stuck the project in the fridge for awhile.  Also, there seems to be
some sort of mapping-type interface in ice-9/, but again, no docs.

Cheers,

dj trombley
<dtrom@building.clark.net>


bickiia@earlham.edu wrote:
> 
> I think there's reason to be optimistic that it will be possible to use
> existing Python interpreter code to parse.  In particular, I'd look to
> whatever portion of Python compiles to .pyc.
> 
> Though I haven't looked at it specifically, my impression of compiled
> Python code is that it speeds up loading by parsing the code into
> something fast to read, without performing any other fancy compiling.  I
> would imagine that it would be possible to retarget this to create SCM
> objects instead of .pyc files, but in the short term it would probably
> be a good place to start by taking a .pyc file and parsing it into a
> Scheme object -- no doubt a bunch of lists.  I'd even go so far as to
> imagine that this will look very much like Scheme code, as the compiled
> Python is probably in a tree representation, and Scheme is conveniently
> tree like.
> 
> Since someone on this list seems to know something about what that .pyc
> file looks like (I'm afraid I don't have his name in front of me), that
> would probably be the place to start.  I'd expect that once you got the
> .pyc reader working you could whip up something that evaluated it in a
> couple hours.  Of course, it would only be Scheme with a Python syntax,
> but I'm sure that will be quite satisfying anyway :)  Then you get to
> write things like "display(cons('a', 10+10))".  At that point you'll
> have done nearly as much as CTAX did, as CTAX didn't really match C's
> symantics at all.
> 
> Then you can get to the harder, but probably more enjoyable part of
> trying to match Python's symatics.  No doubt that would give all
> involved a greater appreciation of both languages :)
> 
> Well, that's my prediction of how it could go... I almost feel like
> trying to do it myself now :)
> 
>   -- Ian

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]