Commit | Line | Data |
---|---|---|
c438cd71 | 1 | /* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2006, 2008, 2009, |
510ca126 | 2 | * 2010, 2011, 2012, 2013 Free Software Foundation, Inc. |
c438cd71 | 3 | * |
73be1d9e | 4 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
5 | * modify it under the terms of the GNU Lesser General Public License |
6 | * as published by the Free Software Foundation; either version 3 of | |
7 | * the License, or (at your option) any later version. | |
0f2d19dd | 8 | * |
53befeb7 NJ |
9 | * This library is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. | |
0f2d19dd | 13 | * |
73be1d9e MV |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | * 02110-1301 USA | |
73be1d9e | 18 | */ |
1bbd0b84 | 19 | |
1bbd0b84 | 20 | |
0f2d19dd | 21 | \f |
dbb605f5 LC |
22 | #ifdef HAVE_CONFIG_H |
23 | # include <config.h> | |
24 | #endif | |
0f2d19dd | 25 | |
a0599745 | 26 | #include "libguile/_scm.h" |
0f2d19dd | 27 | |
a0599745 MD |
28 | #include "libguile/strings.h" |
29 | #include "libguile/vectors.h" | |
0717dfd8 | 30 | #include "libguile/smob.h" |
c88a8162 | 31 | #include "libguile/deprecation.h" |
bdc88419 | 32 | |
a0599745 MD |
33 | #include "libguile/validate.h" |
34 | #include "libguile/procs.h" | |
3fd8807e | 35 | #include "libguile/procprop.h" |
53e28ed9 | 36 | #include "libguile/objcodes.h" |
7e580328 | 37 | #include "libguile/programs.h" |
0f2d19dd JB |
38 | \f |
39 | ||
40 | ||
41 | /* {Procedures} | |
42 | */ | |
43 | ||
9de33deb | 44 | |
3b3b36dd | 45 | SCM_DEFINE (scm_procedure_p, "procedure?", 1, 0, 0, |
8cf97abf MG |
46 | (SCM obj), |
47 | "Return @code{#t} if @var{obj} is a procedure.") | |
1bbd0b84 | 48 | #define FUNC_NAME s_scm_procedure_p |
0f2d19dd | 49 | { |
8b33752b | 50 | return scm_from_bool (SCM_PROGRAM_P (obj) |
510ca126 | 51 | || SCM_RTL_PROGRAM_P (obj) |
8b33752b AW |
52 | || (SCM_STRUCTP (obj) && SCM_STRUCT_APPLICABLE_P (obj)) |
53 | || (SCM_HAS_TYP7 (obj, scm_tc7_smob) | |
54 | && SCM_SMOB_APPLICABLE_P (obj))); | |
0f2d19dd | 55 | } |
1bbd0b84 | 56 | #undef FUNC_NAME |
0f2d19dd | 57 | |
3b3b36dd | 58 | SCM_DEFINE (scm_thunk_p, "thunk?", 1, 0, 0, |
8cf97abf MG |
59 | (SCM obj), |
60 | "Return @code{#t} if @var{obj} is a thunk.") | |
1bbd0b84 | 61 | #define FUNC_NAME s_scm_thunk_p |
44bd53b9 | 62 | { |
314b8716 AW |
63 | int req, opt, rest; |
64 | return scm_from_bool (scm_i_procedure_arity (obj, &req, &opt, &rest) | |
65 | && req == 0); | |
44bd53b9 | 66 | } |
1bbd0b84 | 67 | #undef FUNC_NAME |
44bd53b9 | 68 | |
0f2d19dd | 69 | |
b4cd6492 MD |
70 | /* Procedure-with-setter |
71 | */ | |
72 | ||
ea68d342 AW |
73 | static SCM pws_vtable; |
74 | ||
75 | ||
a1ec6916 | 76 | SCM_DEFINE (scm_procedure_with_setter_p, "procedure-with-setter?", 1, 0, 0, |
1bbd0b84 | 77 | (SCM obj), |
8cf97abf MG |
78 | "Return @code{#t} if @var{obj} is a procedure with an\n" |
79 | "associated setter procedure.") | |
1bbd0b84 | 80 | #define FUNC_NAME s_scm_procedure_with_setter_p |
b4cd6492 | 81 | { |
ea68d342 | 82 | return scm_from_bool (SCM_STRUCTP (obj) && SCM_STRUCT_SETTER_P (obj)); |
b4cd6492 | 83 | } |
1bbd0b84 | 84 | #undef FUNC_NAME |
b4cd6492 | 85 | |
a1ec6916 | 86 | SCM_DEFINE (scm_make_procedure_with_setter, "make-procedure-with-setter", 2, 0, 0, |
1bbd0b84 | 87 | (SCM procedure, SCM setter), |
8cf97abf MG |
88 | "Create a new procedure which behaves like @var{procedure}, but\n" |
89 | "with the associated setter @var{setter}.") | |
1bbd0b84 | 90 | #define FUNC_NAME s_scm_make_procedure_with_setter |
b4cd6492 | 91 | { |
e1f8eb2b MD |
92 | SCM_VALIDATE_PROC (1, procedure); |
93 | SCM_VALIDATE_PROC (2, setter); | |
30b7cf9d AW |
94 | return scm_make_struct (pws_vtable, SCM_INUM0, |
95 | scm_list_2 (procedure, setter)); | |
b4cd6492 | 96 | } |
1bbd0b84 | 97 | #undef FUNC_NAME |
b4cd6492 | 98 | |
a1ec6916 | 99 | SCM_DEFINE (scm_procedure, "procedure", 1, 0, 0, |
1bbd0b84 | 100 | (SCM proc), |
ea68d342 AW |
101 | "Return the procedure of @var{proc}, which must be an\n" |
102 | "applicable struct.") | |
1bbd0b84 | 103 | #define FUNC_NAME s_scm_procedure |
b4cd6492 | 104 | { |
05e0e22b AW |
105 | SCM_ASSERT (SCM_STRUCTP (proc) && SCM_STRUCT_APPLICABLE_P (proc), |
106 | proc, SCM_ARG1, FUNC_NAME); | |
ea68d342 | 107 | return SCM_STRUCT_PROCEDURE (proc); |
b4cd6492 | 108 | } |
1bbd0b84 | 109 | #undef FUNC_NAME |
b4cd6492 | 110 | |
ea68d342 AW |
111 | SCM_PRIMITIVE_GENERIC (scm_setter, "setter", 1, 0, 0, |
112 | (SCM proc), | |
113 | "Return the setter of @var{proc}, which must be an\n" | |
114 | "applicable struct with a setter.") | |
115 | #define FUNC_NAME s_scm_setter | |
b4cd6492 | 116 | { |
fa075d40 AW |
117 | if (SCM_UNLIKELY (!SCM_STRUCTP (proc))) |
118 | return scm_wta_dispatch_1 (g_scm_setter, proc, SCM_ARG1, FUNC_NAME); | |
ea68d342 AW |
119 | if (SCM_STRUCT_SETTER_P (proc)) |
120 | return SCM_STRUCT_SETTER (proc); | |
534491d0 AW |
121 | if (SCM_PUREGENERICP (proc) |
122 | && SCM_IS_A_P (proc, scm_class_generic_with_setter)) | |
ea68d342 AW |
123 | /* FIXME: might not be an accessor */ |
124 | return SCM_GENERIC_SETTER (proc); | |
fa075d40 | 125 | return scm_wta_dispatch_1 (g_scm_setter, proc, SCM_ARG1, FUNC_NAME); |
b038d983 | 126 | return SCM_BOOL_F; /* not reached */ |
b4cd6492 | 127 | } |
ea68d342 | 128 | #undef FUNC_NAME |
1cc91f1b | 129 | |
ac51e74b | 130 | \f |
0f2d19dd JB |
131 | void |
132 | scm_init_procs () | |
0f2d19dd | 133 | { |
bbd41a6a AW |
134 | pws_vtable = |
135 | scm_c_make_struct (scm_applicable_struct_with_setter_vtable_vtable, | |
136 | 0, | |
137 | 1, | |
4a655e50 | 138 | SCM_UNPACK (scm_from_latin1_symbol ("pwpw"))); |
ea68d342 | 139 | |
a0599745 | 140 | #include "libguile/procs.x" |
0f2d19dd | 141 | } |
89e00824 ML |
142 | |
143 | /* | |
144 | Local Variables: | |
145 | c-file-style: "gnu" | |
146 | End: | |
147 | */ |