K Stol wrote:
> 
> ----- Original Message -----
> From: "Michal Wallace" <[EMAIL PROTECTED]>
> To: "Luke Palmer" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Thursday, July 24, 2003 12:01 PM
> Subject: Re: approaching python
> 
> >
> > On 24 Jul 2003, Luke Palmer wrote:
> > > Klass-Jan Stol writes:
> > > > module, right? I don't know Python, and I've a little experience
> > > > with IMC, but it seems to me only a new code generator module
> > > > should
> >
> > ...[snip]
> >
> > > Well... sortof.  It's definitely going to take writing a whole new
> > > code generator module; it's not just a matter of getting the right
> > > instructions.  Python's interpreter is stack-based, while Parrot's
> > > is register-based, which are two very different kinds of data.
> >
> > Right. The implementation would be completely yanked out, but
> > if we keep the code generator's interface, then that's the only
> > file we have to touch.
> >
> > The other idea i had was a little crazy, but might make
> > life a lot easier: if perl 6 can use pmcs directly,
> > why not just compile it down to perl and let the perl
> > compiler handle all the register stuff? [I honestly
> > have no idea which way would be easier, since I don't
> > realy know much about IMCC]
> 
> The register stuff, I presume, is register allocation and the like? When
> targeting IMCC, you can use an infinite amount of registers. Just keep a
> counter in the code generator, each time a new register is needed, just
> increment the counter and add a "${S|N|I|P}" in front of it (example:
> $P1). IMCC does register allocation and spilling.
> So this is not really difficult.

Nono, the problem isn't that python uses *more* registers than
<whatever>, but rather, that it doesn't use registers at all.  Instead,
it uses a stack.  So, for example, python's add instruction might get
translated into the following pir or pasm code:

   restore P0
   restore P1
   clone P0, P0
   add P0, P1
   save P0

Needless to say, this is not efficient, due to how slow parrot's push
and pop operations are.

Hmm...  If imcc is smart enough, (or perhaps I should say, when the flow
control is simple/clear enough) it should be able to see when a value is
pushed onto the stack, and later popped off, when there are enough
registers free that we could have stored it in a spare register instead
of on the stack.  That is, a sort of register *un*spilling.

> It may be that this is not as efficient, because it adds an extra layer
> of translation:
> 
> Python->Perl6->IMCC->PASM[1]

?  Why would we translate Python into Perl6 code?

Also, don't you mean IMCC->PBC ?  AFAIK, the parrot assembly language is
a mostly vestigal creation whose purpose was to allow us to write code
for parrot while imcc was being developed.  Now that imcc exists&works,
we no longer need nor use a seperate assembly language.

> instead of
> 
> Python->IMCC->PASM
> 
> [1]. IMCC->PASM integrated in Parrot exec.
> 
> Klaas-Jan
> >
> > Also, there's an older project called rattlesnake that
> > never really got off the ground. I don't know if any
> > code was produced, but the point was to make a register
> > based python vm. Maybe someone from that camp could help
> > us out.
> >
> > > I think it would be good design to have the python binary parse for
> > > us, but it's not likely practical.  Python has eval, so unless we
> > > want to link with python, we should probably write our own
> > > parser.[1]
> >
> > But there's already a parser written in python (in the
> > pypython project), and it makes trees that work with the
> > code generator. :) So I'm saying, use those tools, and
> > just run the compiler from python until it's good enough
> > to compile itself.
> >
> > That just seems like the quickest way to get python
> > working.  (Of course, then there's all the C-based
> > python modules, but that's another story)

Well, we're already writing a parrot <-> perl5/XS compatibility later...
if necessary, we could probably (if the python/C interface has
sufficient encapsulation of python objects) write a compatibility layer
for parrot <-> python/C, if there's sufficient demand for it.  But such
a thing would have to wait until we get python running on parrot in the
first place :)

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED]
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}

Reply via email to