• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tueda / form / 15241916852

25 May 2025 08:59PM UTC coverage: 47.908% (-2.8%) from 50.743%
15241916852

push

github

tueda
ci: build arm64-windows binaries

39009 of 81425 relevant lines covered (47.91%)

1079780.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.89
/sources/compiler.c
1
/** @file compiler.c
2
 * 
3
 *  The heart of the compiler.
4
 *  It contains the tables of statements.
5
 *        It finds the statements in the tables and calls the proper routines.
6
 *        For algebraic expressions it runs the compilation by first calling
7
 *        the tokenizer, splitting things into subexpressions and generating
8
 *        the code. There is a system for recognizing already existing
9
 *        subexpressions. This economizes on the length of the output.
10
 *
11
 *        Note: the compiler of FORM doesn't attempt to normalize the input.
12
 *        Hence x+1 and 1+x are different objects during compilation.
13
 *        Similarly (a+b-b) will not be simplified to (a).
14
 */
15
/* #[ License : */
16
/*
17
 *   Copyright (C) 1984-2023 J.A.M. Vermaseren
18
 *   When using this file you are requested to refer to the publication
19
 *   J.A.M.Vermaseren "New features of FORM" math-ph/0010025
20
 *   This is considered a matter of courtesy as the development was paid
21
 *   for by FOM the Dutch physics granting agency and we would like to
22
 *   be able to track its scientific use to convince FOM of its value
23
 *   for the community.
24
 *
25
 *   This file is part of FORM.
26
 *
27
 *   FORM is free software: you can redistribute it and/or modify it under the
28
 *   terms of the GNU General Public License as published by the Free Software
29
 *   Foundation, either version 3 of the License, or (at your option) any later
30
 *   version.
31
 *
32
 *   FORM is distributed in the hope that it will be useful, but WITHOUT ANY
33
 *   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34
 *   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
35
 *   details.
36
 *
37
 *   You should have received a copy of the GNU General Public License along
38
 *   with FORM.  If not, see <http://www.gnu.org/licenses/>.
39
 */
40
/* #] License : */ 
41
/*
42
          #[ includes :
43
*/
44

45
#include "form3.h"
46

47
/*
48
        com1commands are the commands of which only part of the word has to
49
        be present. The order is rather important here.
50
        com2commands are the commands that must have their whole word match.
51
        here we can do a binary search.
52
        {[(
53
*/
54

55
static KEYWORD com1commands[] = {
56
         {"also",           (TFUN)CoIdOld,            STATEMENT,    PARTEST}
57
        ,{"abrackets",      (TFUN)CoAntiBracket,      TOOUTPUT,     PARTEST}
58
        ,{"antisymmetrize", (TFUN)CoAntiSymmetrize,   STATEMENT,    PARTEST}
59
        ,{"antibrackets",   (TFUN)CoAntiBracket,      TOOUTPUT,     PARTEST}
60
        ,{"brackets",       (TFUN)CoBracket,          TOOUTPUT,     PARTEST}
61
        ,{"cfunctions",     (TFUN)CoCFunction,        DECLARATION,  PARTEST|WITHAUTO}
62
        ,{"commuting",      (TFUN)CoCFunction,        DECLARATION,  PARTEST|WITHAUTO}
63
        ,{"compress",       (TFUN)CoCompress,         DECLARATION,  PARTEST}
64
        ,{"ctensors",       (TFUN)CoCTensor,          DECLARATION,  PARTEST|WITHAUTO}
65
        ,{"cyclesymmetrize",(TFUN)CoCycleSymmetrize,  STATEMENT,    PARTEST}
66
        ,{"dimension",      (TFUN)CoDimension,        DECLARATION,  PARTEST}
67
        ,{"discard",        (TFUN)CoDiscard,          STATEMENT,    PARTEST}
68
        ,{"functions",      (TFUN)CoNFunction,        DECLARATION,  PARTEST|WITHAUTO}
69
        ,{"format",         (TFUN)CoFormat,           TOOUTPUT,     PARTEST}
70
        ,{"fixindex",       (TFUN)CoFixIndex,         DECLARATION,  PARTEST}
71
        ,{"global",         (TFUN)CoGlobal,           DEFINITION,   PARTEST}
72
        ,{"gfactorized",    (TFUN)CoGlobalFactorized, DEFINITION,   PARTEST}
73
        ,{"globalfactorized",(TFUN)CoGlobalFactorized,DEFINITION,   PARTEST}
74
        ,{"goto",           (TFUN)CoGoTo,             STATEMENT,    PARTEST}
75
        ,{"indexes",        (TFUN)CoIndex,            DECLARATION,  PARTEST|WITHAUTO}
76
        ,{"indices",        (TFUN)CoIndex,            DECLARATION,  PARTEST|WITHAUTO}
77
        ,{"identify",       (TFUN)CoId,               STATEMENT,    PARTEST}
78
        ,{"idnew",          (TFUN)CoIdNew,            STATEMENT,    PARTEST}
79
        ,{"idold",          (TFUN)CoIdOld,            STATEMENT,    PARTEST}
80
        ,{"local",          (TFUN)CoLocal,            DEFINITION,   PARTEST}
81
        ,{"lfactorized",    (TFUN)CoLocalFactorized,  DEFINITION,   PARTEST}
82
        ,{"localfactorized",(TFUN)CoLocalFactorized,  DEFINITION,   PARTEST}
83
        ,{"load",           (TFUN)CoLoad,             DECLARATION,  PARTEST}
84
        ,{"label",          (TFUN)CoLabel,            STATEMENT,    PARTEST}
85
        ,{"modulus",        (TFUN)CoModulus,          DECLARATION,  PARTEST}
86
        ,{"multiply",       (TFUN)CoMultiply,         STATEMENT,    PARTEST}
87
        ,{"nfunctions",     (TFUN)CoNFunction,        DECLARATION,  PARTEST|WITHAUTO}
88
        ,{"nprint",         (TFUN)CoNPrint,           TOOUTPUT,     PARTEST}
89
        ,{"ntensors",       (TFUN)CoNTensor,          DECLARATION,  PARTEST|WITHAUTO}
90
        ,{"nwrite",         (TFUN)CoNWrite,           DECLARATION,  PARTEST}
91
        ,{"print",          (TFUN)CoPrint,            MIXED,        0}
92
        ,{"redefine",       (TFUN)CoRedefine,         STATEMENT,    0}
93
        ,{"rcyclesymmetrize",(TFUN)CoRCycleSymmetrize,STATEMENT,    PARTEST}
94
        ,{"symbols",        (TFUN)CoSymbol,           DECLARATION,  PARTEST|WITHAUTO}
95
        ,{"save",           (TFUN)CoSave,             DECLARATION,  PARTEST}
96
        ,{"symmetrize",     (TFUN)CoSymmetrize,       STATEMENT,    PARTEST}
97
        ,{"tensors",        (TFUN)CoCTensor,          DECLARATION,  PARTEST|WITHAUTO}
98
        ,{"unittrace",      (TFUN)CoUnitTrace,        DECLARATION,  PARTEST}
99
        ,{"vectors",        (TFUN)CoVector,           DECLARATION,  PARTEST|WITHAUTO}
100
        ,{"write",          (TFUN)CoWrite,            DECLARATION,  PARTEST}
101
};
102

103
static KEYWORD com2commands[] = {
104
         {"antiputinside",  (TFUN)CoAntiPutInside,    STATEMENT,    PARTEST}
105
        ,{"apply",          (TFUN)CoApply,            STATEMENT,    PARTEST}
106
        ,{"aputinside",     (TFUN)CoAntiPutInside,    STATEMENT,    PARTEST}
107
        ,{"argexplode",     (TFUN)CoArgExplode,       STATEMENT,    PARTEST}
108
        ,{"argimplode",     (TFUN)CoArgImplode,       STATEMENT,    PARTEST}
109
        ,{"argtoextrasymbol",(TFUN)CoArgToExtraSymbol,STATEMENT,    PARTEST}
110
        ,{"argument",       (TFUN)CoArgument,         STATEMENT,    PARTEST}
111
        ,{"assign",         (TFUN)CoAssign,           STATEMENT,    PARTEST}
112
        ,{"auto",           (TFUN)CoAuto,             DECLARATION,  PARTEST}
113
        ,{"autodeclare",    (TFUN)CoAuto,             DECLARATION,  PARTEST}
114
        ,{"break",          (TFUN)CoBreak,            STATEMENT,    PARTEST}
115
        ,{"canonicalize",   (TFUN)CoCanonicalize,     STATEMENT,    PARTEST}
116
        ,{"case",           (TFUN)CoCase,             STATEMENT,    PARTEST}
117
        ,{"chainin",        (TFUN)CoChainin,          STATEMENT,    PARTEST}
118
        ,{"chainout",       (TFUN)CoChainout,         STATEMENT,    PARTEST}
119
        ,{"chisholm",       (TFUN)CoChisholm,         STATEMENT,    PARTEST}
120
        ,{"cleartable",     (TFUN)CoClearTable,       DECLARATION,  PARTEST}
121
        ,{"clearflag",      (TFUN)CoClearUserFlag,    STATEMENT,    PARTEST}
122
        ,{"collect",        (TFUN)CoCollect,          SPECIFICATION,PARTEST}
123
        ,{"commuteinset",   (TFUN)CoCommuteInSet,     DECLARATION,  PARTEST}
124
        ,{"contract",       (TFUN)CoContract,         STATEMENT,    PARTEST}
125
        ,{"copyspectator",  (TFUN)CoCopySpectator,    DEFINITION,   PARTEST}
126
        ,{"createall",      (TFUN)CoCreateAll,        STATEMENT,    PARTEST}
127
        ,{"createspectator",(TFUN)CoCreateSpectator,  DECLARATION,  PARTEST}
128
        ,{"ctable",         (TFUN)CoCTable,           DECLARATION,  PARTEST}
129
        ,{"deallocatetable",(TFUN)CoDeallocateTable,  DECLARATION,  PARTEST}
130
        ,{"default",        (TFUN)CoDefault,          STATEMENT,    PARTEST}
131
        ,{"delete",         (TFUN)CoDelete,           SPECIFICATION,PARTEST}
132
        ,{"denominators",   (TFUN)CoDenominators,     STATEMENT,    PARTEST}
133
        ,{"disorder",       (TFUN)CoDisorder,         STATEMENT,    PARTEST}
134
        ,{"do",             (TFUN)CoDo,               STATEMENT,    PARTEST}
135
        ,{"drop",           (TFUN)CoDrop,             SPECIFICATION,PARTEST}
136
        ,{"dropcoefficient",(TFUN)CoDropCoefficient,  STATEMENT,    PARTEST}
137
        ,{"dropsymbols",    (TFUN)CoDropSymbols,      STATEMENT,    PARTEST}
138
        ,{"else",           (TFUN)CoElse,             STATEMENT,    PARTEST}
139
        ,{"elseif",         (TFUN)CoElseIf,           STATEMENT,    PARTEST}
140
        ,{"emptyspectator", (TFUN)CoEmptySpectator,   SPECIFICATION,PARTEST}
141
        ,{"endargument",    (TFUN)CoEndArgument,      STATEMENT,    PARTEST}
142
        ,{"enddo",          (TFUN)CoEndDo,            STATEMENT,    PARTEST}
143
        ,{"endif",          (TFUN)CoEndIf,            STATEMENT,    PARTEST}
144
        ,{"endinexpression",(TFUN)CoEndInExpression,  STATEMENT,    PARTEST}
145
        ,{"endinside",      (TFUN)CoEndInside,        STATEMENT,    PARTEST}
146
        ,{"endmodel",       (TFUN)CoEndModel,         DECLARATION,  PARTEST}
147
        ,{"endrepeat",      (TFUN)CoEndRepeat,        STATEMENT,    PARTEST}
148
        ,{"endswitch",      (TFUN)CoEndSwitch,        STATEMENT,    PARTEST}
149
        ,{"endterm",        (TFUN)CoEndTerm,          STATEMENT,    PARTEST}
150
        ,{"endwhile",       (TFUN)CoEndWhile,         STATEMENT,    PARTEST}
151
#ifdef WITHFLOAT
152
        ,{"evaluate",       (TFUN)CoEvaluate,         STATEMENT,    PARTEST}
153
#endif
154
        ,{"exit",           (TFUN)CoExit,             STATEMENT,    PARTEST}
155
        ,{"extrasymbols",   (TFUN)CoExtraSymbols,     DECLARATION,  PARTEST}
156
        ,{"factarg",        (TFUN)CoFactArg,          STATEMENT,    PARTEST}
157
        ,{"factdollar",     (TFUN)CoFactDollar,       STATEMENT,    PARTEST}
158
        ,{"factorize",      (TFUN)CoFactorize,        TOOUTPUT,     PARTEST}
159
        ,{"fill",           (TFUN)CoFill,             DECLARATION,  PARTEST}
160
        ,{"fillexpression", (TFUN)CoFillExpression,   DECLARATION,  PARTEST}
161
        ,{"frompolynomial", (TFUN)CoFromPolynomial,   STATEMENT,    PARTEST}
162
        ,{"funpowers",      (TFUN)CoFunPowers,        DECLARATION,  PARTEST}
163
        ,{"hide",           (TFUN)CoHide,             SPECIFICATION,PARTEST}
164
        ,{"if",             (TFUN)CoIf,               STATEMENT,    PARTEST}
165
        ,{"ifmatch",        (TFUN)CoIfMatch,          STATEMENT,    PARTEST}
166
        ,{"ifnomatch",      (TFUN)CoIfNoMatch,        STATEMENT,    PARTEST}
167
        ,{"ifnotmatch",     (TFUN)CoIfNoMatch,        STATEMENT,    PARTEST}
168
        ,{"inexpression",   (TFUN)CoInExpression,     STATEMENT,    PARTEST}
169
        ,{"inparallel",     (TFUN)CoInParallel,       SPECIFICATION,PARTEST}
170
        ,{"inside",         (TFUN)CoInside,           STATEMENT,    PARTEST}
171
        ,{"insidefirst",    (TFUN)CoInsideFirst,      DECLARATION,  PARTEST}
172
        ,{"intohide",       (TFUN)CoIntoHide,         SPECIFICATION,PARTEST}
173
        ,{"keep",           (TFUN)CoKeep,             SPECIFICATION,PARTEST}
174
        ,{"makeinteger",    (TFUN)CoMakeInteger,      STATEMENT,    PARTEST}
175
        ,{"many",           (TFUN)CoMany,             STATEMENT,    PARTEST}
176
        ,{"merge",          (TFUN)CoMerge,            STATEMENT,    PARTEST}
177
        ,{"metric",         (TFUN)CoMetric,           DECLARATION,  PARTEST}
178
        ,{"model",          (TFUN)CoModel,            DECLARATION,  PARTEST}
179
        ,{"moduleoption",   (TFUN)CoModuleOption,     ATENDOFMODULE,PARTEST}
180
        ,{"multi",          (TFUN)CoMulti,            STATEMENT,    PARTEST}
181
        ,{"multibracket",   (TFUN)CoMultiBracket,     STATEMENT,    PARTEST}
182
        ,{"ndrop",          (TFUN)CoNoDrop,           SPECIFICATION,PARTEST}
183
        ,{"nfactorize",     (TFUN)CoNFactorize,       TOOUTPUT,     PARTEST}
184
        ,{"nhide",          (TFUN)CoNoHide,           SPECIFICATION,PARTEST}
185
        ,{"normalize",      (TFUN)CoNormalize,        STATEMENT,    PARTEST}
186
        ,{"notinparallel",  (TFUN)CoNotInParallel,    SPECIFICATION,PARTEST}
187
        ,{"nskip",          (TFUN)CoNoSkip,           SPECIFICATION,PARTEST}
188
        ,{"ntable",         (TFUN)CoNTable,           DECLARATION,  PARTEST}
189
        ,{"nunfactorize",   (TFUN)CoNUnFactorize,     TOOUTPUT,     PARTEST}
190
        ,{"nunhide",        (TFUN)CoNoUnHide,         SPECIFICATION,PARTEST}
191
        ,{"off",            (TFUN)CoOff,              DECLARATION,  PARTEST}
192
        ,{"on",             (TFUN)CoOn,               DECLARATION,  PARTEST}
193
        ,{"once",           (TFUN)CoOnce,             STATEMENT,    PARTEST}
194
        ,{"only",           (TFUN)CoOnly,             STATEMENT,    PARTEST}
195
        ,{"particle",       (TFUN)CoParticle,         DECLARATION,  PARTEST}
196
        ,{"polyfun",        (TFUN)CoPolyFun,          DECLARATION,  PARTEST}
197
        ,{"polyratfun",     (TFUN)CoPolyRatFun,       DECLARATION,  PARTEST}
198
        ,{"pophide",        (TFUN)CoPopHide,          SPECIFICATION,PARTEST}
199
        ,{"print[]",        (TFUN)CoPrintB,           TOOUTPUT,     PARTEST}
200
        ,{"printtable",     (TFUN)CoPrintTable,       MIXED,        PARTEST}
201
        ,{"processbucketsize",(TFUN)CoProcessBucket,  DECLARATION,  PARTEST}
202
        ,{"propercount",    (TFUN)CoProperCount,      DECLARATION,  PARTEST}
203
        ,{"pushhide",       (TFUN)CoPushHide,         SPECIFICATION,PARTEST}
204
        ,{"putinside",      (TFUN)CoPutInside,        STATEMENT,    PARTEST}
205
        ,{"ratio",          (TFUN)CoRatio,            STATEMENT,    PARTEST}
206
        ,{"removespectator",(TFUN)CoRemoveSpectator,  SPECIFICATION,PARTEST}
207
        ,{"renumber",       (TFUN)CoRenumber,         STATEMENT,    PARTEST}
208
        ,{"repeat",         (TFUN)CoRepeat,           STATEMENT,    PARTEST}
209
        ,{"replaceloop",    (TFUN)CoReplaceLoop,      STATEMENT,    PARTEST}
210
        ,{"select",         (TFUN)CoSelect,           STATEMENT,    PARTEST}
211
        ,{"set",            (TFUN)CoSet,              DECLARATION,  PARTEST}
212
        ,{"setexitflag",    (TFUN)CoSetExitFlag,      STATEMENT,    PARTEST}
213
        ,{"setflag",        (TFUN)CoSetUserFlag,      STATEMENT,    PARTEST}
214
        ,{"shuffle",        (TFUN)CoMerge,            STATEMENT,    PARTEST}
215
        ,{"skip",           (TFUN)CoSkip,             SPECIFICATION,PARTEST}
216
        ,{"sort",           (TFUN)CoSort,             STATEMENT,    PARTEST}
217
        ,{"splitarg",       (TFUN)CoSplitArg,         STATEMENT,    PARTEST}
218
        ,{"splitfirstarg",  (TFUN)CoSplitFirstArg,    STATEMENT,    PARTEST}
219
        ,{"splitlastarg",   (TFUN)CoSplitLastArg,     STATEMENT,    PARTEST}
220
        ,{"stuffle",        (TFUN)CoStuffle,          STATEMENT,    PARTEST}
221
        ,{"sum",            (TFUN)CoSum,              STATEMENT,    PARTEST}
222
        ,{"switch",         (TFUN)CoSwitch,           STATEMENT,    PARTEST}
223
        ,{"table",          (TFUN)CoTable,            DECLARATION,  PARTEST}
224
        ,{"tablebase",      (TFUN)CoTableBase,        DECLARATION,  PARTEST}
225
        ,{"tb",             (TFUN)CoTableBase,        DECLARATION,  PARTEST}
226
        ,{"term",           (TFUN)CoTerm,             STATEMENT,    PARTEST}
227
        ,{"testuse",        (TFUN)CoTestUse,          STATEMENT,    PARTEST}
228
        ,{"threadbucketsize",(TFUN)CoThreadBucket,    DECLARATION,  PARTEST}
229
#ifdef WITHFLOAT
230
        ,{"tofloat",        (TFUN)CoToFloat,          STATEMENT,    PARTEST}
231
#endif
232
        ,{"topolynomial",   (TFUN)CoToPolynomial,     STATEMENT,    PARTEST}
233
#ifdef WITHFLOAT
234
        ,{"torat",          (TFUN)CoToRat,            STATEMENT,    PARTEST}
235
        ,{"torational",     (TFUN)CoToRat,            STATEMENT,    PARTEST}
236
#endif
237
        ,{"tospectator",    (TFUN)CoToSpectator,      STATEMENT,    PARTEST}
238
        ,{"totensor",       (TFUN)CoToTensor,         STATEMENT,    PARTEST}
239
        ,{"tovector",       (TFUN)CoToVector,         STATEMENT,    PARTEST}
240
        ,{"trace4",         (TFUN)CoTrace4,           STATEMENT,    PARTEST}
241
        ,{"tracen",         (TFUN)CoTraceN,           STATEMENT,    PARTEST}
242
        ,{"transform",      (TFUN)CoTransform,        STATEMENT,    PARTEST}
243
        ,{"tryreplace",     (TFUN)CoTryReplace,       STATEMENT,    PARTEST}
244
        ,{"unfactorize",    (TFUN)CoUnFactorize,      TOOUTPUT,     PARTEST}
245
        ,{"unhide",         (TFUN)CoUnHide,           SPECIFICATION,PARTEST}
246
        ,{"vertex",         (TFUN)CoVertex,           DECLARATION,  PARTEST}
247
        ,{"while",          (TFUN)CoWhile,            STATEMENT,    PARTEST}
248
};
249

