Adapt GDB integration to newest patches
[bpt/guile.git] / libguile / evalext.c
1 /* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2015 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 */
18
19
20 \f
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include "libguile/_scm.h"
26 #include "libguile/eval.h"
27 #include "libguile/fluids.h"
28 #include "libguile/modules.h"
29
30 #include "libguile/validate.h"
31 #include "libguile/evalext.h"
32
33 SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
34 (SCM sym, SCM module),
35 "Return @code{#t} if @var{sym} is defined in the module "
36 "@var{module} or the current module when @var{module} is not"
37 "specified.")
38 #define FUNC_NAME s_scm_defined_p
39 {
40 SCM var;
41
42 SCM_VALIDATE_SYMBOL (1, sym);
43
44 if (SCM_UNBNDP (module))
45 module = scm_current_module ();
46 else
47 SCM_VALIDATE_MODULE (2, module);
48
49 var = scm_module_variable (module, sym);
50
51 return (scm_is_false (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
52 ? SCM_BOOL_F
53 : SCM_BOOL_T);
54 }
55 #undef FUNC_NAME
56
57
58 SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
59 (SCM obj),
60 "Return #t for objects which Guile considers self-evaluating")
61 #define FUNC_NAME s_scm_self_evaluating_p
62 {
63 switch (SCM_ITAG3 (obj))
64 {
65 case scm_tc3_int_1:
66 case scm_tc3_int_2:
67 /* inum */
68 return SCM_BOOL_T;
69 case scm_tc3_imm24:
70 /* characters, booleans, other immediates */
71 return scm_from_bool (!scm_is_null_and_not_nil (obj));
72 case scm_tc3_cons:
73 switch (SCM_TYP7 (obj))
74 {
75 case scm_tc7_vector:
76 case scm_tc7_wvect:
77 case scm_tc7_pointer:
78 case scm_tc7_hashtable:
79 case scm_tc7_weak_set:
80 case scm_tc7_weak_table:
81 case scm_tc7_fluid:
82 case scm_tc7_dynamic_state:
83 case scm_tc7_frame:
84 case scm_tc7_keyword:
85 case scm_tc7_vm_cont:
86 case scm_tc7_number:
87 case scm_tc7_string:
88 case scm_tc7_smob:
89 case scm_tc7_program:
90 case scm_tc7_bytevector:
91 case scm_tc7_array:
92 case scm_tc7_bitvector:
93 case scm_tcs_struct:
94 return SCM_BOOL_T;
95 default:
96 return SCM_BOOL_F;
97 }
98 }
99 SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
100 scm_list_1 (obj));
101 return SCM_UNSPECIFIED; /* never reached */
102 }
103 #undef FUNC_NAME
104
105 void
106 scm_init_evalext ()
107 {
108 #include "libguile/evalext.x"
109 }
110
111 /*
112 Local Variables:
113 c-file-style: "gnu"
114 End:
115 */