Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
dee01b01 DH |
3 | #ifndef SCM_GSUBR_H |
4 | #define SCM_GSUBR_H | |
5 | ||
e20d7001 | 6 | /* Copyright (C) 1995,1996,1998,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc. |
dee01b01 | 7 | * |
73be1d9e | 8 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
9 | * modify it under the terms of the GNU Lesser General Public License |
10 | * as published by the Free Software Foundation; either version 3 of | |
11 | * the License, or (at your option) any later version. | |
dee01b01 | 12 | * |
53befeb7 NJ |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
dee01b01 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301 USA | |
73be1d9e | 22 | */ |
dee01b01 | 23 | |
0f2d19dd JB |
24 | \f |
25 | ||
b4309c3c | 26 | #include "libguile/__scm.h" |
0f2d19dd | 27 | |
9fdf9fd3 AW |
28 | |
29 | \f | |
30 | ||
31 | /* Subrs | |
32 | */ | |
33 | ||
34 | #define SCM_PRIMITIVE_P(x) (SCM_NIMP (x) && SCM_TYP7 (x) == scm_tc7_gsubr) | |
35 | #define SCM_PRIMITIVE_GENERIC_P(x) (SCM_PRIMITIVE_P (x) && SCM_SUBR_GENERIC (x)) | |
36 | ||
37 | #define SCM_SUBR_META_INFO(x) ((SCM *) SCM_CELL_WORD_3 (x)) | |
38 | #define SCM_SUBR_NAME(x) (SCM_SUBR_META_INFO (x) [0]) | |
39 | #define SCM_SUBRF(x) ((SCM (*)()) SCM_CELL_WORD_1 (x)) | |
40 | #define SCM_SUBR_PROPS(x) (SCM_SUBR_META_INFO (x) [1]) | |
41 | #define SCM_SUBR_GENERIC(x) ((SCM *) SCM_CELL_WORD_2 (x)) | |
42 | #define SCM_SET_SUBR_GENERIC(x, g) (*((SCM *) SCM_CELL_WORD_2 (x)) = (g)) | |
43 | #define SCM_SET_SUBR_GENERIC_LOC(x, g) (SCM_SET_CELL_WORD_2 (x, (scm_t_bits) g)) | |
44 | ||
45 | /* Return the most suitable subr type for a subr with REQ required arguments, | |
46 | OPT optional arguments, and REST (0 or 1) arguments. This has to be in | |
47 | sync with `create_gsubr ()'. */ | |
48 | #define SCM_SUBR_ARITY_TO_TYPE(req, opt, rest) \ | |
49 | (scm_tc7_gsubr | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)) | |
50 | ||
51 | ||
52 | \f | |
53 | ||
0f2d19dd | 54 | \f |
0f2d19dd | 55 | |
e20d7001 LC |
56 | /* Return an integer describing the arity of GSUBR, a subr of type |
57 | `scm_tc7_gsubr'. The result can be interpreted with `SCM_GSUBR_REQ ()' | |
58 | and similar. */ | |
59 | #define SCM_GSUBR_TYPE(gsubr) (SCM_CELL_TYPE (gsubr) >> 8) | |
60 | ||
dc0938d8 | 61 | #define SCM_GSUBR_MAKTYPE(req, opt, rst) ((req)|((opt)<<4)|((rst)<<8)) |
e20d7001 | 62 | #define SCM_GSUBR_MAX 33 |
c014a02e ML |
63 | #define SCM_GSUBR_REQ(x) ((long)(x)&0xf) |
64 | #define SCM_GSUBR_OPT(x) (((long)(x)&0xf0)>>4) | |
65 | #define SCM_GSUBR_REST(x) ((long)(x)>>8) | |
dc0938d8 | 66 | |
33b001fd MV |
67 | SCM_API SCM scm_c_make_gsubr (const char *name, |
68 | int req, int opt, int rst, SCM (*fcn) ()); | |
69 | SCM_API SCM scm_c_make_gsubr_with_generic (const char *name, | |
70 | int req, int opt, int rst, | |
71 | SCM (*fcn) (), SCM *gf); | |
72 | SCM_API SCM scm_c_define_gsubr (const char *name, | |
73 | int req, int opt, int rst, SCM (*fcn) ()); | |
74 | SCM_API SCM scm_c_define_gsubr_with_generic (const char *name, | |
75 | int req, int opt, int rst, | |
76 | SCM (*fcn) (), SCM *gf); | |
9d78586f | 77 | |
8321ed20 LC |
78 | SCM_INTERNAL SCM scm_i_gsubr_apply (SCM proc, SCM arg, ...); |
79 | SCM_INTERNAL SCM scm_i_gsubr_apply_list (SCM proc, SCM args); | |
23f276de AW |
80 | SCM_INTERNAL SCM scm_i_gsubr_apply_array (SCM proc, SCM *args, int nargs, |
81 | int headroom); | |
102dbb6f | 82 | SCM_INTERNAL void scm_init_gsubr (void); |
9d78586f | 83 | |
dee01b01 | 84 | #endif /* SCM_GSUBR_H */ |
89e00824 ML |
85 | |
86 | /* | |
87 | Local Variables: | |
88 | c-file-style: "gnu" | |
89 | End: | |
90 | */ |