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 { \ |
228a24ef | 75 | z = scm_cell ((tc), (scm_t_bits) (data)); \ |
23a62151 MD |
76 | } while (0) |
77 | ||
78 | #define SCM_RETURN_NEWSMOB(tc, data) \ | |
79 | do { SCM __SCM_smob_answer; \ | |
94113249 | 80 | SCM_NEWSMOB (__SCM_smob_answer, (tc), (data)); \ |
23a62151 MD |
81 | return __SCM_smob_answer; \ |
82 | } while (0) | |
83 | ||
87621a14 MD |
84 | #define SCM_NEWSMOB2(z, tc, data1, data2) \ |
85 | do { \ | |
228a24ef | 86 | z = scm_double_cell ((tc), (scm_t_bits)(data1), (scm_t_bits)(data2), 0); \ |
87621a14 MD |
87 | } while (0) |
88 | ||
89 | #define SCM_RETURN_NEWSMOB2(tc, data1, data2) \ | |
90 | do { SCM __SCM_smob_answer; \ | |
94113249 | 91 | SCM_NEWSMOB2 (__SCM_smob_answer, (tc), (data1), (data2)); \ |
87621a14 MD |
92 | return __SCM_smob_answer; \ |
93 | } while (0) | |
94 | ||
95 | #define SCM_NEWSMOB3(z, tc, data1, data2, data3) \ | |
96 | do { \ | |
228a24ef DH |
97 | z = scm_double_cell ((tc), (scm_t_bits)(data1), \ |
98 | (scm_t_bits)(data2), (scm_t_bits)(data3)); \ | |
87621a14 MD |
99 | } while (0) |
100 | ||
101 | #define SCM_RETURN_NEWSMOB3(tc, data1, data2, data3) \ | |
102 | do { SCM __SCM_smob_answer; \ | |
94113249 | 103 | SCM_NEWSMOB3 (__SCM_smob_answer, (tc), (data1), (data2), (data3)); \ |
87621a14 MD |
104 | return __SCM_smob_answer; \ |
105 | } while (0) | |
106 | ||
9dd5943c | 107 | |
94113249 DH |
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))) | |
2c16a78a | 112 | /* SCM_SMOBNAME can be 0 if name is missing */ |
94113249 | 113 | #define SCM_SMOBNAME(smobnum) (scm_smobs[smobnum].name) |
e841c3e0 | 114 | #define SCM_SMOB_PREDICATE(tag, obj) SCM_TYP16_PREDICATE (tag, obj) |
0717dfd8 | 115 | #define SCM_SMOB_DESCRIPTOR(x) (scm_smobs[SCM_SMOBNUM (x)]) |
68b06924 KN |
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)) | |
34d19ef6 HWN |
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))) | |
0f2d19dd | 121 | |
33b001fd MV |
122 | SCM_API long scm_numsmob; |
123 | SCM_API scm_smob_descriptor scm_smobs[]; | |
0f2d19dd JB |
124 | |
125 | \f | |
0f2d19dd | 126 | |
33b001fd MV |
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); | |
23a62151 | 132 | |
c72baaaa MD |
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 | */ | |
23a62151 | 140 | |
33b001fd | 141 | SCM_API scm_t_bits scm_make_smob_type (char *name, size_t size); |
23a62151 | 142 | |
33b001fd MV |
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); | |
c72baaaa | 153 | |
7c58e21b | 154 | /* Function for creating smobs */ |
c72baaaa | 155 | |
33b001fd MV |
156 | SCM_API SCM scm_make_smob (scm_t_bits tc); |
157 | SCM_API void scm_smob_prehistory (void); | |
7c58e21b | 158 | |
7a7f7c53 | 159 | #endif /* SCM_SMOB_H */ |
89e00824 ML |
160 | |
161 | /* | |
162 | Local Variables: | |
163 | c-file-style: "gnu" | |
164 | End: | |
165 | */ |