Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Basic compilation example (a + b)?

22 views
Skip to first unread message

Jeff Clites

unread,
Nov 7, 2004, 10:29:24 PM11/7/04
to Perl 6 Internals List
What pasm is supposed to correspond to this snippet of Python code
(assume this is inside a function, so these can be considered to be
local variables):

a = 7
b = 12
c = a + b

Just a basic compilation question, brought to mind by a recent thread,
because the answer isn't obvious to me.

JEff

Leopold Toetsch

unread,
Nov 8, 2004, 5:47:21 AM11/8/04
to Jeff Clites, perl6-i...@perl.org
Jeff Clites <jcl...@mac.com> wrote:
> What pasm is supposed to correspond to this snippet of Python code
> (assume this is inside a function, so these can be considered to be
> local variables):

> a = 7
> b = 12
> c = a + b

Run it through pie-thon. It should produce some reasonable code. For
leaf-functions (w/o introspection i.e. calls to locals()), the lexical
handling would get dropped. And a better translator would use lexical
opcodes by index and not by name.

> JEff

leo

Jeff Clites

unread,
Nov 8, 2004, 9:54:34 PM11/8/04
to l...@toetsch.at, perl6-i...@perl.org

It doesn't do-the-right-thing in the cases I'm interested in:

% cat pythonClass.py
class A:
def __add__(x,y) : return "boo"

x = A()
y = x + 3
print y
% python pythonClass.py
boo
% perl pie-thon.pl pythonClass.py | ./parrot --python -
Can't find method '__get_number' for object 'py::A'

It looks like it's trying to get the float-value of x, rather than
calling x's __add__ method.

But the part I was really wondering about is the "a + b". This is what
pie-thon.pl produces for that (you can just run it on the code fragment
"a + b"--it doesn't matter the context):

$P1 = new PerlInt # BINARY_ADD
$P1 = a + b

corresponding pasm:

find_global P18, "a"
find_global P17, "b"
new P16, 32 # .PerlInt
add P16, P18, P17

That's what worries me, and what prompted the question. You don't know
at compile-time that the return type should be a PerlInt. It could be
anything--it's really up to "a". This is regarding my concern that the
p_p_p ops aren't very useful (in Python at least), and I can't figure
out what we should be using instead.

So I'm still left wondering, how *should* this compile?

JEff

Leopold Toetsch

unread,
Nov 9, 2004, 2:42:51 AM11/9/04
to Jeff Clites, Perl 6 Internals
Jeff Clites wrote:
> % cat pythonClass.py
> class A:
> def __add__(x,y) : return "boo"

Only a few standard methods are implemented. __add__ IIRC isn't.

> new P16, 32 # .PerlInt
> add P16, P18, P17
>
> That's what worries me, and what prompted the question. You don't know
> at compile-time that the return type should be a PerlInt.

Yes, I've already stated that this needs fixing and I've proposed a
scheme how to fix it.

leo

Jeff Clites

unread,
Nov 9, 2004, 3:58:02 AM11/9/04
to Leopold Toetsch, Perl 6 Internals
On Nov 8, 2004, at 11:42 PM, Leopold Toetsch wrote:

> Jeff Clites wrote:
>
>> new P16, 32 # .PerlInt
>> add P16, P18, P17
>> That's what worries me, and what prompted the question. You don't
>> know at compile-time that the return type should be a PerlInt.
>
> Yes, I've already stated that this needs fixing and I've proposed a
> scheme how to fix it.

Fine then, but in the scheme you recently mentioned, you were
explicitly null-ing out the return register. That shouldn't be
needed--unnecessary overhead. That is, unless we're assuming the
semantics of references types--that the return register would hold a
reference object to store into, always. But I don't think we can mix
the behaviors--unless there's some special flag on a PMC to indicate
that it's a reference type, but that seems awkward. But since the
pie-thon output doesn't do that, I'll assume the plan is not to use
such reference types, if that's meant to be the canonical example.

JEff

Dan Sugalski

unread,
Nov 9, 2004, 9:14:36 AM11/9/04
to Jeff Clites, l...@toetsch.at, perl6-i...@perl.org
At 6:54 PM -0800 11/8/04, Jeff Clites wrote:
>But the part I was really wondering about is the "a + b". This is
>what pie-thon.pl produces for that (you can just run it on the code
>fragment "a + b"--it doesn't matter the context):
>
> $P1 = new PerlInt # BINARY_ADD
> $P1 = a + b
>
>corresponding pasm:
>
> find_global P18, "a"
> find_global P17, "b"
> new P16, 32 # .PerlInt
> add P16, P18, P17
>
>That's what worries me, and what prompted the question. You don't
>know at compile-time that the return type should be a PerlInt. It
>could be anything--it's really up to "a". This is regarding my
>concern that the p_p_p ops aren't very useful (in Python at least),
>and I can't figure out what we should be using instead.

Right. PerlInt is wrong. The destination type for the intermediates
should be Undef, which changes itself on assignment to the proper
type.
--
Dan

--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

0 new messages