struct.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* classes: h_files */
  2. #ifndef STRUCTH
  3. #define STRUCTH
  4. /* Copyright (C) 1995, 1997, 1999, 2000, 2002 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. /* Number of words with negative index */
  47. #define scm_struct_n_extra_words 4
  48. #define scm_struct_entity_n_extra_words 6
  49. /* These are how the initial words of a vtable are allocated. */
  50. #define scm_struct_i_setter -6 /* Setter */
  51. #define scm_struct_i_procedure -5 /* Optional procedure slot */
  52. #define scm_struct_i_free -4 /* Destructor */
  53. #define scm_struct_i_ptr -3 /* Start of block (see alloc_struct) */
  54. #define scm_struct_i_n_words -2 /* How many words allocated to this struct? */
  55. #define scm_struct_i_size -1 /* Instance size */
  56. #define scm_struct_i_flags -1 /* Upper 12 bits used as flags */
  57. #define scm_vtable_index_layout 0 /* A symbol describing the physical arrangement of this type. */
  58. #define scm_vtable_index_vcell 1 /* An opaque word, managed by the garbage collector. */
  59. #define scm_vtable_index_vtable 2 /* A pointer to the handle for this vtable. */
  60. #define scm_vtable_index_printer 3 /* A printer for this struct type. */
  61. #define scm_vtable_offset_user 4 /* Where do user fields start? */
  62. typedef scm_sizet (*scm_struct_free_t) (scm_bits_t * vtable, scm_bits_t * data);
  63. #define SCM_STRUCTF_MASK (0xFFF << 20)
  64. #define SCM_STRUCTF_ENTITY (1L << 30) /* Indicates presence of proc slots */
  65. #define SCM_STRUCTF_LIGHT (1L << 31) /* Light representation
  66. (no hidden words) */
  67. /* Dirk:FIXME:: the SCM_STRUCTP predicate is also fulfilled for glocs */
  68. #define SCM_STRUCTP(X) (SCM_NIMP(X) && (SCM_TYP3(X) == scm_tc3_cons_gloc))
  69. #define SCM_STRUCT_DATA(X) ((scm_bits_t *) SCM_CELL_WORD_1 (X))
  70. #define SCM_STRUCT_VTABLE_DATA(X) ((scm_bits_t *) (SCM_CELL_WORD_0 (X) - scm_tc3_cons_gloc))
  71. #define SCM_STRUCT_LAYOUT(X) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (X) [scm_vtable_index_layout]))
  72. #define SCM_SET_STRUCT_LAYOUT(X, v) (SCM_STRUCT_VTABLE_DATA (X) [scm_vtable_index_layout] = SCM_UNPACK (v))
  73. #define SCM_STRUCT_VTABLE(X) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (X) [scm_vtable_index_vtable]))
  74. #define SCM_STRUCT_PRINTER(X) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (X) [scm_vtable_index_printer]))
  75. #define SCM_SET_VTABLE_DESTRUCTOR(X, D) (SCM_STRUCT_DATA (X) [scm_struct_i_free] = (scm_bits_t) (D))
  76. /* Efficiency is important in the following macro, since it's used in GC */
  77. #define SCM_LAYOUT_TAILP(X) (((X) & 32) == 0) /* R, W or O */
  78. #define SCM_STRUCT_TABLE_NAME(X) SCM_CAR (X)
  79. #define SCM_SET_STRUCT_TABLE_NAME(X, NAME) SCM_SETCAR (X, NAME)
  80. #define SCM_STRUCT_TABLE_CLASS(X) SCM_CDR (X)
  81. #define SCM_SET_STRUCT_TABLE_CLASS(X, CLASS) SCM_SETCDR (X, CLASS)
  82. extern SCM scm_struct_table;
  83. extern scm_bits_t * scm_alloc_struct (int n_words, int n_extra, char * who);
  84. extern scm_sizet scm_struct_free_0 (scm_bits_t * vtable, scm_bits_t * data);
  85. extern scm_sizet scm_struct_free_light (scm_bits_t * vtable, scm_bits_t * data);
  86. extern scm_sizet scm_struct_free_standard (scm_bits_t * vtable, scm_bits_t * data);
  87. extern scm_sizet scm_struct_free_entity (scm_bits_t * vtable, scm_bits_t * data);
  88. extern void scm_struct_init (SCM handle, int tail_elts, SCM inits);
  89. extern SCM scm_make_struct_layout (SCM fields);
  90. extern SCM scm_struct_p (SCM x);
  91. extern SCM scm_struct_vtable_p (SCM x);
  92. extern SCM scm_make_struct (SCM vtable, SCM tail_array_size, SCM init);
  93. extern SCM scm_make_vtable_vtable (SCM extra_fields, SCM tail_array_size, SCM init);
  94. extern SCM scm_struct_ref (SCM handle, SCM pos);
  95. extern SCM scm_struct_set_x (SCM handle, SCM pos, SCM val);
  96. extern SCM scm_struct_vtable (SCM handle);
  97. extern SCM scm_struct_vtable_tag (SCM handle);
  98. extern unsigned int scm_struct_ihashq (SCM obj, unsigned int n);
  99. extern SCM scm_struct_create_handle (SCM obj);
  100. extern SCM scm_struct_vtable_name (SCM vtable);
  101. extern SCM scm_set_struct_vtable_name_x (SCM vtable, SCM name);
  102. extern void scm_print_struct (SCM exp, SCM port, scm_print_state *);
  103. extern void scm_init_struct (void);
  104. #endif /* STRUCTH */
  105. /*
  106. Local Variables:
  107. c-file-style: "gnu"
  108. End:
  109. */