- 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/
--------------------------------------
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
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
>
>
Presumably it would just return the new object like an
ordinary function call.
/s
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
>
>
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
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."
> 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.
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
> 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
> > ... 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...
> 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!)
> 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
> > 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
> 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.