* keywords.h, keywords.c, deprecated.h, deprecated.c
[bpt/guile.git] / libguile / deprecated.h
1 /* This file contains definitions for deprecated features. When you
2 deprecate something, move it here when that is feasible.
3 */
4
5 #ifndef SCM_DEPRECATED_H
6 #define SCM_DEPRECATED_H
7
8 /* Copyright (C) 2003,2004 Free Software Foundation, Inc.
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include "libguile/__scm.h"
26 #include "libguile/strings.h"
27
28 #if (SCM_ENABLE_DEPRECATED == 1)
29
30 /* From eval.h: Macros for handling ilocs. These were deprecated in guile
31 * 1.7.0 on 2004-04-22. */
32 #define SCM_IFRINC (0x00000100L)
33 #define SCM_ICDR (0x00080000L)
34 #define SCM_IFRAME(n) ((long)((SCM_ICDR-SCM_IFRINC)>>8) \
35 & (SCM_UNPACK (n) >> 8))
36 #define SCM_IDIST(n) (SCM_UNPACK (n) >> 20)
37 #define SCM_ICDRP(n) (SCM_ICDR & SCM_UNPACK (n))
38
39
40 /* From tags.h: Macros to access internal symbol names of isyms. Deprecated
41 * in guile 1.7.0 on 2004-04-22. */
42 SCM_API char *scm_isymnames[];
43 #define SCM_ISYMNUM(n) 0
44 #define SCM_ISYMCHARS(n) "#@<deprecated>"
45
46
47 /* From tags.h: Macro checking for two tc16 types that are allocated to differ
48 * only in the 's'-bit. Deprecated in guile 1.7.0 on 2003-09-21. */
49 #define SCM_TYP16S(x) (0xfeff & SCM_CELL_TYPE (x))
50
51
52 /* From numbers.h: Macros checking for types, but avoiding a redundant check
53 * for !SCM_IMP. These were deprecated in guile 1.7.0 on 2003-09-06. */
54 #define SCM_SLOPPY_INEXACTP(x) (SCM_TYP16S (x) == scm_tc16_real)
55 #define SCM_SLOPPY_REALP(x) (SCM_TYP16 (x) == scm_tc16_real)
56 #define SCM_SLOPPY_COMPLEXP(x) (SCM_TYP16 (x) == scm_tc16_complex)
57
58
59 /* From eval.h: Macros for handling ilocs. These were deprecated in guile
60 * 1.7.0 on 2003-06-04. */
61 #define SCM_ILOC00 SCM_MAKE_ITAG8(0L, scm_tc8_iloc)
62 #define SCM_IDINC (0x00100000L)
63 #define SCM_IDSTMSK (-SCM_IDINC)
64
65
66 /* From eval.h: Error messages of the evaluator. These were deprecated in
67 * guile 1.7.0 on 2003-06-02. */
68 SCM_API const char scm_s_expression[];
69 SCM_API const char scm_s_test[];
70 SCM_API const char scm_s_body[];
71 SCM_API const char scm_s_bindings[];
72 SCM_API const char scm_s_variable[];
73 SCM_API const char scm_s_clauses[];
74 SCM_API const char scm_s_formals[];
75
76
77 /* From eval.h: Helper macros for evaluation and application. These were
78 * deprecated in guile 1.7.0 on 2003-06-02. */
79 #define SCM_EVALIM2(x) \
80 ((scm_is_eq ((x), SCM_EOL) \
81 ? scm_misc_error (NULL, scm_s_expression, SCM_EOL), 0 \
82 : 0), \
83 (x))
84 #define SCM_EVALIM(x, env) (SCM_ILOCP (x) \
85 ? *scm_ilookup ((x), env) \
86 : SCM_EVALIM2(x))
87 #define SCM_XEVAL(x, env) (scm_i_eval_x ((x), (env)))
88 #define SCM_XEVALCAR(x, env) (SCM_SYMBOLP (SCM_CAR (x)) \
89 ? *scm_lookupcar (x, env, 1) \
90 : scm_i_eval_x (SCM_CAR (x), (env)))
91
92
93 #define scm_substring_move_left_x scm_substring_move_x
94 #define scm_substring_move_right_x scm_substring_move_x
95
96 #define scm_sizet size_t
97
98 SCM_API SCM scm_wta (SCM arg, const char *pos, const char *s_subr);
99
100 #define SCM_WNA 8
101 #define SCM_OUTOFRANGE 10
102 #define SCM_NALLOC 11
103
104 SCM_API void scm_register_module_xxx (char *module_name, void *init_func);
105 SCM_API SCM scm_registered_modules (void);
106 SCM_API SCM scm_clear_registered_modules (void);
107
108 SCM_API SCM scm_protect_object (SCM obj);
109 SCM_API SCM scm_unprotect_object (SCM obj);
110
111 #define SCM_SETAND_CAR(x, y) \
112 (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y))))
113 #define SCM_SETOR_CAR(x, y)\
114 (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y))))
115 #define SCM_SETAND_CDR(x, y)\
116 (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y))))
117 #define SCM_SETOR_CDR(x, y)\
118 (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y))))
119 #define SCM_FREEP(x) (SCM_FREE_CELL_P (x))
120 #define SCM_NFREEP(x) (!SCM_FREE_CELL_P (x))
121 #define SCM_GC8MARKP(x) SCM_GC_MARK_P (x)
122 #define SCM_SETGC8MARK(x) SCM_SET_GC_MARK (x)
123 #define SCM_CLRGC8MARK(x) SCM_CLEAR_GC_MARK (x)
124 #define SCM_GCTYP16(x) SCM_TYP16 (x)
125 #define SCM_GCCDR(x) SCM_CDR (x)
126 SCM_API void scm_remember (SCM * ptr);
127
128 SCM_API SCM scm_the_root_module (void);
129 SCM_API SCM scm_make_module (SCM name);
130 SCM_API SCM scm_ensure_user_module (SCM name);
131 SCM_API SCM scm_load_scheme_module (SCM name);
132
133 #define scm_port scm_t_port
134 #define scm_ptob_descriptor scm_t_ptob_descriptor
135 #define scm_port_rw_active scm_t_port_rw_active
136
137 SCM_API SCM scm_close_all_ports_except (SCM ports);
138
139 #define scm_rstate scm_t_rstate
140 #define scm_rng scm_t_rng
141
142 #define SCM_SLOPPY_CONSP(x) ((1 & SCM_CELL_TYPE (x)) == 0)
143 #define SCM_SLOPPY_NCONSP(x) (!SCM_SLOPPY_CONSP(x))
144
145 #define scm_tc7_ssymbol scm_tc7_symbol
146 #define scm_tc7_msymbol scm_tc7_symbol
147 #define scm_tcs_symbols scm_tc7_symbol
148
149 SCM_API SCM scm_makstr (size_t len, int);
150 SCM_API SCM scm_makfromstr (const char *src, size_t len, int);
151
152 SCM_API SCM scm_variable_set_name_hint (SCM var, SCM hint);
153 SCM_API SCM scm_builtin_variable (SCM name);
154
155 SCM_API SCM scm_internal_with_fluids (SCM fluids, SCM vals,
156 SCM (*cproc)(void *), void *cdata);
157
158 SCM_API SCM scm_make_gsubr (const char *name, int req, int opt, int rst,
159 SCM (*fcn)());
160 SCM_API SCM scm_make_gsubr_with_generic (const char *name,
161 int req,
162 int opt,
163 int rst,
164 SCM (*fcn)(),
165 SCM *gf);
166
167 extern SCM scm_create_hook (const char* name, int n_args);
168
169 #define SCM_LIST0 SCM_EOL
170 #define SCM_LIST1(e0) scm_cons ((e0), SCM_EOL)
171 #define SCM_LIST2(e0, e1) scm_cons2 ((e0), (e1), SCM_EOL)
172 #define SCM_LIST3(e0, e1, e2) scm_cons ((e0), SCM_LIST2 ((e1), (e2)))
173 #define SCM_LIST4(e0, e1, e2, e3)\
174 scm_cons2 ((e0), (e1), SCM_LIST2 ((e2), (e3)))
175 #define SCM_LIST5(e0, e1, e2, e3, e4)\
176 scm_cons ((e0), SCM_LIST4 ((e1), (e2), (e3), (e4)))
177 #define SCM_LIST6(e0, e1, e2, e3, e4, e5)\
178 scm_cons2 ((e0), (e1), SCM_LIST4 ((e2), (e3), (e4), (e5)))
179 #define SCM_LIST7(e0, e1, e2, e3, e4, e5, e6)\
180 scm_cons ((e0), SCM_LIST6 ((e1), (e2), (e3), (e4), (e5), (e6)))
181 #define SCM_LIST8(e0, e1, e2, e3, e4, e5, e6, e7)\
182 scm_cons2 ((e0), (e1), SCM_LIST6 ((e2), (e3), (e4), (e5), (e6), (e7)))
183 #define SCM_LIST9(e0, e1, e2, e3, e4, e5, e6, e7, e8)\
184 scm_cons ((e0),\
185 SCM_LIST8 ((e1), (e2), (e3), (e4), (e5), (e6), (e7), (e8)))
186
187 #define scm_listify scm_list_n
188
189 SCM_API SCM scm_sloppy_memq (SCM x, SCM lst);
190 SCM_API SCM scm_sloppy_memv (SCM x, SCM lst);
191 SCM_API SCM scm_sloppy_member (SCM x, SCM lst);
192
193 SCM_API SCM scm_read_and_eval_x (SCM port);
194
195 #define scm_subr_entry scm_t_subr_entry
196
197 #define SCM_SUBR_DOC(x) SCM_BOOL_F
198
199 SCM_API SCM scm_make_subr (const char *name, int type, SCM (*fcn) ());
200 SCM_API SCM scm_make_subr_with_generic (const char *name,
201 int type,
202 SCM (*fcn) (),
203 SCM *gf);
204 SCM_API SCM scm_make_subr_opt (const char *name,
205 int type,
206 SCM (*fcn) (),
207 int set);
208
209 SCM_API SCM scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(),
210 void * closure);
211
212 SCM_API long scm_make_smob_type_mfpe (char *name, size_t size,
213 SCM (*mark) (SCM),
214 size_t (*free) (SCM),
215 int (*print) (SCM, SCM,
216 scm_print_state*),
217 SCM (*equalp) (SCM, SCM));
218
219 SCM_API void scm_set_smob_mfpe (long tc,
220 SCM (*mark) (SCM),
221 size_t (*free) (SCM),
222 int (*print) (SCM, SCM, scm_print_state*),
223 SCM (*equalp) (SCM, SCM));
224
225 SCM_API SCM scm_strprint_obj (SCM obj);
226 SCM_API SCM scm_read_0str (char *expr);
227 SCM_API SCM scm_eval_0str (const char *expr);
228
229 #define scm_strhash(str, len, n) (scm_string_hash ((str), (len)) % (n))
230
231 SCM_API SCM scm_sym2ovcell_soft (SCM sym, SCM obarray);
232 SCM_API SCM scm_sym2ovcell (SCM sym, SCM obarray);
233 SCM_API SCM scm_intern_obarray_soft (const char *name, size_t len,
234 SCM obarray, unsigned int softness);
235 SCM_API SCM scm_intern_obarray (const char *name, size_t len, SCM obarray);
236 SCM_API SCM scm_symbol_value0 (const char *name);
237
238 SCM_API SCM scm_string_to_obarray_symbol (SCM o, SCM s, SCM softp);
239 SCM_API SCM scm_intern_symbol (SCM o, SCM s);
240 SCM_API SCM scm_unintern_symbol (SCM o, SCM s);
241 SCM_API SCM scm_symbol_binding (SCM o, SCM s);
242 #if 0
243 /* This name has been reused for real uninterned symbols. */
244 SCM_API SCM scm_symbol_interned_p (SCM o, SCM s);
245 #endif
246 SCM_API SCM scm_symbol_bound_p (SCM o, SCM s);
247 SCM_API SCM scm_symbol_set_x (SCM o, SCM s, SCM v);
248
249 SCM_API SCM scm_gentemp (SCM prefix, SCM obarray);
250
251 #define SCM_OPDIRP(x) (SCM_DIRP (x) && (SCM_DIR_OPEN_P (x)))
252 #define scm_fport scm_t_fport
253 #define scm_option scm_t_option
254 #define scm_srcprops scm_t_srcprops
255 #define scm_srcprops_chunk scm_t_srcprops_chunk
256 #define scm_info_frame scm_t_info_frame
257 #define scm_stack scm_t_stack
258 #define scm_array scm_t_array
259 #define scm_array_dim scm_t_array_dim
260 #define SCM_ARRAY_CONTIGUOUS SCM_ARRAY_FLAG_CONTIGUOUS
261 #define SCM_FUNC_NAME (scm_makfrom0str (FUNC_NAME))
262
263 #define SCM_WTA(pos, scm) \
264 do { scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)
265
266 #define RETURN_SCM_WTA(pos, scm) \
267 do { return scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)
268
269 #define SCM_VALIDATE_NUMBER_COPY(pos, z, cvar) \
270 do { \
271 if (SCM_I_INUMP (z)) \
272 cvar = (double) SCM_I_INUM (z); \
273 else if (SCM_REALP (z)) \
274 cvar = SCM_REAL_VALUE (z); \
275 else if (SCM_BIGP (z)) \
276 cvar = scm_i_big2dbl (z); \
277 else \
278 { \
279 cvar = 0.0; \
280 SCM_WRONG_TYPE_ARG (pos, z); \
281 } \
282 } while (0)
283
284 #define SCM_VALIDATE_NUMBER_DEF_COPY(pos, number, def, cvar) \
285 do { \
286 if (SCM_UNBNDP (number)) \
287 cvar = def; \
288 else \
289 SCM_VALIDATE_NUMBER_COPY(pos, number, cvar); \
290 } while (0)
291
292 #define SCM_VALIDATE_OPDIR(pos, port) SCM_MAKE_VALIDATE (pos, port, OPDIRP)
293
294 /* Deprecated because we can not safely cast a SCM* to a scm_t_bits*
295 */
296
297 #define SCM_CELL_WORD_LOC(x, n) ((scm_t_bits*)SCM_CELL_OBJECT_LOC((x),(n)))
298
299 /* Users shouldn't know about INUMs.
300 */
301
302 SCM_API SCM SCM_MAKINUM (scm_t_signed_bits val);
303 SCM_API int SCM_INUMP (SCM obj);
304 #define SCM_NINUMP(x) (!SCM_INUMP(x))
305 SCM_API scm_t_signed_bits SCM_INUM (SCM obj);
306
307 #define SCM_VALIDATE_INUM(pos, k) SCM_MAKE_VALIDATE_MSG (pos, k, INUMP, "exact integer")
308
309 #define SCM_VALIDATE_INUM_COPY(pos, k, cvar) \
310 do { \
311 SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
312 cvar = SCM_I_INUM (k); \
313 } while (0)
314
315 #define SCM_VALIDATE_BIGINT(pos, k) SCM_MAKE_VALIDATE_MSG (pos, k, BIGP, "bignum")
316
317 #define SCM_VALIDATE_INUM_MIN(pos, k, min) \
318 do { \
319 SCM_ASSERT (SCM_I_INUMP(k), k, pos, FUNC_NAME); \
320 SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
321 } while (0)
322
323 #define SCM_VALIDATE_INUM_MIN_COPY(pos, k, min, cvar) \
324 do { \
325 SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
326 SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
327 cvar = SCM_INUM (k); \
328 } while (0)
329
330 #define SCM_VALIDATE_INUM_MIN_DEF_COPY(pos, k, min, default, cvar) \
331 do { \
332 if (SCM_UNBNDP (k)) \
333 k = SCM_I_MAKINUM (default); \
334 SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
335 SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
336 cvar = SCM_INUM (k); \
337 } while (0)
338
339 #define SCM_VALIDATE_INUM_DEF(pos, k, default) \
340 do { \
341 if (SCM_UNBNDP (k)) \
342 k = SCM_I_MAKINUM (default); \
343 else SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
344 } while (0)
345
346 #define SCM_VALIDATE_INUM_DEF_COPY(pos, k, default, cvar) \
347 do { \
348 if (SCM_UNBNDP (k)) \
349 { \
350 k = SCM_I_MAKINUM (default); \
351 cvar = default; \
352 } \
353 else \
354 { \
355 SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
356 cvar = SCM_INUM (k); \
357 } \
358 } while (0)
359
360 /* [low, high) */
361 #define SCM_VALIDATE_INUM_RANGE(pos, k, low, high) \
362 do { SCM_ASSERT(SCM_I_INUMP(k), k, pos, FUNC_NAME); \
363 SCM_ASSERT_RANGE(pos, k, \
364 (SCM_I_INUM (k) >= low && \
365 SCM_I_INUM (k) < high)); \
366 } while (0)
367
368 #define SCM_VALIDATE_INUM_RANGE_COPY(pos, k, low, high, cvar) \
369 do { \
370 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
371 SCM_ASSERT_RANGE (pos, k, low <= SCM_INUM (k) && SCM_INUM (k) < high); \
372 cvar = SCM_INUM (k); \
373 } while (0)
374
375 #define SCM_STRING_COERCE_0TERMINATION_X(x) (x)
376
377 /* XXX - buggy interface, STR might not be large enough.
378
379 Converts the given Scheme string OBJ into a C string, containing a copy
380 of OBJ's content with a trailing null byte. If LENP is non-NULL, set
381 *LENP to the string's length.
382
383 When STR is non-NULL it receives the copy and is returned by the function,
384 otherwise new memory is allocated and the caller is responsible for
385 freeing it via free(). If out of memory, NULL is returned.
386
387 Note that Scheme strings may contain arbitrary data, including null
388 characters. This means that null termination is not a reliable way to
389 determine the length of the returned value. However, the function always
390 copies the complete contents of OBJ, and sets *LENP to the length of the
391 scheme string (if LENP is non-null).
392 */
393 SCM_API char *scm_c_string2str (SCM obj, char *str, size_t *lenp);
394
395 /* XXX - buggy interface, you don't know how many bytes have been copied.
396
397 Copy LEN characters at START from the Scheme string OBJ to memory
398 at STR. START is an index into OBJ; zero means the beginning of
399 the string. STR has already been allocated by the caller.
400
401 If START + LEN is off the end of OBJ, silently truncate the source
402 region to fit the string. If truncation occurs, the corresponding
403 area of STR is left unchanged.
404 */
405 SCM_API char *scm_c_substring2str (SCM obj, char *str, size_t start, size_t len);
406
407 SCM_API char *scm_c_symbol2str (SCM obj, char *str, size_t *lenp);
408
409 /* Deprecated because the names belong to what is now
410 scm_truncate_number and scm_round_number.
411 */
412 SCM_API double scm_truncate (double x);
413 SCM_API double scm_round (double x);
414
415 /* Deprecated because we don't want people to access the internal
416 representation of strings directly.
417 */
418
419 #define SCM_VALIDATE_STRING_COPY(pos, str, cvar) \
420 do { \
421 SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
422 cvar = SCM_STRING_CHARS(str); \
423 } while (0)
424
425 /* validate a string and optional start/end arguments which default to
426 0/string-len. this is unrelated to the old shared substring
427 support, so please do not deprecate it :) */
428 #define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
429 pos_start, start, c_start,\
430 pos_end, end, c_end) \
431 do {\
432 SCM_VALIDATE_STRING_COPY (pos_str, str, c_str);\
433 c_start = SCM_UNBNDP(start)? 0 : scm_to_size_t (start);\
434 c_end = SCM_UNBNDP(end)? SCM_STRING_LENGTH(str) : scm_to_size_t (end);\
435 SCM_ASSERT_RANGE (pos_start, start,\
436 0 <= c_start \
437 && (size_t) c_start <= SCM_STRING_LENGTH (str));\
438 SCM_ASSERT_RANGE (pos_end, end,\
439 c_start <= c_end \
440 && (size_t) c_end <= SCM_STRING_LENGTH (str));\
441 } while (0)
442
443 /* Deprecated because we don't want people to access the internals of
444 symbols directly.
445 */
446
447 SCM_API char *SCM_SYMBOL_CHARS (SCM sym);
448 SCM_API size_t SCM_SYMBOL_LENGTH (SCM sym);
449
450 /* Deprecated because the macros used to evaluate the arguments more
451 than once and because the symbol of a keyword now has no dash.
452 */
453
454 SCM_API int SCM_KEYWORDP (SCM obj);
455 SCM_API SCM SCM_KEYWORDSYM (SCM keyword);
456
457
458 void scm_i_init_deprecated (void);
459
460 #endif
461
462 #endif /* SCM_DEPRECATED_H */