goops.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* classes: h_files */
  2. #ifndef SCM_GOOPS_H
  3. #define SCM_GOOPS_H
  4. /* Copyright (C) 1998,1999,2000,2001 Free Software Foundation, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice. */
  44. /* This software is a derivative work of other copyrighted softwares; the
  45. * copyright notices of these softwares are placed in the file COPYRIGHTS
  46. *
  47. * This file is based upon stklos.h from the STk distribution by
  48. * Erick Gallesio <eg@unice.fr>.
  49. */
  50. #include "libguile/__scm.h"
  51. #include "libguile/validate.h"
  52. /*
  53. * scm_class_class
  54. */
  55. #define SCM_CLASS_CLASS_LAYOUT "pruosrpwpopopwururururururururpwpwpwpwpwpwpwpwpwpwpwpw"
  56. #define scm_si_layout 0 /* the struct layout */
  57. #define scm_si_vcell 1
  58. #define scm_si_vtable 2
  59. #define scm_si_print 3 /* the struct print closure */
  60. #define scm_si_proc 4
  61. #define scm_si_setter 5
  62. #define scm_si_goops_fields 6
  63. /* Defined in libguile/objects.c:
  64. #define scm_si_redefined 6 The class to which class was redefined.
  65. #define scm_si_hashsets 7
  66. */
  67. #define scm_si_name 15 /* a symbol */
  68. #define scm_si_direct_supers 16 /* (class ...) */
  69. #define scm_si_direct_slots 17 /* ((name . options) ...) */
  70. #define scm_si_direct_subclasses 18 /* (class ...) */
  71. #define scm_si_direct_methods 19 /* (methods ...) */
  72. #define scm_si_cpl 20 /* (class ...) */
  73. #define scm_si_slotdef_class 21
  74. #define scm_si_slots 22 /* ((name . options) ...) */
  75. #define scm_si_name_access 23
  76. #define scm_si_keyword_access 24
  77. #define scm_si_nfields 25 /* an integer */
  78. #define scm_si_environment 26 /* The environment in which class is built */
  79. #define SCM_N_CLASS_SLOTS 27
  80. typedef struct scm_t_method {
  81. SCM generic_function;
  82. SCM specializers;
  83. SCM procedure;
  84. } scm_t_method;
  85. #define SCM_METHOD(obj) ((scm_t_method *) SCM_STRUCT_DATA (obj))
  86. #define SCM_CLASSF_SIMPLE_METHOD (0x004 << 20)
  87. #define SCM_CLASSF_ACCESSOR_METHOD (0x008 << 20)
  88. /* Defined in libguile/objects.c */
  89. /* #define SCM_CLASSF_PURE_GENERIC (0x010 << 20) */
  90. #define SCM_CLASSF_FOREIGN (0x020 << 20)
  91. #define SCM_CLASSF_METACLASS (0x040 << 20)
  92. /* Defined in libguile/objects.c */
  93. /* #define SCM_CLASSF_GOOPS_VALID (0x080 << 20) */
  94. /* #define SCM_CLASSF_GOOPS (0x100 << 20) */
  95. #define SCM_CLASSF_GOOPS_OR_VALID (SCM_CLASSF_GOOPS | SCM_CLASSF_GOOPS_VALID)
  96. #define SCM_CLASSF_INHERIT (~(SCM_CLASSF_PURE_GENERIC \
  97. | SCM_CLASSF_SIMPLE_METHOD \
  98. | SCM_CLASSF_ACCESSOR_METHOD \
  99. | SCM_STRUCTF_LIGHT) \
  100. & SCM_CLASSF_MASK)
  101. #define SCM_INST(x) SCM_STRUCT_DATA (x)
  102. /* Also defined in libguile/objects.c */
  103. #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
  104. #define SCM_ACCESSORS_OF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (x)[scm_si_getters_n_setters]))
  105. #define SCM_NUMBER_OF_SLOTS(x) \
  106. (SCM_UNPACK (SCM_STRUCT_DATA (x)[scm_struct_i_n_words]) \
  107. - scm_struct_n_extra_words)
  108. #define SCM_CLASSP(x) \
  109. (SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS)
  110. #define SCM_VALIDATE_CLASS(pos, x) SCM_MAKE_VALIDATE (pos, x, CLASSP)
  111. #define SCM_INSTANCEP(x) \
  112. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_GOOPS))
  113. #define SCM_VALIDATE_INSTANCE(pos, x) SCM_MAKE_VALIDATE (pos, x, INSTANCEP)
  114. #define SCM_PUREGENERICP(x) \
  115. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_PURE_GENERIC))
  116. #define SCM_VALIDATE_PUREGENERIC(pos, x) SCM_MAKE_VALIDATE (pos, x, PUREGENERICP)
  117. #define SCM_ACCESSORP(x) \
  118. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_ACCESSOR_METHOD))
  119. #define SCM_VALIDATE_ACCESSOR(pos, x) SCM_MAKE_VALIDATE (pos, x, ACCESSORP)
  120. #define SCM_SLOT(x, i) (SCM_PACK (SCM_INST (x) [i]))
  121. #define SCM_SET_SLOT(x, i, v) (SCM_INST (x) [i] = SCM_UNPACK (v))
  122. #define SCM_SET_HASHSET(c, i, h) (SCM_INST (c) [scm_si_hashsets + (i)] = (h))
  123. #define SCM_SUBCLASSP(c1, c2) (!SCM_FALSEP (scm_c_memq (c2, SCM_SLOT (c1, scm_si_cpl))))
  124. #define SCM_IS_A_P(x, c) \
  125. (SCM_INSTANCEP (x) && SCM_SUBCLASSP (SCM_CLASS_OF (x), c))
  126. #define SCM_GENERICP(x) \
  127. (SCM_INSTANCEP (x) && SCM_SUBCLASSP (SCM_CLASS_OF (x), scm_class_generic))
  128. #define SCM_VALIDATE_GENERIC(pos, x) SCM_MAKE_VALIDATE (pos, x, GENERICP)
  129. #define SCM_METHODP(x) \
  130. (SCM_INSTANCEP (x) && SCM_SUBCLASSP (SCM_CLASS_OF (x), scm_class_method))
  131. #define SCM_VALIDATE_METHOD(pos, x) SCM_MAKE_VALIDATE (pos, x, METHODP)
  132. #define SCM_MCACHE_N_SPECIALIZED(C) SCM_CADDR (C)
  133. #define SCM_SET_MCACHE_N_SPECIALIZED(C, X) SCM_SETCAR (SCM_CDDR (C), X)
  134. #define SCM_INITIAL_MCACHE_SIZE 1
  135. #define scm_si_getters_n_setters scm_si_name_access
  136. #define scm_si_constructor SCM_N_CLASS_SLOTS
  137. #define scm_si_destructor SCM_N_CLASS_SLOTS + 1
  138. #define scm_si_methods 0 /* offset of methods slot in a <generic> */
  139. #define scm_si_n_specialized 1
  140. #define scm_si_used_by 2
  141. #define scm_si_cache_mutex 3
  142. #define scm_si_generic_function 0 /* offset of gf slot in a <method> */
  143. #define scm_si_specializers 1 /* offset of spec. slot in a <method> */
  144. #define scm_si_procedure 2 /* offset of proc. slot in a <method> */
  145. #define scm_si_code_table 3 /* offset of code. slot in a <method> */
  146. /* C interface */
  147. extern SCM scm_class_top, scm_class_object, scm_class_class;
  148. extern SCM scm_class_entity, scm_class_entity_with_setter;
  149. extern SCM scm_class_generic, scm_class_generic_with_setter, scm_class_method;
  150. extern SCM scm_class_simple_method, scm_class_accessor;
  151. extern SCM scm_class_procedure_class;
  152. extern SCM scm_class_operator_class, scm_class_operator_with_setter_class;
  153. extern SCM scm_class_entity_class;
  154. extern SCM scm_class_number, scm_class_list;
  155. extern SCM scm_class_keyword;
  156. extern SCM scm_class_port, scm_class_input_output_port;
  157. extern SCM scm_class_input_port, scm_class_output_port;
  158. extern SCM scm_class_foreign_class, scm_class_foreign_object;
  159. extern SCM scm_class_foreign_slot;
  160. extern SCM scm_class_self, scm_class_protected;
  161. extern SCM scm_class_opaque, scm_class_read_only;
  162. extern SCM scm_class_protected_opaque, scm_class_protected_read_only;
  163. extern SCM scm_class_scm;
  164. extern SCM scm_class_int, scm_class_float, scm_class_double;
  165. extern const char *scm_s_slot_set_x;
  166. extern SCM scm_module_goops;
  167. SCM scm_goops_version (void);
  168. SCM scm_oldfmt (SCM);
  169. char *scm_c_oldfmt0 (char *);
  170. char *scm_c_oldfmt (char *, int n);
  171. void scm_load_goops (void);
  172. SCM scm_make_foreign_object (SCM cls, SCM initargs);
  173. SCM scm_make_class (SCM meta, char *s_name, SCM supers, size_t size,
  174. void * (*constructor) (SCM initargs),
  175. size_t (*destructor) (void *));
  176. void scm_add_slot (SCM c, char *slot, SCM slot_class,
  177. SCM (*getter) (SCM obj),
  178. SCM (*setter) (SCM obj, SCM x),
  179. char *accessor_name);
  180. SCM scm_wrap_object (SCM c, void *);
  181. SCM scm_wrap_component (SCM c, SCM obj, void *);
  182. SCM scm_ensure_accessor (SCM name);
  183. void scm_add_method (SCM gf, SCM m);
  184. /* Low level functions exported */
  185. SCM scm_make_next_method (SCM methods, SCM args, SCM gf);
  186. SCM scm_basic_basic_make_class (SCM c, SCM name, SCM dsupers, SCM dslots);
  187. SCM scm_basic_make_class (SCM c, SCM name, SCM dsupers, SCM dslots);
  188. /* Primitives exported */
  189. SCM scm_sys_allocate_instance (SCM c, SCM initargs);
  190. SCM scm_sys_set_object_setter_x (SCM obj, SCM setter);
  191. SCM scm_slot_ref (SCM obj, SCM slot_name);
  192. SCM scm_slot_set_x (SCM obj, SCM slot_name, SCM value);
  193. SCM scm_compute_applicable_methods (SCM gf, SCM args, long len, int scm_find_method);
  194. SCM scm_sys_compute_applicable_methods (SCM gf, SCM args);
  195. SCM scm_m_atslot_ref (SCM xorig, SCM env);
  196. SCM scm_m_atslot_set_x (SCM xorig, SCM env);
  197. SCM scm_m_atdispatch (SCM xorig, SCM env);
  198. #ifdef GUILE_DEBUG
  199. SCM scm_pure_generic_p (SCM obj);
  200. #endif
  201. SCM scm_sys_compute_slots (SCM c);
  202. SCM scm_i_get_keyword (SCM key, SCM l, long len, SCM default_value, const char *subr);
  203. SCM scm_get_keyword (SCM key, SCM l, SCM default_value);
  204. SCM scm_sys_initialize_object (SCM obj, SCM initargs);
  205. SCM scm_sys_prep_layout_x (SCM c);
  206. SCM scm_sys_inherit_magic_x (SCM c, SCM dsupers);
  207. SCM scm_instance_p (SCM obj);
  208. SCM scm_class_name (SCM obj);
  209. SCM scm_class_direct_supers (SCM obj);
  210. SCM scm_class_direct_slots (SCM obj);
  211. SCM scm_class_direct_subclasses (SCM obj);
  212. SCM scm_class_direct_methods (SCM obj);
  213. SCM scm_class_precedence_list (SCM obj);
  214. SCM scm_class_slots (SCM obj);
  215. SCM scm_class_environment (SCM obj);
  216. SCM scm_generic_function_name (SCM obj);
  217. SCM scm_generic_function_methods (SCM obj);
  218. SCM scm_method_generic_function (SCM obj);
  219. SCM scm_method_specializers (SCM obj);
  220. SCM scm_method_procedure (SCM obj);
  221. SCM scm_accessor_method_slot_definition (SCM obj);
  222. SCM scm_sys_tag_body (SCM body);
  223. SCM scm_sys_fast_slot_ref (SCM obj, SCM index);
  224. SCM scm_sys_fast_slot_set_x (SCM obj, SCM index, SCM value);
  225. SCM scm_slot_ref_using_class (SCM cls, SCM obj, SCM slot_name);
  226. SCM scm_slot_set_using_class_x (SCM cls, SCM obj, SCM slot_name, SCM value);
  227. SCM scm_slot_bound_using_class_p (SCM cls, SCM obj, SCM slot_name);
  228. SCM scm_slot_exists_using_class_p (SCM cls, SCM obj, SCM slot_name);
  229. SCM scm_slot_bound_p (SCM obj, SCM slot_name);
  230. SCM scm_slot_exists_p (SCM obj, SCM slot_name);
  231. SCM scm_sys_modify_instance (SCM old, SCM newinst);
  232. SCM scm_sys_modify_class (SCM old, SCM newcls);
  233. SCM scm_sys_invalidate_class (SCM cls);
  234. SCM scm_make_method_cache (SCM gf);
  235. SCM scm_sys_invalidate_method_cache_x (SCM gf);
  236. SCM scm_generic_capability_p (SCM proc);
  237. SCM scm_enable_primitive_generic_x (SCM subrs);
  238. SCM scm_primitive_generic_generic (SCM subr);
  239. SCM stklos_version (void);
  240. SCM scm_make (SCM args);
  241. SCM scm_find_method (SCM args);
  242. SCM scm_sys_method_more_specific_p (SCM m1, SCM m2, SCM targs);
  243. SCM scm_init_goops_builtins (void);
  244. void scm_init_goops (void);
  245. #if (SCM_DEBUG_DEPRECATED == 0)
  246. #define SCM_INST_TYPE(x) SCM_OBJ_CLASS_FLAGS (x)
  247. #define SCM_SIMPLEMETHODP(x) \
  248. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_SIMPLE_METHOD))
  249. #define SCM_FASTMETHODP(x) \
  250. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) \
  251. & (SCM_CLASSF_ACCESSOR_METHOD \
  252. | SCM_CLASSF_SIMPLE_METHOD)))
  253. #endif
  254. #endif /* SCM_GOOPS_H */