250
int alfatable1[27];
251

252
#define OPTION0 1
253
#define OPTION1 2
254
#define OPTION2 3
255

256
typedef struct SuBbUf {
257
        WORD        subexpnum;
258
        WORD        buffernum;
259
} SUBBUF;
260

261
SUBBUF *subexpbuffers = 0;
262
SUBBUF *topsubexpbuffers = 0;
263
LONG insubexpbuffers = 0;
264

265
#define REDUCESUBEXPBUFFERS { if ( (topsubexpbuffers-subexpbuffers) > 256 ) {\
266
        M_free(subexpbuffers,"subexpbuffers");\
267
        subexpbuffers = (SUBBUF *)Malloc1(256*sizeof(SUBBUF),"subexpbuffers");\
268
        topsubexpbuffers = subexpbuffers+256; } insubexpbuffers = 0; }
269

270
#if defined(ILP32)
271

272
#define PUTNUMBER128(t,n) { if ( n >= 16384 ) { \
273
                                *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
274
                        else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; }      \
275
                        else *t++ = n; }
276
#define PUTNUMBER100(t,n) { if ( n >= 10000 ) { \
277
                                *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
278
                        else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; }   \
279
                        else *t++ = n; }
280

281
#elif ( defined(LLP64) || defined(LP64) )
282

283
#define PUTNUMBER128(t,n) { if ( n >= 2097152 ) { \
284
                                *t++ = ((n/128)/128)/128; *t++ = ((n/128)/128)%128; *t++ = (n/128)%128; *t++ = n%128; } \
285
                        else if ( n >= 16384 ) { \
286
                                *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
287
                        else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; }      \
288
                        else *t++ = n; }
289
#define PUTNUMBER100(t,n) { if ( n >= 1000000 ) { \
290
                                *t++ = ((n/100)/100)/100; *t++ = ((n/100)/100)%100; *t++ = (n/100)%100; *t++ = n%100; } \
291
                        else if ( n >= 10000 ) { \
292
                                *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
293
                        else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; }   \
294
                        else *t++ = n; }
295

296
#endif
297

298
/*
299
        )]}
300
          #] includes : 
301
        #[ Compiler :
302
                 #[ inictable :
303

304
                Routine sets the table for 1-st characters that allow a faster
305
                start in the search in table 1 which should be sequential.
306
                Search in table 2 can be binary.
307
*/
308

309
VOID inictable(VOID)
886✔
310
{
311
        KEYWORD *k = com1commands;
886✔
312
        int i, j, ksize;
886✔
313
        ksize = sizeof(com1commands)/sizeof(KEYWORD);
886✔
314
        j = 0;
886✔
315
        alfatable1[0] = 0;
886✔
316
        for ( i = 0; i < 26; i++ ) {
23,922✔
317
                while ( j < ksize && k[j].name[0] == 'a'+i ) j++;
62,906✔
318
                alfatable1[i+1] = j;
23,036✔
319
        }
320
}
886✔
321

322
/*
323
                 #] inictable : 
324
                 #[ findcommand :
325

326
                Checks whether a command is in the command table.
327
                If so a pointer to the table element is returned.
328
                If not we return 0.
329
                Note that when a command is not in the table, we have
330
                to test whether it is an id command without id. It should
331
                then have the structure pattern = rhs. This should be done
332
                in the calling routine.
333
*/
334

335
KEYWORD *findcommand(UBYTE *in)
11,183✔
336
{
337
        int hi, med, lo, i;
11,183✔
338
        UBYTE *s, c;
11,183✔
339
        s = in;
11,183✔
340
        while ( FG.cTable[*s] <= 1 ) s++;
63,305✔
341
        if ( s > in && *s == '[' && s[1] == ']' ) s += 2;
11,183✔
342
        if ( *s ) { c = *s; *s = 0; }
11,183✔
343
        else c = 0;
344
/*
345
        First do a binary search in the second table
346
*/
347
        lo = 0;
11,183✔
348
        hi = sizeof(com2commands)/sizeof(KEYWORD)-1;
11,183✔
349
        do {
81,682✔
350
                med = ( hi + lo ) / 2;
81,682✔
351
                i = StrICmp(in,(UBYTE *)com2commands[med].name);
81,682✔
352
                if ( i == 0 ) { if ( c ) *s = c; return(com2commands+med); }
81,682✔
353
                if ( i < 0 ) hi = med-1;
79,326✔
354
                else         lo = med+1;
51,110✔
355
        } while ( hi >= lo );
79,326✔
356
/*
357
        Now do a 'hashed' search in the first table. It is sequential.
358
*/
359
        i = tolower(*in) - 'a'; 
8,827✔
360
        med = alfatable1[i];
8,827✔
361
        hi  = alfatable1[i+1];
8,827✔
362
        while ( med < hi ) {
14,967✔
363
                if ( StrICont(in,(UBYTE *)com1commands[med].name) == 0 )
14,967✔
364
                        { if ( c ) *s = c; return(com1commands+med); }
8,827✔
365
                med++;
6,140✔
366
        }
367
        if ( c ) *s = c;
×
368
/*
369
        Unrecognized. Too bad!
370
*/
371
        return(0);
372
}
373

374
/*
375
                 #] findcommand : 
376
                 #[ ParenthesesTest :
377
*/
378

379
int ParenthesesTest(UBYTE *sin)
9,061✔
380
{
381
        WORD L1 = 0, L2 = 0, L3 = 0;
9,061✔
382
        UBYTE *s = sin;
9,061✔
383
        while ( *s ) {
6,334,515✔
384
                if ( *s == '[' ) L1++;
6,325,454✔
385
                else if ( *s == ']' ) {
6,325,277✔
386
                        L1--;
177✔
387
                        if ( L1 < 0 ) { MesPrint("&Unmatched []"); return(1); }
177✔
388
                }
389
                s++;
6,325,454✔
390
        }
391
        if ( L1 > 0 ) { MesPrint("&Unmatched []"); return(1); }
9,061✔
392
        s = sin;
393
        while ( *s ) {
6,333,708✔
394
                if ( *s == '[' ) SKIPBRA1(s)
6,325,454✔
395
                else if ( *s == '(' ) { L2++; s++; }
6,324,479✔
396
                else if ( *s == ')' ) {
6,091,581✔
397
                        L2--; s++;
232,898✔
398
                        if ( L2 < 0 ) { MesPrint("&Unmatched ()"); return(1); }
232,898✔
399
                }
400
                else s++;
5,858,683✔
401
        }
402
        if ( L2 > 0 ) { MesPrint("&Unmatched ()"); return(1); }
9,061✔
403
        s = sin;
404
        while ( *s ) {
6,333,708✔
405
                if ( *s == '[' ) SKIPBRA1(s)
6,325,454✔
406
                else if ( *s == '[' ) SKIPBRA4(s)
6,324,479✔
407
                else if ( *s == '{' ) { L3++; s++; }
6,324,479✔
408
                else if ( *s == '}' ) {
6,323,459✔
409
                        L3--; s++;
1,020✔
410
                        if ( L3 < 0 ) { MesPrint("&Unmatched {}"); return(1); }
1,020✔
411
                }
412
                else s++;
6,322,439✔
413
        }
414
        if ( L3 > 0 ) { MesPrint("&Unmatched {}"); return(1); }
9,061✔
415
        return(0);
416
}
417

418
/*
419
                 #] ParenthesesTest : 
420
                 #[ SkipAName :
421

422
                Skips a name and gives a pointer to the object after the name.
423
                If there is not a proper name, it returns a zero pointer.
424
                In principle the brackets match already, so the `if ( *s == 0 )'
425
                code is not really needed, but you never know how the program
426
                is extended later.
427
*/
428

429
UBYTE *SkipAName(UBYTE *s)
7,932✔
430
{
431
        UBYTE *t = s;
7,932✔
432
        if ( *s == '[' ) {
7,932✔
433
                SKIPBRA1(s)
576✔
434
                if ( *s == 0 ) {
63✔
435
                        MesPrint("&Illegal name: '%s'",t);
×
436
                        return(0);
×
437
                }
438
                s++;
63✔
439
        }
440
        else if ( FG.cTable[*s] == 0 || *s == '_' || *s == '$' ) {
7,869✔
441
                if ( *s == '$' ) s++;
7,869✔
442
                while ( FG.cTable[*s] <= 1 ) s++;
27,741✔
443
                if ( *s == '_' ) s++;
7,869✔
444
        }
445
        else {
446
                MesPrint("&Illegal name: '%s'",t);
×
447
                return(0);
×
448
        }
449
        return(s);
450
}
451

452
/*
453
                 #] SkipAName : 
454
                 #[ IsRHS :
455
*/
456

