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