root/src/gauche/class.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ScmSlotAccessor

   1 /*
   2  * class.h - Gauche object system private header
   3  *
   4  *   Copyright (c) 2000-2005 Shiro Kawai, All rights reserved.
   5  * 
   6  *   Redistribution and use in source and binary forms, with or without
   7  *   modification, are permitted provided that the following conditions
   8  *   are met:
   9  * 
  10  *   1. Redistributions of source code must retain the above copyright
  11  *      notice, this list of conditions and the following disclaimer.
  12  *
  13  *   2. Redistributions in binary form must reproduce the above copyright
  14  *      notice, this list of conditions and the following disclaimer in the
  15  *      documentation and/or other materials provided with the distribution.
  16  *
  17  *   3. Neither the name of the authors nor the names of its contributors
  18  *      may be used to endorse or promote products derived from this
  19  *      software without specific prior written permission.
  20  *
  21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  *  $Id: class.h,v 1.44 2005/09/12 09:22:25 shirok Exp $
  34  */
  35 
  36 #ifndef GAUCHE_CLASS_H
  37 #define GAUCHE_CLASS_H
  38 
  39 SCM_DECL_BEGIN
  40 
  41 /*
  42  * SlotAccessor
  43  *  - Packages slot initialization and accessing methods.
  44  */
  45 typedef struct ScmSlotAccessorRec {
  46     SCM_HEADER;
  47     ScmClass *klass;            /* the class this accessor belongs to.
  48                                    need to be checked before used, for the
  49                                    class may be changed. */
  50     ScmObj name;                /* slot name (symbol) */
  51     ScmObj (*getter)(ScmObj instance); /* getter for C accessor */
  52     void (*setter)(ScmObj instance, ScmObj value); /* setter for C accessor */
  53     ScmObj initValue;           /* :init-value */
  54     ScmObj initKeyword;         /* :init-keyword */
  55     ScmObj initThunk;           /* :initform or :init-thunk */
  56     int initializable;          /* is this slot initializable? */
  57     int slotNumber;             /* for :instance slot access */
  58     ScmObj schemeGetter;        /* for :virtual slot getter; #f if N/A */
  59     ScmObj schemeSetter;        /* for :virtual slot setter; #f if N/A */
  60     ScmObj schemeBoundp;        /* for :virtual slot bound?; #f if N/A */
  61 } ScmSlotAccessor;
  62 
  63 typedef ScmObj (*ScmNativeGetterProc)(ScmObj);
  64 typedef void   (*ScmNativeSetterProc)(ScmObj, ScmObj);
  65 
  66 SCM_CLASS_DECL(Scm_SlotAccessorClass);
  67 #define SCM_CLASS_SLOT_ACCESSOR    (&Scm_SlotAccessorClass)
  68 #define SCM_SLOT_ACCESSOR(obj)     ((ScmSlotAccessor*)obj)
  69 #define SCM_SLOT_ACCESSOR_P(obj)   SCM_XTYPEP(obj, SCM_CLASS_SLOT_ACCESSOR)
  70 
  71 /* for static declaration of fields */
  72 struct ScmClassStaticSlotSpecRec {
  73     const char *name;
  74     ScmSlotAccessor accessor;
  75 };
  76 
  77 #define SCM_CLASS_SLOT_SPEC(name, getter, setter)       \
  78     { name, { {SCM_CLASS2TAG(SCM_CLASS_SLOT_ACCESSOR)}, \
  79               NULL, NULL,                               \
  80               (ScmNativeGetterProc)getter,              \
  81               (ScmNativeSetterProc)setter,              \
  82               SCM_UNBOUND,                              \
  83               SCM_FALSE,                                \
  84               SCM_FALSE,                                \
  85               TRUE, -1,                                 \
  86               SCM_FALSE, SCM_FALSE, SCM_FALSE,          \
  87              } }
  88 
  89 #define SCM_CLASS_SLOT_SPEC_END()   { NULL }
  90 
  91 /*
  92  * AccessorMethod
  93  *  - A special method to be used as a slot accessor
  94  *    It keeps ScmSlotAccessor in data field, and uses specialized
  95  *    routine to access the slot.
  96  */
  97 typedef ScmMethod ScmAccessorMethod;
  98 
  99 SCM_CLASS_DECL(Scm_AccessorMethodClass);
 100 #define SCM_CLASS_ACCESSOR_METHOD    (&Scm_AccessorMethodClass)
 101 #define SCM_ACCESSOR_METHOD(obj)     ((ScmAccessorMethod*)obj)
 102 #define SCM_ACCESSOR_METHOD_P(obj)   SCM_ISA(obj, SCM_CLASS_SLOT_ACCESSOR)
 103 
 104 /* cliche in allocate method */
 105 #define SCM_ALLOCATE(klassname, klass) \
 106     ((klassname*)Scm_AllocateInstance(klass, sizeof(klassname)))
 107 
 108 /* some internal methods */
 109 
 110 SCM_EXTERN ScmObj Scm_ObjectAllocate(ScmClass *klass, ScmObj initargs);
 111 SCM_EXTERN ScmObj Scm_AllocateInstance(ScmClass *klass, int coresize);
 112 SCM_EXTERN ScmObj Scm_ComputeCPL(ScmClass *klass);
 113 SCM_EXTERN ScmObj Scm_ComputeApplicableMethods(ScmGeneric *gf,
 114                                                ScmObj *args,
 115                                                int nargs);
 116 SCM_EXTERN ScmObj Scm_SortMethods(ScmObj methods, ScmObj *args, int nargs);
 117 SCM_EXTERN ScmObj Scm_MakeNextMethod(ScmGeneric *gf, ScmObj methods,
 118                                      ScmObj *args, int nargs, int copyArgs);
 119 SCM_EXTERN ScmObj Scm_AddMethod(ScmGeneric *gf, ScmMethod *method);
 120 SCM_EXTERN ScmObj Scm_DeleteMethod(ScmGeneric *gf, ScmMethod *method);
 121 
 122 SCM_EXTERN ScmObj Scm_VMSlotInitializeUsingAccessor(ScmObj obj,
 123                                                     ScmSlotAccessor *ca,
 124                                                     ScmObj initargs);
 125 SCM_EXTERN ScmObj Scm_VMSlotRefUsingAccessor(ScmObj obj,
 126                                              ScmSlotAccessor *acc,
 127                                              int boundp);
 128 SCM_EXTERN ScmObj Scm_VMSlotSetUsingAccessor(ScmObj obj,
 129                                              ScmSlotAccessor *acc,
 130                                              ScmObj val);
 131 
 132 SCM_EXTERN ScmObj Scm_VMClassOf(ScmObj obj);
 133 SCM_EXTERN ScmObj Scm_VMIsA(ScmObj obj, ScmClass *klass);
 134 
 135 SCM_EXTERN ScmObj Scm_InstanceSlotRef(ScmObj obj, int number);
 136 SCM_EXTERN void   Scm_InstanceSlotSet(ScmObj obj, int number, ScmObj val);
 137 
 138 SCM_EXTERN void   Scm_StartClassRedefinition(ScmClass *klass);
 139 SCM_EXTERN void   Scm_CommitClassRedefinition(ScmClass *klass, ScmObj newk);
 140 SCM_EXTERN ScmObj Scm_CheckClassBinding(ScmObj name, ScmModule *module);
 141 SCM_EXTERN void   Scm_ReplaceClassBinding(ScmClass *klass, ScmClass *newk);
 142 SCM_EXTERN void   Scm_AddDirectSubclass(ScmClass *super, ScmClass *sub);
 143 SCM_EXTERN void   Scm_RemoveDirectSubclass(ScmClass *super, ScmClass *sub);
 144 SCM_EXTERN void   Scm_AddDirectMethod(ScmClass *super, ScmMethod *m);
 145 SCM_EXTERN void   Scm_RemoveDirectMethod(ScmClass *super, ScmMethod *m);
 146 SCM_EXTERN void   Scm_TransplantInstance(ScmObj src, ScmObj dst);
 147 SCM_EXTERN ScmObj Scm_VMTouchInstance(ScmObj obj);
 148 
 149 SCM_EXTERN void   Scm_DeleteDirectSubclass(ScmClass *super, ScmClass *sub);
 150 SCM_EXTERN void   Scm_DeleteDirectMethod(ScmClass *super, ScmMethod *m);
 151 
 152 SCM_EXTERN ScmObj Scm__InternalClassName(ScmClass *klass);
 153 
 154 SCM_EXTERN ScmGeneric Scm_GenericApplyGeneric;
 155 SCM_EXTERN ScmGeneric Scm_GenericObjectHash;
 156 SCM_EXTERN ScmGeneric Scm_GenericObjectApply;
 157 SCM_EXTERN ScmGeneric Scm_GenericObjectSetter;
 158 SCM_EXTERN ScmGeneric Scm_GenericChangeClass;
 159 
 160 SCM_EXTERN ScmObj Scm_UpdateDirectMethod(ScmMethod *m,
 161                                          ScmClass *oldk,
 162                                          ScmClass *newk);
 163 
 164 SCM_DECL_END
 165 
 166 #endif /* GAUCHE_CLASS_H */

/* [<][>][^][v][top][bottom][index][help] */