CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / gvars.h
Views: 418346
1
/****************************************************************************
2
**
3
*W gvars.h GAP source Martin Schönert
4
**
5
**
6
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
7
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
8
*Y Copyright (C) 2002 The GAP Group
9
**
10
** This file declares the functions of the global variables package.
11
**
12
** The global variables package is the part of the kernel that manages
13
** global variables, i.e., the global namespace. A global variable binds an
14
** identifier to a value.
15
**
16
** A global variable can be automatic. That means that the global variable
17
** binds the identifier to a function and an argument. When the value of
18
** the global variable is needed, the function is called with the argument.
19
** This function call should, as a side-effect, execute an assignment of a
20
** value to the global variable, otherwise an error is signalled.
21
**
22
** A global variable can have a number of internal copies, i.e., C variables
23
** that always reference the same value as the global variable. In fact the
24
** internal copies are only used for functions, i.e., the internal copies
25
** only reference the same value as the global variable if it is a function.
26
** Otherwise the internal copies reference functions that signal an error.
27
*/
28
29
#ifndef GAP_GVARS_H
30
#define GAP_GVARS_H
31
32
33
/****************************************************************************
34
**
35
*V ValGVars . . . . . . . . . . . . . . . . . . values of global variables
36
*V PtrGVars . . . . . . . . . . . . . pointer to values of global variables
37
**
38
** 'ValGVars' is the bag containing the values of the global variables.
39
**
40
** 'PtrGVars' is a pointer to the 'ValGVars' bag. This makes it faster to
41
** access global variables.
42
*/
43
extern Obj ValGVars;
44
45
extern Obj * PtrGVars;
46
47
48
/****************************************************************************
49
**
50
*F VAL_GVAR(<gvar>) . . . . . . . . . . . . . . . value of global variable
51
**
52
** 'VAL_GVAR' returns the value of the global variable <gvar>. If <gvar>
53
** has no assigned value, 'VAL_GVAR' returns 0. In this case <gvar> might
54
** be an automatic global variable, and one should call 'ValAutoGVar', which
55
** will return the value of <gvar> after evaluating <gvar>-s expression, or
56
** 0 if <gvar> was not an automatic variable.
57
*/
58
#define VAL_GVAR(gvar) PtrGVars[ (gvar) ]
59
60
61
/****************************************************************************
62
**
63
*V WriteGVars . . . . . . . . . . . . . writable flags of global variables
64
*/
65
extern Obj WriteGVars;
66
67
68
/****************************************************************************
69
**
70
*V ErrorMustEvalToFuncFunc . . . . . . . . . function that signals an error
71
**
72
** 'ErrorMustEvalToFuncFunc' is a (variable number of args) function that
73
** signals the error ``Function: <func> be a function''.
74
*/
75
extern Obj ErrorMustEvalToFuncFunc;
76
77
78
/****************************************************************************
79
**
80
*V ErrorMustHaveAssObjFunc . . . . . . . . . function that signals an error
81
**
82
** 'ErrorMustHaveAssObjFunc' is a (variable number of args) function that
83
** signals the error ``Variable: <<unknown>> must have an assigned value''.
84
*/
85
extern Obj ErrorMustHaveAssObjFunc;
86
87
88
/****************************************************************************
89
**
90
*F AssGVar(<gvar>,<val>) . . . . . . . . . . . . assign to a global variable
91
**
92
** 'AssGVar' assigns the value <val> to the global variable <gvar>.
93
*/
94
extern void AssGVar (
95
UInt gvar,
96
Obj val );
97
98
99
/****************************************************************************
100
**
101
*F ValAutoGVar(<gvar>) . . . . . . . . value of a automatic global variable
102
**
103
** 'ValAutoGVar' returns the value of the global variable <gvar>. This will
104
** be 0 if <gvar> has no assigned value. It will also cause a function
105
** call, if <gvar> is automatic.
106
*/
107
extern Obj ValAutoGVar (
108
UInt gvar );
109
110
111
/****************************************************************************
112
**
113
*F NameGVar(<gvar>) . . . . . . . . . . . . . . . name of a global variable
114
**
115
** 'NameGVar' returns the name of the global variable <gvar> as a C string.
116
*/
117
extern Char * NameGVar (
118
UInt gvar );
119
120
121
/****************************************************************************
122
**
123
*F NameGVarObj(<gvar>) . . . . . . . . . . . . . name of a global variable
124
**
125
** 'NameGVarObj' returns the name of the global variable <gvar> as a GAP
126
** string.
127
*/
128
extern Obj NameGVarObj (
129
UInt gvar );
130
131
132
/****************************************************************************
133
**
134
*F GVarName(<name>) . . . . . . . . . . . . . . global variable for a name
135
**
136
** 'GVarName' returns the global variable with the name <name>.
137
*/
138
extern UInt GVarName (
139
const Char * name );
140
141
142
/****************************************************************************
143
**
144
*V Tilde . . . . . . . . . . . . . . . . . . . . . . . . global variable '~'
145
**
146
** 'Tilde' is the identifier for the global variable '~', the one used in
147
** expressions such as '[ [ 1, 2 ], ~[1] ]'.
148
**
149
** Actually when such expressions appear in functions, one should probably
150
** use a local variable. But for now this is good enough.
151
*/
152
extern UInt Tilde;
153
154
155
/****************************************************************************
156
**
157
*F iscomplete_gvar( <name>, <len> ) . . . . . . . . . . . . . check <name>
158
*/
159
extern UInt iscomplete_gvar (
160
Char * name,
161
UInt len );
162
163
164
/****************************************************************************
165
**
166
*F completion_gvar( <name>, <len> ) . . . . . . . . . . . . find completion
167
*/
168
extern UInt completion_gvar (
169
Char * name,
170
UInt len );
171
172
173
/****************************************************************************
174
**
175
*F MakeReadOnlyGVar( <gvar> ) . . . . . . make a global variable read only
176
*F MakeReadWriteGVar( <gvar> ) . . . . . . make a global variable read-write
177
*/
178
extern void MakeReadOnlyGVar (
179
UInt gvar );
180
181
extern void MakeReadWriteGVar (
182
UInt gvar );
183
184
extern Int IsReadOnlyGVar (
185
UInt gvar );
186
187
/****************************************************************************
188
**
189
190
*F * * * * * * * * * * * * * copies and fopies * * * * * * * * * * * * * * *
191
*/
192
193
194
/****************************************************************************
195
**
196
197
*F InitCopyGVar( <name>, <copy> ) . . declare C variable as copy of global
198
**
199
** 'InitCopyGVar' makes the C variable <cvar> at address <copy> a copy of
200
** the global variable named <name> (which must be a kernel string).
201
**
202
** The function only registers the information in <CopyAndFopyGVars>. At a
203
** latter stage one has to call 'UpdateCopyFopyInfo' to actually enter the
204
** information stored in <CopyAndFopyGVars> into a plain list.
205
**
206
** This is OK for garbage collection, but a real problem for saving in any
207
** event, this information does not really want to be saved because it is
208
** kernel centred rather than workspace centred.
209
**
210
** Accordingly we provide two functions `RemoveCopyFopyInfo' and
211
** `RestoreCopyFopyInfo' to remove or restore the information from the
212
** workspace. The Restore function is also intended to be used after
213
** loading a saved workspace
214
*/
215
extern void InitCopyGVar (
216
const Char * name ,
217
Obj * copy );
218
219
220
/****************************************************************************
221
**
222
*F InitFopyGVar( <name>, <copy> ) . . declare C variable as copy of global
223
**
224
** 'InitFopyGVar' makes the C variable <cvar> at address <copy> a (function)
225
** copy of the global variable <gvar>, whose name is <name>. That means
226
** that whenever the value of <gvar> is a function, then <cvar> will
227
** reference the same value (i.e., will hold the same bag identifier). When
228
** the value of <gvar> is not a function, then <cvar> will reference a
229
** function that signals the error ``<func> must be a function''. When
230
** <gvar> has no assigned value, then <cvar> will reference a function that
231
** signals the error ``<gvar> must have an assigned value''.
232
*/
233
extern void InitFopyGVar (
234
const Char * name,
235
Obj * copy );
236
237
238
/****************************************************************************
239
**
240
*F UpdateCopyFopyInfo() . . . . . . . . . . convert kernel info into plist
241
*/
242
extern void UpdateCopyFopyInfo ( void );
243
244
245
/****************************************************************************
246
**
247
*F RemoveCopyFopyInfo() . . . remove the info about copies of gvars from ws
248
*/
249
extern void RemoveCopyFopyInfo( void );
250
251
252
/****************************************************************************
253
**
254
*F RestoreCopyFopyInfo() . . . restore the info from the copy in the kernel
255
*/
256
extern void RestoreCopyFopyInfo( void );
257
258
259
260
/****************************************************************************
261
**
262
263
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
264
*/
265
266
267
/****************************************************************************
268
**
269
270
*F InitInfoGVars() . . . . . . . . . . . . . . . . . table of init functions
271
*/
272
StructInitInfo * InitInfoGVars ( void );
273
274
275
#endif // GAP_GVARS_H
276
277
/****************************************************************************
278
**
279
280
*E gvars.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
281
*/
282
283