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 / exprs.h
Views: 418346
1
/****************************************************************************
2
**
3
*W exprs.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 expressions package.
11
**
12
** The expressions package is the part of the interpreter that evaluates
13
** expressions to their values and prints expressions.
14
*/
15
16
#ifndef GAP_EXPRS_H
17
#define GAP_EXPRS_H
18
19
20
/****************************************************************************
21
**
22
*F OBJ_REFLVAR(<expr>) . . . . . . . . . . . value of a reference to a local
23
**
24
** 'OBJ_REFLVAR' returns the value of the reference to a local variable
25
** <expr>.
26
*/
27
#ifdef NO_LVAR_CHECKS
28
#define OBJ_REFLVAR(expr) \
29
OBJ_LVAR( LVAR_REFLVAR( (expr) ) )
30
#endif
31
#ifndef NO_LVAR_CHECKS
32
33
#ifdef SYS_IS_64_BIT
34
#define OFFSET_REFLVAR(expr) (((expr)*2)+10)
35
#else
36
#define OFFSET_REFLVAR(expr) ((expr) + 5)
37
#endif
38
39
#define OBJ_REFLVAR(expr) \
40
(*(Obj*)(((char*)TLS(PtrLVars))+OFFSET_REFLVAR(expr)) != 0 ? \
41
*(Obj*)(((char*)TLS(PtrLVars))+OFFSET_REFLVAR(expr)) : \
42
ObjLVar( LVAR_REFLVAR( expr ) ) )
43
#endif
44
45
46
/****************************************************************************
47
**
48
*F OBJ_INTEXPR(<expr>) . . . . . . . . . . . value of an integer expression
49
**
50
** 'OBJ_INTEXPR' returns the (immediate) integer value of the (immediate)
51
** integer expression <expr>.
52
**
53
** 'OBJ_INTEXPR(<expr>)' should be 'OBJ_INT(INT_INTEXPR(<expr>))', but for
54
** performance reasons we implement it as '(Obj)(<expr>)'. This is of
55
** course highly dependent on (immediate) integer expressions and
56
** (immediate) integer values having the same representation.
57
*/
58
59
#ifndef SYS_IS_64_BIT
60
#define OBJ_INTEXPR(expr) \
61
((Obj)(Int)(Int4)(expr))
62
#else
63
#define OBJ_INTEXPR(expr) \
64
(INTOBJ_INT(INT_INTEXPR((expr))))
65
#endif
66
67
/****************************************************************************
68
**
69
*F EVAL_EXPR(<expr>) . . . . . . . . . . . . . . . . evaluate an expression
70
**
71
** 'EVAL_EXPR' evaluates the expression <expr>.
72
**
73
** 'EVAL_EXPR' returns the value of <expr>.
74
**
75
** 'EVAL_EXPR' causes the evaluation of <expr> by dispatching to the
76
** evaluator, i.e., to the function that evaluates expressions of the type
77
** of <expr>.
78
**
79
** Note that 'EVAL_EXPR' does not use 'TNUM_EXPR', since it also handles the
80
** two special cases that 'TNUM_EXPR' handles.
81
*/
82
#define EVAL_EXPR(expr) \
83
(IS_REFLVAR(expr) ? OBJ_REFLVAR(expr) : \
84
(IS_INTEXPR(expr) ? OBJ_INTEXPR(expr) : \
85
(*EvalExprFuncs[ TNUM_STAT(expr) ])( expr ) ))
86
87
88
/****************************************************************************
89
**
90
*V EvalExprFuncs[<type>] . . . . . evaluator for expressions of type <type>
91
**
92
** 'EvalExprFuncs' is the dispatch table that contains for every type of
93
** expressions a pointer to the evaluator for expressions of this type,
94
** i.e., the function that should be called to evaluate expressions of this
95
** type.
96
*/
97
extern Obj (* EvalExprFuncs [256]) ( Expr expr );
98
99
100
/****************************************************************************
101
**
102
*F EVAL_BOOL_EXPR(<expr>) . . . . evaluate an expression to a boolean value
103
**
104
** 'EVAL_BOOL_EXPR' evaluates the expression <expr> and checks that the
105
** value is either 'true' or 'false'. If the expression does not evaluate
106
** to 'true' or 'false', then an error is signalled.
107
**
108
** 'EVAL_BOOL_EXPR' returns the value of <expr> (which is either 'true' or
109
** 'false').
110
*/
111
#define EVAL_BOOL_EXPR(expr) \
112
( (*EvalBoolFuncs[ TNUM_EXPR( expr ) ])( expr ) )
113
114
115
/****************************************************************************
116
**
117
*V EvalBoolFuncs[<type>] . . boolean evaluator for expression of type <type>
118
**
119
** 'EvalBoolFuncs' is the dispatch table that contains for every type of
120
** expression a pointer to a boolean evaluator for expressions of this type,
121
** i.e., a pointer to a function which is guaranteed to return a boolean
122
** value that should be called to evaluate expressions of this type.
123
*/
124
extern Obj (* EvalBoolFuncs [256]) ( Expr expr );
125
126
127
/****************************************************************************
128
**
129
*F PrintExpr(<expr>) . . . . . . . . . . . . . . . . . . print an expression
130
**
131
** 'PrintExpr' prints the expression <expr>.
132
*/
133
extern void PrintExpr (
134
Expr expr );
135
136
137
extern void PrintRecExpr1 ( Expr expr ); /* needed for printing
138
function calls with options */
139
140
/****************************************************************************
141
**
142
*V PrintExprFuncs[<type>] . . printing function for objects of type <type>
143
**
144
** 'PrintExprFuncs' is the dispatching table that contains for every type of
145
** expressions a pointer to the printer for expressions of this type, i.e.,
146
** the function that should be called to print expressions of this type.
147
*/
148
extern void (* PrintExprFuncs [256] ) ( Expr expr );
149
150
151
/****************************************************************************
152
**
153
154
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
155
*/
156
157
158
/****************************************************************************
159
**
160
161
*F InitInfoExprs() . . . . . . . . . . . . . . . . . table of init functions
162
*/
163
StructInitInfo * InitInfoExprs ( void );
164
165
166
#endif // GAP_EXPRS_H
167
168
/****************************************************************************
169
**
170
171
*E exprs.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
172
*/
173
174