Commit | Line | Data |
---|---|---|
5d3e2388 DH |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef ENVIRONMENTS_H | |
4 | #define ENVIRONMENTS_H | |
5 | /* Copyright (C) 1999, 2000 Free Software Foundation, Inc. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2, or (at your option) | |
10 | * any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this software; see the file COPYING. If not, write to | |
19 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
20 | * Boston, MA 02111-1307 USA | |
21 | * | |
22 | * As a special exception, the Free Software Foundation gives permission | |
23 | * for additional uses of the text contained in its release of GUILE. | |
24 | * | |
25 | * The exception is that, if you link the GUILE library with other files | |
26 | * to produce an executable, this does not by itself cause the | |
27 | * resulting executable to be covered by the GNU General Public License. | |
28 | * Your use of that executable is in no way restricted on account of | |
29 | * linking the GUILE library code into it. | |
30 | * | |
31 | * This exception does not however invalidate any other reasons why | |
32 | * the executable file might be covered by the GNU General Public License. | |
33 | * | |
34 | * This exception applies only to the code released by the | |
35 | * Free Software Foundation under the name GUILE. If you copy | |
36 | * code from other Free Software Foundation releases into a copy of | |
37 | * GUILE, as the General Public License permits, the exception does | |
38 | * not apply to the code that you add in this way. To avoid misleading | |
39 | * anyone as to the status of such modified files, you must delete | |
40 | * this exception notice from them. | |
41 | * | |
42 | * If you write modifications of your own for GUILE, it is your choice | |
43 | * whether to permit this exception to apply to your modifications. | |
44 | * If you do not wish that, delete this exception notice. */ | |
45 | \f | |
46 | ||
47 | #include "libguile/__scm.h" | |
48 | ||
49 | \f | |
50 | ||
51 | /* The type for folding functions written in C. A function meant to be passed | |
52 | * to scm_c_environment_fold should have the type scm_environment_folder. | |
53 | */ | |
54 | typedef SCM (*scm_environment_folder) (SCM data, SCM sym, SCM val, SCM tail); | |
55 | ||
56 | ||
57 | /* The type for observer functions written in C. A function meant to be | |
58 | * passed to scm_c_environment_observe should have the type | |
59 | * scm_environment_observer. | |
60 | */ | |
61 | typedef void (*scm_environment_observer) (SCM env, SCM data); | |
62 | ||
63 | ||
64 | struct scm_environment_funcs { | |
65 | SCM (*ref) (SCM self, SCM symbol); | |
66 | SCM (*fold) (SCM self, scm_environment_folder proc, SCM data, SCM init); | |
67 | ||
68 | SCM (*define) (SCM self, SCM symbol, SCM value); | |
69 | SCM (*undefine) (SCM self, SCM symbol); | |
70 | SCM (*set) (SCM self, SCM symbol, SCM value); | |
71 | ||
72 | SCM (*cell) (SCM self, SCM symbol, int for_write); | |
73 | SCM (*observe) (SCM self, scm_environment_observer proc, SCM data, int weak_p); | |
74 | void (*unobserve) (SCM self, SCM token); | |
75 | ||
76 | SCM (*mark) (SCM self); | |
77 | scm_sizet (*free) (SCM self); | |
78 | int (*print) (SCM self, SCM port, scm_print_state *pstate); | |
79 | }; | |
80 | ||
81 | \f | |
82 | ||
83 | #define SCM_ENVIRONMENT_SUCCESS SCM_BOOL_T | |
84 | #define SCM_ENVIRONMENT_BINDING_IMMUTABLE SCM_MAKINUM (0) | |
85 | #define SCM_ENVIRONMENT_LOCATION_IMMUTABLE SCM_MAKINUM (1) | |
86 | #define SCM_ENVIRONMENT_LOCATION_NO_CELL SCM_BOOL_F | |
87 | ||
88 | extern long scm_tc16_environment; | |
89 | ||
90 | #define SCM_ENVIRONMENT_P(x) \ | |
91 | (!SCM_IMP (x) && SCM_CELL_TYPE (x) == scm_tc16_environment) | |
92 | #define SCM_ENVIRONMENT_FUNCS(env) \ | |
93 | (*((struct scm_environment_funcs **) SCM_CELL_WORD_1 (env))) | |
94 | #define SCM_ENVIRONMENT_BOUND_P(env, symbol) \ | |
95 | (!SCM_UNBNDP (SCM_ENVIRONMENT_REF (env, symbol))) | |
96 | #define SCM_ENVIRONMENT_REF(env, symbol) \ | |
97 | ((*(SCM_ENVIRONMENT_FUNCS (env)->ref)) (env, symbol)) | |
98 | #define SCM_ENVIRONMENT_FOLD(env, proc, data, init) \ | |
99 | ((*(SCM_ENVIRONMENT_FUNCS (env)->fold)) (env, proc, data, init)) | |
100 | #define SCM_ENVIRONMENT_DEFINE(env, symbol, value) \ | |
101 | ((*(SCM_ENVIRONMENT_FUNCS (env)->define)) (env, symbol, value)) | |
102 | #define SCM_ENVIRONMENT_UNDEFINE(env, symbol) \ | |
103 | ((*(SCM_ENVIRONMENT_FUNCS (env)->undefine)) (env, symbol)) | |
104 | #define SCM_ENVIRONMENT_SET(env, symbol, value) \ | |
105 | ((*(SCM_ENVIRONMENT_FUNCS (env)->set)) (env, symbol, value)) | |
106 | #define SCM_ENVIRONMENT_CELL(env, symbol, for_write) \ | |
107 | ((*(SCM_ENVIRONMENT_FUNCS (env)->cell)) (env, symbol, for_write)) | |
108 | #define SCM_ENVIRONMENT_OBSERVE(env, proc, data, weak_p) \ | |
109 | ((*(SCM_ENVIRONMENT_FUNCS (env)->observe)) (env, proc, data, weak_p)) | |
110 | #define SCM_ENVIRONMENT_UNOBSERVE(env, token) \ | |
111 | ((*(SCM_ENVIRONMENT_FUNCS (env)->unobserve)) (env, token)) | |
112 | ||
113 | extern long scm_tc16_observer; | |
114 | ||
115 | #define SCM_OBSERVER_P(x) \ | |
116 | (!SCM_IMP (x) && (SCM_CELL_TYPE (x) == scm_tc16_observer)) | |
117 | #define SCM_OBSERVER_ENVIRONMENT(x) \ | |
118 | (SCM_CELL_OBJECT_1 (x)) | |
119 | #define SCM_OBSERVER_DATA(x) \ | |
120 | (SCM_CELL_OBJECT_2 (x)) | |
121 | #define SCM_OBSERVER_PROC(x) \ | |
122 | ((scm_environment_observer) SCM_CELL_WORD_3 (x)) | |
123 | ||
124 | extern void scm_error_environment_unbound (const char *, SCM, SCM) SCM_NORETURN; | |
125 | extern void scm_error_environment_immutable_binding (const char *, SCM, SCM) SCM_NORETURN; | |
126 | extern void scm_error_environment_immutable_location (const char *, SCM, SCM) SCM_NORETURN; | |
127 | ||
128 | extern SCM scm_make_environment (void *type); | |
129 | extern SCM scm_environment_p (SCM env); | |
130 | extern SCM scm_environment_bound_p (SCM env, SCM sym); | |
131 | extern SCM scm_environment_ref (SCM env, SCM sym); | |
132 | extern SCM scm_c_environment_ref (SCM env, SCM sym); | |
133 | extern SCM scm_environment_fold (SCM env, SCM proc, SCM init); | |
134 | extern SCM scm_c_environment_fold (SCM env, scm_environment_folder proc, SCM data, SCM init); | |
135 | extern SCM scm_environment_define (SCM env, SCM sym, SCM val); | |
136 | extern SCM scm_environment_undefine (SCM env, SCM sym); | |
137 | extern SCM scm_environment_set_x (SCM env, SCM sym, SCM val); | |
138 | extern SCM scm_environment_cell (SCM env, SCM sym, SCM for_write); | |
139 | extern SCM scm_c_environment_cell (SCM env, SCM sym, int for_write); | |
140 | extern SCM scm_environment_observe (SCM env, SCM proc); | |
141 | extern SCM scm_environment_observe_weak (SCM env, SCM proc); | |
142 | extern SCM scm_c_environment_observe (SCM env, scm_environment_observer proc, SCM data, int weak_p); | |
143 | extern SCM scm_environment_unobserve (SCM token); | |
144 | ||
145 | extern void scm_environments_prehistory (void); | |
146 | extern void scm_init_environments (void); | |
147 | ||
148 | \f | |
149 | ||
150 | extern void *scm_type_leaf_environment; | |
151 | ||
152 | #define SCM_LEAF_ENVIRONMENT_P(env) \ | |
153 | (SCM_ENVIRONMENT_P (env) \ | |
154 | && SCM_ENVIRONMENT_FUNCS (env) == scm_type_leaf_environment) | |
155 | ||
156 | extern SCM scm_make_leaf_environment (void); | |
157 | extern SCM scm_leaf_environment_p (SCM env); | |
158 | ||
159 | \f | |
160 | ||
161 | extern void *scm_type_eval_environment; | |
162 | ||
163 | #define SCM_EVAL_ENVIRONMENT_P(env) \ | |
164 | (SCM_ENVIRONMENT_P (env) \ | |
165 | && SCM_ENVIRONMENT_FUNCS (env) == scm_type_eval_environment) | |
166 | ||
167 | extern SCM scm_make_eval_environment (SCM local, SCM imported); | |
168 | extern SCM scm_eval_environment_p (SCM env); | |
169 | extern SCM scm_eval_environment_local (SCM env); | |
170 | extern SCM scm_eval_environment_set_local_x (SCM env, SCM local); | |
171 | extern SCM scm_eval_environment_imported (SCM env); | |
172 | extern SCM scm_eval_environment_set_imported_x (SCM env, SCM imported); | |
173 | ||
174 | \f | |
175 | ||
176 | extern void *scm_type_import_environment; | |
177 | ||
178 | #define SCM_IMPORT_ENVIRONMENT_P(env) \ | |
179 | (SCM_ENVIRONMENT_FUNCS (env) == scm_type_import_environment) | |
180 | ||
181 | extern SCM scm_make_import_environment (SCM imports, SCM conflict_proc); | |
182 | extern SCM scm_import_environment_p (SCM env); | |
183 | extern SCM scm_import_environment_imports (SCM env); | |
184 | extern SCM scm_import_environment_set_imports_x (SCM env, SCM imports); | |
185 | ||
186 | \f | |
187 | ||
188 | extern void *scm_type_export_environment; | |
189 | ||
190 | #define SCM_EXPORT_ENVIRONMENT_P(env) \ | |
191 | (SCM_ENVIRONMENT_FUNCS (env) == scm_type_export_environment) | |
192 | ||
193 | extern SCM scm_make_export_environment (SCM private, SCM signature); | |
194 | extern SCM scm_export_environment_p (SCM env); | |
195 | extern SCM scm_export_environment_private (SCM env); | |
196 | extern SCM scm_export_environment_set_private_x (SCM env, SCM private); | |
197 | extern SCM scm_export_environment_signature (SCM env); | |
198 | extern SCM scm_export_environment_set_signature_x (SCM env, SCM signature); | |
199 | ||
200 | ||
201 | #endif | |
202 | ||
203 | ||
204 | /* | |
205 | Local Variables: | |
206 | c-file-style: "gnu" | |
207 | End: | |
208 | */ |