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

pirate status / need help with instances

8 views
Skip to first unread message

Michal Wallace

unread,
Aug 11, 2003, 5:47:59 AM8/11/03
to perl6-i...@perl.org

Just wrapping up an all-night coding spree...
Py-pirate can now handle:

- functions (closures, recursion, etc)
- global variables
- tuples (but they turn into lists)
- dictionaries (create, setitem, getitem, print)
- list comprehensions
- raise (strings only)
- try...except (partial)
- try...finally
- assert

The only "tricky" parts left for the code
generator are classes, exec/eval/import,
and possibly slices.

Right now, I'm a bit stuck with classes. I've
got the class statement working, and it creates
a parrot class... But I'm not quite sure
how to instantiate a class.

The problem is that for:

class Clown:
pass

I have a lexical variable "Clown" pointing at
a parrotclass pmc.

However, when I go to instantiate Clown, I do
this:

bozo = Clown()

There's no "new" operator like in java, so
the problem is that this looks just like a
function call to python. So I have to figure
out whether to call "invoke" or "new"... Though
now that I think about it, I'm not really sure
what operator to use to make a new instance.

Anyway, there's no way to tell at compile-time
whether something is a constructor or a normal
function... So I'm trying to decide between two
approaches:

* make parrotclass handle "invoke"
this strikes me as the most efficient,
but I'm not really confident with C
so I'm hesitant to try it

* grab the lexical, check whether it's a class,
and if so, do "newclass" instead of "invoke".

I also thought about making a constructor into
just a normal function, but then the lexical would
have to bind to either the class or the function,
and that's no good because classes and functions
can both have attributes in python.

Any advice?

Sincerely,

Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: mic...@sabren.com
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
--------------------------------------


Sean O'Rourke

unread,
Aug 11, 2003, 9:43:18 AM8/11/03
to Michal Wallace, perl6-i...@perl.org
Michal Wallace <mic...@sabren.com> writes:
> Py-pirate can now handle:

Cool...

> * make parrotclass handle "invoke"
> this strikes me as the most efficient,
> but I'm not really confident with C
> so I'm hesitant to try it

This seems to me like the way to go, except you might
subclass parrotclass to pythonclass (since this lack-
of-"new" seems to be the "Pythonic way"). The C should
pretty much just turn around and call pmc_new, then
return the original return address that was passed in.

/s

K Stol

unread,
Aug 11, 2003, 7:27:59 PM8/11/03
to Michal Wallace, Sean O'Rourke, perl6-i...@perl.org

I may be wrong, but where should the class be stored? The newclass op has an
out-parameter
where the newly created class is stored. Invoke doesn't have that. (right?)

Klaas-Jan

> /s
>
>


Sean O'Rourke

unread,
Aug 11, 2003, 10:36:47 AM8/11/03
to K Stol, Michal Wallace, perl6-i...@perl.org
"K Stol" <k...@home.nl> writes:
> I may be wrong, but where should the class be stored?
> The newclass op has an out-parameter where the newly
> created class is stored. Invoke doesn't have
> that. (right?)

Presumably it would just return the new object like an
ordinary function call.

/s

K Stol

unread,
Aug 11, 2003, 7:50:11 PM8/11/03
to Sean O'Rourke, Michal Wallace, perl6-i...@perl.org

----- Original Message -----
From: "Sean O'Rourke" <soro...@cs.ucsd.edu>
To: "K Stol" <k...@home.nl>
Cc: "Michal Wallace" <mic...@sabren.com>; <perl6-i...@perl.org>
Sent: Monday, August 11, 2003 7:36 AM
Subject: Re: pirate status / need help with instances

invoke is defined in core.ops, and the return value of the PMC
implementation should be an address, because
this result is used in the GOTO macro. So, only an address can be returned.

KJ
> /s
>
>


Sean O'Rourke

unread,
Aug 11, 2003, 11:19:23 AM8/11/03
to K Stol, Michal Wallace, perl6-i...@perl.org
"K Stol" <k...@home.nl> writes:
> invoke is defined in core.ops, and the return value
> of the PMC implementation should be an address,
> because this result is used in the GOTO macro. So,
> only an address can be returned.

Sorry, I mean "return" in the parrot sense, i.e. place
on top of the stack, or put in P5, or whatever your
calling convention would be for normal language
subroutines.

/s

Brent Dax