457
UBYTE *IsRHS(UBYTE *s, UBYTE c)
×
458
{
459
        while ( *s && *s != c ) {
×
460
                if ( *s == '[' ) {
×
461
                        SKIPBRA1(s);
×
462
                        if ( *s != ']' ) {
×
463
                                MesPrint("&Unmatched []");
×
464
                                return(0);
×
465
                        }
466
                }
467
                else if ( *s == '{' ) {
468
                        SKIPBRA2(s);
×
469
                        if ( *s != '}' ) {
×
470
                                MesPrint("&Unmatched {}");
×
471
                                return(0);
×
472
                        }
473
                }
474
                else if ( *s == '(' ) {
475
                        SKIPBRA3(s);
×
476
                        if ( *s != ')' ) {
×
477
                                MesPrint("&Unmatched ()");
×
478
                                return(0);
×
479
                        }
480
                }
481
                else if ( *s == ')' ) {
482
                        MesPrint("&Unmatched ()");
×
483
                        return(0);
×
484
                }
485
                else if ( *s == '}' ) {
486
                        MesPrint("&Unmatched {}");
×
487
                        return(0);
×
488
                }
489
                else if ( *s == ']' ) {
490
                        MesPrint("&Unmatched []");
×
491
                        return(0);
×
492
                }
493
                s++;
×
494
        }
495
        return(s);
496
}
497

498
/*
499
                 #] IsRHS : 
500
                 #[ IsIdStatement :
501
*/
502

503
int IsIdStatement(UBYTE *s)
×
504
{
505
        DUMMYUSE(s);
×
506
        return(0);
×
507
}
508

509
/*
510
                 #] IsIdStatement : 
511
                 #[ CompileAlgebra :
512

513
                Returns either the number of the main level RHS (>= 0)
514
                or an error code (< 0)
515
*/
516

517
int CompileAlgebra(UBYTE *s, int leftright, WORD *prototype)
8,346✔
518
{
519
        GETIDENTITY
5,562✔
520
        int error;
8,346✔
521
        WORD *oldproto = AC.ProtoType;
8,346✔
522
        AC.ProtoType = prototype;
8,346✔
523
        if ( AC.TokensWriteFlag ) {
8,346✔
524
                MesPrint("To tokenize: %s",s);
×
525
                error = tokenize(s,leftright);
×
526
                MesPrint("  The contents of the token buffer are:");
×
527
                WriteTokens(AC.tokens);
×
528
        }
529
        else error = tokenize(s,leftright);
8,346✔
530
        if ( error == 0 ) {
8,346✔
531
                AR.Eside = leftright;
8,337✔
532
                AC.CompileLevel = 0;
8,337✔
533
                if ( leftright == LHSIDE ) { AC.DumNum = AR.CurDum = 0; }
8,337✔
534
                error = CompileSubExpressions(AC.tokens);
8,337✔
535
                REDUCESUBEXPBUFFERS
8,337✔
536
        }
537
        else {
538
                AC.ProtoType = oldproto;
9✔
539
                return(-1);
9✔
540
        }
541
        AC.ProtoType = oldproto;
8,337✔
542
        if ( error < 0 ) return(-1);
8,337✔
543
        else if ( leftright == LHSIDE ) return(cbuf[AC.cbufnum].numlhs);
8,334✔
544
        else                            return(cbuf[AC.cbufnum].numrhs);
5,510✔
545
}
546

547
/*
548
                 #] CompileAlgebra : 
549
                 #[ CompileStatement :
550

551
*/
552

553
int CompileStatement(UBYTE *in)
11,183✔
554
{
555
        KEYWORD *k;
11,183✔
556
        UBYTE *s;
11,183✔
557
        int error1 = 0, error2;
11,183✔
558
        /* A.iStatement = */ s = in;
11,183✔
559
        if ( *s == 0 ) return(0);
11,183✔
560
        if ( *s == '$' ) {
11,183✔
561
                k = findcommand((UBYTE *)"assign");
384✔
562
        }
563
        else {
564
                if ( ( k = findcommand(s) ) == 0 && IsIdStatement(s) == 0 ) {
10,799✔
565
                        MesPrint("&Unrecognized statement %s",s);
×
566
                        return(1);
×
567
                }
568
                if ( k == 0 ) {        /* Id statement without id. Note: id must be in table */
10,799✔
569
                        k = com1commands + alfatable1['i'-'a'];
×
570
                        while ( k->name[1] != 'd' || k->name[2] ) k++;
×
571
                }
572
                else {
573
                        while ( FG.cTable[*s] <= 1 ) s++;
60,617✔
574
                        if ( s > in && *s == '[' && s[1] == ']' ) s += 2;
10,799✔
575
/*
576
                        The next statement is rather mysterious
577
                        It is undone in DoPrint and CoMultiply, but it also causes effects
578
                        in other (wrong) statements like dimension -4; or Trace4 -1;
579
                        The code in pre.c (LoadStatement) has been changed 8-sep-2009
580
                        to force a comma after the keyword. This means that the
581
                        'mysterious' line is automatically inactive. Hence it is taken out.
582

583
                        if ( *s == '+' || *s == '-' ) s++;
584
*/
585
                        if ( *s == ',' ) s++;
10,799✔
586
                }
587
        }
588
/*
589
        First the test on the order of the statements.
590
        This is relatively new (2.2c) and may cause some problems with old
591
        programs. Hence the first error message should explain!
592
*/
593
        if ( AP.PreAssignFlag == 0 && AM.OldOrderFlag == 0 ) {
11,183✔
594
         if ( AP.PreInsideLevel ) {
10,856✔
595
          if ( k->type != STATEMENT && k->type != MIXED ) {
42✔
596
                MesPrint("&Only executable and print statements are allowed in an %#inside/%#endinside construction");
×
597
                return(-1);
×
598
          }
599
         }
600
         else {
601
          if ( ( AC.compiletype == DECLARATION || AC.compiletype == SPECIFICATION )
10,814✔
602
          && ( k->type == STATEMENT || k->type == DEFINITION || k->type == TOOUTPUT ) ) {
1,982✔
603
                if ( AC.tablecheck == 0 ) {
919✔
604
                        AC.tablecheck = 1;
889✔
605
                        if ( TestTables() ) error1 = 1;
889✔
606
                }
607
          }
608
          if ( k->type == MIXED ) {
10,814✔
609
                if ( AC.compiletype <= DEFINITION ) {
2,107✔
610
                        AC.compiletype = STATEMENT;
432✔
611
                }
612
          }
613
          else if ( k->type == MIXED2 ) {}
8,707✔
614
          else if ( k->type > AC.compiletype ) {
8,707✔
615
                if ( StrCmp((UBYTE *)(k->name),(UBYTE *)"format") != 0 )
2,946✔
616
                        AC.compiletype = k->type;
2,811✔
617
          }
618
          else if ( k->type < AC.compiletype ) {
5,761✔
619
                switch ( k->type ) {
×
620
                        case DECLARATION:
×
621
                                MesPrint("&Declaration out of order");
×
622
                                MesPrint("&  %s",in);
×
623
                                break;
×
624
                        case DEFINITION:
×
625
                                MesPrint("&Definition out of order");
×
626
                                MesPrint("&  %s",in);
×
627
                                break;
×
628
                        case SPECIFICATION:
×
629
                                MesPrint("&Specification out of order");
×
630
                                MesPrint("&  %s",in);
×
631
                                break;
×
632
                        case STATEMENT:
×
633
                                MesPrint("&Statement out of order");
×
634
                                break;
×
635
                        case TOOUTPUT:
×
636
                                MesPrint("&Output control statement out of order");
×
637
                                MesPrint("&  %s",in);
×
638
                                break;
×
639
                }
640
                AC.compiletype = k->type;
×
641
                if ( AC.firstctypemessage == 0 ) {
×
642
                        MesPrint("&Proper order inside a module is:");
×
643
                        MesPrint("Declarations, specifications, definitions, statements, output control statements");
×
644
                        AC.firstctypemessage = 1;
×
645
                }
646
                error1 = 1;
647
          }
648
         }
649
        }
650
/*
651
        Now we execute the tests that are prescribed by the flags.
652
*/
653
        if ( AC.AutoDeclareFlag && ( ( k->flags & WITHAUTO ) == 0 ) ) {
11,183✔
654
                MesPrint("&Illegal type of auto-declaration");
×
655
                return(1);
×
656
        }
657
        if ( ( ( k->flags & PARTEST ) != 0 ) && ParenthesesTest(s) ) return(1);
11,183✔
658
        error2 = (*k->func)(s);
11,183✔
659
        if ( error2 == 0 ) return(error1);
11,183✔
660
        return(error2);
661
}
662

663
/*
664
                 #] CompileStatement : 
665
                 #[ TestTables :
666
*/
667

668
int TestTables(VOID)
1,628✔
669
{
670
        FUNCTIONS f = functions;
1,628✔
671
        TABLES t;
1,628✔
672
        WORD j;
1,628✔
673
        int error = 0, i;
1,628✔
674
        LONG x;
1,628✔
675
        i = NumFunctions + FUNCTION - MAXBUILTINFUNCTION - 1;
1,628✔
676
        f = f + MAXBUILTINFUNCTION - FUNCTION + 1;
1,628✔
677
        if ( AC.MustTestTable > 0 ) {
1,628✔
678
          while ( i > 0 ) {
×
679
                if ( ( t = f->tabl ) != 0 && t->strict > 0 && !t->sparse ) {
×
680
                        for ( x = 0, j = 0; x < t->totind; x++ ) {
×
681
                                if ( t->tablepointers[TABLEEXTENSION*x] < 0 ) j++;
×
682
                        }
683
                        if ( j > 0 ) {
×
684
                                if ( j > 1 ) {
×
685
                                        MesPrint("&In table %s there are %d unfilled elements",
×
686
                                        AC.varnames->namebuffer+f->name,j);
×
687
                                }
688
                                else {
689
                                        MesPrint("&In table %s there is one unfilled element",
×
690
                                        AC.varnames->namebuffer+f->name);
×
691
                                }
692
                                error = 1;
693
                        }
694
                }
695
                i--; f++;
×
696
          }
697
          AC.MustTestTable--;
×
698
        }
699
        return(error);
1,628✔
700
}
701

702
/*
703
                 #] TestTables : 
704
                 #[ CompileSubExpressions :
705

706
                Now we attack the subexpressions from inside out.
707
                We try to see whether we had any of them already.
708
                We have to worry about adding the wildcard sum parameter
709
                to the prototype.
710
*/
711

712
int CompileSubExpressions(SBYTE *tokens)
108,584✔
713
{
714
        GETIDENTITY
72,386✔
715
        SBYTE *fill = tokens, *s = tokens, *t;
108,584✔
716
        WORD number[MAXNUMSIZE], *oldwork, *w1, *w2;
108,584✔
717
        int level, num, i, sumlevel = 0, sumtype = SYMTOSYM;
108,584✔
718
        int retval, error = 0;
108,584✔
719
/*
720
        Eliminate all subexpressions. They are marked by LPARENTHESIS,RPARENTHESIS
721
*/
722
        AC.CompileLevel++;
108,584✔
723
        while ( *s != TENDOFIT ) {
6,577,300✔
724
                if ( *s == TFUNOPEN ) {
725
                        if ( fill < s ) *fill = TENDOFIT;
215,129✔
726
                        t = fill - 1;
215,129✔
727
                        while ( t >= tokens && t[0] >= 0 ) t--;
644,077✔
728
                        if ( t >= tokens && *t == TFUNCTION ) {
215,129✔
729
                                t++; i = 0; while ( *t >= 0 ) i = 128*i + *t++;
643,948✔
730
                                if ( i == AM.sumnum || i == AM.sumpnum ) {
215,030✔
731
                                        t = s + 1;
19✔
732
                                        if ( *t == TSYMBOL || *t == TINDEX ) {
19✔
733
                                                t++; i = 0; while ( *t >= 0 ) i = 128*i + *t++;
38✔
734
                                                if ( s[1] == TINDEX ) {
19✔
735
                                                        i += AM.OffsetIndex;
×
736
                                                        sumtype = INDTOIND;
×
737
                                                }
738
                                                else sumtype = SYMTOSYM;
739
                                                sumlevel = i;
740
                                        }
741
                                }
742
                        }
743
                        *fill++ = *s++;
215,129✔
744
                }
745
                else if ( *s == TFUNCLOSE ) { sumlevel = 0; *fill++ = *s++; }
215,129✔
746
                else if ( *s == LPARENTHESIS ) {
747
/*
748
                        We must make an exception here.
749
                        If the subexpression is just an integer, whatever its length,
750
                        we should try to keep it.
751
                        This is important when we have a function with an integer
752
                        argument. In particular this is relevant for the MZV program.
753
*/
754
                        t = s; level = 0;
5,924,480✔
755
                        while ( level >= 0 ) {
5,924,480✔
756
                                s++;
5,824,233✔
757
                                if ( *s == LPARENTHESIS ) level++;
5,824,233✔
758
                                else if ( *s == RPARENTHESIS ) level--;
5,790,219✔
759
                                else if ( *s == TENDOFIT ) {
5,655,958✔
760
                                        MesPrint("&Unbalanced subexpression parentheses");
×
761
                                        return(-1);
×
762
                                }
763
                        }
764
                        t++; *s = TENDOFIT;
100,247✔
765
                        if ( sumlevel > 0 ) { /* Inside sum. Add wildcard to prototype */
100,247✔
766
                                oldwork = w1 = AT.WorkPointer;
19✔
767
                                w2 = AC.ProtoType;
19✔
768
                                i = w2[1];
19✔
769
                                while ( --i >= 0 ) *w1++ = *w2++;
114✔
770
                                oldwork[1] += 4;
19✔
771
                                *w1++ = sumtype; *w1++ = 4; *w1++ = sumlevel; *w1++ = sumlevel;
19✔
772
                                w2 = AC.ProtoType; AT.WorkPointer = w1;
19✔
773
                                AC.ProtoType = oldwork;
19✔
774
                                num = CompileSubExpressions(t);
19✔
775
                                AC.ProtoType = w2; AT.WorkPointer = oldwork;
19✔
776
                        }
777
                        else num = CompileSubExpressions(t);
100,228✔
778
                        if ( num < 0 ) return(-1);
100,247✔
779
/*
780
                        Note that the subexpression code should always fit.
781
                        We had two parentheses and at least two bytes contents.
782
                        There cannot be more than 2^21 subexpressions or we get outside
783
                        this minimum. Ignoring this might lead to really rare and
784
                        hard to find errors, years from now.
785
*/
786
                        if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
100,247✔
787
                                MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
×
788
                                Terminate(-1);
×
789
                        }
790
                        if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
100,247✔
791
                                DoubleBuffer((void **)((VOID *)(&subexpbuffers))
463✔
792
                                ,(void **)((VOID *)(&topsubexpbuffers)),sizeof(SUBBUF),"subexpbuffers");
793
                        }
794
                        subexpbuffers[insubexpbuffers].subexpnum = num;
100,247✔
795
                        subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
100,247✔
796
                        num = insubexpbuffers++;
100,247✔
797
                        *fill++ = TSUBEXP;
100,247✔
798
                        i = 0;
100,247✔
799
                        do { number[i++] = num & 0x7F; num >>= 7; } while ( num );
148,979✔
800
                        while ( --i >= 0 ) *fill++ = (SBYTE)(number[i]);
249,226✔
801
                        s++;
100,247✔
802
                }
