smob.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* classes: h_files */
  2. #ifndef SMOBH
  3. #define SMOBH
  4. /* Copyright (C) 1995, 1996, 1998, 1999, 2000 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., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 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. #include "libguile/__scm.h"
  45. #include "libguile/print.h"
  46. /* This is the internal representation of a smob type */
  47. typedef struct scm_smob_descriptor
  48. {
  49. char *name;
  50. scm_sizet size;
  51. SCM (*mark) (SCM);
  52. scm_sizet (*free) (SCM);
  53. int (*print) (SCM exp, SCM port, scm_print_state *pstate);
  54. SCM (*equalp) (SCM, SCM);
  55. } scm_smob_descriptor;
  56. #define SCM_NEWSMOB(z, tc, data) \
  57. do { \
  58. SCM_NEWCELL (z); \
  59. SCM_SET_CELL_WORD_1 ((z), (data)); \
  60. SCM_SET_CELL_TYPE ((z), (tc)); \
  61. } while (0)
  62. #define SCM_RETURN_NEWSMOB(tc, data) \
  63. do { SCM __SCM_smob_answer; \
  64. SCM_NEWSMOB (__SCM_smob_answer, (tc), (data)); \
  65. return __SCM_smob_answer; \
  66. } while (0)
  67. #define SCM_NEWSMOB2(z, tc, data1, data2) \
  68. do { \
  69. SCM_NEWCELL2 (z); \
  70. SCM_SET_CELL_WORD_1 ((z), (data1)); \
  71. SCM_SET_CELL_WORD_2 ((z), (data2)); \
  72. SCM_SET_CELL_TYPE ((z), (tc)); \
  73. } while (0)
  74. #define SCM_RETURN_NEWSMOB2(tc, data1, data2) \
  75. do { SCM __SCM_smob_answer; \
  76. SCM_NEWSMOB2 (__SCM_smob_answer, (tc), (data1), (data2)); \
  77. return __SCM_smob_answer; \
  78. } while (0)
  79. #define SCM_NEWSMOB3(z, tc, data1, data2, data3) \
  80. do { \
  81. SCM_NEWCELL2 (z); \
  82. SCM_SET_CELL_WORD_1 ((z), (data1)); \
  83. SCM_SET_CELL_WORD_2 ((z), (data2)); \
  84. SCM_SET_CELL_WORD_3 ((z), (data3)); \
  85. SCM_SET_CELL_TYPE ((z), (tc)); \
  86. } while (0)
  87. #define SCM_RETURN_NEWSMOB3(tc, data1, data2, data3) \
  88. do { SCM __SCM_smob_answer; \
  89. SCM_NEWSMOB3 (__SCM_smob_answer, (tc), (data1), (data2), (data3)); \
  90. return __SCM_smob_answer; \
  91. } while (0)
  92. #define SCM_SMOB_DATA(x) (SCM_CELL_WORD_1 (x))
  93. #define SCM_SET_SMOB_DATA(x, data) (SCM_SET_CELL_WORD_1 ((x), (data)))
  94. #define SCM_TC2SMOBNUM(x) (0x0ff & ((x) >> 8))
  95. #define SCM_SMOBNUM(x) (SCM_TC2SMOBNUM (SCM_CELL_TYPE (x)))
  96. /* SCM_SMOBNAME can be 0 if name is missing */
  97. #define SCM_SMOBNAME(smobnum) (scm_smobs[smobnum].name)
  98. #define SCM_SMOB_PREDICATE(tag, obj) (SCM_NIMP (obj) \
  99. && SCM_TYP16 (obj) == (tag))
  100. extern int scm_numsmob;
  101. extern scm_smob_descriptor *scm_smobs;
  102. extern SCM scm_mark0 (SCM ptr);
  103. extern SCM scm_markcdr (SCM ptr);
  104. extern scm_sizet scm_free0 (SCM ptr);
  105. extern scm_sizet scm_smob_free (SCM obj);
  106. extern int scm_smob_print (SCM exp, SCM port, scm_print_state *pstate);
  107. /* The following set of functions is the standard way to create new
  108. * SMOB types.
  109. *
  110. * Create a type tag using `scm_make_smob_type', accept default values
  111. * for mark, free, print and/or equalp functions, or set your own
  112. * values using `scm_set_smob_xxx'.
  113. */
  114. extern long scm_make_smob_type (char *name, scm_sizet size);
  115. extern void scm_set_smob_mark (long tc, SCM (*mark) (SCM));
  116. extern void scm_set_smob_free (long tc, scm_sizet (*free) (SCM));
  117. extern void scm_set_smob_print (long tc, int (*print) (SCM,
  118. SCM,
  119. scm_print_state*));
  120. extern void scm_set_smob_equalp (long tc, SCM (*equalp) (SCM, SCM));
  121. /* Functions for registering multiple handler functions simultaneously.
  122. *
  123. * (There is a discussion among the developers whether or not these
  124. * should be deprecated in the future.)
  125. */
  126. extern long scm_make_smob_type_mfpe (char *name, scm_sizet size,
  127. SCM (*mark) (SCM),
  128. scm_sizet (*free) (SCM),
  129. int (*print) (SCM, SCM, scm_print_state*),
  130. SCM (*equalp) (SCM, SCM));
  131. extern void scm_set_smob_mfpe (long tc,
  132. SCM (*mark) (SCM),
  133. scm_sizet (*free) (SCM),
  134. int (*print) (SCM, SCM, scm_print_state*),
  135. SCM (*equalp) (SCM, SCM));
  136. /* Function for creating smobs */
  137. extern SCM scm_make_smob (long tc);
  138. extern void scm_smob_prehistory (void);
  139. #endif /* SMOBH */
  140. /*
  141. Local Variables:
  142. c-file-style: "gnu"
  143. End:
  144. */