6 /* Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation, Inc.
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)
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.
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
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
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.
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
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.
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. */
49 #include "libguile/__scm.h"
50 #include "libguile/print.h"
53 /* This is the internal representation of a smob type */
55 typedef struct scm_smob_descriptor
61 int (*print
) (SCM exp
, SCM port
, scm_print_state
*pstate
);
62 SCM (*equalp
) (SCM
, 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
;
73 #define SCM_NEWSMOB(z, tc, data) \
76 SCM_SET_CELL_WORD_1 ((z), (data)); \
77 SCM_SET_CELL_TYPE ((z), (tc)); \
80 #define SCM_RETURN_NEWSMOB(tc, data) \
81 do { SCM __SCM_smob_answer; \
82 SCM_NEWSMOB (__SCM_smob_answer, (tc), (data)); \
83 return __SCM_smob_answer; \
86 #define SCM_NEWSMOB2(z, tc, data1, data2) \
89 SCM_SET_CELL_WORD_1 ((z), (data1)); \
90 SCM_SET_CELL_WORD_2 ((z), (data2)); \
91 SCM_SET_CELL_TYPE ((z), (tc)); \
94 #define SCM_RETURN_NEWSMOB2(tc, data1, data2) \
95 do { SCM __SCM_smob_answer; \
96 SCM_NEWSMOB2 (__SCM_smob_answer, (tc), (data1), (data2)); \
97 return __SCM_smob_answer; \
100 #define SCM_NEWSMOB3(z, tc, data1, data2, data3) \
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)); \
109 #define SCM_RETURN_NEWSMOB3(tc, data1, data2, data3) \
110 do { SCM __SCM_smob_answer; \
111 SCM_NEWSMOB3 (__SCM_smob_answer, (tc), (data1), (data2), (data3)); \
112 return __SCM_smob_answer; \
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)))
120 /* SCM_SMOBNAME can be 0 if name is missing */
121 #define SCM_SMOBNAME(smobnum) (scm_smobs[smobnum].name)
122 #define SCM_SMOB_PREDICATE(tag, obj) SCM_TYP16_PREDICATE (tag, obj)
123 #define SCM_SMOB_DESCRIPTOR(x) (scm_smobs[SCM_SMOBNUM (x)])
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)))
130 extern long scm_numsmob
;
131 extern scm_smob_descriptor scm_smobs
[];
135 extern SCM
scm_mark0 (SCM ptr
);
136 extern SCM
scm_markcdr (SCM ptr
);
137 extern size_t scm_free0 (SCM ptr
);
138 extern size_t scm_smob_free (SCM obj
);
139 extern int scm_smob_print (SCM exp
, SCM port
, scm_print_state
*pstate
);
141 /* The following set of functions is the standard way to create new
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'.
149 extern scm_t_bits
scm_make_smob_type (char *name
, size_t size
);
151 extern void scm_set_smob_mark (scm_t_bits tc
, SCM (*mark
) (SCM
));
152 extern void scm_set_smob_free (scm_t_bits tc
, size_t (*free
) (SCM
));
153 extern void scm_set_smob_print (scm_t_bits tc
,
154 int (*print
) (SCM
, SCM
, scm_print_state
*));
155 extern void scm_set_smob_equalp (scm_t_bits tc
, SCM (*equalp
) (SCM
, SCM
));
156 extern void scm_set_smob_apply (scm_t_bits tc
,
162 /* Function for creating smobs */
164 extern SCM
scm_make_smob (scm_t_bits tc
);
165 extern void scm_smob_prehistory (void);
167 #endif /* SCM_SMOB_H */