evalext.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008 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
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but 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 02110-1301 USA
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/eval.h"
  22. #include "libguile/fluids.h"
  23. #include "libguile/modules.h"
  24. #include "libguile/validate.h"
  25. #include "libguile/evalext.h"
  26. SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
  27. (SCM sym, SCM env),
  28. "Return @code{#t} if @var{sym} is defined in the lexical "
  29. "environment @var{env}. When @var{env} is not specified, "
  30. "look in the top-level environment as defined by the "
  31. "current module.")
  32. #define FUNC_NAME s_scm_defined_p
  33. {
  34. SCM var;
  35. SCM_VALIDATE_SYMBOL (1, sym);
  36. if (SCM_UNBNDP (env))
  37. var = scm_sym2var (sym, scm_current_module_lookup_closure (),
  38. SCM_BOOL_F);
  39. else
  40. {
  41. SCM frames = env;
  42. register SCM b;
  43. for (; SCM_NIMP (frames); frames = SCM_CDR (frames))
  44. {
  45. SCM_ASSERT (scm_is_pair (frames), env, SCM_ARG2, FUNC_NAME);
  46. b = SCM_CAR (frames);
  47. if (scm_is_true (scm_procedure_p (b)))
  48. break;
  49. SCM_ASSERT (scm_is_pair (b), env, SCM_ARG2, FUNC_NAME);
  50. for (b = SCM_CAR (b); SCM_NIMP (b); b = SCM_CDR (b))
  51. {
  52. if (!scm_is_pair (b))
  53. {
  54. if (scm_is_eq (b, sym))
  55. return SCM_BOOL_T;
  56. else
  57. break;
  58. }
  59. if (scm_is_eq (SCM_CAR (b), sym))
  60. return SCM_BOOL_T;
  61. }
  62. }
  63. var = scm_sym2var (sym,
  64. SCM_NIMP (frames) ? SCM_CAR (frames) : SCM_BOOL_F,
  65. SCM_BOOL_F);
  66. }
  67. return (scm_is_false (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
  68. ? SCM_BOOL_F
  69. : SCM_BOOL_T);
  70. }
  71. #undef FUNC_NAME
  72. SCM_REGISTER_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
  73. SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
  74. (SCM obj),
  75. "Return #t for objects which Guile considers self-evaluating")
  76. #define FUNC_NAME s_scm_self_evaluating_p
  77. {
  78. switch (SCM_ITAG3 (obj))
  79. {
  80. case scm_tc3_int_1:
  81. case scm_tc3_int_2:
  82. /* inum */
  83. return SCM_BOOL_T;
  84. case scm_tc3_imm24:
  85. /* characters, booleans, other immediates */
  86. return scm_from_bool (!scm_is_null (obj));
  87. case scm_tc3_cons:
  88. switch (SCM_TYP7 (obj))
  89. {
  90. case scm_tcs_closures:
  91. case scm_tc7_vector:
  92. case scm_tc7_wvect:
  93. case scm_tc7_number:
  94. case scm_tc7_string:
  95. case scm_tc7_smob:
  96. case scm_tc7_cclo:
  97. case scm_tc7_pws:
  98. case scm_tcs_subrs:
  99. case scm_tcs_struct:
  100. return SCM_BOOL_T;
  101. default:
  102. return SCM_BOOL_F;
  103. }
  104. }
  105. SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
  106. scm_list_1 (obj));
  107. return SCM_UNSPECIFIED; /* never reached */
  108. }
  109. #undef FUNC_NAME
  110. void
  111. scm_init_evalext ()
  112. {
  113. #include "libguile/evalext.x"
  114. }
  115. /*
  116. Local Variables:
  117. c-file-style: "gnu"
  118. End:
  119. */