goops.h 5.9 KB

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