803
                else if ( *s == TEMPTY ) s++;
×
804
                else *fill++ = *s++;
5,938,211✔
805
        }
806
        *fill = TENDOFIT;
108,584✔
807
/*
808
        At this stage there are no more subexpressions.
809
        Hence we can do the basic compilation.
810
*/
811
        if ( AC.CompileLevel == 1 && AC.ToBeInFactors ) {
108,584✔
812
                error = CodeFactors(tokens);
42✔
813
        }
814
        AC.CompileLevel--;
108,584✔
815
        retval = CodeGenerator(tokens);
108,584✔
816
        if ( error < 0 ) return(error);
108,584✔
817
        return(retval);
818
}
819

820
/*
821
                 #] CompileSubExpressions : 
822
                 #[ CodeGenerator :
823

824
                This routine does the real code generation.
825
                It returns the number of the rhs subexpression.
826
                At this point we do not have to worry about subexpressions,
827
                sets, setelements, simple vs complicated function arguments
828
                simple vs complicated powers etc.
829

830
                The variable 'first' indicates whether we are starting a new term
831

832
                The major complication are the set elements of type set[n].
833
                We have marked them as TSETNUM,n,Ttype,setnum
834
                They go into
835
                SETSET,size,subterm,relocation list
836
                in which the subterm should be ready to become a regular
837
                subterm in which the sets have been replaced by their element
838
                The relocation list consists of pairs of numbers:
839
                1: offset in the subterm, 2: the symbol n.
840
                Note that such a subterm can be a whole function with its arguments.
841
                We use the variable inset to indicate that we have something going.
842
                The relocation list is collected in the top of the WorkSpace.
843
*/
844

845
static UWORD *CGscrat7 = 0;
846

847
int CodeGenerator(SBYTE *tokens)
108,650✔
848
{
849
        GETIDENTITY
72,430✔
850
        SBYTE *s = tokens, c;
108,650✔
851
        int i, sign = 1, first = 1, deno = 1, error = 0, minus, n, needarg, numexp, cc;
108,650✔
852
        int base, sumlevel = 0, sumtype = SYMTOSYM, firstsumarg, inset = 0;
108,650✔
853
        int funflag = 0, settype, x1, x2, mulflag = 0;
108,650✔
854
        WORD *t, *v, *r, *term, nnumerator, ndenominator, *oldwork, x3, y, nin;
108,650✔
855
        WORD *w1, *w2, *tsize = 0, *relo = 0;
108,650✔
856
        UWORD *numerator, *denominator, *innum;
108,650✔
857
        CBUF *C;
108,650✔
858
        POSITION position;
108,650✔
859
        WORD TMproto[SUBEXPSIZE];
108,650✔
860
/*
861
#ifdef WITHPTHREADS
862
        RENUMBER renumber;
863
#endif
864
*/
865
        RENUMBER renumber;
108,650✔
866
        if ( AC.TokensWriteFlag ) WriteTokens(tokens);
108,650✔
867
        if ( CGscrat7 == 0 )
108,650✔
868
                CGscrat7 = (UWORD *)Malloc1((AM.MaxTal+2)*sizeof(WORD),"CodeGenerator");
844✔
869
        AddRHS(AC.cbufnum,0);
108,650✔
870
        C = cbuf + AC.cbufnum;
108,650✔
871
        numexp = C->numrhs;
108,650✔
872
        C->NumTerms[numexp] = 0;
108,650✔
873
        C->numdum[numexp] = 0;
108,650✔
874
        oldwork = AT.WorkPointer;
108,650✔
875
        numerator = (UWORD *)(AT.WorkPointer);
108,650✔
876
        denominator = numerator + 2*AM.MaxTal;
108,650✔
877
        innum = denominator + 2*AM.MaxTal;
108,650✔
878
        term = (WORD *)(innum + 2*AM.MaxTal);
108,650✔
879
        AT.WorkPointer = term + AM.MaxTer/sizeof(WORD);
108,650✔
880
        if ( AT.WorkPointer > AT.WorkTop ) goto OverWork;
108,650✔
881
        cc = 0;
108,650✔
882
        t = term+1;
108,650✔
883
        numerator[0] = denominator[0] = 1;
108,650✔
884
        nnumerator = ndenominator = 1;
108,650✔
885
        while ( *s != TENDOFIT ) {
2,655,786✔
886
                if ( *s == TPLUS || *s == TMINUS ) {
2,547,136✔
887
                        if ( first || mulflag ) { if ( *s == TMINUS ) sign = -sign; }
471,368✔
888
                        else {
889
                                *term = t-term;
444,842✔
890
                                C->NumTerms[numexp]++;
444,842✔
891
                                if ( cc && sign ) C->CanCommu[numexp]++;
444,842✔
892
                                CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
444,842✔
893
                                first = 1; cc = 0; t = term + 1; deno = 1;
444,842✔
894
                                numerator[0] = denominator[0] = 1;
444,842✔
895
                                nnumerator = ndenominator = 1;
444,842✔
896
                                if ( *s == TMINUS ) sign = -1;
444,842✔
897
                                else sign = 1;
326,614✔
898
                        }
899
                        s++;
471,368✔
900
                }
901
                else {
902
                        mulflag = first = 0; c = *s++;
2,075,768✔
903
                        switch ( c ) {
2,075,768✔
904
                        case TSYMBOL:
905
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1,586,299✔
906
                                if ( *s == TWILDCARD ) { s++; x1 += 2*MAXPOWER; }
789,863✔
907
                                *t++ = SYMBOL; *t++ = 4; *t++ = x1;
789,863✔
908
                                if ( inset ) *relo = 2;
789,863✔
909
TryPower:                if ( *s == TPOWER ) {
790,364✔
910
                                        s++;
291,613✔
911
                                        if ( *s == TMINUS ) { s++; deno = -deno; }
291,613✔
912
                                        c = *s++;
291,613✔
913
                                        base = ( c == TNUMBER ) ? 100: 128;
291,613✔
914
                                        x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
583,226✔
915
                                        if ( c == TSYMBOL ) {
291,613✔
916
                                                if ( *s == TWILDCARD ) s++;
232✔
917
                                                x2 += 2*MAXPOWER;
232✔
918
                                        }
919
                                        *t++ = deno*x2;
291,613✔
920
                                }
921
                                else *t++ = deno;
498,751✔
922
fin:                        deno = 1;
1,005,718✔
923
                                if ( inset ) {
1,005,718✔
924
                                        while ( relo < AT.WorkTop ) *t++ = *relo++;
69✔
925
                                        inset = 0; tsize[1] = t - tsize;
21✔
926
                                }
927
                                break;
928
                        case TINDEX:
929
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
60✔
930
                                *t++ = INDEX; *t++ = 3;
30✔
931
                                if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
30✔
932
                                if ( inset ) { *t++ = x1; *relo = 2; }
30✔
933
                                else           *t++ = x1 + AM.OffsetIndex;
30✔
934
                                if ( t[-1] > AM.IndDum ) {
30✔
935
                                        x1 = t[-1] - AM.IndDum;
×
936
                                        if ( x1 > C->numdum[numexp] ) C->numdum[numexp] = x1;
×
937
                                }
938
                                goto fin;
30✔
939
                        case TGENINDEX:
×
940
                                *t++ = INDEX; *t++ = 3; *t++ = AC.DumNum+WILDOFFSET;
×
941
                                deno = 1;
×
942
                                break;
×
943
                        case TVECTOR:
944
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1,200✔
945
dovector:                if ( inset == 0 ) x1 += AM.OffsetVector;
600✔
946
                                if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
600✔
947
                                if ( inset ) *relo = 2;
600✔
948
                                if ( *s == TDOT ) {                /* DotProduct ? */
600✔
949
                                        s++;
501✔
950
                                        if ( *s == TSETNUM || *s == TSETDOL ) {
501✔
951
                                                settype = ( *s == TSETDOL );
×
952
                                                s++; x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
×
953
                                                if ( settype ) x2 = -x2;
×
954
                                                if ( inset == 0 ) {
×
955
                                                        tsize = t; *t++ = SETSET; *t++ = 0;
×
956
                                                        relo = AT.WorkTop;
×
957
                                                }
958
                                                inset += 2;
×
959
                                                *--relo = x2; *--relo = 3;
×
960
                                        }
961
                                        if ( *s != TVECTOR && *s != TDUBIOUS ) {
501✔
962
                                                MesPrint("&Illegally formed dotproduct");
×
963
                                                error = 1;
×
964
                                        }
965
                                        s++; x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
1,002✔
966
                                        if ( inset < 2 ) x2 += AM.OffsetVector;
501✔
967
                                        if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
501✔
968
                                        *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2;
501✔
969
                                        goto TryPower;
501✔
970
                                }
971
                                else if ( *s == TFUNOPEN ) {
99✔
972
                                        s++;
30✔
973
                                        if ( *s == TSETNUM || *s == TSETDOL ) {
30✔
974
                                                settype = ( *s == TSETDOL );
×
975
                                                s++; x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
×
976
                                                if ( settype ) x2 = -x2;
×
977
                                                if ( inset == 0 ) {
×
978
                                                        tsize = t; *t++ = SETSET; *t++ = 0;
×
979
                                                        relo = AT.WorkTop;
×
980
                                                }
981
                                                inset += 2;
×
982
                                                *--relo = x2; *--relo = 3;
×
983
                                        }
984
                                        if ( *s == TINDEX || *s == TDUBIOUS ) {
30✔
985
                                                s++;
30✔
986
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
84✔
987
                                                if ( inset < 2 ) x2 += AM.OffsetIndex;
30✔
988
                                                if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
30✔
989
                                                *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
30✔
990
                                                if ( t[-1] > AM.IndDum ) {
30✔
991
                                                        x2 = t[-1] - AM.IndDum;
6✔
992
                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
6✔
993
                                                }
994
                                        }
995
                                        else if ( *s == TGENINDEX ) {
996
                                                *t++ = VECTOR; *t++ = 4; *t++ = x1;
×
997
                                                *t++ = AC.DumNum + WILDOFFSET;
×
998
                                        }
999
                                        else if ( *s == TNUMBER || *s == TNUMBER1 ) {
1000
                                                base = ( *s == TNUMBER ) ? 100: 128;
×
1001
                                                s++;
×
1002
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*base + *s++; }
×
1003
                                                if ( x2 >= AM.OffsetIndex && inset < 2 ) {
×
1004
                                                        MesPrint("&Fixed index in vector greater than %d",
×
1005
                                                        AM.OffsetIndex);
1006
                                                        return(-1);
×
1007
                                                }
1008
                                                *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
×
1009
                                        }
1010
                                        else if ( *s == TVECTOR || ( *s == TMINUS && s[1] == TVECTOR ) ) {
×
1011
                                                if ( *s == TMINUS ) { s++; sign = -sign; }
×
1012
                                                s++;
×
1013
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
×
1014
                                                if ( inset < 2 ) x2 += AM.OffsetVector;
×
1015
                                                if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
×
1016
                                                *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2; *t++ = deno;
×
1017
                                        }
1018
                                        else {
1019
                                                MesPrint("&Illegal argument for vector");
×
1020
                                                return(-1);
×
1021
                                        }
1022
                                        if ( *s != TFUNCLOSE ) {
30✔
1023
                                                MesPrint("&Illegal argument for vector");
×
1024
                                                return(-1);
×
1025
                                        }
1026
                                        s++;
30✔
1027
                                }
1028
                                else {
1029
                                        if ( AC.DumNum ) {
69✔
1030
                                                *t++ = VECTOR; *t++ = 4; *t++ = x1;
×
1031
                                                *t++ = AC.DumNum + WILDOFFSET;
×
1032
                                        }
1033
                                        else {
1034
                                                *t++ = INDEX; *t++ = 3; *t++ = x1;
69✔
1035
                                        }
1036
                                }
1037
                                goto fin;
99✔
1038
                        case TDELTA:
15✔
1039
                                if ( *s != TFUNOPEN ) {
15✔
1040
                                        MesPrint("&d_ needs two arguments");
×
1041
                                        error = -1;
×
1042
                                }
1043
                                v = t; *t++ = DELTA; *t++ = 4;
15✔
1044
                                needarg = 2; x3 = x1 = -1;
15✔
1045
                                goto dotensor;
15✔
1046
                        case TFUNCTION:
1047
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
644,461✔
1048
                                if ( x1 == AM.sumnum || x1 == AM.sumpnum ) sumlevel = x1;
215,210✔
1049
                                x1 += FUNCTION;
215,210✔
1050
                                if ( x1 == FIRSTBRACKET ) {
215,210✔
1051
                                        if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION ) {
×
1052
doexpr:                                        s += 2;
×
1053
                                                *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
36✔
1054
                                                if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
36✔
1055
                                                                t[-1] |= MUSTCLEANPRF;
×
1056
                                                FILLFUN3(t)
1057
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
72✔
1058
                                                *t++ = -EXPRESSION; *t++ = x2;
36✔
1059
/*
1060
                                                The next code is added to facilitate parallel processing
1061
                                                We need to call GetTable here to make sure all processors
1062
                                                have the same numbering of all variables.
1063
*/
1064
                                                if ( Expressions[x2].status == STOREDEXPRESSION ) {
36✔
1065
                                                        TMproto[0] = EXPRESSION;
×
1066
                                                        TMproto[1] = SUBEXPSIZE;
×
1067
                                                        TMproto[2] = x2;
×
1068
                                                        TMproto[3] = 1;
×
1069
                                                        { int ie; for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
×
1070
                                                        AT.TMaddr = TMproto;
×
1071
                                                        PUTZERO(position);
×
1072
/*
1073
                                                        if ( (
1074
#ifdef WITHPTHREADS
1075
                                                                        renumber = 
1076
#endif
1077
                                                                        GetTable(x2,&position,0) ) == 0 ) {
1078
                                                                error = 1;
1079
                                                                MesPrint("&Problems getting information about stored expression %s(1)"
1080
                                                                ,EXPRNAME(x2));
1081
                                                        }
1082
#ifdef WITHPTHREADS
1083
                                                        M_free(renumber->symb.lo,"VarSpace");
1084
                                                        M_free(renumber,"Renumber");
1085
#endif
1086
*/
1087
                                                        if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
×
1088
                                                                error = 1;
×
1089
                                                                MesPrint("&Problems getting information about stored expression %s(1)"
×
1090
                                                                ,EXPRNAME(x2));
×
1091
                                                        }
1092
                                                        if ( renumber->symb.lo != AN.dummyrenumlist )
×
1093
                                                                M_free(renumber->symb.lo,"VarSpace");
×
1094
                                                        M_free(renumber,"Renumber");
×
1095
                                                        AR.StoreData.dirtyflag = 1;
×
1096
                                                }
1097
                                                if ( *s != TFUNCLOSE ) {
36✔
1098
                                                        if ( x1 == FIRSTBRACKET )
×
1099
                                                                MesPrint("&Problems with argument of FirstBracket_");
×
1100
                                                        else if ( x1 == FIRSTTERM )
1101
                                                                MesPrint("&Problems with argument of FirstTerm_");
×
1102
                                                        else if ( x1 == CONTENTTERM )
1103
                                                                MesPrint("&Problems with argument of FirstTerm_");
×
1104
                                                        else if ( x1 == TERMSINEXPR )
1105
                                                                MesPrint("&Problems with argument of TermsIn_");
×
1106
                                                        else if ( x1 == SIZEOFFUNCTION )
1107
                                                                MesPrint("&Problems with argument of SizeOf_");
×
1108
                                                        else if ( x1 == NUMFACTORS )
1109
                                                                MesPrint("&Problems with argument of NumFactors_");
×
1110
                                                        else
1111
                                                                MesPrint("&Problems with argument of FactorIn_");
×
1112
                                                        error = 1;
×
1113
                                                        while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
×
1114
                                                }
1115
                                                if ( *s == TFUNCLOSE ) s++;
36✔
1116
                                                goto fin;
36✔
1117
                                        }
1118
                                }
1119
                                else if ( x1 == TERMSINEXPR || x1 == SIZEOFFUNCTION || x1 == FACTORIN
1120
                                 || x1 == NUMFACTORS || x1 == FIRSTTERM || x1 == CONTENTTERM ) {
1121
                                        if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION ) goto doexpr;
51✔
1122
                                        if ( s[0] == TFUNOPEN && s[1] == TDOLLAR ) {
15✔
1123
                                                s += 2;
15✔
1124
                                                *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
15✔
1125
                                                FILLFUN3(t)
1126
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*128 + *s++; }
30✔
1127
                                                *t++ = -DOLLAREXPRESSION; *t++ = x2;
15✔
1128
                                                if ( *s != TFUNCLOSE ) {
15✔
1129
                                                        if ( x1 == TERMSINEXPR )
×
1130
                                                                MesPrint("&Problems with argument of TermsIn_");
×
1131
                                                        else if ( x1 == SIZEOFFUNCTION )
×
1132
                                                                MesPrint("&Problems with argument of SizeOf_");
×
1133
                                                        else if ( x1 == NUMFACTORS )
×
1134
                                                                MesPrint("&Problems with argument of NumFactors_");
×
1135
                                                        else
1136
                                                                MesPrint("&Problems with argument of FactorIn_");
×
1137
                                                        error = 1;
×
1138
                                                        while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
×
1139
                                                }
1140
                                                if ( *s == TFUNCLOSE ) s++;
15✔
1141
                                                goto fin;
15✔
1142
                                        }
1143
                                }
