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}
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 ,{
"chainin", (TFUN)CoChainin, STATEMENT, PARTEST}
115 ,{
"chainout", (TFUN)CoChainout, STATEMENT, PARTEST}
116 ,{
"chisholm", (TFUN)CoChisholm, STATEMENT, PARTEST}
117 ,{
"cleartable", (TFUN)CoClearTable, DECLARATION, PARTEST}
118 ,{
"collect", (TFUN)CoCollect, SPECIFICATION,PARTEST}
119 ,{
"commuteinset", (TFUN)CoCommuteInSet, DECLARATION, PARTEST}
120 ,{
"contract", (TFUN)CoContract, STATEMENT, PARTEST}
121 ,{
"copyspectator" ,(TFUN)CoCopySpectator, DEFINITION, PARTEST}
122 ,{
"createspectator",(TFUN)CoCreateSpectator, DECLARATION, PARTEST}
123 ,{
"ctable", (TFUN)CoCTable, DECLARATION, PARTEST}
124 ,{
"deallocatetable",(TFUN)CoDeallocateTable, DECLARATION, PARTEST}
125 ,{
"delete", (TFUN)CoDelete, SPECIFICATION,PARTEST}
126 ,{
"denominators", (TFUN)CoDenominators, STATEMENT, PARTEST}
127 ,{
"disorder", (TFUN)CoDisorder, STATEMENT, PARTEST}
128 ,{
"do", (TFUN)CoDo, STATEMENT, PARTEST}
129 ,{
"drop", (TFUN)CoDrop, SPECIFICATION,PARTEST}
130 ,{
"dropcoefficient",(TFUN)CoDropCoefficient, STATEMENT, PARTEST}
131 ,{
"dropsymbols", (TFUN)CoDropSymbols, STATEMENT, PARTEST}
132 ,{
"else", (TFUN)CoElse, STATEMENT, PARTEST}
133 ,{
"elseif", (TFUN)CoElseIf, STATEMENT, PARTEST}
134 ,{
"emptyspectator", (TFUN)CoEmptySpectator, SPECIFICATION,PARTEST}
135 ,{
"endargument", (TFUN)CoEndArgument, STATEMENT, PARTEST}
136 ,{
"enddo", (TFUN)CoEndDo, STATEMENT, PARTEST}
137 ,{
"endif", (TFUN)CoEndIf, STATEMENT, PARTEST}
138 ,{
"endinexpression",(TFUN)CoEndInExpression, STATEMENT, PARTEST}
139 ,{
"endinside", (TFUN)CoEndInside, STATEMENT, PARTEST}
140 ,{
"endrepeat", (TFUN)CoEndRepeat, STATEMENT, PARTEST}
141 ,{
"endterm", (TFUN)CoEndTerm, STATEMENT, PARTEST}
142 ,{
"endwhile", (TFUN)CoEndWhile, STATEMENT, PARTEST}
143 ,{
"exit", (TFUN)CoExit, STATEMENT, PARTEST}
144 ,{
"extrasymbols", (TFUN)CoExtraSymbols, DECLARATION, PARTEST}
145 ,{
"factarg", (TFUN)CoFactArg, STATEMENT, PARTEST}
146 ,{
"factdollar", (TFUN)CoFactDollar, STATEMENT, PARTEST}
147 ,{
"factorize", (TFUN)CoFactorize, TOOUTPUT, PARTEST}
148 ,{
"fill", (TFUN)CoFill, DECLARATION, PARTEST}
149 ,{
"fillexpression", (TFUN)CoFillExpression, DECLARATION, PARTEST}
150 ,{
"frompolynomial", (TFUN)CoFromPolynomial, STATEMENT, PARTEST}
151 ,{
"funpowers", (TFUN)CoFunPowers, DECLARATION, PARTEST}
152 ,{
"hide", (TFUN)CoHide, SPECIFICATION,PARTEST}
153 ,{
"if", (TFUN)CoIf, STATEMENT, PARTEST}
154 ,{
"ifmatch", (TFUN)CoIfMatch, STATEMENT, PARTEST}
155 ,{
"ifnomatch", (TFUN)CoIfNoMatch, STATEMENT, PARTEST}
156 ,{
"ifnotmatch", (TFUN)CoIfNoMatch, STATEMENT, PARTEST}
157 ,{
"inexpression", (TFUN)CoInExpression, STATEMENT, PARTEST}
158 ,{
"inparallel", (TFUN)CoInParallel, SPECIFICATION,PARTEST}
159 ,{
"inside", (TFUN)CoInside, STATEMENT, PARTEST}
160 ,{
"insidefirst", (TFUN)CoInsideFirst, DECLARATION, PARTEST}
161 ,{
"intohide", (TFUN)CoIntoHide, SPECIFICATION,PARTEST}
162 ,{
"keep", (TFUN)CoKeep, SPECIFICATION,PARTEST}
163 ,{
"makeinteger", (TFUN)CoMakeInteger, STATEMENT, PARTEST}
164 ,{
"many", (TFUN)CoMany, STATEMENT, PARTEST}
165 ,{
"merge", (TFUN)CoMerge, STATEMENT, PARTEST}
166 ,{
"metric", (TFUN)CoMetric, DECLARATION, PARTEST}
167 ,{
"moduleoption", (TFUN)CoModuleOption, ATENDOFMODULE,PARTEST}
168 ,{
"multi", (TFUN)CoMulti, STATEMENT, PARTEST}
169 ,{
"multibracket", (TFUN)CoMultiBracket, STATEMENT, PARTEST}
170 ,{
"ndrop", (TFUN)CoNoDrop, SPECIFICATION,PARTEST}
171 ,{
"nfactorize", (TFUN)CoNFactorize, TOOUTPUT, PARTEST}
172 ,{
"nhide", (TFUN)CoNoHide, SPECIFICATION,PARTEST}
173 ,{
"normalize", (TFUN)CoNormalize, STATEMENT, PARTEST}
174 ,{
"notinparallel", (TFUN)CoNotInParallel, SPECIFICATION,PARTEST}
175 ,{
"nskip", (TFUN)CoNoSkip, SPECIFICATION,PARTEST}
176 ,{
"ntable", (TFUN)CoNTable, DECLARATION, PARTEST}
177 ,{
"nunfactorize", (TFUN)CoNUnFactorize, TOOUTPUT, PARTEST}
178 ,{
"nunhide", (TFUN)CoNoUnHide, SPECIFICATION,PARTEST}
179 ,{
"off", (TFUN)CoOff, DECLARATION, PARTEST}
180 ,{
"on", (TFUN)CoOn, DECLARATION, PARTEST}
181 ,{
"once", (TFUN)CoOnce, STATEMENT, PARTEST}
182 ,{
"only", (TFUN)CoOnly, STATEMENT, PARTEST}
183 ,{
"polyfun", (TFUN)CoPolyFun, DECLARATION, PARTEST}
184 ,{
"polyratfun", (TFUN)CoPolyRatFun, DECLARATION, PARTEST}
185 ,{
"pophide", (TFUN)CoPopHide, SPECIFICATION,PARTEST}
186 ,{
"print[]", (TFUN)CoPrintB, TOOUTPUT, PARTEST}
187 ,{
"printtable", (TFUN)CoPrintTable, MIXED, PARTEST}
188 ,{
"processbucketsize",(TFUN)CoProcessBucket, DECLARATION, PARTEST}
189 ,{
"propercount", (TFUN)CoProperCount, DECLARATION, PARTEST}
190 ,{
"pushhide", (TFUN)CoPushHide, SPECIFICATION,PARTEST}
191 ,{
"putinside", (TFUN)CoPutInside, STATEMENT, PARTEST}
192 ,{
"ratio", (TFUN)CoRatio, STATEMENT, PARTEST}
193 ,{
"removespectator",(TFUN)CoRemoveSpectator, SPECIFICATION,PARTEST}
194 ,{
"renumber", (TFUN)CoRenumber, STATEMENT, PARTEST}
195 ,{
"repeat", (TFUN)CoRepeat, STATEMENT, PARTEST}
196 ,{
"replaceloop", (TFUN)CoReplaceLoop, STATEMENT, PARTEST}
197 ,{
"select", (TFUN)CoSelect, STATEMENT, PARTEST}
198 ,{
"set", (TFUN)CoSet, DECLARATION, PARTEST}
199 ,{
"setexitflag", (TFUN)CoSetExitFlag, STATEMENT, PARTEST}
200 ,{
"shuffle", (TFUN)CoMerge, STATEMENT, PARTEST}
201 ,{
"skip", (TFUN)CoSkip, SPECIFICATION,PARTEST}
202 ,{
"sort", (TFUN)CoSort, STATEMENT, PARTEST}
203 ,{
"splitarg", (TFUN)CoSplitArg, STATEMENT, PARTEST}
204 ,{
"splitfirstarg", (TFUN)CoSplitFirstArg, STATEMENT, PARTEST}
205 ,{
"splitlastarg", (TFUN)CoSplitLastArg, STATEMENT, PARTEST}
206 ,{
"stuffle", (TFUN)CoStuffle, STATEMENT, PARTEST}
207 ,{
"sum", (TFUN)CoSum, STATEMENT, PARTEST}
208 ,{
"table", (TFUN)CoTable, DECLARATION, PARTEST}
209 ,{
"tablebase", (TFUN)CoTableBase, DECLARATION, PARTEST}
210 ,{
"tb", (TFUN)CoTableBase, DECLARATION, PARTEST}
211 ,{
"term", (TFUN)CoTerm, STATEMENT, PARTEST}
212 ,{
"testuse", (TFUN)CoTestUse, STATEMENT, PARTEST}
213 ,{
"threadbucketsize",(TFUN)CoThreadBucket, DECLARATION, PARTEST}
214 ,{
"topolynomial", (TFUN)CoToPolynomial, STATEMENT, PARTEST}
215 ,{
"tospectator", (TFUN)CoToSpectator, STATEMENT, PARTEST}
216 ,{
"totensor", (TFUN)CoToTensor, STATEMENT, PARTEST}
217 ,{
"tovector", (TFUN)CoToVector, STATEMENT, PARTEST}
218 ,{
"trace4", (TFUN)CoTrace4, STATEMENT, PARTEST}
219 ,{
"tracen", (TFUN)CoTraceN, STATEMENT, PARTEST}
220 ,{
"transform", (TFUN)CoTransform, STATEMENT, PARTEST}
221 ,{
"tryreplace", (TFUN)CoTryReplace, STATEMENT, PARTEST}
222 ,{
"unfactorize", (TFUN)CoUnFactorize, TOOUTPUT, PARTEST}
223 ,{
"unhide", (TFUN)CoUnHide, SPECIFICATION,PARTEST}
224 ,{
"while", (TFUN)CoWhile, STATEMENT, PARTEST}
238 SUBBUF *subexpbuffers = 0;
239 SUBBUF *topsubexpbuffers = 0;
240 LONG insubexpbuffers = 0;
242 #define REDUCESUBEXPBUFFERS { if ( (topsubexpbuffers-subexpbuffers) > 256 ) {\ 243 M_free(subexpbuffers,"subexpbuffers");\ 244 subexpbuffers = (SUBBUF *)Malloc1(256*sizeof(SUBBUF),"subexpbuffers");\ 245 topsubexpbuffers = subexpbuffers+256; } insubexpbuffers = 0; } 249 #define PUTNUMBER128(t,n) { if ( n >= 16384 ) { \ 250 *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \ 251 else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \ 253 #define PUTNUMBER100(t,n) { if ( n >= 10000 ) { \ 254 *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \ 255 else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \ 258 #elif ( defined(LLP64) || defined(LP64) ) 260 #define PUTNUMBER128(t,n) { if ( n >= 2097152 ) { \ 261 *t++ = ((n/128)/128)/128; *t++ = ((n/128)/128)%128; *t++ = (n/128)%128; *t++ = n%128; } \ 262 else if ( n >= 16384 ) { \ 263 *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \ 264 else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \ 266 #define PUTNUMBER100(t,n) { if ( n >= 1000000 ) { \ 267 *t++ = ((n/100)/100)/100; *t++ = ((n/100)/100)%100; *t++ = (n/100)%100; *t++ = n%100; } \ 268 else if ( n >= 10000 ) { \ 269 *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \ 270 else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \ 290 ksize =
sizeof(com1commands)/
sizeof(
KEYWORD);
293 for ( i = 0; i < 26; i++ ) {
294 while ( j < ksize && k[j].name[0] ==
'a'+i ) j++;
312 KEYWORD *findcommand(UBYTE *in)
317 while ( FG.cTable[*s] <= 1 ) s++;
318 if ( s > in && *s ==
'[' && s[1] ==
']' ) s += 2;
319 if ( *s ) { c = *s; *s = 0; }
325 hi =
sizeof(com2commands)/
sizeof(
KEYWORD)-1;
327 med = ( hi + lo ) / 2;
328 i = StrICmp(in,(UBYTE *)com2commands[med].name);
329 if ( i == 0 ) {
if ( c ) *s = c;
return(com2commands+med); }
330 if ( i < 0 ) hi = med-1;
332 }
while ( hi >= lo );
336 i = tolower(*in) -
'a';
338 hi = alfatable1[i+1];
340 if ( StrICont(in,(UBYTE *)com1commands[med].name) == 0 )
341 {
if ( c ) *s = c;
return(com1commands+med); }
356 int ParenthesesTest(UBYTE *sin)
358 WORD L1 = 0, L2 = 0, L3 = 0;
361 if ( *s ==
'[' ) L1++;
362 else if ( *s ==
']' ) {
364 if ( L1 < 0 ) { MesPrint(
"&Unmatched []");
return(1); }
368 if ( L1 > 0 ) { MesPrint(
"&Unmatched []");
return(1); }
371 if ( *s ==
'[' ) SKIPBRA1(s)
372 else if ( *s ==
'(' ) { L2++; s++; }
373 else if ( *s ==
')' ) {
375 if ( L2 < 0 ) { MesPrint(
"&Unmatched ()");
return(1); }
379 if ( L2 > 0 ) { MesPrint(
"&Unmatched ()");
return(1); }
382 if ( *s ==
'[' ) SKIPBRA1(s)
383 else if ( *s ==
'[' ) SKIPBRA4(s)
384 else if ( *s ==
'{' ) { L3++; s++; }
385 else if ( *s ==
'}' ) {
387 if ( L3 < 0 ) { MesPrint(
"&Unmatched {}");
return(1); }
391 if ( L3 > 0 ) { MesPrint(
"&Unmatched {}");
return(1); }
406 UBYTE *SkipAName(UBYTE *s)
412 MesPrint(
"&Illegal name: '%s'",t);
417 else if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'$' ) {
418 if ( *s ==
'$' ) s++;
419 while ( FG.cTable[*s] <= 1 ) s++;
420 if ( *s ==
'_' ) s++;
423 MesPrint(
"&Illegal name: '%s'",t);
434 UBYTE *IsRHS(UBYTE *s, UBYTE c)
436 while ( *s && *s != c ) {
440 MesPrint(
"&Unmatched []");
444 else if ( *s ==
'{' ) {
447 MesPrint(
"&Unmatched {}");
451 else if ( *s ==
'(' ) {
454 MesPrint(
"&Unmatched ()");
458 else if ( *s ==
')' ) {
459 MesPrint(
"&Unmatched ()");
462 else if ( *s ==
'}' ) {
463 MesPrint(
"&Unmatched {}");
466 else if ( *s ==
']' ) {
467 MesPrint(
"&Unmatched []");
480 int IsIdStatement(UBYTE *s)
494 int CompileAlgebra(UBYTE *s,
int leftright, WORD *prototype)
498 WORD *oldproto = AC.ProtoType;
499 AC.ProtoType = prototype;
500 if ( AC.TokensWriteFlag ) {
501 MesPrint(
"To tokenize: %s",s);
502 error = tokenize(s,leftright);
503 MesPrint(
" The contents of the token buffer are:");
504 WriteTokens(AC.tokens);
506 else error = tokenize(s,leftright);
508 AR.Eside = leftright;
510 if ( leftright == LHSIDE ) { AC.DumNum = AR.CurDum = 0; }
511 error = CompileSubExpressions(AC.tokens);
515 AC.ProtoType = oldproto;
518 AC.ProtoType = oldproto;
519 if ( error < 0 )
return(-1);
520 else if ( leftright == LHSIDE )
return(cbuf[AC.cbufnum].numlhs);
521 else return(cbuf[AC.cbufnum].numrhs);
530 int CompileStatement(UBYTE *in)
534 int error1 = 0, error2;
536 if ( *s == 0 )
return(0);
538 k = findcommand((UBYTE *)
"assign");
541 if ( ( k = findcommand(s) ) == 0 && IsIdStatement(s) == 0 ) {
542 MesPrint(
"&Unrecognized statement");
546 k = com1commands + alfatable1[
'i'-
'a'];
547 while ( k->name[1] !=
'd' || k->name[2] ) k++;
550 while ( FG.cTable[*s] <= 1 ) s++;
551 if ( s > in && *s ==
'[' && s[1] ==
']' ) s += 2;
562 if ( *s ==
',' ) s++;
570 if ( AP.PreAssignFlag == 0 && AM.OldOrderFlag == 0 ) {
571 if ( AP.PreInsideLevel ) {
572 if ( k->type != STATEMENT && k->type != MIXED ) {
573 MesPrint(
"&Only executable and print statements are allowed in an %#inside/%#endinside construction");
578 if ( ( AC.compiletype == DECLARATION || AC.compiletype == SPECIFICATION )
579 && ( k->type == STATEMENT || k->type == DEFINITION || k->type == TOOUTPUT ) ) {
580 if ( AC.tablecheck == 0 ) {
582 if ( TestTables() ) error1 = 1;
585 if ( k->type == MIXED ) {
586 if ( AC.compiletype <= DEFINITION ) {
587 AC.compiletype = STATEMENT;
590 else if ( k->type > AC.compiletype ) {
591 if ( StrCmp((UBYTE *)(k->name),(UBYTE *)
"format") != 0 )
592 AC.compiletype = k->type;
594 else if ( k->type < AC.compiletype ) {
597 MesPrint(
"&Declaration out of order");
601 MesPrint(
"&Definition out of order");
605 MesPrint(
"&Specification out of order");
609 MesPrint(
"&Statement out of order");
612 MesPrint(
"&Output control statement out of order");
616 AC.compiletype = k->type;
617 if ( AC.firstctypemessage == 0 ) {
618 MesPrint(
"&Proper order inside a module is:");
619 MesPrint(
"Declarations, specifications, definitions, statements, output control statements");
620 AC.firstctypemessage = 1;
629 if ( AC.AutoDeclareFlag && ( ( k->flags & WITHAUTO ) == 0 ) ) {
630 MesPrint(
"&Illegal type of auto-declaration");
633 if ( ( ( k->flags & PARTEST ) != 0 ) && ParenthesesTest(s) )
return(1);
634 error2 = (*k->func)(s);
635 if ( error2 == 0 )
return(error1);
651 i = NumFunctions + FUNCTION - MAXBUILTINFUNCTION - 1;
652 f = f + MAXBUILTINFUNCTION - FUNCTION + 1;
653 if ( AC.MustTestTable > 0 ) {
656 for ( x = 0, j = 0; x < t->
totind; x++ ) {
661 MesPrint(
"&In table %s there are %d unfilled elements",
662 AC.varnames->namebuffer+f->
name,j);
665 MesPrint(
"&In table %s there is one unfilled element",
666 AC.varnames->namebuffer+f->
name);
688 int CompileSubExpressions(SBYTE *tokens)
691 SBYTE *fill = tokens, *s = tokens, *t;
692 WORD number[MAXNUMSIZE], *oldwork, *w1, *w2;
693 int level, num, i, sumlevel = 0, sumtype = SYMTOSYM;
694 int retval, error = 0;
699 while ( *s != TENDOFIT ) {
700 if ( *s == TFUNOPEN ) {
701 if ( fill < s ) *fill = TENDOFIT;
703 while ( t >= tokens && t[0] >= 0 ) t--;
704 if ( t >= tokens && *t == TFUNCTION ) {
705 t++; i = 0;
while ( *t >= 0 ) i = 128*i + *t++;
706 if ( i == AM.sumnum || i == AM.sumpnum ) {
708 if ( *t == TSYMBOL || *t == TINDEX ) {
709 t++; i = 0;
while ( *t >= 0 ) i = 128*i + *t++;
710 if ( s[1] == TINDEX ) {
714 else sumtype = SYMTOSYM;
721 else if ( *s == TFUNCLOSE ) { sumlevel = 0; *fill++ = *s++; }
722 else if ( *s == LPARENTHESIS ) {
731 while ( level >= 0 ) {
733 if ( *s == LPARENTHESIS ) level++;
734 else if ( *s == RPARENTHESIS ) level--;
735 else if ( *s == TENDOFIT ) {
736 MesPrint(
"&Unbalanced subexpression parentheses");
741 if ( sumlevel > 0 ) {
742 oldwork = w1 = AT.WorkPointer;
745 while ( --i >= 0 ) *w1++ = *w2++;
747 *w1++ = sumtype; *w1++ = 4; *w1++ = sumlevel; *w1++ = sumlevel;
748 w2 = AC.ProtoType; AT.WorkPointer = w1;
749 AC.ProtoType = oldwork;
750 num = CompileSubExpressions(t);
751 AC.ProtoType = w2; AT.WorkPointer = oldwork;
753 else num = CompileSubExpressions(t);
754 if ( num < 0 )
return(-1);
762 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
763 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
766 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
767 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
768 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(
SUBBUF),
"subexpbuffers");
770 subexpbuffers[insubexpbuffers].subexpnum = num;
771 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
772 num = insubexpbuffers++;
775 do { number[i++] = num & 0x7F; num >>= 7; }
while ( num );
776 while ( --i >= 0 ) *fill++ = (SBYTE)(number[i]);
779 else if ( *s == TEMPTY ) s++;
787 if ( AC.CompileLevel == 1 && AC.ToBeInFactors ) {
788 error = CodeFactors(tokens);
791 retval = CodeGenerator(tokens);
792 if ( error < 0 )
return(error);
821 static UWORD *CGscrat7 = 0;
823 int CodeGenerator(SBYTE *tokens)
826 SBYTE *s = tokens, c;
827 int i, sign = 1, first = 1, deno = 1, error = 0, minus, n, needarg, numexp, cc;
828 int base, sumlevel = 0, sumtype = SYMTOSYM, firstsumarg, inset = 0;
829 int funflag = 0, settype, x1, x2, mulflag = 0;
830 WORD *t, *v, *r, *term, nnumerator, ndenominator, *oldwork, x3, y, nin;
831 WORD *w1, *w2, *tsize = 0, *relo = 0;
832 UWORD *numerator, *denominator, *innum;
835 WORD TMproto[SUBEXPSIZE];
842 if ( AC.TokensWriteFlag ) WriteTokens(tokens);
844 CGscrat7 = (UWORD *)Malloc1((AM.MaxTal+2)*
sizeof(WORD),
"CodeGenerator");
846 C = cbuf + AC.cbufnum;
850 oldwork = AT.WorkPointer;
851 numerator = (UWORD *)(AT.WorkPointer);
852 denominator = numerator + 2*AM.MaxTal;
853 innum = denominator + 2*AM.MaxTal;
854 term = (WORD *)(innum + 2*AM.MaxTal);
855 AT.WorkPointer = term + AM.MaxTer/
sizeof(WORD);
856 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
859 numerator[0] = denominator[0] = 1;
860 nnumerator = ndenominator = 1;
861 while ( *s != TENDOFIT ) {
862 if ( *s == TPLUS || *s == TMINUS ) {
863 if ( first || mulflag ) {
if ( *s == TMINUS ) sign = -sign; }
867 if ( cc && sign ) C->
CanCommu[numexp]++;
868 CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
869 first = 1; cc = 0; t = term + 1; deno = 1;
870 numerator[0] = denominator[0] = 1;
871 nnumerator = ndenominator = 1;
872 if ( *s == TMINUS ) sign = -1;
878 mulflag = first = 0; c = *s++;
881 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
882 if ( *s == TWILDCARD ) { s++; x1 += 2*MAXPOWER; }
883 *t++ = SYMBOL; *t++ = 4; *t++ = x1;
884 if ( inset ) *relo = 2;
885 TryPower:
if ( *s == TPOWER ) {
887 if ( *s == TMINUS ) { s++; deno = -deno; }
889 base = ( c == TNUMBER ) ? 100: 128;
890 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
891 if ( c == TSYMBOL ) {
892 if ( *s == TWILDCARD ) s++;
900 while ( relo < AT.WorkTop ) *t++ = *relo++;
901 inset = 0; tsize[1] = t - tsize;
905 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
906 *t++ = INDEX; *t++ = 3;
907 if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
908 if ( inset ) { *t++ = x1; *relo = 2; }
909 else *t++ = x1 + AM.OffsetIndex;
910 if ( t[-1] > AM.IndDum ) {
911 x1 = t[-1] - AM.IndDum;
916 *t++ = INDEX; *t++ = 3; *t++ = AC.DumNum+WILDOFFSET;
920 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
921 dovector:
if ( inset == 0 ) x1 += AM.OffsetVector;
922 if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
923 if ( inset ) *relo = 2;
926 if ( *s == TSETNUM || *s == TSETDOL ) {
927 settype = ( *s == TSETDOL );
928 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
929 if ( settype ) x2 = -x2;
931 tsize = t; *t++ = SETSET; *t++ = 0;
935 *--relo = x2; *--relo = 3;
937 if ( *s != TVECTOR && *s != TDUBIOUS ) {
938 MesPrint(
"&Illegally formed dotproduct");
941 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
942 if ( inset < 2 ) x2 += AM.OffsetVector;
943 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
944 *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2;
947 else if ( *s == TFUNOPEN ) {
949 if ( *s == TSETNUM || *s == TSETDOL ) {
950 settype = ( *s == TSETDOL );
951 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
952 if ( settype ) x2 = -x2;
954 tsize = t; *t++ = SETSET; *t++ = 0;
958 *--relo = x2; *--relo = 3;
960 if ( *s == TINDEX || *s == TDUBIOUS ) {
962 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
963 if ( inset < 2 ) x2 += AM.OffsetIndex;
964 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
965 *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
966 if ( t[-1] > AM.IndDum ) {
967 x2 = t[-1] - AM.IndDum;
971 else if ( *s == TGENINDEX ) {
972 *t++ = VECTOR; *t++ = 4; *t++ = x1;
973 *t++ = AC.DumNum + WILDOFFSET;
975 else if ( *s == TNUMBER || *s == TNUMBER1 ) {
976 base = ( *s == TNUMBER ) ? 100: 128;
978 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
979 if ( x2 >= AM.OffsetIndex && inset < 2 ) {
980 MesPrint(
"&Fixed index in vector greater than %d",
984 *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
986 else if ( *s == TVECTOR || ( *s == TMINUS && s[1] == TVECTOR ) ) {
987 if ( *s == TMINUS ) { s++; sign = -sign; }
989 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
990 if ( inset < 2 ) x2 += AM.OffsetVector;
991 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
992 *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2; *t++ = deno;
995 MesPrint(
"&Illegal argument for vector");
998 if ( *s != TFUNCLOSE ) {
999 MesPrint(
"&Illegal argument for vector");
1006 *t++ = VECTOR; *t++ = 4; *t++ = x1;
1007 *t++ = AC.DumNum + WILDOFFSET;
1010 *t++ = INDEX; *t++ = 3; *t++ = x1;
1015 if ( *s != TFUNOPEN ) {
1016 MesPrint(
"&d_ needs two arguments");
1019 v = t; *t++ = DELTA; *t++ = 4;
1020 needarg = 2; x3 = x1 = -1;
1023 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1024 if ( x1 == AM.sumnum || x1 == AM.sumpnum ) sumlevel = x1;
1026 if ( x1 == FIRSTBRACKET ) {
1027 if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION ) {
1029 *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
1030 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1031 t[-1] |= MUSTCLEANPRF;
1033 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
1034 *t++ = -EXPRESSION; *t++ = x2;
1040 if ( Expressions[x2].status == STOREDEXPRESSION ) {
1041 TMproto[0] = EXPRESSION;
1042 TMproto[1] = SUBEXPSIZE;
1045 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1046 AT.TMaddr = TMproto;
1063 if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
1065 MesPrint(
"&Problems getting information about stored expression %s(1)" 1068 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1069 M_free(renumber->
symb.
lo,
"VarSpace");
1070 M_free(renumber,
"Renumber");
1071 AR.StoreData.dirtyflag = 1;
1073 if ( *s != TFUNCLOSE ) {
1074 if ( x1 == FIRSTBRACKET )
1075 MesPrint(
"&Problems with argument of FirstBracket_");
1076 else if ( x1 == FIRSTTERM )
1077 MesPrint(
"&Problems with argument of FirstTerm_");
1078 else if ( x1 == CONTENTTERM )
1079 MesPrint(
"&Problems with argument of FirstTerm_");
1080 else if ( x1 == TERMSINEXPR )
1081 MesPrint(
"&Problems with argument of TermsIn_");
1082 else if ( x1 == NUMFACTORS )
1083 MesPrint(
"&Problems with argument of NumFactors_");
1085 MesPrint(
"&Problems with argument of FactorIn_");
1087 while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
1089 if ( *s == TFUNCLOSE ) s++;
1093 else if ( x1 == TERMSINEXPR || x1 == FACTORIN
1094 || x1 == NUMFACTORS || x1 == FIRSTTERM || x1 == CONTENTTERM ) {
1095 if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION )
goto doexpr;
1096 if ( s[0] == TFUNOPEN && s[1] == TDOLLAR ) {
1098 *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
1100 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
1101 *t++ = -DOLLAREXPRESSION; *t++ = x2;
1102 if ( *s != TFUNCLOSE ) {
1103 if ( x1 == TERMSINEXPR )
1104 MesPrint(
"&Problems with argument of TermsIn_");
1105 else if ( x1 == NUMFACTORS )
1106 MesPrint(
"&Problems with argument of NumFactors_");
1108 MesPrint(
"&Problems with argument of FactorIn_");
1110 while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
1112 if ( *s == TFUNCLOSE ) s++;
1117 if ( inset && ( t-tsize == 2 ) ) x1 -= FUNCTION;
1118 if ( *s == TWILDCARD ) { x1 += WILDOFFSET; s++; }
1119 if ( functions[x3-FUNCTION].commute ) cc = 1;
1120 if ( *s != TFUNOPEN ) {
1121 *t++ = x1; *t++ = FUNHEAD; *t++ = 0;
1122 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1123 t[-1] |= MUSTCLEANPRF;
1124 FILLFUN3(t) sumlevel = 0;
goto fin;
1126 v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
1127 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1128 t[-1] |= MUSTCLEANPRF;
1131 if ( !inset && functions[x3-FUNCTION].spec >= TENSORFUNCTION ) {
1134 if ( needarg == 0 ) {
1137 if ( x3 >= FUNCTION+WILDOFFSET ) x3 -= WILDOFFSET;
1138 MesPrint(
"&Too many arguments in function %s",
1139 VARNAME(functions,(x3-FUNCTION)) );
1142 MesPrint(
"&d_ needs exactly two arguments");
1146 else if ( needarg > 0 ) needarg--;
1149 if ( c == TMINUS && *s == TVECTOR ) { sign = -sign; c = *s++; }
1150 base = ( c == TNUMBER ) ? 100: 128;
1151 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1152 if ( *s == TWILDCARD && c != TNUMBER ) { x2 += WILDOFFSET; s++; }
1153 if ( c == TSETNUM || c == TSETDOL ) {
1154 if ( c == TSETDOL ) x2 = -x2;
1156 w1 = t; t += 2; w2 = t;
1157 while ( w1 > v ) *--w2 = *--w1;
1158 tsize = v; relo = AT.WorkTop;
1159 *v++ = SETSET; *v++ = 0;
1161 inset = 2; *--relo = x2; *--relo = t - v;
1163 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1167 if ( t[-1]+AM.OffsetIndex > AM.IndDum ) {
1168 x2 = t[-1]+AM.OffsetIndex - AM.IndDum;
1175 if ( x2 >= 0 && x2 < AM.OffsetIndex ) {
1179 MesPrint(
"&Illegal type of set inside tensor");
1185 else {
switch ( c ) {
1187 if ( inset < 2 ) *t++ = x2 + AM.OffsetIndex;
1189 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1190 x2 = x2+AM.OffsetIndex - AM.IndDum;
1195 *t++ = AC.DumNum + WILDOFFSET;
1198 if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
1202 *t++ = FUNNYWILD; *t++ = x2;
1206 *t++ = FUNNYDOLLAR; *t++ = x2;
1209 if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
1213 if ( x3 != GAMMA ) {
1214 MesPrint(
"&5_,6_,7_ can only be used inside g_");
1221 if ( x2 >= AM.OffsetIndex && inset < 2 ) {
1222 MesPrint(
"&Value of constant index in tensor too large");
1228 MesPrint(
"&Illegal object in tensor");
1232 if ( inset >= 2 ) inset = 1;
1233 }
while ( *s == TCOMMA );
1236 dofunction: firstsumarg = 1;
1240 if ( c == TMINUS && ( *s == TVECTOR || *s == TNUMBER
1241 || *s == TNUMBER1 || *s == TSUBEXP ) ) {
1242 minus = 1; c = *s++;
1245 base = ( c == TNUMBER ) ? 100: 128;
1246 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1250 if ( firstsumarg ) {
1252 if ( sumlevel > 0 ) {
1253 if ( c == TSYMBOL ) {
1254 sumlevel = x2; sumtype = SYMTOSYM;
1256 else if ( c == TINDEX ) {
1257 sumlevel = x2+AM.OffsetIndex; sumtype = INDTOIND;
1258 if ( sumlevel > AM.IndDum ) {
1259 x2 = sumlevel - AM.IndDum;
1265 if ( *s == TWILDCARD ) {
1266 if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
1267 else if ( c != TNUMBER ) x2 += WILDOFFSET;
1272 *t++ = -SYMBOL; *t++ = x2;
break;
1274 *t++ = -DOLLAREXPRESSION; *t++ = x2;
break;
1276 *t++ = -EXPRESSION; *t++ = x2;
1282 if ( Expressions[x2].status == STOREDEXPRESSION ) {
1283 TMproto[0] = EXPRESSION;
1284 TMproto[1] = SUBEXPSIZE;
1287 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1288 AT.TMaddr = TMproto;
1305 if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
1307 MesPrint(
"&Problems getting information about stored expression %s(2)" 1310 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1311 M_free(renumber->
symb.
lo,
"VarSpace");
1312 M_free(renumber,
"Renumber");
1313 AR.StoreData.dirtyflag = 1;
1317 *t++ = -INDEX; *t++ = x2 + AM.OffsetIndex;
1318 if ( t[-1] > AM.IndDum ) {
1319 x2 = t[-1] - AM.IndDum;
1324 *t++ = -INDEX; *t++ = AC.DumNum + WILDOFFSET;
1327 if ( minus ) *t++ = -MINVECTOR;
1328 else *t++ = -VECTOR;
1329 *t++ = x2 + AM.OffsetVector;
1332 MesPrint(
"&5_,6_,7_ can only be used inside g_");
1338 *t++ = -SYMBOL; *t++ = x2;
break;
1340 *t++ = -x2-FUNCTION;
1343 *t++ = -ARGWILD; *t++ = x2;
break;
1348 w1 = t; t += 2; w2 = t;
1349 while ( w1 > v ) *--w2 = *--w1;
1350 tsize = v; relo = AT.WorkTop;
1351 *v++ = SETSET; *v++ = 0;
1354 *--relo = x2; *--relo = t-v+1;
1356 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1359 (*relo)--; *t++ = -x2-1;
break;
1361 *t++ = -SYMBOL; *t++ = x2;
break;
1363 *t++ = -INDEX; *t++ = x2;
1364 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1365 x2 = x2+AM.OffsetIndex - AM.IndDum;
1370 *t++ = -VECTOR; *t++ = x2;
break;
1372 *t++ = -SNUMBER; *t++ = x2;
break;
1374 MesPrint(
"&Internal error 435");
1376 *t++ = -SYMBOL; *t++ = x2;
break;
1380 w2 = AC.ProtoType; i = w2[1];
1386 while ( --i >= 0 ) *t++ = *w2++;
1387 w1[ARGHEAD+3] = subexpbuffers[x2].subexpnum;
1388 w1[ARGHEAD+5] = subexpbuffers[x2].buffernum;
1389 if ( sumlevel > 0 ) {
1393 *t++ = sumtype; *t++ = 4;
1394 *t++ = sumlevel; *t++ = sumlevel;
1397 if ( minus ) *t++ = -3;
1402 if ( minus ) x2 = -x2;
1407 MesPrint(
"&Illegal object in function");
1411 }
while ( *s == TCOMMA );
1413 if ( *s != TFUNCLOSE ) {
1414 MesPrint(
"&Illegal argument field for function. Expected )");
1428 x1 = 0;
while ( *s >= 0 ) x1 = 128*x1 + *s++;
1429 if ( *s == TWILDCARD ) s++;
1430 if ( *s == TDOT )
goto dovector;
1431 if ( *s == TFUNOPEN ) {
1434 v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
1435 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1436 t[-1] |= MUSTCLEANPRF;
1438 needarg = -1;
goto dofunction;
1440 *t++ = SYMBOL; *t++ = 4; *t++ = 0;
1441 if ( inset ) *relo = 2;
1444 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1445 if ( *s == TPOWER ) {
1447 base = ( c == TNUMBER ) ? 100: 128;
1448 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1449 if ( *s == TWILDCARD ) { x2 += 2*MAXPOWER; s++; }
1450 else if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
1453 r = AC.ProtoType; n = r[1] - 5; r += 5;
1454 *t++ = SUBEXPRESSION; *t++ = r[-4];
1455 *t++ = subexpbuffers[x1].subexpnum;
1457 *t++ = subexpbuffers[x1].buffernum;
1459 if ( cbuf[subexpbuffers[x1].buffernum].CanCommu[subexpbuffers[x1].subexpnum] ) cc = 1;
1471 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1473 *t++ = EXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1; *t++ = deno;
1474 *t++ = 0; FILLSUB(t)
1480 if ( *s == TFUNOPEN ) {
1483 base = ( c == TNUMBER ) ? 100: 128;
1484 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1487 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
1490 *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetIndex;
1491 if ( t[-1] > AM.IndDum ) {
1492 x2 = t[-1] - AM.IndDum;
1497 *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetVector;
1500 *t++ = x2+FUNCTION; *t++ = 2;
break;
1503 if ( x2 >= AM.OffsetIndex || x2 < 0 ) {
1504 MesPrint(
"&Index as argument of expression has illegal value");
1507 *t++ = INDEX; *t++ = 3; *t++ = x2;
break;
1512 w1 = t; t += 2; w2 = t;
1513 while ( w1 > v ) *--w2 = *--w1;
1514 tsize = v; relo = AT.WorkTop;
1515 *v++ = SETSET; *v++ = 0;
1518 *--relo = x2; *--relo = t-v+2;
1520 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1523 *relo -= 2; *t++ = -x2-1;
break;
1525 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1527 *t++ = INDEX; *t++ = 3; *t++ = x2;
1528 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1529 x2 = x2+AM.OffsetIndex - AM.IndDum;
1534 *t++ = VECTOR; *t++ = 3; *t++ = x2;
break;
1536 *t++ = SNUMBER; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1538 MesPrint(
"&Internal error 435");
1540 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1544 MesPrint(
"&Argument of expression can only be symbol, index, vector or function");
1548 }
while ( *s == TCOMMA );
1549 if ( *s != TFUNCLOSE ) {
1550 MesPrint(
"&Illegal object in argument field for expression");
1552 while ( *s != TFUNCLOSE ) s++;
1556 r = AC.ProtoType; n = r[1];
1557 if ( n > SUBEXPSIZE ) {
1558 *t++ = WILDCARDS; *t++ = n+2;
1566 if ( Expressions[x1].status == STOREDEXPRESSION ) {
1585 if ( ( renumber = GetTable(x1,&position,0) ) == 0 ) {
1587 MesPrint(
"&Problems getting information about stored expression %s(3)" 1590 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1591 M_free(renumber->
symb.
lo,
"VarSpace");
1592 M_free(renumber,
"Renumber");
1593 AR.StoreData.dirtyflag = 1;
1595 if ( *s == LBRACE ) {
1603 if ( *s != TSUBEXP ) {
1604 MesPrint(
"&Internal error 23");
1607 s++; x2 = 0;
while ( *s >= 0 ) { x2 = 128*x2 + *s++; }
1608 r = cbuf[subexpbuffers[x2].buffernum].rhs[subexpbuffers[x2].subexpnum];
1609 *t++ = FROMBRAC; *t++ = *r+2;
1613 MesPrint(
"&Object between [] in expression should be a single term");
1616 if ( *s != RBRACE ) {
1617 MesPrint(
"&Internal error 23b");
1622 if ( *s == TPOWER ) {
1624 base = ( c == TNUMBER ) ? 100: 128;
1625 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1626 if ( *s == TWILDCARD || c == TSYMBOL ) { x2 += 2*MAXPOWER; s++; }
1635 if ( *s == TPOWER ) {
1636 s++;
if ( *s == TMINUS ) { s++; deno = -deno; }
1637 c = *s++; base = ( c == TNUMBER ) ? 100: 128;
1638 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
1641 MesPrint(
"&Encountered 0^0 during compilation");
1645 MesPrint(
"&Division by zero during compilation (0 to the power negative number)");
1648 else if ( deno < 0 ) {
1650 MesPrint(
"&Division by zero during compilation");
1655 if ( *s >= 0 ) { y = 100*y + *s++; }
1656 innum[0] = y; nin = 1;
1659 if ( *s >= 0 ) { y = 100*y + *s++; x2 = 10000; }
1660 Product(innum,&nin,(WORD)x2);
1661 if ( y ) AddLong(innum,nin,(UWORD *)(&y),(WORD)1,innum,&nin);
1664 if ( *s == TPOWER ) {
1665 s++;
if ( *s == TMINUS ) { s++; deno = -deno; }
1666 c = *s++; base = ( c == TNUMBER ) ? 100: 128;
1667 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
1669 innum[0] = 1; nin = 1;
1671 else if ( RaisPow(BHEAD innum,&nin,x2) ) {
1672 error = -1; innum[0] = 1; nin = 1;
1676 Simplify(BHEAD innum,&nin,denominator,&ndenominator);
1677 for ( i = 0; i < nnumerator; i++ ) CGscrat7[i] = numerator[i];
1678 MulLong(innum,nin,CGscrat7,nnumerator,numerator,&nnumerator);
1680 else if ( deno < 0 ) {
1681 Simplify(BHEAD innum,&nin,numerator,&nnumerator);
1682 for ( i = 0; i < ndenominator; i++ ) CGscrat7[i] = denominator[i];
1683 MulLong(innum,nin,CGscrat7,ndenominator,denominator,&ndenominator);
1688 if ( *s == 0 ) { s++; sign = 0;
break; }
1690 if ( *s >= 0 ) { y = 128*y + *s++; }
1692 innum[0] = y; nin = 1;
1695 if ( *s >= 0 ) { y = 128*y + *s++; x2 = 16384; }
1696 Product(innum,&nin,(WORD)x2);
1697 if ( y ) AddLong(innum,nin,(UWORD *)&y,(WORD)1,innum,&nin);
1701 *relo = 2; *t++ = SNUMBER; *t++ = 4; *t++ = y;
1706 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1707 if ( AR.Eside != LHSIDE ) {
1708 *t++ = SUBEXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
1711 *t++ = DOLLAREXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
1714 *t++ = AM.dbufnum; FILLSUB(t)
1718 if ( *s == LBRACE ) {
1721 while ( bracelevel > 0 ) {
1722 if ( *s == RBRACE ) {
1725 else if ( *s == TNUMBER ) {
1727 x2 = 0;
while ( *s >= 0 ) { x2 = 100*x2 + *s++; }
1728 *t++ = DOLLAREXPR2; *t++ = 3; *t++ = -x2-1;
1730 while ( bracelevel > 0 ) {
1731 if ( *s != RBRACE ) {
1734 MesPrint(
"&Improper use of [] in $-variable.");
1742 else if ( *s == TDOLLAR ) {
1744 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1745 *t++ = DOLLAREXPR2; *t++ = 3; *t++ = x1;
1746 if ( *s == RBRACE )
goto CloseBraces;
1747 else if ( *s == LBRACE ) {
1751 else goto ErrorBraces;
1757 if ( *s == TPOWER ) {
1759 if ( *s == TMINUS ) { s++; deno = -deno; }
1761 base = ( c == TNUMBER ) ? 100: 128;
1762 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1763 if ( c == TSYMBOL ) {
1764 if ( *s == TWILDCARD ) s++;
1767 *powplace = deno*x2;
1769 else *powplace = deno;
1780 inset = 1; tsize = t; relo = AT.WorkTop;
1781 *t++ = SETSET; *t++ = 0;
1782 x1 = 0;
while ( *s >= 0 ) x1 = x1*128 + *s++;
1783 *--relo = x1; *--relo = 0;
1786 inset = 1; tsize = t; relo = AT.WorkTop;
1787 *t++ = SETSET; *t++ = 0;
1788 x1 = 0;
while ( *s >= 0 ) x1 = x1*128 + *s++;
1789 *--relo = -x1; *--relo = 0;
1792 MesPrint(
"&Illegal use of function arguments");
1799 MesPrint(
"&Illegal use of function arguments");
1805 MesPrint(
"&Illegal use special gamma symbols 5_, 6_, 7_");
1811 MesPrint(
"&Internal error in code generator. Unknown object: %d",c);
1819 MesPrint(
"&Irregular end of statement.");
1822 if ( !first && error == 0 ) {
1825 if ( cc && sign ) C->
CanCommu[numexp]++;
1826 error = CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
1828 AT.WorkPointer = oldwork;
1829 if ( error )
return(-1);
1831 if ( AC.CompileLevel > 0 && AR.Eside != LHSIDE ) {
1833 error = InsTree(AC.cbufnum,C->numrhs);
1834 if ( error < (C->numrhs) ) {
1841 MLOCK(ErrorMessageLock);
1843 MUNLOCK(ErrorMessageLock);
1855 int CompleteTerm(WORD *term, UWORD *numer, UWORD *denom, WORD nnum, WORD nden,
int sign)
1859 if ( sign == 0 )
return(0);
1860 if ( nnum >= nden ) nsize = nnum;
1863 for ( i = 0; i < nnum; i++ ) *t++ = numer[i];
1864 for ( ; i < nsize; i++ ) *t++ = 0;
1865 for ( i = 0; i < nden; i++ ) *t++ = denom[i];
1866 for ( ; i < nsize; i++ ) *t++ = 0;
1867 *t++ = (2*nsize+1)*sign;
1869 AddNtoC(AC.cbufnum,*term,term,7);
1892 int CodeFactors(SBYTE *tokens)
1896 int nfactor = 1, nparenthesis, i, last = 0, error = 0;
1897 SBYTE *t, *startobject, *tt, *s1, *out, *outtokens;
1898 WORD nexp, subexp = 0, power, pow, x2, powfactor, first;
1903 while ( *t != TENDOFIT ) {
1904 if ( *t >= 0 ) {
while ( *t >= 0 ) t++;
continue; }
1905 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
1906 nparenthesis = 0; t++;
1907 while ( nparenthesis >= 0 ) {
1908 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
1909 else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
1914 else if ( ( *t == TPLUS || *t == TMINUS ) && ( t > tokens )
1915 && ( t[-1] != TPLUS && t[-1] != TMINUS ) ) {
1916 if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
1917 || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
1918 subexp = CodeGenerator(tokens);
1919 if ( subexp < 0 ) error = -1;
1920 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
1921 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
1924 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
1925 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
1926 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(
SUBBUF),
"subexpbuffers");
1928 subexpbuffers[insubexpbuffers].subexpnum = subexp;
1929 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
1930 subexp = insubexpbuffers++;
1932 *t++ = TSYMBOL; *t++ = FACTORSYMBOL;
1933 *t++ = TMULTIPLY; *t++ = TSUBEXP;
1934 PUTNUMBER128(t,subexp)
1937 e->vflags |= ISFACTORIZED;
1941 else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && t > tokens ) {
1944 else if ( *t == TEXPRESSION ) {
1946 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
1947 if ( *t == LBRACE )
continue;
1948 if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) != 0 ) {
1949 nfactor += AS.OldNumFactors[nexp];
1954 else if ( *t == TDOLLAR ) {
1956 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
1957 if ( *t == LBRACE )
continue;
1958 if ( Dollars[nexp].nfactors > 0 ) {
1959 nfactor += Dollars[nexp].nfactors;
1970 outtokens = (SBYTE *)Malloc1(((t-tokens)+(nfactor+2)*25)*
sizeof(SBYTE),
"CodeFactors");
1972 t = tokens; first = 1; powfactor = 1;
1973 while ( *t == TPLUS || *t == TMINUS ) {
if ( *t == TMINUS ) first = -first; t++; }
1975 *out++ = TMINUS; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
1976 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
1979 startobject = t; power = 1;
1980 while ( *t != TENDOFIT ) {
1981 if ( *t >= 0 ) {
while ( *t >= 0 ) t++;
continue; }
1982 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
1983 nparenthesis = 0; t++;
1984 while ( nparenthesis >= 0 ) {
1985 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
1986 else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
1991 else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && ( t > tokens ) ) {
1992 if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
1993 || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
1995 if ( startobject ) {
1997 if ( power < 0 ) { *out++ = TNUMBER; *out++ = 1; *out++ = TDIVIDE; }
1999 while ( s1 < t ) *out++ = *s1++;
2000 *out++ = TMULTIPLY; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2001 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2004 if ( last ) { startobject = 0;
break; }
2006 if ( *t == TDIVIDE ) power = -1;
2007 if ( *t == TMULTIPLY ) power = 1;
2010 else if ( *t == TPOWER ) {
2013 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2014 if ( *tt == TMINUS ) pow = -pow;
2017 if ( *tt == TSYMBOL ) {
2018 tt++;
while ( *tt >= 0 ) tt++;
2021 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2026 power = power*pow*x2;
2027 if ( power < 0 ) { pow = -power; power = -1; }
2028 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2029 else { pow = power; power = 1; }
2032 subexp = GenerateFactors(pow,1);
2033 if ( subexp < 0 ) { error = -1; subexp = 0; }
2034 *out++ = TSUBEXP; PUTNUMBER128(out,subexp);
2036 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2037 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2039 if ( power > 0 ) *out++ = TMULTIPLY;
2040 else *out++ = TDIVIDE;
2041 s1 = startobject;
while ( s1 < t ) *out++ = *s1++;
2042 startobject = 0; t = tt;
continue;
2044 else if ( *t == TEXPRESSION ) {
2047 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
2048 if ( *t == LBRACE )
continue;
2049 if ( *t == LPARENTHESIS ) {
2050 nparenthesis = 0; t++;
2051 while ( nparenthesis >= 0 ) {
2052 if ( *t == LPARENTHESIS ) nparenthesis++;
2053 else if ( *t == RPARENTHESIS ) nparenthesis--;
2057 if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) == 0 )
continue;
2058 if ( *t == TPOWER ) {
2061 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2062 if ( *tt == TMINUS ) pow = -pow;
2065 if ( *tt != TNUMBER ) {
2066 MesPrint(
"Internal problems(1) in CodeFactors");
2069 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2075 power = power*pow*x2;
2076 if ( power < 0 ) { pow = -power; power = -1; }
2077 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2078 else { pow = power; power = 1; }
2081 subexp = GenerateFactors(pow,AS.OldNumFactors[nexp]);
2082 if ( subexp < 0 ) { error = -1; subexp = 0; }
2083 *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
2088 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2090 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,i)
2094 powfactor += AS.OldNumFactors[nexp]*pow;
2096 while ( s1 < t ) *out++ = *s1++;
2097 startobject = 0; t = tt;
continue;
2100 tt = t; pow = 1; x2 = 1;
goto dopower;
2103 else if ( *t == TDOLLAR ) {
2106 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
2107 if ( *t == LBRACE )
continue;
2108 if ( Dollars[nexp].nfactors == 0 )
continue;
2109 if ( *t == TPOWER ) {
2112 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2113 if ( *tt == TMINUS ) pow = -pow;
2116 if ( *tt != TNUMBER ) {
2117 MesPrint(
"Internal problems(2) in CodeFactors");
2120 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2126 power = power*pow*x2;
2127 if ( power < 0 ) { pow = -power; power = -1; }
2128 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2129 else { pow = power; power = 1; }
2131 subexp = GenerateFactors(pow,1);
2132 if ( subexp < 0 ) { error = -1; subexp = 0; }
2134 for ( i = 1; i <= Dollars[nexp].nfactors; i++ ) {
2135 s1 = startobject; *out++ = TPLUS;
2136 while ( s1 < t ) *out++ = *s1++;
2137 *out++ = LBRACE; *out++ = TNUMBER; PUTNUMBER128(out,i)
2140 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2141 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2144 *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
2147 startobject = 0; t = tt;
continue;
2150 tt = t; pow = 1; x2 = 1;
goto dopowerd;
2155 if ( last == 0 ) { last = 1;
goto dolast; }
2157 e->numfactors = powfactor-1;
2158 e->vflags |= ISFACTORIZED;
2159 subexp = CodeGenerator(outtokens);
2160 if ( subexp < 0 ) error = -1;
2161 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
2162 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
2165 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
2166 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
2167 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(
SUBBUF),
"subexpbuffers");
2169 subexpbuffers[insubexpbuffers].subexpnum = subexp;
2170 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
2171 subexp = insubexpbuffers++;
2172 M_free(outtokens,
"CodeFactors");
2174 *s1++ = TSUBEXP; PUTNUMBER128(s1,subexp); *s1++ = TENDOFIT;
2175 if ( error < 0 )
return(-1);
2176 else return(subexp);
2189 WORD GenerateFactors(WORD n,WORD inc)
2194 SBYTE *tokenbuffer = (SBYTE *)Malloc1(8*n*
sizeof(SBYTE),
"GenerateFactors");
2196 *s++ = TNUMBER; *s++ = 1;
2197 for ( i = inc; i < n*inc; i += inc ) {
2198 *s++ = TPLUS; *s++ = TSYMBOL; *s++ = FACTORSYMBOL;
2200 *s++ = TPOWER; *s++ = TNUMBER;
2205 subexp = CodeGenerator(tokenbuffer);
2206 if ( subexp < 0 ) error = -1;
2207 M_free(tokenbuffer,
"GenerateFactors");
2208 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
2209 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
2212 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
2213 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
2214 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(
SUBBUF),
"subexpbuffers");
2216 subexpbuffers[insubexpbuffers].subexpnum = subexp;
2217 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
2218 subexp = insubexpbuffers++;
2219 if ( error < 0 )
return(error);