2006-04-17 00:05:42 +00:00
|
|
|
|
/* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006 Free Software Foundation, Inc.
|
1998-10-31 13:31:25 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
1998-10-31 13:31:25 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
1998-10-31 13:31:25 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
1999-12-12 02:36:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/_scm.h"
|
|
|
|
|
|
#include "libguile/eval.h"
|
2000-06-21 02:46:01 +00:00
|
|
|
|
#include "libguile/fluids.h"
|
2003-05-06 20:05:04 +00:00
|
|
|
|
#include "libguile/modules.h"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/validate.h"
|
|
|
|
|
|
#include "libguile/evalext.h"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2002-10-19 09:07:23 +00:00
|
|
|
|
SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
|
(SCM sym, SCM env),
|
2001-05-05 19:03:42 +00:00
|
|
|
|
"Return @code{#t} if @var{sym} is defined in the lexical "
|
2001-05-06 00:02:06 +00:00
|
|
|
|
"environment @var{env}. When @var{env} is not specified, "
|
|
|
|
|
|
"look in the top-level environment as defined by the "
|
2001-05-05 19:03:42 +00:00
|
|
|
|
"current module.")
|
2002-10-19 09:07:23 +00:00
|
|
|
|
#define FUNC_NAME s_scm_defined_p
|
1998-10-31 13:31:25 +00:00
|
|
|
|
{
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM var;
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2002-07-20 14:08:34 +00:00
|
|
|
|
SCM_VALIDATE_SYMBOL (1, sym);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
1998-11-20 17:14:41 +00:00
|
|
|
|
if (SCM_UNBNDP (env))
|
2001-05-15 14:57:22 +00:00
|
|
|
|
var = scm_sym2var (sym, scm_current_module_lookup_closure (),
|
|
|
|
|
|
SCM_BOOL_F);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM frames = env;
|
|
|
|
|
|
register SCM b;
|
|
|
|
|
|
for (; SCM_NIMP (frames); frames = SCM_CDR (frames))
|
|
|
|
|
|
{
|
2004-09-22 17:41:37 +00:00
|
|
|
|
SCM_ASSERT (scm_is_pair (frames), env, SCM_ARG2, FUNC_NAME);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
b = SCM_CAR (frames);
|
2004-07-06 10:59:25 +00:00
|
|
|
|
if (scm_is_true (scm_procedure_p (b)))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
break;
|
2004-09-22 17:41:37 +00:00
|
|
|
|
SCM_ASSERT (scm_is_pair (b), env, SCM_ARG2, FUNC_NAME);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
for (b = SCM_CAR (b); SCM_NIMP (b); b = SCM_CDR (b))
|
|
|
|
|
|
{
|
2004-09-22 17:41:37 +00:00
|
|
|
|
if (!scm_is_pair (b))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
{
|
2004-07-27 15:41:49 +00:00
|
|
|
|
if (scm_is_eq (b, sym))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
else
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2004-07-27 15:41:49 +00:00
|
|
|
|
if (scm_is_eq (SCM_CAR (b), sym))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2001-05-15 14:57:22 +00:00
|
|
|
|
var = scm_sym2var (sym,
|
|
|
|
|
|
SCM_NIMP (frames) ? SCM_CAR (frames) : SCM_BOOL_F,
|
|
|
|
|
|
SCM_BOOL_F);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-06 10:59:25 +00:00
|
|
|
|
return (scm_is_false (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
? SCM_BOOL_F
|
|
|
|
|
|
: SCM_BOOL_T);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2002-11-24 18:21:48 +00:00
|
|
|
|
|
1999-12-12 02:36:16 +00:00
|
|
|
|
SCM_REGISTER_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
|
1998-12-07 16:48:35 +00:00
|
|
|
|
|
2003-05-06 20:05:04 +00:00
|
|
|
|
|
2003-01-20 10:12:39 +00:00
|
|
|
|
SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
|
|
|
|
|
|
(SCM obj),
|
|
|
|
|
|
"Return #t for objects which Guile considers self-evaluating")
|
|
|
|
|
|
#define FUNC_NAME s_scm_self_evaluating_p
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (SCM_ITAG3 (obj))
|
|
|
|
|
|
{
|
|
|
|
|
|
case scm_tc3_int_1:
|
|
|
|
|
|
case scm_tc3_int_2:
|
|
|
|
|
|
/* inum */
|
|
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
case scm_tc3_imm24:
|
|
|
|
|
|
/* characters, booleans, other immediates */
|
2004-09-22 17:41:37 +00:00
|
|
|
|
return scm_from_bool (!scm_is_null (obj));
|
2003-01-20 10:12:39 +00:00
|
|
|
|
case scm_tc3_cons:
|
|
|
|
|
|
switch (SCM_TYP7 (obj))
|
|
|
|
|
|
{
|
|
|
|
|
|
case scm_tcs_closures:
|
|
|
|
|
|
case scm_tc7_vector:
|
|
|
|
|
|
case scm_tc7_wvect:
|
This set of patches introduces a new tc7 code scm_tc7_number for
numbers. Bignums, reals and complex numbers are turned from smobs
into subtypes of scm_tc7_number.
* tags.h (scm_tc7_number): New.
* eq.c (scm_equal_p), eval.c (SCM_CEVAL), evalext.c
(scm_self_evaluating_p), gc-card.c (scm_i_sweep_card), gc-mark.c
(scm_gc_mark_dependencies), goops.c (create_smob_classes), hash.c
(scm_hasher), numbers.c, numbers.h (SCM_NUMP), objects.c
(scm_class_of), print.c (scm_iprin1), smob.c
(scm_smob_prehistory): Don't handle bignums, reals and complex
numbers as subtypes of scm_tc7_smob any more.
* numbers.h, tags.h (scm_tc16_big, scm_tc16_real,
scm_tc16_complex): Moved definitions from tags.h to numbers.h.
2003-09-18 20:55:40 +00:00
|
|
|
|
case scm_tc7_number:
|
2003-01-20 10:12:39 +00:00
|
|
|
|
case scm_tc7_string:
|
|
|
|
|
|
case scm_tc7_smob:
|
|
|
|
|
|
case scm_tc7_cclo:
|
|
|
|
|
|
case scm_tc7_pws:
|
|
|
|
|
|
case scm_tcs_subrs:
|
|
|
|
|
|
case scm_tcs_struct:
|
|
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
|
|
|
|
|
|
scm_list_1 (obj));
|
|
|
|
|
|
return SCM_UNSPECIFIED; /* never reached */
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
1998-10-31 13:31:25 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_init_evalext ()
|
|
|
|
|
|
{
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/evalext.x"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
}
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|