1144
                                x3 = x1;
215,159✔
1145
                                if ( inset && ( t-tsize == 2 ) ) x1 -= FUNCTION;
215,159✔
1146
                                if ( *s == TWILDCARD ) { x1 += WILDOFFSET; s++; }
215,159✔
1147
                                if ( functions[x3-FUNCTION].commute ) cc = 1;
215,159✔
1148
                                if ( *s != TFUNOPEN ) {
215,159✔
1149
                                        *t++ = x1; *t++ = FUNHEAD; *t++ = 0;
126✔
1150
                                        if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
126✔
1151
                                                        t[-1] |= MUSTCLEANPRF;
×
1152
                                        FILLFUN3(t) sumlevel = 0; goto fin;
126✔
1153
                                }
1154
                                v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
215,033✔
1155
                                if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
215,033✔
1156
                                                t[-1] |= MUSTCLEANPRF;
12,165✔
1157
                                FILLFUN3(t)
1158
                                needarg = -1;
215,033✔
1159
                                if ( !inset && functions[x3-FUNCTION].spec >= TENSORFUNCTION ) {
215,033✔
1160
dotensor:
207✔
1161
                                        do {
645✔
1162
                                                if ( needarg == 0 ) {
645✔
1163
                                                        if ( x1 >= 0 ) {
×
1164
                                                                x3 = x1;
×
1165
                                                                if ( x3 >= FUNCTION+WILDOFFSET ) x3 -= WILDOFFSET;
×
1166
                                                                MesPrint("&Too many arguments in function %s",
×
1167
                                                                        VARNAME(functions,(x3-FUNCTION)) );
×
1168
                                                        }
1169
                                                        else
1170
                                                                MesPrint("&d_ needs exactly two arguments");
×
1171
                                                        error = -1;
×
1172
                                                        needarg--;
×
1173
                                                }
1174
                                                else if ( needarg > 0 ) needarg--;
645✔
1175
                                                s++;
645✔
1176
                                                c = *s++;
645✔
1177
                                                if ( c == TMINUS && *s == TVECTOR ) { sign = -sign; c = *s++; }
645✔
1178
                                                base = ( c == TNUMBER ) ? 100: 128;
645✔
1179
                                                x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1,287✔
1180
                                                if ( *s == TWILDCARD && c != TNUMBER ) { x2 += WILDOFFSET; s++; }
645✔
1181
                                                if ( c == TSETNUM || c == TSETDOL ) {
645✔
1182
                                                        if ( c == TSETDOL ) x2 = -x2;
×
1183
                                                        if ( inset == 0 ) {
×
1184
                                                                w1 = t; t += 2; w2 = t;
×
1185
                                                                while ( w1 > v ) *--w2 = *--w1;
×
1186
                                                                tsize = v; relo = AT.WorkTop;
×
1187
                                                                *v++ = SETSET; *v++ = 0;
×
1188
                                                        }
1189
                                                        inset = 2; *--relo = x2; *--relo = t - v;
×
1190
                                                        c = *s++;
×
1191
                                                        x2 = 0; while ( *s >= 0 ) x2 = 128*x2 + *s++;
×
1192
                                                        switch ( c ) {
×
1193
                                                                case TINDEX:
×
1194
                                                                        *t++ = x2;
×
1195
                                                                        if ( t[-1]+AM.OffsetIndex > AM.IndDum ) {
×
1196
                                                                                x2 = t[-1]+AM.OffsetIndex - AM.IndDum;
×
1197
                                                                                if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1198
                                                                        }
1199
                                                                        break;
1200
                                                                case TVECTOR:
×
1201
                                                                        *t++ = x2; break;
×
1202
                                                                case TNUMBER1:
×
1203
                                                                        if ( x2 >= 0 && x2 < AM.OffsetIndex ) {
×
1204
                                                                                *t++ = x2; break;
×
1205
                                                                        }
1206
                                                                        /* fall through */
1207
                                                                default:
1208
                                                                        MesPrint("&Illegal type of set inside tensor");
×
1209
                                                                        error = 1;
×
1210
                                                                        *t++ = x2;
×
1211
                                                                        break;
×
1212
                                                        }
1213
                                                }
1214
                                                else { switch ( c ) {
645✔
1215
                                                        case TINDEX:
336✔
1216
                                                                if ( inset < 2 ) *t++ = x2 + AM.OffsetIndex;
336✔
1217
                                                                else *t++ = x2;
×
1218
                                                                if ( x2+AM.OffsetIndex > AM.IndDum ) {
336✔
1219
                                                                        x2 = x2+AM.OffsetIndex - AM.IndDum;
×
1220
                                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1221
                                                                }
1222
                                                                break;
1223
                                                        case TGENINDEX:
3✔
1224
                                                                *t++ = AC.DumNum + WILDOFFSET;
3✔
1225
                                                                break;
3✔
1226
                                                        case TVECTOR:
135✔
1227
                                                                if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
135✔
1228
                                                                else *t++ = x2;
×
1229
                                                                break;
1230
                                                        case TWILDARG:
63✔
1231
                                                                *t++ = FUNNYWILD; *t++ = x2;
63✔
1232
/*                                                                v[2] = 0; */
1233
                                                                break;
63✔
1234
                                                        case TDOLLAR:
×
1235
                                                                *t++ = FUNNYDOLLAR; *t++ = x2;
×
1236
                                                                break;
×
1237
                                                        case TDUBIOUS:
×
1238
                                                                if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
×
1239
                                                                else *t++ = x2;
×
1240
                                                                break;
1241
                                                        case TSGAMMA:        /* Special gamma's */
6✔
1242
                                                                if ( x3 != GAMMA ) {
6✔
1243
                                                                        MesPrint("&5_,6_,7_ can only be used inside g_");
×
1244
                                                                        error = -1;
×
1245
                                                                }
1246
                                                                *t++ = -x2;
6✔
1247
                                                                break;
6✔
1248
                                                        case TNUMBER:
102✔
1249
                                                        case TNUMBER1:
1250
                                                                if ( x2 >= AM.OffsetIndex && inset < 2 ) {
102✔
1251
                                                                        MesPrint("&Value of constant index in tensor too large");
×
1252
                                                                        error = -1;
×
1253
                                                                }
1254
                                                                *t++ = x2;
102✔
1255
                                                                break;
102✔
1256
                                                        default:
×
1257
                                                                MesPrint("&Illegal object in tensor");
×
1258
                                                                error = -1;
×
1259
                                                                break;
×
1260
                                                }}
1261
                                                if ( inset >= 2 ) inset = 1;
645✔
1262
                                        } while ( *s == TCOMMA );
645✔
1263
                                }
1264
                                else {
1265
dofunction:                        firstsumarg = 1;
214,841✔
1266
                                        do {
338,772✔
1267
                                                unsigned int ux2;
338,772✔
1268
                                                s++;
338,772✔
1269
                                                c = *s++;
338,772✔
1270
                                                if ( c == TMINUS && ( *s == TVECTOR || *s == TNUMBER
338,772✔
1271
                                                || *s == TNUMBER1 || *s == TSUBEXP ) ) {
1272
                                                        minus = 1; c = *s++;
1,314✔
1273
                                                }
1274
                                                else minus = 0;
1275
                                                base = ( c == TNUMBER ) ? 100: 128;
338,772✔
1276
                                                ux2 = 0; while ( *s >= 0 ) { ux2 = base*ux2 + *s++; }
1,004,063✔
1277
                                                x2 = ux2;  /* may cause an implementation-defined behaviour */
338,772✔
1278
/*
1279
                !!!!!!!!  What if it does not fit?
1280
*/
1281
                                                if ( firstsumarg ) {
338,772✔
1282
                                                        firstsumarg = 0;
214,841✔
1283
                                                        if ( sumlevel > 0 ) {
214,841✔
1284
                                                                if ( c == TSYMBOL ) {
19✔
1285
                                                                        sumlevel = x2; sumtype = SYMTOSYM;
1286
                                                                }
1287
                                                                else if ( c == TINDEX ) {
×
1288
                                                                        sumlevel = x2+AM.OffsetIndex; sumtype = INDTOIND;
×
1289
                                                                        if ( sumlevel > AM.IndDum ) {
×
1290
                                                                                x2 = sumlevel - AM.IndDum;
×
1291
                                                                                if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1292
                                                                        }
1293
                                                                }
1294
                                                        }
1295
                                                }
1296
                                                if ( *s == TWILDCARD ) {
338,772✔
1297
                                                        if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
6,462✔
1298
                                                        else if ( c != TNUMBER ) x2 += WILDOFFSET;
675✔
1299
                                                        s++;
6,462✔
1300
                                                }
1301
                                                switch ( c ) {
338,772✔
1302
                                                        case TSYMBOL:
25,944✔
1303
                                                                *t++ = -SYMBOL; *t++ = x2; break;
25,944✔
1304
                                                        case TDOLLAR:
237✔
1305
                                                                *t++ = -DOLLAREXPRESSION; *t++ = x2; break;
237✔
1306
                                                        case TEXPRESSION:
180✔
1307
                                                                *t++ = -EXPRESSION; *t++ = x2;
180✔
1308
/*
1309
                                                                The next code is added to facilitate parallel processing
1310
                                                                We need to call GetTable here to make sure all processors
1311
                                                                have the same numbering of all variables.
1312
*/
1313
                                                                if ( Expressions[x2].status == STOREDEXPRESSION ) {
180✔
1314
                                                                        TMproto[0] = EXPRESSION;
×
1315
                                                                        TMproto[1] = SUBEXPSIZE;
×
1316
                                                                        TMproto[2] = x2;
×
1317
                                                                        TMproto[3] = 1;
×
1318
                                                                        { int ie; for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
×
1319
                                                                        AT.TMaddr = TMproto;
×
1320
                                                                        PUTZERO(position);
×
1321
/*
1322
                                                                        if ( ( 
1323
#ifdef WITHPTHREADS
1324
                                                                                renumber = 
1325
#endif
1326
                                                                                        GetTable(x2,&position,0) ) == 0 ) {
1327
                                                                                error = 1;
1328
                                                                                MesPrint("&Problems getting information about stored expression %s(2)"
1329
                                                                                ,EXPRNAME(x2));
1330
                                                                        }
1331
#ifdef WITHPTHREADS
1332
                                                                        M_free(renumber->symb.lo,"VarSpace");
1333
                                                                        M_free(renumber,"Renumber");
1334
#endif
1335
*/
1336
                                                                        if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
×
1337
                                                                                error = 1;
×
1338
                                                                                MesPrint("&Problems getting information about stored expression %s(2)"
×
1339
                                                                                ,EXPRNAME(x2));
×
1340
                                                                        }
1341
                                                                        if ( renumber->symb.lo != AN.dummyrenumlist )
×
1342
                                                                                M_free(renumber->symb.lo,"VarSpace");
×
1343
                                                                        M_free(renumber,"Renumber");
×
1344
                                                                        AR.StoreData.dirtyflag = 1;
×
1345
                                                                }
1346
                                                                break;
1347
                                                        case TINDEX:
291✔
1348
                                                                *t++ = -INDEX; *t++ = x2 + AM.OffsetIndex;
291✔
1349
                                                                if ( t[-1] > AM.IndDum ) {
291✔
1350
                                                                        x2 = t[-1] - AM.IndDum;
3✔
1351
                                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
3✔
1352
                                                                }
1353
                                                                break;
1354
                                                        case TGENINDEX:
3✔
1355
                                                                *t++ = -INDEX; *t++ = AC.DumNum + WILDOFFSET;
3✔
1356
                                                                break;
3✔
1357
                                                        case TVECTOR:
7,179✔
1358
                                                                if ( minus ) *t++ = -MINVECTOR;
7,179✔
1359
                                                                else *t++ = -VECTOR;
6,750✔
1360
                                                                *t++ = x2 + AM.OffsetVector;
7,179✔
1361
                                                                break;
7,179✔
1362
                                                        case TSGAMMA:        /* Special gamma's */
×
1363
                                                                MesPrint("&5_,6_,7_ can only be used inside g_");
×
1364
                                                                error = -1;
×
1365
                                                                *t++ = -INDEX;
×
1366
                                                                *t++ = -x2;
×
1367
                                                                break;
×
1368
                                                        case TDUBIOUS:
×
1369
                                                                *t++ = -SYMBOL; *t++ = x2; break;
×
1370
                                                        case TFUNCTION:
195✔
1371
                                                                *t++ = -x2-FUNCTION;
195✔
1372
                                                                break;
195✔
1373
                                                        case TSET:
15✔
1374
                                                                *t++ = -SETSET;
15✔
1375
                                                                *t++ = x2;
15✔
1376
                                                                break;
15✔
1377
                                                        case TWILDARG:
1,206✔
1378
                                                                *t++ = -ARGWILD; *t++ = x2; break;
1,206✔
1379
                                                        case TSETDOL:
×
1380
                                                                x2 = -x2;
×
1381
                                                                /* fall through */
1382
                                                        case TSETNUM:
21✔
1383
                                                                if ( inset == 0 ) {
21✔
1384
                                                                        w1 = t; t += 2; w2 = t;
18✔
1385
                                                                        while ( w1 > v ) *--w2 = *--w1;
72✔
1386
                                                                        tsize = v; relo = AT.WorkTop;
18✔
1387
                                                                        *v++ = SETSET; *v++ = 0;
18✔
1388
                                                                        inset = 1;
18✔
1389
                                                                }
1390
                                                                *--relo = x2; *--relo = t-v+1;
21✔
1391
                                                                c = *s++;
21✔
1392
                                                                x2 = 0; while ( *s >= 0 ) x2 = 128*x2 + *s++;
42✔
1393
                                                                switch ( c ) {
21✔
1394
                                                                        case TFUNCTION:
×
1395
                                                                                (*relo)--; *t++ = -x2-1; break;
×
1396
                                                                        case TSYMBOL:
15✔
1397
                                                                                *t++ = -SYMBOL; *t++ = x2; break;
15✔
1398
                                                                        case TINDEX:
×
1399
                                                                                *t++ = -INDEX; *t++ = x2;
×
1400
                                                                                if ( x2+AM.OffsetIndex > AM.IndDum ) {
×
1401
                                                                                        x2 = x2+AM.OffsetIndex - AM.IndDum;
×
1402
                                                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1403
                                                                                }
1404
                                                                                break;
1405
                                                                        case TVECTOR:
×
1406
                                                                                *t++ = -VECTOR; *t++ = x2; break;
×
1407
                                                                        case TNUMBER1:
6✔
1408
                                                                                *t++ = -SNUMBER; *t++ = x2; break;
6✔
1409
                                                                        default:
×
1410
                                                                                MesPrint("&Internal error 435");
×
1411
                                                                                error = 1;
×
1412
                                                                                *t++ = -SYMBOL; *t++ = x2; break;
×
1413
                                                                }
1414
                                                                break;
1415
                                                        case TSUBEXP:
83,323✔
1416
                                                                w2 = AC.ProtoType; i = w2[1];
83,323✔
1417
                                                                w1 = t;
83,323✔
1418
                                                                *t++ = i+ARGHEAD+4;
83,323✔
1419
                                                                *t++ = 1;
83,323✔
1420
                                                                FILLARG(t);
83,323✔
1421
                                                                *t++ = i + 4;
83,323✔
1422
                                                                while ( --i >= 0 ) *t++ = *w2++;
1,903,974✔
1423
                                                                w1[ARGHEAD+3] = subexpbuffers[x2].subexpnum;
83,323✔
1424
                                                                w1[ARGHEAD+5] = subexpbuffers[x2].buffernum;
83,323✔
1425
                                                                if ( sumlevel > 0 ) {
83,323✔
1426
                                                                        w1[0] += 4;
19✔
1427
                                                                        w1[ARGHEAD] += 4;
19✔
1428
                                                                        w1[ARGHEAD+2] += 4;
19✔
1429
                                                                        *t++ = sumtype; *t++ = 4;
19✔
1430
                                                                        *t++ = sumlevel; *t++ = sumlevel;
19✔
1431
                                                                }
1432
                                                                *t++ = 1; *t++ = 1;
83,323✔
1433
                                                                if ( minus ) *t++ = -3;
83,323✔
1434
                                                                else         *t++ =  3;
83,131✔
1435
                                                                break;
1436
                                                        case TNUMBER:
220,178✔
1437
                                                        case TNUMBER1:
1438
                                                                if ( minus ) x2 = UnsignedToInt(-IntAbs(x2));
220,871✔
1439
                                                                *t++ = -SNUMBER;
220,178✔
1440
                                                                *t++ = x2;
220,178✔
1441
                                                                break;
220,178✔
1442
                                                        default:
×
1443
                                                                MesPrint("&Illegal object in function");
×
1444
                                                                error = -1;
×
1445
                                                                break;
×
1446
                                                }
1447
                                        } while ( *s == TCOMMA );
338,772✔
1448
                                }
