What's the cleanest way to return a new PMC from an op?
e.g. Suppose I have a Vec2D_in_X_plane and a Vec2D_in_Y_plane and I add them
and want to always produce a Vec3D - is this correct (and is it efficient?):
void add(PMC* value, PMC* dest) {
if(value->vtable == &Parrot_base_vtables[enum_class_Vec2D_in_Y_plane]) {
PMC* ret = pmc_new(INTERP,enum_class_Vec3D);
/* set the correct x,y,z coords somehow (method? property?) */
if(dest->flags & PMC_active_destroy_FLAG)
dest->vtable->destroy(interpreter,dest);
*dest = *ret;
} else
/* handle other cases, crash and burn, whatever */
}
(Arising from this is: how do I check the type of an extension PMC? which I
presume still isn't supported so I'll accept "you can't, yet, because there
aren't any.")
(Yes, this is a bit of a stealth resurrection of part of the logical_not
thread, separated out into its own question; substitude "logical_not" for
"add", "RubyInteger" for "Vec3D_in_X_plane", and "RubyBoolean" for "Vec3D".)
Dave
Isa. 40:31