Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
7a7f7c53 DH |
3 | #ifndef SCM_SMOB_H |
4 | #define SCM_SMOB_H | |
dee01b01 | 5 | |
7a7f7c53 | 6 | /* Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation, Inc. |
dee01b01 | 7 | * |
0f2d19dd JB |
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. | |
dee01b01 | 12 | * |
0f2d19dd JB |
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. | |
dee01b01 | 17 | * |
0f2d19dd JB |
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 | |
82892bed JB |
20 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
21 | * Boston, MA 02111-1307 USA | |
0f2d19dd JB |
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. | |
82892bed | 45 | * If you do not wish that, delete this exception notice. */ |
dee01b01 | 46 | |
0f2d19dd | 47 | \f |
dee01b01 | 48 | |
b4309c3c | 49 | #include "libguile/__scm.h" |
b08323d1 | 50 | #include "libguile/print.h" |
0f2d19dd JB |
51 | |
52 | \f | |
9dd5943c MD |
53 | /* This is the internal representation of a smob type */ |
54 | ||
55 | typedef struct scm_smob_descriptor | |
56 | { | |
57 | char *name; | |
1be6b49c | 58 | size_t size; |
7866a09b | 59 | SCM (*mark) (SCM); |
1be6b49c | 60 | size_t (*free) (SCM); |
7866a09b GB |
61 | int (*print) (SCM exp, SCM port, scm_print_state *pstate); |
62 | SCM (*equalp) (SCM, SCM); | |
cb1c46c5 KN |
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); | |
68b06924 | 68 | int gsubr_type; /* Used in procprop.c */ |
9dd5943c MD |
69 | } scm_smob_descriptor; |
70 | ||
0f2d19dd JB |
71 | \f |
72 | ||
9dd5943c | 73 | #define SCM_NEWSMOB(z, tc, data) \ |
23a62151 | 74 | do { \ |
9dd5943c | 75 | SCM_NEWCELL (z); \ |
94113249 DH |
76 | SCM_SET_CELL_WORD_1 ((z), (data)); \ |
77 | SCM_SET_CELL_TYPE ((z), (tc)); \ | |
23a62151 MD |
78 | } while (0) |
79 | ||
80 | #define SCM_RETURN_NEWSMOB(tc, data) \ | |
81 | do { SCM __SCM_smob_answer; \ | |
94113249 | 82 | SCM_NEWSMOB (__SCM_smob_answer, (tc), (data)); \ |
23a62151 MD |
83 | return __SCM_smob_answer; \ |
84 | } while (0) | |
85 | ||
87621a14 MD |
86 | #define SCM_NEWSMOB2(z, tc, data1, data2) \ |
87 | do { \ | |
88 | SCM_NEWCELL2 (z); \ | |
94113249 DH |
89 | SCM_SET_CELL_WORD_1 ((z), (data1)); \ |
90 | SCM_SET_CELL_WORD_2 ((z), (data2)); \ | |
91 | SCM_SET_CELL_TYPE ((z), (tc)); \ | |
87621a14 MD |
92 | } while (0) |
93 | ||
94 | #define SCM_RETURN_NEWSMOB2(tc, data1, data2) \ | |
95 | do { SCM __SCM_smob_answer; \ | |
94113249 | 96 | SCM_NEWSMOB2 (__SCM_smob_answer, (tc), (data1), (data2)); \ |
87621a14 MD |
97 | return __SCM_smob_answer; \ |
98 | } while (0) | |
99 | ||
100 | #define SCM_NEWSMOB3(z, tc, data1, data2, data3) \ | |
101 | do { \ | |
102 | SCM_NEWCELL2 (z); \ | |
94113249 DH |
103 | SCM_SET_CELL_WORD_1 ((z), (data1)); \ |
104 | SCM_SET_CELL_WORD_2 ((z), (data2)); \ | |
105 | SCM_SET_CELL_WORD_3 ((z), (data3)); \ | |
106 | SCM_SET_CELL_TYPE ((z), (tc)); \ | |
87621a14 MD |
107 | } while (0) |
108 | ||
109 | #define SCM_RETURN_NEWSMOB3(tc, data1, data2, data3) \ | |
110 | do { SCM __SCM_smob_answer; \ | |
94113249 | 111 | SCM_NEWSMOB3 (__SCM_smob_answer, (tc), (data1), (data2), (data3)); \ |
87621a14 MD |
112 | return __SCM_smob_answer; \ |
113 | } while (0) | |
114 | ||
9dd5943c | 115 | |
94113249 DH |
116 | #define SCM_SMOB_DATA(x) (SCM_CELL_WORD_1 (x)) |
117 | #define SCM_SET_SMOB_DATA(x, data) (SCM_SET_CELL_WORD_1 ((x), (data))) | |
118 | #define SCM_TC2SMOBNUM(x) (0x0ff & ((x) >> 8)) | |
119 | #define SCM_SMOBNUM(x) (SCM_TC2SMOBNUM (SCM_CELL_TYPE (x))) | |
2c16a78a | 120 | /* SCM_SMOBNAME can be 0 if name is missing */ |
94113249 | 121 | #define SCM_SMOBNAME(smobnum) (scm_smobs[smobnum].name) |
e841c3e0 | 122 | #define SCM_SMOB_PREDICATE(tag, obj) SCM_TYP16_PREDICATE (tag, obj) |
0717dfd8 | 123 | #define SCM_SMOB_DESCRIPTOR(x) (scm_smobs[SCM_SMOBNUM (x)]) |
68b06924 KN |
124 | #define SCM_SMOB_APPLICABLE_P(x) (SCM_SMOB_DESCRIPTOR (x).apply) |
125 | #define SCM_SMOB_APPLY_0(x) (SCM_SMOB_DESCRIPTOR (x).apply_0 (x)) | |
126 | #define SCM_SMOB_APPLY_1(x,a1) (SCM_SMOB_DESCRIPTOR (x).apply_1 (x, (a1))) | |
127 | #define SCM_SMOB_APPLY_2(x,a1,a2) (SCM_SMOB_DESCRIPTOR (x).apply_2 (x, (a1), (a2))) | |
128 | #define SCM_SMOB_APPLY_3(x,a1,a2,rst) (SCM_SMOB_DESCRIPTOR (x).apply_3 (x, (a1), (a2), (rst))) | |
0f2d19dd | 129 | |
33b001fd MV |
130 | SCM_API long scm_numsmob; |
131 | SCM_API scm_smob_descriptor scm_smobs[]; | |
0f2d19dd JB |
132 | |
133 | \f | |
0f2d19dd | 134 | |
33b001fd MV |
135 | SCM_API SCM scm_mark0 (SCM ptr); |
136 | SCM_API SCM scm_markcdr (SCM ptr); | |
137 | SCM_API size_t scm_free0 (SCM ptr); | |
138 | SCM_API size_t scm_smob_free (SCM obj); | |
139 | SCM_API int scm_smob_print (SCM exp, SCM port, scm_print_state *pstate); | |
23a62151 | 140 | |
c72baaaa MD |
141 | /* The following set of functions is the standard way to create new |
142 | * SMOB types. | |
143 | * | |
144 | * Create a type tag using `scm_make_smob_type', accept default values | |
145 | * for mark, free, print and/or equalp functions, or set your own | |
146 | * values using `scm_set_smob_xxx'. | |
147 | */ | |
23a62151 | 148 | |
33b001fd | 149 | SCM_API scm_t_bits scm_make_smob_type (char *name, size_t size); |
23a62151 | 150 | |
33b001fd MV |
151 | SCM_API void scm_set_smob_mark (scm_t_bits tc, SCM (*mark) (SCM)); |
152 | SCM_API void scm_set_smob_free (scm_t_bits tc, size_t (*free) (SCM)); | |
153 | SCM_API void scm_set_smob_print (scm_t_bits tc, | |
154 | int (*print) (SCM, SCM, scm_print_state*)); | |
155 | SCM_API void scm_set_smob_equalp (scm_t_bits tc, SCM (*equalp) (SCM, SCM)); | |
156 | SCM_API void scm_set_smob_apply (scm_t_bits tc, | |
157 | SCM (*apply) (), | |
158 | unsigned int req, | |
159 | unsigned int opt, | |
160 | unsigned int rst); | |
c72baaaa | 161 | |
7c58e21b | 162 | /* Function for creating smobs */ |
c72baaaa | 163 | |
33b001fd MV |
164 | SCM_API SCM scm_make_smob (scm_t_bits tc); |
165 | SCM_API void scm_smob_prehistory (void); | |
7c58e21b | 166 | |
7a7f7c53 | 167 | #endif /* SCM_SMOB_H */ |
89e00824 ML |
168 | |
169 | /* | |
170 | Local Variables: | |
171 | c-file-style: "gnu" | |
172 | End: | |
173 | */ |