1449
                                if ( *s != TFUNCLOSE ) {
215,048✔
1450
                                        MesPrint("&Illegal argument field for function. Expected )");
×
1451
                                        return(-1);
×
1452
                                }
1453
                                s++; sumlevel = 0;
215,048✔
1454
                                v[1] = t-v;
215,048✔
1455
/*
1456
                                if ( *v == AM.termfunnum && ( v[1] != FUNHEAD+2 ||
1457
                                v[FUNHEAD] != -DOLLAREXPRESSION ) ) {
1458
                                        MesPrint("&The function term_ can only have one argument with a single $-expression");
1459
                                        error = 1;
1460
                                }
1461
*/
1462
                                goto fin;
215,048✔
1463
                        case TDUBIOUS:
1464
                                x1 = 0; while ( *s >= 0 ) x1 = 128*x1 + *s++;
×
1465
                                if ( *s == TWILDCARD ) s++;
×
1466
                                if ( *s == TDOT ) goto dovector;
×
1467
                                if ( *s == TFUNOPEN ) {
×
1468
                                        x1 += FUNCTION;
×
1469
                                        cc = 1;
×
1470
                                        v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
×
1471
                                        if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
×
1472
                                                        t[-1] |= MUSTCLEANPRF;
×
1473
                                        FILLFUN3(t)
1474
                                        needarg = -1; goto dofunction;
×
1475
                                }
1476
                                *t++ = SYMBOL; *t++ = 4; *t++ = 0;
×
1477
                                if ( inset ) *relo = 2;
×
1478
                                goto TryPower;
×
1479
                        case TSUBEXP:
1480
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
48,776✔
1481
                                if ( *s == TPOWER ) {
16,951✔
1482
                                        s++; c = *s++;
15,198✔
1483
                                        base = ( c == TNUMBER ) ? 100: 128;
15,198✔
1484
                                        x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
30,396✔
1485
                                        if ( *s == TWILDCARD ) { x2 += 2*MAXPOWER; s++; }
15,198✔
1486
                                        else if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
15,198✔
1487
                                }
1488
                                else x2 = 1;
1489
                                r = AC.ProtoType; n = r[1] - 5; r += 5;
16,951✔
1490
                                *t++ = SUBEXPRESSION; *t++ = r[-4];
16,951✔
1491
                                *t++ = subexpbuffers[x1].subexpnum;
16,951✔
1492
                                *t++ = x2*deno;
16,951✔
1493
                                *t++ = subexpbuffers[x1].buffernum;
16,951✔
1494
                                NCOPY(t,r,n);
55,471✔
1495
                                if ( cbuf[subexpbuffers[x1].buffernum].CanCommu[subexpbuffers[x1].subexpnum] ) cc = 1;
16,951✔
1496
                                deno = 1;
1497
                                break;
1498
                        case TMULTIPLY:
1499
                                mulflag = 1;
1500
                                break;
1501
                        case TDIVIDE:
30,241✔
1502
                                mulflag = 1;
30,241✔
1503
                                deno = -deno;
30,241✔
1504
                                break;
30,241✔
1505
                        case TEXPRESSION:
1506
                                cc = 1;
810✔
1507
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
810✔
1508
                                v = t;
405✔
1509
                                *t++ = EXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1; *t++ = deno;
405✔
1510
                                *t++ = 0; FILLSUB(t)
405✔
1511
/*
1512
                                Here we had some erroneous code before. It should be after
1513
                                the reading of the parameters as it is now (after 15-jan-2007).
1514
                                Thomas Hahn noticed this and reported it.
1515
*/
1516
                                if ( *s == TFUNOPEN ) {
405✔
1517
                                        do {
×
1518
                                                s++; c = *s++;
×
1519
                                                base = ( c == TNUMBER ) ? 100: 128;
×
1520
                                                x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
×
1521
                                                switch ( c ) {
×
1522
                                                        case TSYMBOL:
×
1523
                                                                *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
×
1524
                                                                break;
×
1525
                                                        case TINDEX:
×
1526
                                                                *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetIndex;
×
1527
                                                                if ( t[-1] > AM.IndDum ) {
×
1528
                                                                        x2 = t[-1] - AM.IndDum;
×
1529
                                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1530
                                                                }
1531
                                                                break;
1532
                                                        case TVECTOR:
×
1533
                                                                *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetVector;
×
1534
                                                                break;
×
1535
                                                        case TFUNCTION:
×
1536
                                                                *t++ = x2+FUNCTION; *t++ = 2; break;
×
1537
                                                        case TNUMBER:
×
1538
                                                        case TNUMBER1:
1539
                                                                if ( x2 >= AM.OffsetIndex || x2 < 0 ) {
×
1540
                                                                        MesPrint("&Index as argument of expression has illegal value");
×
1541
                                                                        error = -1;
×
1542
                                                                }
1543
                                                                *t++ = INDEX; *t++ = 3; *t++ = x2; break;
×
1544
                                                        case TSETDOL:
×
1545
                                                                x2 = -x2;
×
1546
                                                                /* fall through */
1547
                                                        case TSETNUM:
×
1548
                                                                if ( inset == 0 ) {
×
1549
                                                                        w1 = t; t += 2; w2 = t;
×
1550
                                                                        while ( w1 > v ) *--w2 = *--w1;
×
1551
                                                                        tsize = v; relo = AT.WorkTop;
×
1552
                                                                        *v++ = SETSET; *v++ = 0;
×
1553
                                                                        inset = 1;
×
1554
                                                                }
1555
                                                                *--relo = x2; *--relo = t-v+2;
×
1556
                                                                c = *s++;
×
1557
                                                                x2 = 0; while ( *s >= 0 ) x2 = 128*x2 + *s++;
×
1558
                                                                switch ( c ) {
×
1559
                                                                        case TFUNCTION:
×
1560
                                                                                *relo -= 2; *t++ = -x2-1; break;
×
1561
                                                                        case TSYMBOL:
×
1562
                                                                                *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1; break;
×
1563
                                                                        case TINDEX:
×
1564
                                                                                *t++ = INDEX; *t++ = 3; *t++ = x2;
×
1565
                                                                                if ( x2+AM.OffsetIndex > AM.IndDum ) {
×
1566
                                                                                        x2 = x2+AM.OffsetIndex - AM.IndDum;
×
1567
                                                                                        if ( x2 > C->numdum[numexp] ) C->numdum[numexp] = x2;
×
1568
                                                                                }
1569
                                                                                break;
1570
                                                                        case TVECTOR:
×
1571
                                                                                *t++ = VECTOR; *t++ = 3; *t++ = x2; break;
×
1572
                                                                        case TNUMBER1:
×
1573
                                                                                *t++ = SNUMBER; *t++ = 4; *t++ = x2; *t++ = 1; break;
×
1574
                                                                        default:
×
1575
                                                                                MesPrint("&Internal error 435");
×
1576
                                                                                error = 1;
×
1577
                                                                                *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1; break;
×
1578
                                                                }
1579
                                                                break;
1580
                                                        default:
×
1581
                                                                MesPrint("&Argument of expression can only be symbol, index, vector or function");
×
1582
                                                                error = -1;
×
1583
                                                                break;
×
1584
                                                }
1585
                                        } while ( *s == TCOMMA );
×
1586
                                        if ( *s != TFUNCLOSE ) {
×
1587
                                                MesPrint("&Illegal object in argument field for expression");
×
1588
                                                error = -1;
×
1589
                                                while ( *s != TFUNCLOSE ) s++;
×
1590
                                        }
1591
                                        s++;
×
1592
                                }
1593
                                r = AC.ProtoType; n = r[1];
405✔
1594
                                if ( n > SUBEXPSIZE ) {
405✔
1595
                                        *t++ = WILDCARDS; *t++ = n+2;
3✔
1596
                                        NCOPY(t,r,n);
30✔
1597
                                }
1598
/*
1599
                                Code added for parallel processing.
1600
                                This is different from the other occurrences to test immediately
1601
                                for renumbering. Here we have to read the parameters first.
1602
*/
1603
                                if ( Expressions[x1].status == STOREDEXPRESSION ) {
405✔
1604
                                        v[1] = t-v;
×
1605
                                        AT.TMaddr = v;
×
1606
                                        PUTZERO(position);
×
1607
/*
1608
                                        if ( (
1609
#ifdef WITHPTHREADS
1610
                                                renumber = 
1611
#endif
1612
                                                        GetTable(x1,&position,0) ) == 0 ) {
1613
                                                error = 1;
1614
                                                MesPrint("&Problems getting information about stored expression %s(3)"
1615
                                                ,EXPRNAME(x1));
1616
                                        }
1617
#ifdef WITHPTHREADS
1618
                                        M_free(renumber->symb.lo,"VarSpace");
1619
                                        M_free(renumber,"Renumber");
1620
#endif
1621
*/
1622
                                        if ( ( renumber = GetTable(x1,&position,0) ) == 0 ) {
×
1623
                                                error = 1;
×
1624
                                                MesPrint("&Problems getting information about stored expression %s(3)"
×
1625
                                                ,EXPRNAME(x1));
×
1626
                                        }
1627
                                        if ( renumber->symb.lo != AN.dummyrenumlist )
×
1628
                                                M_free(renumber->symb.lo,"VarSpace");
×
1629
                                        M_free(renumber,"Renumber");
×
1630
                                        AR.StoreData.dirtyflag = 1;
×
1631
                                }
1632
                                if ( *s == LBRACE ) {
405✔
1633
/*
1634
                                        This should be one term that should be inserted
1635
                                        FROMBRAC size+2 ( term )
1636
                                        Because this term should have been translated
1637
                                        already we can copy it from the 'subexpression'
1638
*/
1639
                                        s++;
39✔
1640
                                        if ( *s != TSUBEXP ) {
39✔
1641
                                                MesPrint("&Internal error 23");
×
1642
                                                Terminate(-1);
×
1643
                                        }
1644
                                        s++; x2 = 0; while ( *s >= 0 ) { x2 = 128*x2 + *s++; }
78✔
1645
                                        r = cbuf[subexpbuffers[x2].buffernum].rhs[subexpbuffers[x2].subexpnum];
39✔
1646
                                        *t++ = FROMBRAC; *t++ = *r+2;
39✔
1647
                                        n = *r;
39✔
1648
                                        NCOPY(t,r,n);
345✔
1649
                                        if ( *r != 0 ) {
39✔
1650
                                                MesPrint("&Object between [] in expression should be a single term");
×
1651
                                                error = -1;
×
1652
                                        }
1653
                                        if ( *s != RBRACE ) {
39✔
1654
                                                MesPrint("&Internal error 23b");
×
1655
                                                Terminate(-1);
×
1656
                                        }
1657
                                        s++;
39✔
1658
                                }
