goops.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef SCM_GOOPS_H
  2. #define SCM_GOOPS_H
  3. /* Copyright 1998-2003,2006,2008-2009,2011,2015,2017-2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. /* This software is a derivative work of other copyrighted softwares; the
  18. * copyright notices of these softwares are placed in the file COPYRIGHTS
  19. *
  20. * This file is based upon stklos.h from the STk distribution by
  21. * Erick Gallesio <eg@unice.fr>.
  22. */
  23. #include "libguile/boolean.h"
  24. #include "libguile/list.h"
  25. #include "libguile/ports.h"
  26. /* {Class flags}
  27. *
  28. * These are used for efficient identification of instances of a
  29. * certain class or its subclasses when traversal of the inheritance
  30. * graph would be too costly.
  31. */
  32. /* Set for all GOOPS classes. */
  33. #define SCM_VTABLE_FLAG_GOOPS_CLASS SCM_VTABLE_FLAG_GOOPS_0
  34. /* Set for GOOPS classes whose instances are <slot> objects. */
  35. #define SCM_VTABLE_FLAG_GOOPS_SLOT SCM_VTABLE_FLAG_GOOPS_1
  36. /* Set for GOOPS classes whose instance's slots must always be allocated
  37. to the same indices, for all concrete subclasses. */
  38. #define SCM_VTABLE_FLAG_GOOPS_STATIC_SLOT_ALLOCATION SCM_VTABLE_FLAG_GOOPS_2
  39. /* Set for GOOPS classes whose instances are "indirect", meaning they
  40. just have one slot that indirects to a direct instance with the
  41. slots. For non-class instances, this is at struct slot 0. For class
  42. instances, it's the first slot after the <class> fixed slots. */
  43. #define SCM_VTABLE_FLAG_GOOPS_INDIRECT SCM_VTABLE_FLAG_GOOPS_3
  44. /* For indirect classes, the slots object itself has a direct vtable.
  45. This flag will be set on that vtable if the instance needs to migrate
  46. to a new class. */
  47. #define SCM_VTABLE_FLAG_GOOPS_NEEDS_MIGRATION SCM_VTABLE_FLAG_GOOPS_4
  48. #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
  49. #define SCM_CLASS_FLAGS(class) (SCM_VTABLE_FLAGS (class))
  50. #define SCM_OBJ_CLASS_FLAGS(obj) (SCM_STRUCT_VTABLE_FLAGS (obj))
  51. #define SCM_SET_CLASS_FLAGS(c, f) (SCM_SET_VTABLE_FLAGS (c, f))
  52. #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLEAR_VTABLE_FLAGS (c, f))
  53. #define SCM_CLASSF_METACLASS (SCM_VTABLE_FLAG_GOOPS_CLASS|SCM_VTABLE_FLAG_VTABLE)
  54. #define SCM_CLASSF_GOOPS SCM_VTABLE_FLAG_GOOPS_CLASS
  55. #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
  56. #define SCM_CLASSP(x) \
  57. (SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS)
  58. #define SCM_VALIDATE_CLASS(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, CLASSP, "class")
  59. #define SCM_INSTANCEP(x) \
  60. (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_GOOPS))
  61. #define SCM_VALIDATE_INSTANCE(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, INSTANCEP, "instance")
  62. #define SCM_SLOT(x, i) (SCM_STRUCT_SLOT_REF (x, i))
  63. #define SCM_SET_SLOT(x, i, v) (SCM_STRUCT_SLOT_SET (x, i, v))
  64. #define SCM_SUBCLASSP(c1, c2) \
  65. (scm_is_true (scm_c_memq (c2, scm_class_precedence_list (c1))))
  66. #define SCM_IS_A_P(x, c) \
  67. (SCM_INSTANCEP (x) && SCM_SUBCLASSP (scm_class_of (x), c))
  68. #define SCM_GENERICP(x) (scm_is_generic (x))
  69. #define SCM_VALIDATE_GENERIC(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, GENERICP, "generic function")
  70. #define SCM_METHODP(x) (scm_is_method (x))
  71. #define SCM_VALIDATE_METHOD(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, METHODP, "method")
  72. #define SCM_SET_CLASS_DESTRUCTOR(c, d) SCM_SET_VTABLE_DESTRUCTOR (c, d)
  73. SCM_INTERNAL SCM scm_i_smob_class[];
  74. SCM_API SCM scm_module_goops;
  75. SCM_API SCM scm_goops_version (void);
  76. SCM_API void scm_load_goops (void);
  77. SCM_API SCM scm_make_extended_class (char const *type_name, int applicablep);
  78. SCM_INTERNAL void scm_make_port_classes (scm_t_port_type *ptob);
  79. SCM_API SCM scm_ensure_accessor (SCM name);
  80. SCM_API SCM scm_class_of (SCM obj);
  81. /* Low level functions exported */
  82. SCM_INTERNAL SCM scm_make_standard_class (SCM meta, SCM name, SCM dsupers,
  83. SCM dslots);
  84. /* Primitives exported */
  85. SCM_API SCM scm_slot_ref (SCM obj, SCM slot_name);
  86. SCM_API SCM scm_slot_set_x (SCM obj, SCM slot_name, SCM value);
  87. SCM_INTERNAL void scm_i_inherit_applicable (SCM c);
  88. SCM_API SCM scm_instance_p (SCM obj);
  89. SCM_API int scm_is_generic (SCM x);
  90. SCM_API int scm_is_method (SCM x);
  91. SCM_API SCM scm_class_name (SCM obj);
  92. SCM_API SCM scm_class_direct_supers (SCM obj);
  93. SCM_API SCM scm_class_direct_slots (SCM obj);
  94. SCM_API SCM scm_class_direct_subclasses (SCM obj);
  95. SCM_API SCM scm_class_direct_methods (SCM obj);
  96. SCM_API SCM scm_class_precedence_list (SCM obj);
  97. SCM_API SCM scm_class_slots (SCM obj);
  98. SCM_API SCM scm_generic_function_name (SCM obj);
  99. SCM_API SCM scm_generic_function_methods (SCM obj);
  100. SCM_API SCM scm_method_generic_function (SCM obj);
  101. SCM_API SCM scm_method_specializers (SCM obj);
  102. SCM_API SCM scm_method_procedure (SCM obj);
  103. SCM_API SCM scm_slot_bound_p (SCM obj, SCM slot_name);
  104. SCM_API SCM scm_slot_exists_p (SCM obj, SCM slot_name);
  105. SCM_API SCM scm_sys_modify_instance (SCM old, SCM newinst);
  106. SCM_API SCM scm_generic_capability_p (SCM proc);
  107. SCM_API SCM scm_enable_primitive_generic_x (SCM subrs);
  108. SCM_INTERNAL SCM scm_set_primitive_generic_x (SCM subr, SCM generic);
  109. SCM_API SCM scm_primitive_generic_generic (SCM subr);
  110. SCM_API SCM scm_make (SCM args);
  111. /* These procedures are for dispatching to a generic when a primitive
  112. fails to apply. They raise a wrong-type-arg error if the primitive's
  113. generic has not been initialized yet. */
  114. SCM_API SCM scm_wta_dispatch_0 (SCM gf, const char *subr);
  115. SCM_API SCM scm_wta_dispatch_1 (SCM gf, SCM a1, int pos, const char *subr);
  116. SCM_API SCM scm_wta_dispatch_2 (SCM gf, SCM a1, SCM a2, int pos, const char *subr);
  117. SCM_API SCM scm_wta_dispatch_n (SCM gf, SCM args, int pos, const char *subr);
  118. SCM_INTERNAL SCM scm_i_define_class_for_vtable (SCM vtable);
  119. SCM_INTERNAL void scm_init_goops (void);
  120. #endif /* SCM_GOOPS_H */