unread,
Aug 11, 2003, 6:38:54 PM8/11/03
to Sean O'Rourke, Michal Wallace, perl6-i...@perl.org
Sean O'Rourke:
# > * make parrotclass handle "invoke"
# > this strikes me as the most efficient,
# > but I'm not really confident with C
# > so I'm hesitant to try it
#
# This seems to me like the way to go, except you might
# subclass parrotclass to pythonclass (since this lack-
# of-"new" seems to be the "Pythonic way"). The C should
# pretty much just turn around and call pmc_new, then
# return the original return address that was passed in.

I don't think this is the answer, because...

use PythonClass;
$pyobj=PythonClass.new(); #Doesn't work--need to somehow
invoke
# the class

#Sorry, I'm not very familiar with Python...
import PerlClass
plobj=PerlClass() #Doesn't work--need .new

I think this is a syntactic issue, not a semantic issue; as such, it
needs to be dealt with at the syntactic (bytecode) level, not the
semantic (PMC) level.

--Brent Dax <br...@brentdax.com>
Perl and Parrot hacker

"Yeah, and my underwear is flame-retardant--that doesn't mean I'm gonna
set myself on fire to prove it."

Michal Wallace

unread,
Aug 11, 2003, 7:08:56 PM8/11/03
to Brent Dax, Sean O'Rourke, perl6-i...@perl.org
On Mon, 11 Aug 2003, Brent Dax wrote:

> Sean O'Rourke:
> # > * make parrotclass handle "invoke"
> # > this strikes me as the most efficient,
> # > but I'm not really confident with C
> # > so I'm hesitant to try it
> #
> # This seems to me like the way to go, except you might
> # subclass parrotclass to pythonclass (since this lack-
> # of-"new" seems to be the "Pythonic way"). The C should
> # pretty much just turn around and call pmc_new, then
> # return the original return address that was passed in.
>
> I don't think this is the answer, because...
>
> use PythonClass;
> $pyobj=PythonClass.new(); #Doesn't work--need to somehow
> invoke
> # the class
>
> #Sorry, I'm not very familiar with Python...
> import PerlClass
> plobj=PerlClass() #Doesn't work--need .new
>
> I think this is a syntactic issue, not a semantic issue; as such, it
> needs to be dealt with at the syntactic (bytecode) level, not the
> semantic (PMC) level.

Actually, python has a magic method called __new__.
__new__ actually creates an object (so it gives you
the ability to make meta-classes, which we'd also
need for ruby. Once __new__ is called and the object
is around, python then calls __init__.

> plobj=PerlClass() #Doesn't work--need .new

What DOES this do?

It seems to me that parrotclass could still have invoke
for languages that use it, and that perlclass should
just throw an exception if you try it.

There's no problem doing PerlClass.new() from python. It
wouldn't be transparent, but that's fine. It's a small
price to pay, and if PerlClass() threw an exception
remind us to use it, then it probably wouldn't be a
problem at all.

So I think invoke on the parrotclass is the way to go.

Togos

unread,
Aug 11, 2003, 7:34:08 PM8/11/03
to perl6-i...@perl.org

--- Brent Dax <br...@brentdax.com> wrote:
> Sean O'Rourke:
> # > * make parrotclass handle "invoke"
> # > this strikes me as the most efficient,
> # > but I'm not really confident with C
> # > so I'm hesitant to try it
> #
> # This seems to me like the way to go,
> # except you might subclass parrotclass
> # to pythonclass (since this lack-

> # of-"new" seems to be the "Pythonic way"). The C
> # should pretty much just turn around and call
> # pmc_new, then return the original return address
> # that was passed in.

>
> I think this is a syntactic issue, not a semantic
> issue; as such, it
> needs to be dealt with at the syntactic (bytecode)
> level, not the
> semantic (PMC) level.

Well the fact of the matter is that
Python classes behave as subroutines
that produce instances hen they're
invoked. That's definitely a semantic
issue. You wouldn't want to pass your
class to a function written in Perl
expecting it to be able to call the
thing but have it not work. And given
that Parrot already has a framework
for using anonymous subroutines in place,
I don't see that adding an invoke method
is a big deal.

> I don't think this is the answer, because...
>
> use PythonClass;
> $pyobj=PythonClass.new(); # Doesn't

> # work--need to somehow invoke >
# the class

Just because you can invoke it and get an instance
doesn't mean you can't also get an instance
by calling the 'new' method.

> # Sorry, I'm not very familiar with Python...


> import PerlClass
> plobj=PerlClass() #Doesn't work--need .new

Solution: have all classes (python and otherwise)
respond to invoke by creating a new instance :-)
Unless there's some language in which invoking
a class does something else, I don't see that there
would be any problem with this approach.


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Leopold Toetsch