1659
                                if ( *s == TPOWER ) {
405✔
1660
                                        s++; c = *s++;
12✔
1661
                                        base = ( c == TNUMBER ) ? 100: 128;
12✔
1662
                                        x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
24✔
1663
                                        if ( *s == TWILDCARD || c == TSYMBOL ) { x2 += 2*MAXPOWER; s++; }
12✔
1664
                                        v[3] = x2;
12✔
1665
                                }
1666
                                v[1] = t - v;
405✔
1667
                                deno = 1;
405✔
1668
                                break;
405✔
1669
                        case TNUMBER:
291,436✔
1670
                                if ( *s == 0 ) {
291,436✔
1671
                                        s++;
144✔
1672
                                        if ( *s == TPOWER ) {
144✔
1673
                                                s++; if ( *s == TMINUS ) { s++; deno = -deno; }
×
1674
                                                c = *s++; base = ( c == TNUMBER ) ? 100: 128;
×
1675
                                                x2 = 0; while ( *s >= 0 ) { x2 = x2*base + *s++; }
×
1676
                                                if ( x2 == 0 ) {
×
1677
                                                        error = -1;
×
1678
                                                        MesPrint("&Encountered 0^0 during compilation");
×
1679
                                                }
1680
                                                if ( deno < 0 ) {
×
1681
                                                        error = -1;
×
1682
                                                        MesPrint("&Division by zero during compilation (0 to the power negative number)");
×
1683
                                                }
1684
                                        }
1685
                                        else if ( deno < 0 ) {
144✔
1686
                                                error = -1;
×
1687
                                                MesPrint("&Division by zero during compilation");
×
1688
                                        }
1689
                                        sign = 0; break; /* term is zero */
1690
                                }
1691
                                y = *s++;
291,292✔
1692
                                if ( *s >= 0 ) { y = 100*y + *s++; }
291,292✔
1693
                                innum[0] = y; nin = 1;
291,292✔
1694
                                while ( *s >= 0 ) {
291,876✔
1695
                                        y = *s++; x2 = 100;
584✔
1696
                                        if ( *s >= 0 ) { y = 100*y + *s++; x2 = 10000; }
584✔
1697
                                        Product(innum,&nin,(WORD)x2);
584✔
1698
                                        if ( y ) AddLong(innum,nin,(UWORD *)(&y),(WORD)1,innum,&nin);
584✔
1699
                                }
1700
docoef:
291,292✔
1701
                                if ( *s == TPOWER ) {
291,292✔
1702
                                        s++; if ( *s == TMINUS ) { s++; deno = -deno; }
9✔
1703
                                        c = *s++; base = ( c == TNUMBER ) ? 100: 128;
9✔
1704
                                        x2 = 0; while ( *s >= 0 ) { x2 = x2*base + *s++; }
21✔
1705
                                        if ( x2 == 0 ) {
9✔
1706
                                                innum[0] = 1; nin = 1;
×
1707
                                        }
1708
                                        else if ( RaisPow(BHEAD innum,&nin,x2) ) {
9✔
1709
                                                error = -1; innum[0] = 1; nin = 1;
×
1710
                                        }
1711
                                }
1712
                                if ( deno > 0 ) {
291,292✔
1713
                                        Simplify(BHEAD innum,&nin,denominator,&ndenominator);
261,129✔
1714
                                        for ( i = 0; i < nnumerator; i++ ) CGscrat7[i] = numerator[i];
783,387✔
1715
                                        MulLong(innum,nin,CGscrat7,nnumerator,numerator,&nnumerator);
261,129✔
1716
                                }
1717
                                else if ( deno < 0 ) {
30,163✔
1718
                                        Simplify(BHEAD innum,&nin,numerator,&nnumerator);
30,163✔
1719
                                        for ( i = 0; i < ndenominator; i++ ) CGscrat7[i] = denominator[i];
90,489✔
1720
                                        MulLong(innum,nin,CGscrat7,ndenominator,denominator,&ndenominator);
30,163✔
1721
                                }
1722
                                deno = 1;
1723
                                break;
1724
                        case TNUMBER1:
×
1725
                                if ( *s == 0 ) { s++; sign = 0; break; /* term is zero */ }
×
1726
                                y = *s++;
×
1727
                                if ( *s >= 0 ) { y = 128*y + *s++; }
×
1728
                                if ( inset == 0 ) {
×
1729
                                        innum[0] = y; nin = 1;
×
1730
                                        while ( *s >= 0 ) {
×
1731
                                                y = *s++; x2 = 128;
×
1732
                                                if ( *s >= 0 ) { y = 128*y + *s++; x2 = 16384; }
×
1733
                                                Product(innum,&nin,(WORD)x2);
×
1734
                                                if ( y ) AddLong(innum,nin,(UWORD *)&y,(WORD)1,innum,&nin);
×
1735
                                        }
1736
                                        goto docoef;
×
1737
                                }
1738
                                *relo = 2; *t++ = SNUMBER; *t++ = 4; *t++ = y;
×
1739
                                goto TryPower;
×
1740
#ifdef WITHFLOAT
1741
                        case TFLOAT:
×
1742
                                { WORD *w;
×
1743
                                s = ReadFloat(s);
×
1744
                                i = AT.WorkPointer[1];
×
1745
                                w = AT.WorkPointer;
×
1746
                                NCOPY(t,w,i);
×
1747
/*
1748
Power?
1749
*/
1750
                                }
1751
                                break;
1752
#endif
1753
                        case TDOLLAR:
1754
                        {
1755
                                WORD *powplace;
1756
                                x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
252✔
1757
                                if ( AR.Eside != LHSIDE ) {
126✔
1758
                                        *t++ = SUBEXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
117✔
1759
                                }
1760
                                else {
1761
                                        *t++ = DOLLAREXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
9✔
1762
                                }
1763
                                powplace = t; t++;
126✔
1764
                                *t++ = AM.dbufnum; FILLSUB(t)
126✔
1765
/*
1766
                                Now we have to test for factors of dollars with [ ] and [ [ ]]
1767
*/
1768
                                if ( *s == LBRACE ) {
126✔
1769
                                        int bracelevel = 1;
15✔
1770
                                        s++;
15✔
1771
                                        while ( bracelevel > 0 ) {
30✔
1772
                                                if ( *s == RBRACE ) {
15✔
1773
                                                        bracelevel--; s++;
×
1774
                                                }
1775
                                                else if ( *s == TNUMBER ) {
15✔
1776
                                                        s++;
12✔
1777
                                                        x2 = 0; while ( *s >= 0 ) { x2 = 100*x2 + *s++; }
24✔
1778
                                                        *t++ = DOLLAREXPR2; *t++ = 3; *t++ = -x2-1;
12✔
1779
CloseBraces:
15✔
1780
                                                        while ( bracelevel > 0 ) {
30✔
1781
                                                                if ( *s != RBRACE ) {
15✔
1782
ErrorBraces:
×
1783
                                                                        error = -1;
×
1784
                                                                        MesPrint("&Improper use of [] in $-variable.");
×
1785
                                                                        return(error);
×
1786
                                                                }
1787
                                                                else {
1788
                                                                        s++; bracelevel--;
15✔
1789
                                                                }
1790
                                                        }
1791
                                                }
1792
                                                else if ( *s == TDOLLAR ) {
3✔
1793
                                                        s++;
3✔
1794
                                                        x1 = 0; while ( *s >= 0 ) { x1 = x1*128 + *s++; }
6✔
1795
                                                        *t++ = DOLLAREXPR2; *t++ = 3; *t++ = x1;
3✔
1796
                                                        if ( *s == RBRACE ) goto CloseBraces;
3✔
1797
                                                        else if ( *s == LBRACE ) {
×
1798
                                                                s++; bracelevel++;
×
1799
                                                        }
1800
                                                }
1801
                                                else goto ErrorBraces;
×
1802
                                        }
1803
                                }
1804
/*
1805
                                Finally we can continue with the power
1806
*/
1807
                                if ( *s == TPOWER ) {
126✔
1808
                                        s++;
12✔
1809
                                        if ( *s == TMINUS ) { s++; deno = -deno; }
12✔
1810
                                        c = *s++;
12✔
1811
                                        base = ( c == TNUMBER ) ? 100: 128;
12✔
1812
                                        x2 = 0; while ( *s >= 0 ) { x2 = base*x2 + *s++; }
24✔
1813
                                        if ( c == TSYMBOL ) {
12✔
1814
                                                if ( *s == TWILDCARD ) s++;
6✔
1815
                                                x2 += 2*MAXPOWER;
6✔
1816
                                        }
1817
                                        *powplace = deno*x2;
12✔
1818
                                }
1819
                                else *powplace = deno;
114✔
1820
                                deno = 1;
1821
/*
1822
                                if ( inset ) {
1823
                                        while ( relo < AT.WorkTop ) *t++ = *relo++;
1824
                                        inset = 0; tsize[1] = t - tsize;
1825
                                }
1826
*/
1827
                        }
1828
                                break;
1829
                        case TSETNUM:
3✔
1830
                                inset = 1; tsize = t; relo = AT.WorkTop;
3✔
1831
                                *t++ = SETSET; *t++ = 0;
3✔
1832
                                x1 = 0; while ( *s >= 0 ) x1 = x1*128 + *s++;
6✔
1833
                                *--relo = x1; *--relo = 0;
3✔
1834
                                break;
3✔
1835
                        case TSETDOL:
×
1836
                                inset = 1; tsize = t; relo = AT.WorkTop;
×
1837
                                *t++ = SETSET; *t++ = 0;
×
1838
                                x1 = 0; while ( *s >= 0 ) x1 = x1*128 + *s++;
×
1839
                                *--relo = -x1; *--relo = 0;
×
1840
                                break;
×
1841
                        case TFUNOPEN:
×
1842
                                MesPrint("&Illegal use of function arguments");
×
1843
                                error = -1;
×
1844
                                funflag = 1;
×
1845
                                deno = 1;
×
1846
                                break;
×
1847
                        case TFUNCLOSE:
×
1848
                                if ( funflag == 0 )
×
1849
                                        MesPrint("&Illegal use of function arguments");
×
1850
                                error = -1;
1851
                                funflag = 0;
1852
                                deno = 1;
1853
                                break;
1854
                        case TSGAMMA:
×
1855
                                MesPrint("&Illegal use special gamma symbols 5_, 6_, 7_");
×
1856
                                error = -1;
×
1857
                                funflag = 0;
×
1858
                                deno = 1;
×
1859
                                break;
×
1860
                        case TCONJUGATE:
3✔
1861
                                MesPrint("&Complex conjugate operator (%#) is not implemented");
3✔
1862
                                error = -1;
3✔
1863
                                deno = 1;
3✔
1864
                                break;
3✔
1865
                        default:
×
1866
                                MesPrint("&Internal error in code generator. Unknown object: %d",c);
×
1867
                                error = -1;
×
1868
                                deno = 1;
×
1869
                                break;
×
1870
                        }
1871
                }
1872
        }
1873
        if ( mulflag ) {
108,650✔
1874
                MesPrint("&Irregular end of statement.");
×
1875
                error = 1;
×
1876
        }
1877
        if ( !first && error == 0 ) {
108,650✔
1878
                *term = t-term;
108,647✔
1879
                C->NumTerms[numexp]++;
108,647✔
1880
                if ( cc && sign ) C->CanCommu[numexp]++;
108,647✔
1881
                error = CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
108,647✔
1882
        }
1883
        AT.WorkPointer = oldwork;
108,650✔
1884
        if ( error ) return(-1);
108,650✔
1885
        AddToCB(C,0)
108,647✔
1886
        if ( AC.CompileLevel > 0 && AR.Eside != LHSIDE ) {
108,647✔
1887
                /* See whether we have this one already */
1888
                error = InsTree(AC.cbufnum,C->numrhs);
100,250✔
1889
                if ( error < (C->numrhs) ) {
100,250✔
1890
                        C->Pointer = C->rhs[C->numrhs--];
40,725✔
1891
                        return(error);
40,725✔
1892
                }
1893
        }
1894
        return(C->numrhs);
67,922✔
1895
OverWork:
×
1896
        MLOCK(ErrorMessageLock);
×
1897
        MesWork();
×
1898
        MUNLOCK(ErrorMessageLock);
×
1899
        return(-1);
×
1900
}
1901

1902
/*
1903
                 #] CodeGenerator : 
1904
                 #[ CompleteTerm :
1905

1906
                Completes the term
1907
                Puts it in the buffer
1908
*/
1909

1910
int CompleteTerm(WORD *term, UWORD *numer, UWORD *denom, WORD nnum, WORD nden, int sign)
553,489✔
1911
{
1912
        int nsize, i;
553,489✔
1913
        WORD *t;
553,489✔
1914
        if ( sign == 0 ) return(0);                /* Term is zero */
553,489✔
1915
        if ( nnum >= nden ) nsize = nnum;
553,345✔
1916
        else                nsize = nden;
3✔
1917
        t = term + *term;
553,345✔
1918
        for ( i = 0; i < nnum; i++ ) *t++ = numer[i];
1,106,882✔
1919
        for ( ; i < nsize; i++ ) *t++ = 0;
553,348✔
1920
        for ( i = 0; i < nden; i++ ) *t++ = denom[i];
1,106,693✔
1921
        for ( ; i < nsize; i++ ) *t++ = 0;
553,537✔
1922
        *t++ = (2*nsize+1)*sign;
553,345✔
1923
        *term = t - term;
553,345✔
1924
        AddNtoC(AC.cbufnum,*term,term,7);
553,345✔
1925
        return(0);
553,345✔
1926
}
1927

1928
/*
1929
                 #] CompleteTerm : 
1930
                 #[ CodeFactors :
1931

1932
                This routine does the part of reading in in terms of factors.
1933
                If there is more than one term at this level we have only one
1934
                factor. In that case any expression should first be unfactorized.
1935
                Then the whole expression gets read as a new subexpression and finally
1936
                we generate factor_*subexpression.
1937
                If the whole has only multiplications we have factors. Then the
1938
                nasty thing is powers of objects and in particular powers of
1939
                factorized expressions or dollars.
1940
                For a power we generate a new subexpression of the type
1941
                  1+factor_+...+factor_^(power-1)
1942
                with which we multiply.
1943

1944
                WE HAVE NOT YET WORRIED ABOUT SETS
1945
*/
1946

