Front page | perl.perl6.internals |
Postings from February 2001
Re: PDD 2, vtables
From:
Simon Cozens
Date:
February 17, 2001 08:56
Subject:
Re: PDD 2, vtables
Message ID:
20010217165545.A24826@pembro26.pmb.ox.ac.uk
On Mon, Feb 05, 2001 at 05:14:44PM -0500, Dan Sugalski wrote:
> =item new
>
> void new(PMC[, key]);
>
> Creates a new variable of the appropriate type out of the passed PMC,
> destroying the current contents if there are any. This is a class
> function.
Can I suggest this becomes
PMC new(PMC[, key]);
It gets really hard to get things started otherwise:
PMC mypmc;
(sviv_vtable.new)(mypmc);
printf("mypmc's class is %s\n", (mypmc->vtbl->name)(mypmc));
If PMC is a pointer to a structure, "new" will need to allocate memory for a
new structure, and hence the value of mypmc will have to change. So I'd rather
say
PMC mypmc;
mypmc = (sviv_vtable.new)(mypmc); /* Old value of mypmc is ignored */
Unless it's a pointer to a pointer to a structure. Which is possible, but
yuck.
The structure
struct _pmc {
VTABLE* vtbl;
void* private_data;
};
makes it nice and easy to morph one PMC class into another; the "new" entry in
the hypothetical sviv_vtable becomes:
PMC int_new(PMC pmc, ...) {
if (pmc)
(pmc->vtbl->destroy)(pmc);
else
pmc = (PMC)malloc(sizeof(PMC));
pmc->vtbl = &sviv_vtable;
pmc->private_data = (IV*)malloc(sizeof(IV*));
return pmc;
}
--
If you give a man a fire, he'll be warm for a day. If you set a man on fire,
he'll be warm for the rest of his life.
-
Re: require < 6.x
by Brent Dax
-
PDD 2, vtables
by Dan Sugalski
-
Re: PDD 2, vtables
by Branden
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by David Mitchell
-
Re: PDD 2, vtables
by Dan Sugalski
-
Re: PDD 2, vtables
by Simon Cozens
-
Re: PDD 2, vtables
by Dan Sugalski
-
Re: PDD 2, vtables
by Edwin Steiner
-
Re: PDD 2, vtables
by Dan Sugalski
-
Re: PDD 2, vtables
by Tim Bunce
-
Re: PDD 2, vtables
by Branden