environments.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* classes: h_files */
  2. #ifndef SCM_ENVIRONMENTS_H
  3. #define SCM_ENVIRONMENTS_H
  4. /* Copyright (C) 1999,2000, 2006 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libguile/__scm.h"
  21. /* The type for folding functions written in C. A function meant to be passed
  22. * to scm_c_environment_fold should have the type scm_environment_folder.
  23. */
  24. typedef SCM (*scm_environment_folder) (SCM data, SCM sym, SCM val, SCM tail);
  25. /* The type for observer functions written in C. A function meant to be
  26. * passed to scm_c_environment_observe should have the type
  27. * scm_environment_observer.
  28. */
  29. typedef void (*scm_environment_observer) (SCM env, SCM data);
  30. struct scm_environment_funcs {
  31. SCM (*ref) (SCM self, SCM symbol);
  32. SCM (*fold) (SCM self, scm_environment_folder proc, SCM data, SCM init);
  33. SCM (*define) (SCM self, SCM symbol, SCM value);
  34. SCM (*undefine) (SCM self, SCM symbol);
  35. SCM (*set) (SCM self, SCM symbol, SCM value);
  36. SCM (*cell) (SCM self, SCM symbol, int for_write);
  37. SCM (*observe) (SCM self, scm_environment_observer proc, SCM data, int weak_p);
  38. void (*unobserve) (SCM self, SCM token);
  39. SCM (*mark) (SCM self);
  40. void (*free) (SCM self);
  41. int (*print) (SCM self, SCM port, scm_print_state *pstate);
  42. };
  43. #define SCM_ENVIRONMENT_SUCCESS SCM_BOOL_T
  44. #define SCM_ENVIRONMENT_BINDING_IMMUTABLE scm_from_int (0)
  45. #define SCM_ENVIRONMENT_LOCATION_IMMUTABLE scm_from_int (1)
  46. #define SCM_ENVIRONMENT_LOCATION_NO_CELL SCM_BOOL_F
  47. SCM_API scm_t_bits scm_tc16_environment;
  48. #define SCM_ENVIRONMENT_P(x) \
  49. (!SCM_IMP (x) && SCM_CELL_TYPE (x) == scm_tc16_environment)
  50. #define SCM_ENVIRONMENT_FUNCS(env) \
  51. (*((struct scm_environment_funcs **) SCM_CELL_WORD_1 (env)))
  52. #define SCM_ENVIRONMENT_BOUND_P(env, symbol) \
  53. (!SCM_UNBNDP (SCM_ENVIRONMENT_REF (env, symbol)))
  54. #define SCM_ENVIRONMENT_REF(env, symbol) \
  55. ((*(SCM_ENVIRONMENT_FUNCS (env)->ref)) (env, symbol))
  56. #define SCM_ENVIRONMENT_FOLD(env, proc, data, init) \
  57. ((*(SCM_ENVIRONMENT_FUNCS (env)->fold)) (env, proc, data, init))
  58. #define SCM_ENVIRONMENT_DEFINE(env, symbol, value) \
  59. ((*(SCM_ENVIRONMENT_FUNCS (env)->define)) (env, symbol, value))
  60. #define SCM_ENVIRONMENT_UNDEFINE(env, symbol) \
  61. ((*(SCM_ENVIRONMENT_FUNCS (env)->undefine)) (env, symbol))
  62. #define SCM_ENVIRONMENT_SET(env, symbol, value) \
  63. ((*(SCM_ENVIRONMENT_FUNCS (env)->set)) (env, symbol, value))
  64. #define SCM_ENVIRONMENT_CELL(env, symbol, for_write) \
  65. ((*(SCM_ENVIRONMENT_FUNCS (env)->cell)) (env, symbol, for_write))
  66. #define SCM_ENVIRONMENT_OBSERVE(env, proc, data, weak_p) \
  67. ((*(SCM_ENVIRONMENT_FUNCS (env)->observe)) (env, proc, data, weak_p))
  68. #define SCM_ENVIRONMENT_UNOBSERVE(env, token) \
  69. ((*(SCM_ENVIRONMENT_FUNCS (env)->unobserve)) (env, token))
  70. SCM_API scm_t_bits scm_tc16_observer;
  71. #define SCM_OBSERVER_P(x) \
  72. (!SCM_IMP (x) && (SCM_CELL_TYPE (x) == scm_tc16_observer))
  73. #define SCM_OBSERVER_ENVIRONMENT(x) \
  74. (SCM_CELL_OBJECT_1 (x))
  75. #define SCM_OBSERVER_DATA(x) \
  76. (SCM_CELL_OBJECT_2 (x))
  77. #define SCM_OBSERVER_PROC(x) \
  78. ((scm_environment_observer) SCM_CELL_WORD_3 (x))
  79. SCM_API SCM scm_system_environment;
  80. SCM_API void scm_error_environment_unbound (const char *, SCM, SCM) SCM_NORETURN;
  81. SCM_API void scm_error_environment_immutable_binding (const char *, SCM, SCM) SCM_NORETURN;
  82. SCM_API void scm_error_environment_immutable_location (const char *, SCM, SCM) SCM_NORETURN;
  83. SCM_API SCM scm_make_environment (void *type);
  84. SCM_API SCM scm_environment_p (SCM env);
  85. SCM_API SCM scm_environment_bound_p (SCM env, SCM sym);
  86. SCM_API SCM scm_environment_ref (SCM env, SCM sym);
  87. SCM_API SCM scm_c_environment_ref (SCM env, SCM sym);
  88. SCM_API SCM scm_environment_fold (SCM env, SCM proc, SCM init);
  89. SCM_API SCM scm_c_environment_fold (SCM env, scm_environment_folder proc, SCM data, SCM init);
  90. SCM_API SCM scm_environment_define (SCM env, SCM sym, SCM val);
  91. SCM_API SCM scm_environment_undefine (SCM env, SCM sym);
  92. SCM_API SCM scm_environment_set_x (SCM env, SCM sym, SCM val);
  93. SCM_API SCM scm_environment_cell (SCM env, SCM sym, SCM for_write);
  94. SCM_API SCM scm_c_environment_cell (SCM env, SCM sym, int for_write);
  95. SCM_API SCM scm_environment_observe (SCM env, SCM proc);
  96. SCM_API SCM scm_environment_observe_weak (SCM env, SCM proc);
  97. SCM_API SCM scm_c_environment_observe (SCM env, scm_environment_observer proc, SCM data, int weak_p);
  98. SCM_API SCM scm_environment_unobserve (SCM token);
  99. SCM_API void scm_environments_prehistory (void);
  100. SCM_API void scm_init_environments (void);
  101. SCM_API void *scm_type_leaf_environment;
  102. #define SCM_LEAF_ENVIRONMENT_P(env) \
  103. (SCM_ENVIRONMENT_P (env) \
  104. && SCM_ENVIRONMENT_FUNCS (env) == scm_type_leaf_environment)
  105. SCM_API SCM scm_make_leaf_environment (void);
  106. SCM_API SCM scm_leaf_environment_p (SCM env);
  107. SCM_API void *scm_type_eval_environment;
  108. #define SCM_EVAL_ENVIRONMENT_P(env) \
  109. (SCM_ENVIRONMENT_P (env) \
  110. && SCM_ENVIRONMENT_FUNCS (env) == scm_type_eval_environment)
  111. SCM_API SCM scm_make_eval_environment (SCM local, SCM imported);
  112. SCM_API SCM scm_eval_environment_p (SCM env);
  113. SCM_API SCM scm_eval_environment_local (SCM env);
  114. SCM_API SCM scm_eval_environment_set_local_x (SCM env, SCM local);
  115. SCM_API SCM scm_eval_environment_imported (SCM env);
  116. SCM_API SCM scm_eval_environment_set_imported_x (SCM env, SCM imported);
  117. SCM_API void *scm_type_import_environment;
  118. #define SCM_IMPORT_ENVIRONMENT_P(env) \
  119. (SCM_ENVIRONMENT_P (env) \
  120. && SCM_ENVIRONMENT_FUNCS (env) == scm_type_import_environment)
  121. SCM_API SCM scm_make_import_environment (SCM imports, SCM conflict_proc);
  122. SCM_API SCM scm_import_environment_p (SCM env);
  123. SCM_API SCM scm_import_environment_imports (SCM env);
  124. SCM_API SCM scm_import_environment_set_imports_x (SCM env, SCM imports);
  125. SCM_API void *scm_type_export_environment;
  126. #define SCM_EXPORT_ENVIRONMENT_P(env) \
  127. (SCM_ENVIRONMENT_P (env) \
  128. && SCM_ENVIRONMENT_FUNCS (env) == scm_type_export_environment)
  129. SCM_API SCM scm_make_export_environment (SCM private, SCM signature);
  130. SCM_API SCM scm_export_environment_p (SCM env);
  131. SCM_API SCM scm_export_environment_private (SCM env);
  132. SCM_API SCM scm_export_environment_set_private_x (SCM env, SCM private);
  133. SCM_API SCM scm_export_environment_signature (SCM env);
  134. SCM_API SCM scm_export_environment_set_signature_x (SCM env, SCM signature);
  135. #endif /* SCM_ENVIRONMENTS_H */
  136. /*
  137. Local Variables:
  138. c-file-style: "gnu"
  139. End:
  140. */