forked from gap-system/gap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.c
168 lines (141 loc) · 4.5 KB
/
info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares the functions handling Info statements.
*/
#include "info.h"
#include "bool.h"
#include "calls.h"
#include "error.h"
#include "gapstate.h"
#include "gvars.h"
#include "modules.h"
#include "plist.h"
#ifdef HPCGAP
#include "hpc/aobjects.h"
#endif
enum {
INFODATA_NUM = 1,
INFODATA_CURRENTLEVEL,
INFODATA_CLASSNAME,
INFODATA_HANDLER,
INFODATA_OUTPUT,
};
static Obj InfoDecision;
static Obj IsInfoClassListRep;
static Obj DefaultInfoHandler;
static Obj ResetShowUsedInfoClassesHandler;
static Obj ShowUsedInfoClassesHandler;
static Obj FuncShowUsedInfoClasses(Obj self, Obj choice)
{
RequireTrueOrFalse(SELF_NAME, choice);
if (choice == True) {
STATE(ShowUsedInfoClassesActive) = 1;
CALL_0ARGS(ResetShowUsedInfoClassesHandler);
}
else {
STATE(ShowUsedInfoClassesActive) = 0;
}
return 0;
}
void InfoDoPrint(Obj cls, Obj lvl, Obj args)
{
if (IS_PLIST(cls))
cls = ELM_PLIST(cls, 1);
#ifdef HPCGAP
Obj fun = Elm0AList(cls, INFODATA_HANDLER);
#else
Obj fun = ELM_PLIST(cls, INFODATA_HANDLER);
#endif
if (!fun)
fun = DefaultInfoHandler;
CALL_3ARGS(fun, cls, lvl, args);
}
Obj InfoCheckLevel(Obj selectors, Obj level)
{
if (STATE(ShowUsedInfoClassesActive)) {
CALL_2ARGS(ShowUsedInfoClassesHandler, selectors, level);
}
// Fast-path the most common failing case.
// The fast-path only deals with the case where all arguments are of the
// correct type, and were False is returned.
if (CALL_1ARGS(IsInfoClassListRep, selectors) == True) {
#ifdef HPCGAP
Obj index = ElmAList(selectors, INFODATA_CURRENTLEVEL);
#else
Obj index = ELM_PLIST(selectors, INFODATA_CURRENTLEVEL);
#endif
if (IS_INTOBJ(index) && IS_INTOBJ(level)) {
// < on INTOBJs compares the represented integers.
if (index < level) {
return False;
}
}
}
return CALL_2ARGS(InfoDecision, selectors, level);
}
/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/
/****************************************************************************
**
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
*/
static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC_1ARGS(ShowUsedInfoClasses, choice), { 0, 0, 0, 0, 0 }
};
/****************************************************************************
**
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
*/
static Int InitKernel(StructInitInfo * module)
{
// init filters and functions
InitHdlrFuncsFromTable(GVarFuncs);
// The work of handling Info messages is delegated to the GAP level
ImportFuncFromLibrary("InfoDecision", &InfoDecision);
ImportFuncFromLibrary("DefaultInfoHandler", &DefaultInfoHandler);
ImportFuncFromLibrary("IsInfoClassListRep", &IsInfoClassListRep);
ImportFuncFromLibrary("RESET_SHOW_USED_INFO_CLASSES",
&ResetShowUsedInfoClassesHandler);
ImportFuncFromLibrary("SHOW_USED_INFO_CLASSES",
&ShowUsedInfoClassesHandler);
return 0;
}
/****************************************************************************
**
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
*/
static Int InitLibrary(StructInitInfo * module)
{
InitGVarFuncsFromTable(GVarFuncs);
ExportAsConstantGVar(INFODATA_CURRENTLEVEL);
ExportAsConstantGVar(INFODATA_CLASSNAME);
ExportAsConstantGVar(INFODATA_HANDLER);
ExportAsConstantGVar(INFODATA_OUTPUT);
ExportAsConstantGVar(INFODATA_NUM);
return 0;
}
/****************************************************************************
**
*F InitInfoInfo() . . . . . . . . . . . . . . . . . table of init functions
*/
static StructInitInfo module = {
// init struct using C99 designated initializers; for a full list of
// fields, please refer to the definition of StructInitInfo
.type = MODULE_BUILTIN,
.name = "info",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
};
StructInitInfo * InitInfoInfo(void)
{
return &module;
}