6 /* Copyright (C) 1995,1996,1998,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc.
8 * This library is free software; you can redistribute it and/or
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.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "libguile/__scm.h"
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))
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))
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))
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 ()'
59 #define SCM_GSUBR_TYPE(gsubr) (SCM_CELL_TYPE (gsubr) >> 8)
61 #define SCM_GSUBR_MAKTYPE(req, opt, rst) ((req)|((opt)<<4)|((rst)<<8))
62 #define SCM_GSUBR_MAX 33
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)
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
);
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
);
80 SCM_INTERNAL SCM
scm_i_gsubr_apply_array (SCM proc
, SCM
*args
, int nargs
,
82 SCM_INTERNAL
void scm_init_gsubr (void);
84 #endif /* SCM_GSUBR_H */