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