/* Closure.pmc
 *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
 *  CVS Info
 *     $Id: closure.pmc,v 1.7 2003/08/28 08:11:05 leo Exp $
 *  Overview:
 *     These are the vtable functions for the Closure (subroutine) base class.
 *     This are subroutines which take a context structure.
 *  Data Structure and Algorithms:
 *  History:
 *     Initial version by Leo.
 *  Notes:
 *  References:
 */

#include "parrot/parrot.h"
#include "parrot/method_util.h"

pmclass Closure extends Sub {

   void init () {
       PMC_sub(SELF) = new_closure(INTERP);
       SELF->cache.struct_val = NULL;
       PObj_custom_mark_destroy_SETALL(SELF);
   }

   void mark () {
        struct Parrot_Sub * sub = (struct Parrot_Sub *)PMC_sub(SELF);
        mark_stack(INTERP, sub->ctx.pad_stack);
        SUPER();	/* mark warns ... in class Sub */
   }



   void* invoke (void* next) {
       struct Parrot_Sub * sub = (struct Parrot_Sub *)PMC_sub(SELF);
       INTERP->ctx.pad_stack = sub->ctx.pad_stack;
       return SUPER(next);
   }

   void clone (PMC *ret) {
       struct Parrot_Sub * sub;
       SUPER(ret);
       sub = PMC_sub(ret);
       stack_mark_cow(sub->ctx.pad_stack);
   }

    void set_same (PMC* value) {
	PMC_sub(SELF) = PMC_sub(value);
	SELF->cache.struct_val = value->cache.struct_val;
    }

    INTVAL is_equal (PMC* value) {
	return (SELF->vtable == value->vtable &&
		SELF->cache.struct_val == value->cache.struct_val &&
		memcmp(PMC_sub(value), PMC_sub(SELF),
		    sizeof(struct Parrot_Sub)) == 0);
    }

}