1947
int CodeFactors(SBYTE *tokens)
42✔
1948
{
1949
        GETIDENTITY
28✔
1950
        EXPRESSIONS e = Expressions + AR.CurExpr;
42✔
1951
        int nfactor = 1, nparenthesis, i, last = 0, error = 0;
42✔
1952
        SBYTE *t, *startobject, *tt, *s1, *out, *outtokens;
42✔
1953
        WORD nexp, subexp = 0, power, pow, x2, powfactor, first;
42✔
1954
/*
1955
        First scan the number of factors
1956
*/
1957
        t = tokens;
42✔
1958
        while ( *t != TENDOFIT ) {
486✔
1959
                if ( *t >= 0 ) { while ( *t >= 0 ) t++; continue; }
594✔
1960
                if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
300✔
1961
                        nparenthesis = 0; t++;
×
1962
                        while ( nparenthesis >= 0 ) {
×
1963
                                if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
×
1964
                                else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
×
1965
                                t++;
×
1966
                        }
1967
                        continue;
×
1968
                }
1969
                else if ( ( *t == TPLUS || *t == TMINUS ) && ( t > tokens )
300✔
1970
                && ( t[-1] != TPLUS && t[-1] != TMINUS ) ) {
3✔
1971
                        if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
3✔
1972
                        || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
1973
                                subexp = CodeGenerator(tokens);
3✔
1974
                                if ( subexp < 0 ) error = -1;
3✔
1975
                                if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
3✔
1976
                                        MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
×
1977
                                        Terminate(-1);
×
1978
                                }
1979
                                if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
3✔
1980
                                        DoubleBuffer((void **)((VOID *)(&subexpbuffers))
×
1981
                                        ,(void **)((VOID *)(&topsubexpbuffers)),sizeof(SUBBUF),"subexpbuffers");
1982
                                }
1983
                                subexpbuffers[insubexpbuffers].subexpnum = subexp;
3✔
1984
                                subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
3✔
1985
                                subexp = insubexpbuffers++;
3✔
1986
                                t = tokens;
3✔
1987
                                *t++ = TSYMBOL; *t++ = FACTORSYMBOL;
3✔
1988
                                *t++ = TMULTIPLY; *t++ = TSUBEXP;
3✔
1989
                                PUTNUMBER128(t,subexp)
3✔
1990
                                *t++ = TENDOFIT;
3✔
1991
                                e->numfactors = 1;
3✔
1992
                                e->vflags |= ISFACTORIZED;
3✔
1993
                                return(subexp);
3✔
1994
                        }
1995
                }
1996
                else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && t > tokens ) {
297✔
1997
                        nfactor++;
96✔
1998
                }
1999
                else if ( *t == TEXPRESSION ) {
201✔
2000
                        t++;
15✔
2001
                        nexp = 0; while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
30✔
2002
                        if ( *t == LBRACE ) continue;
15✔
2003
                        if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) != 0 ) {
15✔
2004
                                nfactor += AS.OldNumFactors[nexp];
9✔
2005
                        }
2006
                        else { nfactor++; }
6✔
2007
                        continue;
15✔
2008
                }
2009
                else if ( *t == TDOLLAR ) {
186✔
2010
                        t++;
×
2011
                        nexp = 0; while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
×
2012
                        if ( *t == LBRACE ) continue;
×
2013
                        if ( Dollars[nexp].nfactors > 0 ) {
×
2014
                                nfactor += Dollars[nexp].nfactors;
×
2015
                        }
2016
                        else { nfactor++; }
×
2017
                        continue;
×
2018
                }
2019
                t++;
282✔
2020
        }
2021
/*
2022
        Now the real pass.
2023
        nfactor is a not so reliable measure for the space we need.
2024
*/
2025
        outtokens = (SBYTE *)Malloc1(((t-tokens)+(nfactor+2)*25)*sizeof(SBYTE),"CodeFactors");
39✔
2026
        out = outtokens;
39✔
2027
        t = tokens; first = 1; powfactor = 1;
39✔
2028
        while ( *t == TPLUS || *t == TMINUS ) { if ( *t == TMINUS ) first = -first; t++; }
54✔
2029
        if ( first < 0 ) {
39✔
2030
                *out++ = TMINUS; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
15✔
2031
                *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
15✔
2032
                powfactor++;
15✔
2033
        }
2034
        startobject = t; power = 1;
2035
        while ( *t != TENDOFIT ) {
390✔
2036
                if ( *t >= 0 ) { while ( *t >= 0 ) t++; continue; }
465✔
2037
                if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
237✔
2038
                        nparenthesis = 0; t++;
×
2039
                        while ( nparenthesis >= 0 ) {
×
2040
                                if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
×
2041
                                else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
×
2042
                                t++;
×
2043
                        }
2044
                        continue;
×
2045
                }
2046
                else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && ( t > tokens ) ) {
237✔
2047
                        if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
90✔
2048
                        || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
2049
dolast:
90✔
2050
                                if ( startobject ) {        /* apparently power is 1 or -1 */
129✔
2051
                                        *out++ = TPLUS;
102✔
2052
                                        if ( power < 0 ) { *out++ = TNUMBER; *out++ = 1; *out++ = TDIVIDE; }
102✔
2053
                                        s1 = startobject;
2054
                                        while ( s1 < t ) *out++ = *s1++;
306✔
2055
                                        *out++ = TMULTIPLY; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
102✔
2056
                                        *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
102✔
2057
                                        powfactor++;
102✔
2058
                                }
2059
                                if ( last ) { startobject = 0; break; }
129✔
2060
                                startobject = t+1;
90✔
2061
                                if ( *t == TDIVIDE ) power = -1;
90✔
2062
                                if ( *t == TMULTIPLY ) power = 1;
90✔
2063
                        }
2064
                }
2065
                else if ( *t == TPOWER ) {
147✔
2066
                        pow = 1;
18✔
2067
                        tt = t+1;
18✔
2068
                        while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
18✔
2069
                                if ( *tt == TMINUS ) pow = -pow;
×
2070
                                tt++;
×
2071
                        }
2072
                        if ( *tt == TSYMBOL ) {
18✔
2073
                                tt++; while ( *tt >= 0 ) tt++;
×
2074
                                t = tt; continue;
×
2075
                        }
2076
                        tt++; x2 = 0; while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
36✔
2077
/*
2078
                        We have an object in startobject till t. The power is
2079
                        power*pow*x2
2080
*/
2081
                        power = power*pow*x2;
18✔
2082
                        if ( power < 0 ) { pow = -power; power = -1; }
18✔
2083
                        else if ( power == 0 ) { t = tt; startobject = tt; continue; }
18✔
2084
                        else { pow = power; power = 1; }
2085
                        *out++ = TPLUS;
18✔
2086
                        if ( pow > 1 ) {
18✔
2087
                                subexp = GenerateFactors(pow,1);
18✔
2088
                                if ( subexp < 0 ) { error = -1; subexp = 0; }
18✔
2089
                                *out++ = TSUBEXP; PUTNUMBER128(out,subexp);
18✔
2090
                        }
2091
                        *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
18✔
2092
                        *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
18✔
2093
                        powfactor += pow;
18✔
2094
                        if ( power > 0 ) *out++ = TMULTIPLY;
18✔
2095
                        else *out++ = TDIVIDE;
×
2096
                        s1 = startobject; while ( s1 < t ) *out++ = *s1++;
54✔
2097
                        startobject = 0; t = tt; continue;
18✔
2098
                }
2099
                else if ( *t == TEXPRESSION ) {
129✔
2100
                        startobject = t;
15✔
2101
                        t++;
15✔
2102
                        nexp = 0; while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
30✔
2103
                        if ( *t == LBRACE ) continue;
15✔
2104
                        if ( *t == LPARENTHESIS ) {
15✔
2105
                                nparenthesis = 0; t++;
×
2106
                                while ( nparenthesis >= 0 ) {
×
2107
                                        if ( *t == LPARENTHESIS ) nparenthesis++;
×
2108
                                        else if ( *t == RPARENTHESIS ) nparenthesis--;
×
2109
                                        t++;
×
2110
                                }
2111
                        }
2112
                        if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) == 0 ) continue;
15✔
2113
                        if ( *t == TPOWER ) {
9✔
2114
                                pow = 1;
6✔
2115
                                tt = t+1;
6✔
2116
                                while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
6✔
2117
                                        if ( *tt == TMINUS ) pow = -pow;
×
2118
                                        tt++;
×
2119
                                }
2120
                                if ( *tt != TNUMBER ) {
6✔
2121
                                        MesPrint("Internal problems(1) in CodeFactors");
×
2122
                                        return(-1);
×
2123
                                }
2124
                                tt++; x2 = 0; while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
12✔
2125
/*
2126
                                We have an object in startobject till t. The power is
2127
                                power*pow*x2
2128
*/
2129
dopower:
6✔
2130
                                power = power*pow*x2;
9✔
2131
                                if ( power < 0 ) { pow = -power; power = -1; }
9✔
2132
                                else if ( power == 0 ) { t = tt; startobject = tt; continue; }
9✔
2133
                                else { pow = power; power = 1; }
2134
                                *out++ = TPLUS;
9✔
2135
                                if ( pow > 1 ) {
9✔
2136
                                        subexp = GenerateFactors(pow,AS.OldNumFactors[nexp]);
6✔
2137
                                        if ( subexp < 0 ) { error = -1; subexp = 0; }
6✔
2138
                                        *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
6✔
2139
                                        *out++ = TMULTIPLY;
6✔
2140
                                }
2141
                                i = powfactor-1;
9✔
2142
                                if ( i > 0 ) {
9✔
2143
                                        *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
9✔
2144
                                        if ( i > 1 ) {
9✔
2145
                                                *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,i)
6✔
2146
                                        }
2147
                                        *out++ = TMULTIPLY;
9✔
2148
                                }
2149
                                powfactor += AS.OldNumFactors[nexp]*pow;
9✔
2150
                                s1 = startobject;
9✔
2151
                                while ( s1 < t ) *out++ = *s1++;
27✔
2152
                                startobject = 0; t = tt; continue;
9✔
2153
                        }
2154
                        else {
2155
                                tt = t; pow = 1; x2 = 1; goto dopower;
3✔
2156
                        }
2157
                }
2158
                else if ( *t == TDOLLAR ) {
114✔
2159
                        startobject = t;
×
2160
                        t++;
×
2161
                        nexp = 0; while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
×
2162
                        if ( *t == LBRACE ) continue;
×
2163
                        if ( Dollars[nexp].nfactors == 0 ) continue;
×
2164
                        if ( *t == TPOWER ) {
×
2165
                                pow = 1;
×
2166
                                tt = t+1;
×
2167
                                while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
×
2168
                                        if ( *tt == TMINUS ) pow = -pow;
×
2169
                                        tt++;
×
2170
                                }
2171
                                if ( *tt != TNUMBER ) {
×
2172
                                        MesPrint("Internal problems(2) in CodeFactors");
×
2173
                                        return(-1);
×
2174
                                }
2175
                                tt++; x2 = 0; while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
×
2176
/*
2177
                                We have an object in startobject till t. The power is
2178
                                power*pow*x2
2179
*/
2180
dopowerd:
×
2181
                                power = power*pow*x2;
×
2182
                                if ( power < 0 ) { pow = -power; power = -1; }
×
2183
                                else if ( power == 0 ) { t = tt; startobject = tt; continue; }
×
2184
                                else { pow = power; power = 1; }
2185
                                if ( pow > 1 ) {
×
2186
                                        subexp = GenerateFactors(pow,1);
×
2187
                                        if ( subexp < 0 ) { error = -1; subexp = 0; }
×
2188
                                }
2189
                                for ( i = 1; i <= Dollars[nexp].nfactors; i++ ) {
×
2190
                                        s1 = startobject; *out++ = TPLUS;
×
2191
                                        while ( s1 < t ) *out++ = *s1++;
×
2192
                                        *out++ = LBRACE; *out++ = TNUMBER; PUTNUMBER128(out,i)
×
2193
                                        *out++ = RBRACE;
×
2194
                                        *out++ = TMULTIPLY;
×
2195
                                        *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
×
2196
                                        *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
×
2197
                                        powfactor += pow;
×
2198
                                        if ( pow > 1 ) {
×
2199
                                                *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
×
2200
                                        }
2201
                                }
2202
                                startobject = 0; t = tt; continue;
×
2203
                        }
2204
                        else {
2205
                                tt = t; pow = 1; x2 = 1; goto dopowerd;
×
2206
                        }
2207
                }
2208
                t++;
204✔
2209
        }
2210
        if ( last == 0 ) { last = 1; goto dolast; }
78✔
2211
        *out = TENDOFIT;
39✔
2212
        e->numfactors = powfactor-1;
39✔
2213
        e->vflags |= ISFACTORIZED;
39✔
2214
        subexp = CodeGenerator(outtokens);
39✔
2215
        if ( subexp < 0 ) error = -1;
39✔
2216
        if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
39✔
2217
                MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
×
2218
                Terminate(-1);
×
2219
        }
2220
        if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
39✔
2221
                DoubleBuffer((void **)((VOID *)(&subexpbuffers))
×
2222
                ,(void **)((VOID *)(&topsubexpbuffers)),sizeof(SUBBUF),"subexpbuffers");
2223
        }
2224
        subexpbuffers[insubexpbuffers].subexpnum = subexp;
39✔
2225
        subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
39✔
2226
        subexp = insubexpbuffers++;
39✔
2227
        M_free(outtokens,"CodeFactors");
39✔
2228
        s1 = tokens;
39✔
2229
        *s1++ = TSUBEXP; PUTNUMBER128(s1,subexp); *s1++ = TENDOFIT;
39✔
2230
        if ( error < 0 ) return(-1);
39✔
2231
        else return(subexp);
39✔
2232
}
2233

2234
/*
2235
                 #] CodeFactors : 
2236
                 #[ GenerateFactors :
2237

2238
        Generates an expression of the type
2239
          1+factor_+factor_^2+...+factor_^(n-1)
2240
        (this is if inc=1)
2241
        Returns the subexpression pointer of it.
2242
*/
2243

2244
WORD GenerateFactors(WORD n,WORD inc)
24✔
2245
{
2246
        WORD subexp;
24✔
2247
        int i, error = 0;
24✔
2248
        SBYTE *s;
24✔
2249
        SBYTE *tokenbuffer = (SBYTE *)Malloc1(8*n*sizeof(SBYTE),"GenerateFactors");
24✔
2250
        s = tokenbuffer;
24✔
2251
        *s++ = TNUMBER; *s++ = 1;
24✔
2252
        for ( i = inc; i < n*inc; i += inc ) {
48✔
2253
                *s++ = TPLUS; *s++ = TSYMBOL; *s++ = FACTORSYMBOL;
24✔
2254
                if ( i > 1 ) {
24✔
2255
                        *s++ = TPOWER; *s++ = TNUMBER;
6✔
2256
                        PUTNUMBER100(s,i)
6✔
2257
                }
2258
        }
2259
        *s++ = TENDOFIT;
24✔
2260
        subexp = CodeGenerator(tokenbuffer);
24✔
2261
        if ( subexp < 0 ) error = -1;
24✔
2262
        M_free(tokenbuffer,"GenerateFactors");
24✔
2263
        if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
24✔
2264
                MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
×
2265
                Terminate(-1);
×
2266
        }
2267
        if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
24✔
2268
                DoubleBuffer((void **)((VOID *)(&subexpbuffers))
×
2269
                ,(void **)((VOID *)(&topsubexpbuffers)),sizeof(SUBBUF),"subexpbuffers");
2270
        }
2271
        subexpbuffers[insubexpbuffers].subexpnum = subexp;
24✔
2272
        subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
24✔
2273
        subexp = insubexpbuffers++;
24✔
2274
        if ( error < 0 ) return(error);
24✔
2275
        return(subexp);
2276
}
2277

2278
/*
2279
                 #] GenerateFactors : 
2280
        #] Compiler :
2281
*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc