David Robins wrote:

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]) {

always compare ids (vtables may change) - yes, many pmc's do like above, but will need changes too.


      PMC* ret = pmc_new(INTERP,enum_class_Vec3D);

	morph "dest" to be a "ret"?

unimplemented, unused, but your examples seems to be a typical test case.


      if(dest->flags & PMC_active_destroy_FLAG)
        dest->vtable->destroy(interpreter,dest);

Just forget "dest", it will be collected when unused.


      *dest = *ret;

Brr, will break for sure somewhere. PMCs might even be of different size - Not now, but who knows)


(Arising from this is: how do I check the type of an extension PMC?

All pretty much uncertain in distant fog for me.


Dave

leo




Reply via email to