unread,
Aug 12, 2003, 4:13:53 AM8/12/03
to Michal Wallace, perl6-i...@perl.org
Michal Wallace <mic...@sabren.com> wrote:

> class Clown:
> pass

> I have a lexical variable "Clown" pointing at
> a parrotclass pmc.

> However, when I go to instantiate Clown, I do
> this:

First parrot objects aren't that finished, that you can instantiate an
object...

> bozo = Clown()

... but for this you will have either to subclass ParrotClass or
ParrotClass provides everything in a general way so that on invoke() the
__new__ and __init__ hooks are called.

Anyway, its a function call and the return result in P5 is your new
object.

> ... So I'm trying to decide between two
> approaches:

3) wait until classes and objects are done ;-)

> Sincerely,
>
> Michal J Wallace

leo

Michal Wallace

unread,
Aug 12, 2003, 7:44:49 AM8/12/03
to Leopold Toetsch, perl6-i...@perl.org
On Tue, 12 Aug 2003, Leopold Toetsch wrote:

> > ... So I'm trying to decide between two
> > approaches:
>
> 3) wait until classes and objects are done ;-)

4) simulate an object system with closures :)

I wound up getting a couple C books today. I'm
trying to see what I can do about wrapping
PyObject as a PMC...

Michal Wallace

unread,
Aug 12, 2003, 8:46:42 AM8/12/03
to Leopold Toetsch, perl6-i...@perl.org
On Tue, 12 Aug 2003, Michal Wallace wrote:

> I wound up getting a couple C books today. I'm
> trying to see what I can do about wrapping
> PyObject as a PMC...

What's the secret to making parrot recognize
a new PMC? I've got my .pmc file but I'm
not sure what to do next. The article about
making PMC's on perl.com is WAY out of date.

(I don't care if I can't load it dynamically
yet, I just want to get it running at all!)

K Stol

unread,
Aug 12, 2003, 5:51:13 PM8/12/03
to Michal Wallace, Leopold Toetsch, perl6-i...@perl.org

----- Original Message -----
From: "Michal Wallace" <mic...@sabren.com>
To: "Leopold Toetsch" <l...@toetsch.at>
Cc: <perl6-i...@perl.org>
Sent: Tuesday, August 12, 2003 5:46 AM
Subject: Re: pirate status / need help with instances

> On Tue, 12 Aug 2003, Michal Wallace wrote:
>
> > I wound up getting a couple C books today. I'm
> > trying to see what I can do about wrapping
> > PyObject as a PMC...
>
> What's the secret to making parrot recognize
> a new PMC? I've got my .pmc file but I'm
> not sure what to do next. The article about
> making PMC's on perl.com is WAY out of date.
>

1. create your PMC class, add it to the classes/ directory
2. add the file to MANIFEST in the Parrot root dir.
: classes/pythonclass.pmc []
( I don't know what the "[]" mean)
3. ./Configure.pl (which uses MANIFEST)
4. make

This works for me.

Klaas-Jan

Juergen Boemmels

unread,
Aug 12, 2003, 9:18:53 AM8/12/03
to K Stol, Michal Wallace, Leopold Toetsch, perl6-i...@perl.org
"K Stol" <k...@home.nl> writes:

> > What's the secret to making parrot recognize
> > a new PMC? I've got my .pmc file but I'm
> > not sure what to do next. The article about
> > making PMC's on perl.com is WAY out of date.
> >
>
> 1. create your PMC class, add it to the classes/ directory
> 2. add the file to MANIFEST in the Parrot root dir.
> : classes/pythonclass.pmc []
> ( I don't know what the "[]" mean)

The "[]" have something todo with RPM generation, previously known as
MANIFEST.detailed
see http://groups.google.com/groups?selm=Pine.SOL.4.53.0305010847240.27446%40maxwell.phys.lafayette.edu

2a. make realclean
The Makefiles don't contain all dependencies, and you can get funny
problems when you dont make realclean here. This is a known problem.

> 3. ./Configure.pl (which uses MANIFEST)
> 4. make

bye
boe

Leopold Toetsch

unread,
Aug 12, 2003, 9:38:39 AM8/12/03
to Michal Wallace, perl6-i...@perl.org
Michal Wallace <mic...@sabren.com> wrote:

> What's the secret to making parrot recognize
> a new PMC? I've got my .pmc file but I'm
> not sure what to do next.

Additionally to the static approach, you could try dynclasses/README.

0 new messages