Changes in doc/ref:
[bpt/guile.git] / libguile / smob.h
1 /* classes: h_files */
2
3 #ifndef SCM_SMOB_H
4 #define SCM_SMOB_H
5
6 /* Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
22 *
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
25 *
26 * The exception is that, if you link the GUILE library with other files
27 * to produce an executable, this does not by itself cause the
28 * resulting executable to be covered by the GNU General Public License.
29 * Your use of that executable is in no way restricted on account of
30 * linking the GUILE library code into it.
31 *
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
34 *
35 * This exception applies only to the code released by the
36 * Free Software Foundation under the name GUILE. If you copy
37 * code from other Free Software Foundation releases into a copy of
38 * GUILE, as the General Public License permits, the exception does
39 * not apply to the code that you add in this way. To avoid misleading
40 * anyone as to the status of such modified files, you must delete
41 * this exception notice from them.
42 *
43 * If you write modifications of your own for GUILE, it is your choice
44 * whether to permit this exception to apply to your modifications.
45 * If you do not wish that, delete this exception notice. */
46
47 \f
48
49 #include "libguile/__scm.h"
50 #include "libguile/print.h"
51
52 \f
53 /* This is the internal representation of a smob type */
54
55 typedef struct scm_smob_descriptor
56 {
57 char *name;
58 size_t size;
59 SCM (*mark) (SCM);
60 size_t (*free) (SCM);
61 int (*print) (SCM exp, SCM port, scm_print_state *pstate);
62 SCM (*equalp) (SCM, SCM);
63 SCM (*apply) ();
64 SCM (*apply_0) (SCM);
65 SCM (*apply_1) (SCM, SCM);
66 SCM (*apply_2) (SCM, SCM, SCM);
67 SCM (*apply_3) (SCM, SCM, SCM, SCM);
68 int gsubr_type; /* Used in procprop.c */
69 } scm_smob_descriptor;
70
71 \f
72
73 #define SCM_NEWSMOB(z, tc, data) \
74 do { \
75 z = scm_cell ((tc), (scm_t_bits) (data)); \
76 } while (0)
77
78 #define SCM_RETURN_NEWSMOB(tc, data) \
79 do { SCM __SCM_smob_answer; \
80 SCM_NEWSMOB (__SCM_smob_answer, (tc), (data)); \
81 return __SCM_smob_answer; \
82 } while (0)
83
84 #define SCM_NEWSMOB2(z, tc, data1, data2) \
85 do { \
86 z = scm_double_cell ((tc), (scm_t_bits)(data1), (scm_t_bits)(data2), 0); \
87 } while (0)
88
89 #define SCM_RETURN_NEWSMOB2(tc, data1, data2) \
90 do { SCM __SCM_smob_answer; \
91 SCM_NEWSMOB2 (__SCM_smob_answer, (tc), (data1), (data2)); \
92 return __SCM_smob_answer; \
93 } while (0)
94
95 #define SCM_NEWSMOB3(z, tc, data1, data2, data3) \
96 do { \
97 z = scm_double_cell ((tc), (scm_t_bits)(data1), \
98 (scm_t_bits)(data2), (scm_t_bits)(data3)); \
99 } while (0)
100
101 #define SCM_RETURN_NEWSMOB3(tc, data1, data2, data3) \
102 do { SCM __SCM_smob_answer; \
103 SCM_NEWSMOB3 (__SCM_smob_answer, (tc), (data1), (data2), (data3)); \
104 return __SCM_smob_answer; \
105 } while (0)
106
107
108 #define SCM_SMOB_DATA(x) (SCM_CELL_WORD_1 (x))
109 #define SCM_SET_SMOB_DATA(x, data) (SCM_SET_CELL_WORD_1 ((x), (data)))
110 #define SCM_TC2SMOBNUM(x) (0x0ff & ((x) >> 8))
111 #define SCM_SMOBNUM(x) (SCM_TC2SMOBNUM (SCM_CELL_TYPE (x)))
112 /* SCM_SMOBNAME can be 0 if name is missing */
113 #define SCM_SMOBNAME(smobnum) (scm_smobs[smobnum].name)
114 #define SCM_SMOB_PREDICATE(tag, obj) SCM_TYP16_PREDICATE (tag, obj)
115 #define SCM_SMOB_DESCRIPTOR(x) (scm_smobs[SCM_SMOBNUM (x)])
116 #define SCM_SMOB_APPLICABLE_P(x) (SCM_SMOB_DESCRIPTOR (x).apply)
117 #define SCM_SMOB_APPLY_0(x) (SCM_SMOB_DESCRIPTOR (x).apply_0 (x))
118 #define SCM_SMOB_APPLY_1(x,a1) (SCM_SMOB_DESCRIPTOR (x).apply_1 (x, (a1)))
119 #define SCM_SMOB_APPLY_2(x,a1,a2) (SCM_SMOB_DESCRIPTOR (x).apply_2 (x, (a1), (a2)))
120 #define SCM_SMOB_APPLY_3(x,a1,a2,rst) (SCM_SMOB_DESCRIPTOR (x).apply_3 (x, (a1), (a2), (rst)))
121
122 SCM_API long scm_numsmob;
123 SCM_API scm_smob_descriptor scm_smobs[];
124
125 \f
126
127 SCM_API SCM scm_mark0 (SCM ptr);
128 SCM_API SCM scm_markcdr (SCM ptr);
129 SCM_API size_t scm_free0 (SCM ptr);
130 SCM_API size_t scm_smob_free (SCM obj);
131 SCM_API int scm_smob_print (SCM exp, SCM port, scm_print_state *pstate);
132
133 /* The following set of functions is the standard way to create new
134 * SMOB types.
135 *
136 * Create a type tag using `scm_make_smob_type', accept default values
137 * for mark, free, print and/or equalp functions, or set your own
138 * values using `scm_set_smob_xxx'.
139 */
140
141 SCM_API scm_t_bits scm_make_smob_type (char *name, size_t size);
142
143 SCM_API void scm_set_smob_mark (scm_t_bits tc, SCM (*mark) (SCM));
144 SCM_API void scm_set_smob_free (scm_t_bits tc, size_t (*free) (SCM));
145 SCM_API void scm_set_smob_print (scm_t_bits tc,
146 int (*print) (SCM, SCM, scm_print_state*));
147 SCM_API void scm_set_smob_equalp (scm_t_bits tc, SCM (*equalp) (SCM, SCM));
148 SCM_API void scm_set_smob_apply (scm_t_bits tc,
149 SCM (*apply) (),
150 unsigned int req,
151 unsigned int opt,
152 unsigned int rst);
153
154 /* Function for creating smobs */
155
156 SCM_API SCM scm_make_smob (scm_t_bits tc);
157 SCM_API void scm_smob_prehistory (void);
158
159 #endif /* SCM_SMOB_H */
160
161 /*
162 Local Variables:
163 c-file-style: "gnu"
164 End:
165 */