55static 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}
103static 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 ,{
"collect", (TFUN)CoCollect, SPECIFICATION,PARTEST}
122 ,{
"commuteinset", (TFUN)CoCommuteInSet, DECLARATION, PARTEST}
123 ,{
"contract", (TFUN)CoContract, STATEMENT, PARTEST}
124 ,{
"copyspectator" ,(TFUN)CoCopySpectator, DEFINITION, PARTEST}
125 ,{
"createspectator",(TFUN)CoCreateSpectator, DECLARATION, PARTEST}
126 ,{
"ctable", (TFUN)CoCTable, DECLARATION, PARTEST}
127 ,{
"deallocatetable",(TFUN)CoDeallocateTable, DECLARATION, PARTEST}
128 ,{
"default", (TFUN)CoDefault, STATEMENT, PARTEST}
129 ,{
"delete", (TFUN)CoDelete, SPECIFICATION,PARTEST}
130 ,{
"denominators", (TFUN)CoDenominators, STATEMENT, PARTEST}
131 ,{
"disorder", (TFUN)CoDisorder, STATEMENT, PARTEST}
132 ,{
"do", (TFUN)CoDo, STATEMENT, PARTEST}
133 ,{
"drop", (TFUN)CoDrop, SPECIFICATION,PARTEST}
134 ,{
"dropcoefficient",(TFUN)CoDropCoefficient, STATEMENT, PARTEST}
135 ,{
"dropsymbols", (TFUN)CoDropSymbols, STATEMENT, PARTEST}
136 ,{
"else", (TFUN)CoElse, STATEMENT, PARTEST}
137 ,{
"elseif", (TFUN)CoElseIf, STATEMENT, PARTEST}
138 ,{
"emptyspectator", (TFUN)CoEmptySpectator, SPECIFICATION,PARTEST}
139 ,{
"endargument", (TFUN)CoEndArgument, STATEMENT, PARTEST}
140 ,{
"enddo", (TFUN)CoEndDo, STATEMENT, PARTEST}
141 ,{
"endif", (TFUN)CoEndIf, STATEMENT, PARTEST}
142 ,{
"endinexpression",(TFUN)CoEndInExpression, STATEMENT, PARTEST}
143 ,{
"endinside", (TFUN)CoEndInside, STATEMENT, PARTEST}
144 ,{
"endrepeat", (TFUN)CoEndRepeat, STATEMENT, PARTEST}
145 ,{
"endswitch", (TFUN)CoEndSwitch, STATEMENT, PARTEST}
146 ,{
"endterm", (TFUN)CoEndTerm, STATEMENT, PARTEST}
147 ,{
"endwhile", (TFUN)CoEndWhile, STATEMENT, PARTEST}
148 ,{
"exit", (TFUN)CoExit, STATEMENT, PARTEST}
149 ,{
"extrasymbols", (TFUN)CoExtraSymbols, DECLARATION, PARTEST}
150 ,{
"factarg", (TFUN)CoFactArg, STATEMENT, PARTEST}
151 ,{
"factdollar", (TFUN)CoFactDollar, STATEMENT, PARTEST}
152 ,{
"factorize", (TFUN)CoFactorize, TOOUTPUT, PARTEST}
153 ,{
"fill", (TFUN)CoFill, DECLARATION, PARTEST}
154 ,{
"fillexpression", (TFUN)CoFillExpression, DECLARATION, PARTEST}
155 ,{
"frompolynomial", (TFUN)CoFromPolynomial, STATEMENT, PARTEST}
156 ,{
"funpowers", (TFUN)CoFunPowers, DECLARATION, PARTEST}
157 ,{
"hide", (TFUN)CoHide, SPECIFICATION,PARTEST}
158 ,{
"if", (TFUN)CoIf, STATEMENT, PARTEST}
159 ,{
"ifmatch", (TFUN)CoIfMatch, STATEMENT, PARTEST}
160 ,{
"ifnomatch", (TFUN)CoIfNoMatch, STATEMENT, PARTEST}
161 ,{
"ifnotmatch", (TFUN)CoIfNoMatch, STATEMENT, PARTEST}
162 ,{
"inexpression", (TFUN)CoInExpression, STATEMENT, PARTEST}
163 ,{
"inparallel", (TFUN)CoInParallel, SPECIFICATION,PARTEST}
164 ,{
"inside", (TFUN)CoInside, STATEMENT, PARTEST}
165 ,{
"insidefirst", (TFUN)CoInsideFirst, DECLARATION, PARTEST}
166 ,{
"intohide", (TFUN)CoIntoHide, SPECIFICATION,PARTEST}
167 ,{
"keep", (TFUN)CoKeep, SPECIFICATION,PARTEST}
168 ,{
"makeinteger", (TFUN)CoMakeInteger, STATEMENT, PARTEST}
169 ,{
"many", (TFUN)CoMany, STATEMENT, PARTEST}
170 ,{
"merge", (TFUN)CoMerge, STATEMENT, PARTEST}
171 ,{
"metric", (TFUN)CoMetric, DECLARATION, PARTEST}
172 ,{
"moduleoption", (TFUN)CoModuleOption, ATENDOFMODULE,PARTEST}
173 ,{
"multi", (TFUN)CoMulti, STATEMENT, PARTEST}
174 ,{
"multibracket", (TFUN)CoMultiBracket, STATEMENT, PARTEST}
175 ,{
"ndrop", (TFUN)CoNoDrop, SPECIFICATION,PARTEST}
176 ,{
"nfactorize", (TFUN)CoNFactorize, TOOUTPUT, PARTEST}
177 ,{
"nhide", (TFUN)CoNoHide, SPECIFICATION,PARTEST}
178 ,{
"normalize", (TFUN)CoNormalize, STATEMENT, PARTEST}
179 ,{
"notinparallel", (TFUN)CoNotInParallel, SPECIFICATION,PARTEST}
180 ,{
"nskip", (TFUN)CoNoSkip, SPECIFICATION,PARTEST}
181 ,{
"ntable", (TFUN)CoNTable, DECLARATION, PARTEST}
182 ,{
"nunfactorize", (TFUN)CoNUnFactorize, TOOUTPUT, PARTEST}
183 ,{
"nunhide", (TFUN)CoNoUnHide, SPECIFICATION,PARTEST}
184 ,{
"off", (TFUN)CoOff, DECLARATION, PARTEST}
185 ,{
"on", (TFUN)CoOn, DECLARATION, PARTEST}
186 ,{
"once", (TFUN)CoOnce, STATEMENT, PARTEST}
187 ,{
"only", (TFUN)CoOnly, STATEMENT, PARTEST}
188 ,{
"polyfun", (TFUN)CoPolyFun, DECLARATION, PARTEST}
189 ,{
"polyratfun", (TFUN)CoPolyRatFun, DECLARATION, PARTEST}
190 ,{
"pophide", (TFUN)CoPopHide, SPECIFICATION,PARTEST}
191 ,{
"print[]", (TFUN)CoPrintB, TOOUTPUT, PARTEST}
192 ,{
"printtable", (TFUN)CoPrintTable, MIXED, PARTEST}
193 ,{
"processbucketsize",(TFUN)CoProcessBucket, DECLARATION, PARTEST}
194 ,{
"propercount", (TFUN)CoProperCount, DECLARATION, PARTEST}
195 ,{
"pushhide", (TFUN)CoPushHide, SPECIFICATION,PARTEST}
196 ,{
"putinside", (TFUN)CoPutInside, STATEMENT, PARTEST}
197 ,{
"ratio", (TFUN)CoRatio, STATEMENT, PARTEST}
198 ,{
"removespectator",(TFUN)CoRemoveSpectator, SPECIFICATION,PARTEST}
199 ,{
"renumber", (TFUN)CoRenumber, STATEMENT, PARTEST}
200 ,{
"repeat", (TFUN)CoRepeat, STATEMENT, PARTEST}
201 ,{
"replaceloop", (TFUN)CoReplaceLoop, STATEMENT, PARTEST}
202 ,{
"select", (TFUN)CoSelect, STATEMENT, PARTEST}
203 ,{
"set", (TFUN)CoSet, DECLARATION, PARTEST}
204 ,{
"setexitflag", (TFUN)CoSetExitFlag, STATEMENT, PARTEST}
205 ,{
"shuffle", (TFUN)CoMerge, STATEMENT, PARTEST}
206 ,{
"skip", (TFUN)CoSkip, SPECIFICATION,PARTEST}
207 ,{
"sort", (TFUN)CoSort, STATEMENT, PARTEST}
208 ,{
"splitarg", (TFUN)CoSplitArg, STATEMENT, PARTEST}
209 ,{
"splitfirstarg", (TFUN)CoSplitFirstArg, STATEMENT, PARTEST}
210 ,{
"splitlastarg", (TFUN)CoSplitLastArg, STATEMENT, PARTEST}
211 ,{
"stuffle", (TFUN)CoStuffle, STATEMENT, PARTEST}
212 ,{
"sum", (TFUN)CoSum, STATEMENT, PARTEST}
213 ,{
"switch", (TFUN)CoSwitch, STATEMENT, PARTEST}
214 ,{
"table", (TFUN)CoTable, DECLARATION, PARTEST}
215 ,{
"tablebase", (TFUN)CoTableBase, DECLARATION, PARTEST}
216 ,{
"tb", (TFUN)CoTableBase, DECLARATION, PARTEST}
217 ,{
"term", (TFUN)CoTerm, STATEMENT, PARTEST}
218 ,{
"testuse", (TFUN)CoTestUse, STATEMENT, PARTEST}
219 ,{
"threadbucketsize",(TFUN)CoThreadBucket, DECLARATION, PARTEST}
220 ,{
"topolynomial", (TFUN)CoToPolynomial, STATEMENT, PARTEST}
221 ,{
"tospectator", (TFUN)CoToSpectator, STATEMENT, PARTEST}
222 ,{
"totensor", (TFUN)CoToTensor, STATEMENT, PARTEST}
223 ,{
"tovector", (TFUN)CoToVector, STATEMENT, PARTEST}
224 ,{
"trace4", (TFUN)CoTrace4, STATEMENT, PARTEST}
225 ,{
"tracen", (TFUN)CoTraceN, STATEMENT, PARTEST}
226 ,{
"transform", (TFUN)CoTransform, STATEMENT, PARTEST}
227 ,{
"tryreplace", (TFUN)CoTryReplace, STATEMENT, PARTEST}
228 ,{
"unfactorize", (TFUN)CoUnFactorize, TOOUTPUT, PARTEST}
229 ,{
"unhide", (TFUN)CoUnHide, SPECIFICATION,PARTEST}
230 ,{
"while", (TFUN)CoWhile, STATEMENT, PARTEST}
244SUBBUF *subexpbuffers = 0;
245SUBBUF *topsubexpbuffers = 0;
246LONG insubexpbuffers = 0;
248#define REDUCESUBEXPBUFFERS { if ( (topsubexpbuffers-subexpbuffers) > 256 ) {\
249 M_free(subexpbuffers,"subexpbuffers");\
250 subexpbuffers = (SUBBUF *)Malloc1(256*sizeof(SUBBUF),"subexpbuffers");\
251 topsubexpbuffers = subexpbuffers+256; } insubexpbuffers = 0; }
255#define PUTNUMBER128(t,n) { if ( n >= 16384 ) { \
256 *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
257 else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \
259#define PUTNUMBER100(t,n) { if ( n >= 10000 ) { \
260 *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
261 else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \
264#elif ( defined(LLP64) || defined(LP64) )
266#define PUTNUMBER128(t,n) { if ( n >= 2097152 ) { \
267 *t++ = ((n/128)/128)/128; *t++ = ((n/128)/128)%128; *t++ = (n/128)%128; *t++ = n%128; } \
268 else if ( n >= 16384 ) { \
269 *t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
270 else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \
272#define PUTNUMBER100(t,n) { if ( n >= 1000000 ) { \
273 *t++ = ((n/100)/100)/100; *t++ = ((n/100)/100)%100; *t++ = (n/100)%100; *t++ = n%100; } \
274 else if ( n >= 10000 ) { \
275 *t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
276 else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \
296 ksize =
sizeof(com1commands)/
sizeof(
KEYWORD);
299 for ( i = 0; i < 26; i++ ) {
300 while ( j < ksize && k[j].name[0] ==
'a'+i ) j++;
323 while ( FG.cTable[*s] <= 1 ) s++;
324 if ( s > in && *s ==
'[' && s[1] ==
']' ) s += 2;
325 if ( *s ) { c = *s; *s = 0; }
331 hi =
sizeof(com2commands)/
sizeof(
KEYWORD)-1;
333 med = ( hi + lo ) / 2;
334 i = StrICmp(in,(UBYTE *)com2commands[med].name);
335 if ( i == 0 ) {
if ( c ) *s = c;
return(com2commands+med); }
336 if ( i < 0 ) hi = med-1;
338 }
while ( hi >= lo );
342 i = tolower(*in) -
'a';
344 hi = alfatable1[i+1];
346 if ( StrICont(in,(UBYTE *)com1commands[med].name) == 0 )
347 {
if ( c ) *s = c;
return(com1commands+med); }
362int ParenthesesTest(UBYTE *sin)
364 WORD L1 = 0, L2 = 0, L3 = 0;
367 if ( *s ==
'[' ) L1++;
368 else if ( *s ==
']' ) {
370 if ( L1 < 0 ) { MesPrint(
"&Unmatched []");
return(1); }
374 if ( L1 > 0 ) { MesPrint(
"&Unmatched []");
return(1); }
377 if ( *s ==
'[' ) SKIPBRA1(s)
378 else if ( *s ==
'(' ) { L2++; s++; }
379 else if ( *s ==
')' ) {
381 if ( L2 < 0 ) { MesPrint(
"&Unmatched ()");
return(1); }
385 if ( L2 > 0 ) { MesPrint(
"&Unmatched ()");
return(1); }
388 if ( *s ==
'[' ) SKIPBRA1(s)
389 else if ( *s ==
'[' ) SKIPBRA4(s)
390 else if ( *s ==
'{' ) { L3++; s++; }
391 else if ( *s ==
'}' ) {
393 if ( L3 < 0 ) { MesPrint(
"&Unmatched {}");
return(1); }
397 if ( L3 > 0 ) { MesPrint(
"&Unmatched {}");
return(1); }
412UBYTE *SkipAName(UBYTE *s)
418 MesPrint(
"&Illegal name: '%s'",t);
423 else if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'$' ) {
424 if ( *s ==
'$' ) s++;
425 while ( FG.cTable[*s] <= 1 ) s++;
426 if ( *s ==
'_' ) s++;
429 MesPrint(
"&Illegal name: '%s'",t);
440UBYTE *IsRHS(UBYTE *s, UBYTE c)
442 while ( *s && *s != c ) {
446 MesPrint(
"&Unmatched []");
450 else if ( *s ==
'{' ) {
453 MesPrint(
"&Unmatched {}");
457 else if ( *s ==
'(' ) {
460 MesPrint(
"&Unmatched ()");
464 else if ( *s ==
')' ) {
465 MesPrint(
"&Unmatched ()");
468 else if ( *s ==
'}' ) {
469 MesPrint(
"&Unmatched {}");
472 else if ( *s ==
']' ) {
473 MesPrint(
"&Unmatched []");
486int IsIdStatement(UBYTE *s)
500int CompileAlgebra(UBYTE *s,
int leftright, WORD *prototype)
504 WORD *oldproto = AC.ProtoType;
505 AC.ProtoType = prototype;
506 if ( AC.TokensWriteFlag ) {
507 MesPrint(
"To tokenize: %s",s);
508 error = tokenize(s,leftright);
509 MesPrint(
" The contents of the token buffer are:");
510 WriteTokens(AC.tokens);
512 else error = tokenize(s,leftright);
514 AR.Eside = leftright;
516 if ( leftright == LHSIDE ) { AC.DumNum = AR.CurDum = 0; }
517 error = CompileSubExpressions(AC.tokens);
521 AC.ProtoType = oldproto;
524 AC.ProtoType = oldproto;
525 if ( error < 0 )
return(-1);
526 else if ( leftright == LHSIDE )
return(cbuf[AC.cbufnum].numlhs);
527 else return(cbuf[AC.cbufnum].numrhs);
536int CompileStatement(UBYTE *in)
540 int error1 = 0, error2;
542 if ( *s == 0 )
return(0);
544 k = findcommand((UBYTE *)
"assign");
547 if ( ( k = findcommand(s) ) == 0 && IsIdStatement(s) == 0 ) {
548 MesPrint(
"&Unrecognized statement");
552 k = com1commands + alfatable1[
'i'-
'a'];
553 while ( k->name[1] !=
'd' || k->name[2] ) k++;
556 while ( FG.cTable[*s] <= 1 ) s++;
557 if ( s > in && *s ==
'[' && s[1] ==
']' ) s += 2;
568 if ( *s ==
',' ) s++;
576 if ( AP.PreAssignFlag == 0 && AM.OldOrderFlag == 0 ) {
577 if ( AP.PreInsideLevel ) {
578 if ( k->type != STATEMENT && k->type != MIXED ) {
579 MesPrint(
"&Only executable and print statements are allowed in an %#inside/%#endinside construction");
584 if ( ( AC.compiletype == DECLARATION || AC.compiletype == SPECIFICATION )
585 && ( k->type == STATEMENT || k->type == DEFINITION || k->type == TOOUTPUT ) ) {
586 if ( AC.tablecheck == 0 ) {
588 if ( TestTables() ) error1 = 1;
591 if ( k->type == MIXED ) {
592 if ( AC.compiletype <= DEFINITION ) {
593 AC.compiletype = STATEMENT;
596 else if ( k->type > AC.compiletype ) {
597 if ( StrCmp((UBYTE *)(k->name),(UBYTE *)
"format") != 0 )
598 AC.compiletype = k->type;
600 else if ( k->type < AC.compiletype ) {
603 MesPrint(
"&Declaration out of order");
607 MesPrint(
"&Definition out of order");
611 MesPrint(
"&Specification out of order");
615 MesPrint(
"&Statement out of order");
618 MesPrint(
"&Output control statement out of order");
622 AC.compiletype = k->type;
623 if ( AC.firstctypemessage == 0 ) {
624 MesPrint(
"&Proper order inside a module is:");
625 MesPrint(
"Declarations, specifications, definitions, statements, output control statements");
626 AC.firstctypemessage = 1;
635 if ( AC.AutoDeclareFlag && ( ( k->flags & WITHAUTO ) == 0 ) ) {
636 MesPrint(
"&Illegal type of auto-declaration");
639 if ( ( ( k->flags & PARTEST ) != 0 ) && ParenthesesTest(s) )
return(1);
640 error2 = (*k->func)(s);
641 if ( error2 == 0 )
return(error1);
657 i = NumFunctions + FUNCTION - MAXBUILTINFUNCTION - 1;
658 f = f + MAXBUILTINFUNCTION - FUNCTION + 1;
659 if ( AC.MustTestTable > 0 ) {
662 for ( x = 0, j = 0; x < t->
totind; x++ ) {
667 MesPrint(
"&In table %s there are %d unfilled elements",
668 AC.varnames->namebuffer+f->
name,j);
671 MesPrint(
"&In table %s there is one unfilled element",
672 AC.varnames->namebuffer+f->
name);
694int CompileSubExpressions(SBYTE *tokens)
697 SBYTE *fill = tokens, *s = tokens, *t;
698 WORD number[MAXNUMSIZE], *oldwork, *w1, *w2;
699 int level, num, i, sumlevel = 0, sumtype = SYMTOSYM;
700 int retval, error = 0;
705 while ( *s != TENDOFIT ) {
706 if ( *s == TFUNOPEN ) {
707 if ( fill < s ) *fill = TENDOFIT;
709 while ( t >= tokens && t[0] >= 0 ) t--;
710 if ( t >= tokens && *t == TFUNCTION ) {
711 t++; i = 0;
while ( *t >= 0 ) i = 128*i + *t++;
712 if ( i == AM.sumnum || i == AM.sumpnum ) {
714 if ( *t == TSYMBOL || *t == TINDEX ) {
715 t++; i = 0;
while ( *t >= 0 ) i = 128*i + *t++;
716 if ( s[1] == TINDEX ) {
720 else sumtype = SYMTOSYM;
727 else if ( *s == TFUNCLOSE ) { sumlevel = 0; *fill++ = *s++; }
728 else if ( *s == LPARENTHESIS ) {
737 while ( level >= 0 ) {
739 if ( *s == LPARENTHESIS ) level++;
740 else if ( *s == RPARENTHESIS ) level--;
741 else if ( *s == TENDOFIT ) {
742 MesPrint(
"&Unbalanced subexpression parentheses");
747 if ( sumlevel > 0 ) {
748 oldwork = w1 = AT.WorkPointer;
751 while ( --i >= 0 ) *w1++ = *w2++;
753 *w1++ = sumtype; *w1++ = 4; *w1++ = sumlevel; *w1++ = sumlevel;
754 w2 = AC.ProtoType; AT.WorkPointer = w1;
755 AC.ProtoType = oldwork;
756 num = CompileSubExpressions(t);
757 AC.ProtoType = w2; AT.WorkPointer = oldwork;
759 else num = CompileSubExpressions(t);
760 if ( num < 0 )
return(-1);
768 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
769 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
772 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
773 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
774 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(SUBBUF),
"subexpbuffers");
776 subexpbuffers[insubexpbuffers].subexpnum = num;
777 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
778 num = insubexpbuffers++;
781 do { number[i++] = num & 0x7F; num >>= 7; }
while ( num );
782 while ( --i >= 0 ) *fill++ = (SBYTE)(number[i]);
785 else if ( *s == TEMPTY ) s++;
793 if ( AC.CompileLevel == 1 && AC.ToBeInFactors ) {
794 error = CodeFactors(tokens);
797 retval = CodeGenerator(tokens);
798 if ( error < 0 )
return(error);
827static UWORD *CGscrat7 = 0;
829int CodeGenerator(SBYTE *tokens)
832 SBYTE *s = tokens, c;
833 int i, sign = 1, first = 1, deno = 1, error = 0, minus, n, needarg, numexp, cc;
834 int base, sumlevel = 0, sumtype = SYMTOSYM, firstsumarg, inset = 0;
835 int funflag = 0, settype, x1, x2, mulflag = 0;
836 WORD *t, *v, *r, *term, nnumerator, ndenominator, *oldwork, x3, y, nin;
837 WORD *w1, *w2, *tsize = 0, *relo = 0;
838 UWORD *numerator, *denominator, *innum;
841 WORD TMproto[SUBEXPSIZE];
848 if ( AC.TokensWriteFlag ) WriteTokens(tokens);
850 CGscrat7 = (UWORD *)Malloc1((AM.MaxTal+2)*
sizeof(WORD),
"CodeGenerator");
852 C = cbuf + AC.cbufnum;
856 oldwork = AT.WorkPointer;
857 numerator = (UWORD *)(AT.WorkPointer);
858 denominator = numerator + 2*AM.MaxTal;
859 innum = denominator + 2*AM.MaxTal;
860 term = (WORD *)(innum + 2*AM.MaxTal);
861 AT.WorkPointer = term + AM.MaxTer/
sizeof(WORD);
862 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
865 numerator[0] = denominator[0] = 1;
866 nnumerator = ndenominator = 1;
867 while ( *s != TENDOFIT ) {
868 if ( *s == TPLUS || *s == TMINUS ) {
869 if ( first || mulflag ) {
if ( *s == TMINUS ) sign = -sign; }
873 if ( cc && sign ) C->
CanCommu[numexp]++;
874 CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
875 first = 1; cc = 0; t = term + 1; deno = 1;
876 numerator[0] = denominator[0] = 1;
877 nnumerator = ndenominator = 1;
878 if ( *s == TMINUS ) sign = -1;
884 mulflag = first = 0; c = *s++;
887 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
888 if ( *s == TWILDCARD ) { s++; x1 += 2*MAXPOWER; }
889 *t++ = SYMBOL; *t++ = 4; *t++ = x1;
890 if ( inset ) *relo = 2;
891TryPower:
if ( *s == TPOWER ) {
893 if ( *s == TMINUS ) { s++; deno = -deno; }
895 base = ( c == TNUMBER ) ? 100: 128;
896 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
897 if ( c == TSYMBOL ) {
898 if ( *s == TWILDCARD ) s++;
906 while ( relo < AT.WorkTop ) *t++ = *relo++;
907 inset = 0; tsize[1] = t - tsize;
911 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
912 *t++ = INDEX; *t++ = 3;
913 if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
914 if ( inset ) { *t++ = x1; *relo = 2; }
915 else *t++ = x1 + AM.OffsetIndex;
916 if ( t[-1] > AM.IndDum ) {
917 x1 = t[-1] - AM.IndDum;
922 *t++ = INDEX; *t++ = 3; *t++ = AC.DumNum+WILDOFFSET;
926 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
927dovector:
if ( inset == 0 ) x1 += AM.OffsetVector;
928 if ( *s == TWILDCARD ) { s++; x1 += WILDOFFSET; }
929 if ( inset ) *relo = 2;
932 if ( *s == TSETNUM || *s == TSETDOL ) {
933 settype = ( *s == TSETDOL );
934 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
935 if ( settype ) x2 = -x2;
937 tsize = t; *t++ = SETSET; *t++ = 0;
941 *--relo = x2; *--relo = 3;
943 if ( *s != TVECTOR && *s != TDUBIOUS ) {
944 MesPrint(
"&Illegally formed dotproduct");
947 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
948 if ( inset < 2 ) x2 += AM.OffsetVector;
949 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
950 *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2;
953 else if ( *s == TFUNOPEN ) {
955 if ( *s == TSETNUM || *s == TSETDOL ) {
956 settype = ( *s == TSETDOL );
957 s++; x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
958 if ( settype ) x2 = -x2;
960 tsize = t; *t++ = SETSET; *t++ = 0;
964 *--relo = x2; *--relo = 3;
966 if ( *s == TINDEX || *s == TDUBIOUS ) {
968 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
969 if ( inset < 2 ) x2 += AM.OffsetIndex;
970 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
971 *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
972 if ( t[-1] > AM.IndDum ) {
973 x2 = t[-1] - AM.IndDum;
977 else if ( *s == TGENINDEX ) {
978 *t++ = VECTOR; *t++ = 4; *t++ = x1;
979 *t++ = AC.DumNum + WILDOFFSET;
981 else if ( *s == TNUMBER || *s == TNUMBER1 ) {
982 base = ( *s == TNUMBER ) ? 100: 128;
984 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
985 if ( x2 >= AM.OffsetIndex && inset < 2 ) {
986 MesPrint(
"&Fixed index in vector greater than %d",
990 *t++ = VECTOR; *t++ = 4; *t++ = x1; *t++ = x2;
992 else if ( *s == TVECTOR || ( *s == TMINUS && s[1] == TVECTOR ) ) {
993 if ( *s == TMINUS ) { s++; sign = -sign; }
995 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
996 if ( inset < 2 ) x2 += AM.OffsetVector;
997 if ( *s == TWILDCARD ) { s++; x2 += WILDOFFSET; }
998 *t++ = DOTPRODUCT; *t++ = 5; *t++ = x1; *t++ = x2; *t++ = deno;
1001 MesPrint(
"&Illegal argument for vector");
1004 if ( *s != TFUNCLOSE ) {
1005 MesPrint(
"&Illegal argument for vector");
1012 *t++ = VECTOR; *t++ = 4; *t++ = x1;
1013 *t++ = AC.DumNum + WILDOFFSET;
1016 *t++ = INDEX; *t++ = 3; *t++ = x1;
1021 if ( *s != TFUNOPEN ) {
1022 MesPrint(
"&d_ needs two arguments");
1025 v = t; *t++ = DELTA; *t++ = 4;
1026 needarg = 2; x3 = x1 = -1;
1029 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1030 if ( x1 == AM.sumnum || x1 == AM.sumpnum ) sumlevel = x1;
1032 if ( x1 == FIRSTBRACKET ) {
1033 if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION ) {
1035 *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
1036 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1037 t[-1] |= MUSTCLEANPRF;
1039 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
1040 *t++ = -EXPRESSION; *t++ = x2;
1046 if ( Expressions[x2].status == STOREDEXPRESSION ) {
1047 TMproto[0] = EXPRESSION;
1048 TMproto[1] = SUBEXPSIZE;
1051 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1052 AT.TMaddr = TMproto;
1069 if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
1071 MesPrint(
"&Problems getting information about stored expression %s(1)"
1074 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1075 M_free(renumber->
symb.
lo,
"VarSpace");
1076 M_free(renumber,
"Renumber");
1077 AR.StoreData.dirtyflag = 1;
1079 if ( *s != TFUNCLOSE ) {
1080 if ( x1 == FIRSTBRACKET )
1081 MesPrint(
"&Problems with argument of FirstBracket_");
1082 else if ( x1 == FIRSTTERM )
1083 MesPrint(
"&Problems with argument of FirstTerm_");
1084 else if ( x1 == CONTENTTERM )
1085 MesPrint(
"&Problems with argument of FirstTerm_");
1086 else if ( x1 == TERMSINEXPR )
1087 MesPrint(
"&Problems with argument of TermsIn_");
1088 else if ( x1 == SIZEOFFUNCTION )
1089 MesPrint(
"&Problems with argument of SizeOf_");
1090 else if ( x1 == NUMFACTORS )
1091 MesPrint(
"&Problems with argument of NumFactors_");
1093 MesPrint(
"&Problems with argument of FactorIn_");
1095 while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
1097 if ( *s == TFUNCLOSE ) s++;
1101 else if ( x1 == TERMSINEXPR || x1 == SIZEOFFUNCTION || x1 == FACTORIN
1102 || x1 == NUMFACTORS || x1 == FIRSTTERM || x1 == CONTENTTERM ) {
1103 if ( s[0] == TFUNOPEN && s[1] == TEXPRESSION )
goto doexpr;
1104 if ( s[0] == TFUNOPEN && s[1] == TDOLLAR ) {
1106 *t++ = x1; *t++ = FUNHEAD+2; *t++ = 0;
1108 x2 = 0;
while ( *s >= 0 ) { x2 = x2*128 + *s++; }
1109 *t++ = -DOLLAREXPRESSION; *t++ = x2;
1110 if ( *s != TFUNCLOSE ) {
1111 if ( x1 == TERMSINEXPR )
1112 MesPrint(
"&Problems with argument of TermsIn_");
1113 else if ( x1 == SIZEOFFUNCTION )
1114 MesPrint(
"&Problems with argument of SizeOf_");
1115 else if ( x1 == NUMFACTORS )
1116 MesPrint(
"&Problems with argument of NumFactors_");
1118 MesPrint(
"&Problems with argument of FactorIn_");
1120 while ( *s != TENDOFIT && *s != TFUNCLOSE ) s++;
1122 if ( *s == TFUNCLOSE ) s++;
1127 if ( inset && ( t-tsize == 2 ) ) x1 -= FUNCTION;
1128 if ( *s == TWILDCARD ) { x1 += WILDOFFSET; s++; }
1129 if ( functions[x3-FUNCTION].commute ) cc = 1;
1130 if ( *s != TFUNOPEN ) {
1131 *t++ = x1; *t++ = FUNHEAD; *t++ = 0;
1132 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1133 t[-1] |= MUSTCLEANPRF;
1134 FILLFUN3(t) sumlevel = 0;
goto fin;
1136 v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
1137 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1138 t[-1] |= MUSTCLEANPRF;
1141 if ( !inset && functions[x3-FUNCTION].spec >= TENSORFUNCTION ) {
1144 if ( needarg == 0 ) {
1147 if ( x3 >= FUNCTION+WILDOFFSET ) x3 -= WILDOFFSET;
1148 MesPrint(
"&Too many arguments in function %s",
1149 VARNAME(functions,(x3-FUNCTION)) );
1152 MesPrint(
"&d_ needs exactly two arguments");
1156 else if ( needarg > 0 ) needarg--;
1159 if ( c == TMINUS && *s == TVECTOR ) { sign = -sign; c = *s++; }
1160 base = ( c == TNUMBER ) ? 100: 128;
1161 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1162 if ( *s == TWILDCARD && c != TNUMBER ) { x2 += WILDOFFSET; s++; }
1163 if ( c == TSETNUM || c == TSETDOL ) {
1164 if ( c == TSETDOL ) x2 = -x2;
1166 w1 = t; t += 2; w2 = t;
1167 while ( w1 > v ) *--w2 = *--w1;
1168 tsize = v; relo = AT.WorkTop;
1169 *v++ = SETSET; *v++ = 0;
1171 inset = 2; *--relo = x2; *--relo = t - v;
1173 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1177 if ( t[-1]+AM.OffsetIndex > AM.IndDum ) {
1178 x2 = t[-1]+AM.OffsetIndex - AM.IndDum;
1185 if ( x2 >= 0 && x2 < AM.OffsetIndex ) {
1190 MesPrint(
"&Illegal type of set inside tensor");
1196 else {
switch ( c ) {
1198 if ( inset < 2 ) *t++ = x2 + AM.OffsetIndex;
1200 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1201 x2 = x2+AM.OffsetIndex - AM.IndDum;
1206 *t++ = AC.DumNum + WILDOFFSET;
1209 if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
1213 *t++ = FUNNYWILD; *t++ = x2;
1217 *t++ = FUNNYDOLLAR; *t++ = x2;
1220 if ( inset < 2 ) *t++ = x2 + AM.OffsetVector;
1224 if ( x3 != GAMMA ) {
1225 MesPrint(
"&5_,6_,7_ can only be used inside g_");
1232 if ( x2 >= AM.OffsetIndex && inset < 2 ) {
1233 MesPrint(
"&Value of constant index in tensor too large");
1239 MesPrint(
"&Illegal object in tensor");
1243 if ( inset >= 2 ) inset = 1;
1244 }
while ( *s == TCOMMA );
1247dofunction: firstsumarg = 1;
1252 if ( c == TMINUS && ( *s == TVECTOR || *s == TNUMBER
1253 || *s == TNUMBER1 || *s == TSUBEXP ) ) {
1254 minus = 1; c = *s++;
1257 base = ( c == TNUMBER ) ? 100: 128;
1258 ux2 = 0;
while ( *s >= 0 ) { ux2 = base*ux2 + *s++; }
1263 if ( firstsumarg ) {
1265 if ( sumlevel > 0 ) {
1266 if ( c == TSYMBOL ) {
1267 sumlevel = x2; sumtype = SYMTOSYM;
1269 else if ( c == TINDEX ) {
1270 sumlevel = x2+AM.OffsetIndex; sumtype = INDTOIND;
1271 if ( sumlevel > AM.IndDum ) {
1272 x2 = sumlevel - AM.IndDum;
1278 if ( *s == TWILDCARD ) {
1279 if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
1280 else if ( c != TNUMBER ) x2 += WILDOFFSET;
1285 *t++ = -SYMBOL; *t++ = x2;
break;
1287 *t++ = -DOLLAREXPRESSION; *t++ = x2;
break;
1289 *t++ = -EXPRESSION; *t++ = x2;
1295 if ( Expressions[x2].status == STOREDEXPRESSION ) {
1296 TMproto[0] = EXPRESSION;
1297 TMproto[1] = SUBEXPSIZE;
1300 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1301 AT.TMaddr = TMproto;
1318 if ( ( renumber = GetTable(x2,&position,0) ) == 0 ) {
1320 MesPrint(
"&Problems getting information about stored expression %s(2)"
1323 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1324 M_free(renumber->
symb.
lo,
"VarSpace");
1325 M_free(renumber,
"Renumber");
1326 AR.StoreData.dirtyflag = 1;
1330 *t++ = -INDEX; *t++ = x2 + AM.OffsetIndex;
1331 if ( t[-1] > AM.IndDum ) {
1332 x2 = t[-1] - AM.IndDum;
1337 *t++ = -INDEX; *t++ = AC.DumNum + WILDOFFSET;
1340 if ( minus ) *t++ = -MINVECTOR;
1341 else *t++ = -VECTOR;
1342 *t++ = x2 + AM.OffsetVector;
1345 MesPrint(
"&5_,6_,7_ can only be used inside g_");
1351 *t++ = -SYMBOL; *t++ = x2;
break;
1353 *t++ = -x2-FUNCTION;
1360 *t++ = -ARGWILD; *t++ = x2;
break;
1366 w1 = t; t += 2; w2 = t;
1367 while ( w1 > v ) *--w2 = *--w1;
1368 tsize = v; relo = AT.WorkTop;
1369 *v++ = SETSET; *v++ = 0;
1372 *--relo = x2; *--relo = t-v+1;
1374 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1377 (*relo)--; *t++ = -x2-1;
break;
1379 *t++ = -SYMBOL; *t++ = x2;
break;
1381 *t++ = -INDEX; *t++ = x2;
1382 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1383 x2 = x2+AM.OffsetIndex - AM.IndDum;
1388 *t++ = -VECTOR; *t++ = x2;
break;
1390 *t++ = -SNUMBER; *t++ = x2;
break;
1392 MesPrint(
"&Internal error 435");
1394 *t++ = -SYMBOL; *t++ = x2;
break;
1398 w2 = AC.ProtoType; i = w2[1];
1404 while ( --i >= 0 ) *t++ = *w2++;
1405 w1[ARGHEAD+3] = subexpbuffers[x2].subexpnum;
1406 w1[ARGHEAD+5] = subexpbuffers[x2].buffernum;
1407 if ( sumlevel > 0 ) {
1411 *t++ = sumtype; *t++ = 4;
1412 *t++ = sumlevel; *t++ = sumlevel;
1415 if ( minus ) *t++ = -3;
1420 if ( minus ) x2 = UnsignedToInt(-IntAbs(x2));
1425 MesPrint(
"&Illegal object in function");
1429 }
while ( *s == TCOMMA );
1431 if ( *s != TFUNCLOSE ) {
1432 MesPrint(
"&Illegal argument field for function. Expected )");
1446 x1 = 0;
while ( *s >= 0 ) x1 = 128*x1 + *s++;
1447 if ( *s == TWILDCARD ) s++;
1448 if ( *s == TDOT )
goto dovector;
1449 if ( *s == TFUNOPEN ) {
1452 v = t; *t++ = x1; *t++ = FUNHEAD; *t++ = DIRTYFLAG;
1453 if ( x1 == AR.PolyFun && AR.PolyFunType == 2 && AR.Eside != LHSIDE )
1454 t[-1] |= MUSTCLEANPRF;
1456 needarg = -1;
goto dofunction;
1458 *t++ = SYMBOL; *t++ = 4; *t++ = 0;
1459 if ( inset ) *relo = 2;
1462 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1463 if ( *s == TPOWER ) {
1465 base = ( c == TNUMBER ) ? 100: 128;
1466 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1467 if ( *s == TWILDCARD ) { x2 += 2*MAXPOWER; s++; }
1468 else if ( c == TSYMBOL ) x2 += 2*MAXPOWER;
1471 r = AC.ProtoType; n = r[1] - 5; r += 5;
1472 *t++ = SUBEXPRESSION; *t++ = r[-4];
1473 *t++ = subexpbuffers[x1].subexpnum;
1475 *t++ = subexpbuffers[x1].buffernum;
1477 if ( cbuf[subexpbuffers[x1].buffernum].CanCommu[subexpbuffers[x1].subexpnum] ) cc = 1;
1489 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1491 *t++ = EXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1; *t++ = deno;
1492 *t++ = 0; FILLSUB(t)
1498 if ( *s == TFUNOPEN ) {
1501 base = ( c == TNUMBER ) ? 100: 128;
1502 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1505 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
1508 *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetIndex;
1509 if ( t[-1] > AM.IndDum ) {
1510 x2 = t[-1] - AM.IndDum;
1515 *t++ = INDEX; *t++ = 3; *t++ = x2+AM.OffsetVector;
1518 *t++ = x2+FUNCTION; *t++ = 2;
break;
1521 if ( x2 >= AM.OffsetIndex || x2 < 0 ) {
1522 MesPrint(
"&Index as argument of expression has illegal value");
1525 *t++ = INDEX; *t++ = 3; *t++ = x2;
break;
1531 w1 = t; t += 2; w2 = t;
1532 while ( w1 > v ) *--w2 = *--w1;
1533 tsize = v; relo = AT.WorkTop;
1534 *v++ = SETSET; *v++ = 0;
1537 *--relo = x2; *--relo = t-v+2;
1539 x2 = 0;
while ( *s >= 0 ) x2 = 128*x2 + *s++;
1542 *relo -= 2; *t++ = -x2-1;
break;
1544 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1546 *t++ = INDEX; *t++ = 3; *t++ = x2;
1547 if ( x2+AM.OffsetIndex > AM.IndDum ) {
1548 x2 = x2+AM.OffsetIndex - AM.IndDum;
1553 *t++ = VECTOR; *t++ = 3; *t++ = x2;
break;
1555 *t++ = SNUMBER; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1557 MesPrint(
"&Internal error 435");
1559 *t++ = SYMBOL; *t++ = 4; *t++ = x2; *t++ = 1;
break;
1563 MesPrint(
"&Argument of expression can only be symbol, index, vector or function");
1567 }
while ( *s == TCOMMA );
1568 if ( *s != TFUNCLOSE ) {
1569 MesPrint(
"&Illegal object in argument field for expression");
1571 while ( *s != TFUNCLOSE ) s++;
1575 r = AC.ProtoType; n = r[1];
1576 if ( n > SUBEXPSIZE ) {
1577 *t++ = WILDCARDS; *t++ = n+2;
1585 if ( Expressions[x1].status == STOREDEXPRESSION ) {
1604 if ( ( renumber = GetTable(x1,&position,0) ) == 0 ) {
1606 MesPrint(
"&Problems getting information about stored expression %s(3)"
1609 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1610 M_free(renumber->
symb.
lo,
"VarSpace");
1611 M_free(renumber,
"Renumber");
1612 AR.StoreData.dirtyflag = 1;
1614 if ( *s == LBRACE ) {
1622 if ( *s != TSUBEXP ) {
1623 MesPrint(
"&Internal error 23");
1626 s++; x2 = 0;
while ( *s >= 0 ) { x2 = 128*x2 + *s++; }
1627 r = cbuf[subexpbuffers[x2].buffernum].rhs[subexpbuffers[x2].subexpnum];
1628 *t++ = FROMBRAC; *t++ = *r+2;
1632 MesPrint(
"&Object between [] in expression should be a single term");
1635 if ( *s != RBRACE ) {
1636 MesPrint(
"&Internal error 23b");
1641 if ( *s == TPOWER ) {
1643 base = ( c == TNUMBER ) ? 100: 128;
1644 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1645 if ( *s == TWILDCARD || c == TSYMBOL ) { x2 += 2*MAXPOWER; s++; }
1654 if ( *s == TPOWER ) {
1655 s++;
if ( *s == TMINUS ) { s++; deno = -deno; }
1656 c = *s++; base = ( c == TNUMBER ) ? 100: 128;
1657 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
1660 MesPrint(
"&Encountered 0^0 during compilation");
1664 MesPrint(
"&Division by zero during compilation (0 to the power negative number)");
1667 else if ( deno < 0 ) {
1669 MesPrint(
"&Division by zero during compilation");
1674 if ( *s >= 0 ) { y = 100*y + *s++; }
1675 innum[0] = y; nin = 1;
1678 if ( *s >= 0 ) { y = 100*y + *s++; x2 = 10000; }
1679 Product(innum,&nin,(WORD)x2);
1680 if ( y ) AddLong(innum,nin,(UWORD *)(&y),(WORD)1,innum,&nin);
1683 if ( *s == TPOWER ) {
1684 s++;
if ( *s == TMINUS ) { s++; deno = -deno; }
1685 c = *s++; base = ( c == TNUMBER ) ? 100: 128;
1686 x2 = 0;
while ( *s >= 0 ) { x2 = x2*base + *s++; }
1688 innum[0] = 1; nin = 1;
1690 else if ( RaisPow(BHEAD innum,&nin,x2) ) {
1691 error = -1; innum[0] = 1; nin = 1;
1695 Simplify(BHEAD innum,&nin,denominator,&ndenominator);
1696 for ( i = 0; i < nnumerator; i++ ) CGscrat7[i] = numerator[i];
1697 MulLong(innum,nin,CGscrat7,nnumerator,numerator,&nnumerator);
1699 else if ( deno < 0 ) {
1700 Simplify(BHEAD innum,&nin,numerator,&nnumerator);
1701 for ( i = 0; i < ndenominator; i++ ) CGscrat7[i] = denominator[i];
1702 MulLong(innum,nin,CGscrat7,ndenominator,denominator,&ndenominator);
1707 if ( *s == 0 ) { s++; sign = 0;
break; }
1709 if ( *s >= 0 ) { y = 128*y + *s++; }
1711 innum[0] = y; nin = 1;
1714 if ( *s >= 0 ) { y = 128*y + *s++; x2 = 16384; }
1715 Product(innum,&nin,(WORD)x2);
1716 if ( y ) AddLong(innum,nin,(UWORD *)&y,(WORD)1,innum,&nin);
1720 *relo = 2; *t++ = SNUMBER; *t++ = 4; *t++ = y;
1725 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1726 if ( AR.Eside != LHSIDE ) {
1727 *t++ = SUBEXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
1730 *t++ = DOLLAREXPRESSION; *t++ = SUBEXPSIZE; *t++ = x1;
1733 *t++ = AM.dbufnum; FILLSUB(t)
1737 if ( *s == LBRACE ) {
1740 while ( bracelevel > 0 ) {
1741 if ( *s == RBRACE ) {
1744 else if ( *s == TNUMBER ) {
1746 x2 = 0;
while ( *s >= 0 ) { x2 = 100*x2 + *s++; }
1747 *t++ = DOLLAREXPR2; *t++ = 3; *t++ = -x2-1;
1749 while ( bracelevel > 0 ) {
1750 if ( *s != RBRACE ) {
1753 MesPrint(
"&Improper use of [] in $-variable.");
1761 else if ( *s == TDOLLAR ) {
1763 x1 = 0;
while ( *s >= 0 ) { x1 = x1*128 + *s++; }
1764 *t++ = DOLLAREXPR2; *t++ = 3; *t++ = x1;
1765 if ( *s == RBRACE )
goto CloseBraces;
1766 else if ( *s == LBRACE ) {
1770 else goto ErrorBraces;
1776 if ( *s == TPOWER ) {
1778 if ( *s == TMINUS ) { s++; deno = -deno; }
1780 base = ( c == TNUMBER ) ? 100: 128;
1781 x2 = 0;
while ( *s >= 0 ) { x2 = base*x2 + *s++; }
1782 if ( c == TSYMBOL ) {
1783 if ( *s == TWILDCARD ) s++;
1786 *powplace = deno*x2;
1788 else *powplace = deno;
1799 inset = 1; tsize = t; relo = AT.WorkTop;
1800 *t++ = SETSET; *t++ = 0;
1801 x1 = 0;
while ( *s >= 0 ) x1 = x1*128 + *s++;
1802 *--relo = x1; *--relo = 0;
1805 inset = 1; tsize = t; relo = AT.WorkTop;
1806 *t++ = SETSET; *t++ = 0;
1807 x1 = 0;
while ( *s >= 0 ) x1 = x1*128 + *s++;
1808 *--relo = -x1; *--relo = 0;
1811 MesPrint(
"&Illegal use of function arguments");
1818 MesPrint(
"&Illegal use of function arguments");
1824 MesPrint(
"&Illegal use special gamma symbols 5_, 6_, 7_");
1830 MesPrint(
"&Internal error in code generator. Unknown object: %d",c);
1838 MesPrint(
"&Irregular end of statement.");
1841 if ( !first && error == 0 ) {
1844 if ( cc && sign ) C->
CanCommu[numexp]++;
1845 error = CompleteTerm(term,numerator,denominator,nnumerator,ndenominator,sign);
1847 AT.WorkPointer = oldwork;
1848 if ( error )
return(-1);
1850 if ( AC.CompileLevel > 0 && AR.Eside != LHSIDE ) {
1852 error = InsTree(AC.cbufnum,C->numrhs);
1853 if ( error < (C->numrhs) ) {
1860 MLOCK(ErrorMessageLock);
1862 MUNLOCK(ErrorMessageLock);
1874int CompleteTerm(WORD *term, UWORD *numer, UWORD *denom, WORD nnum, WORD nden,
int sign)
1878 if ( sign == 0 )
return(0);
1879 if ( nnum >= nden ) nsize = nnum;
1882 for ( i = 0; i < nnum; i++ ) *t++ = numer[i];
1883 for ( ; i < nsize; i++ ) *t++ = 0;
1884 for ( i = 0; i < nden; i++ ) *t++ = denom[i];
1885 for ( ; i < nsize; i++ ) *t++ = 0;
1886 *t++ = (2*nsize+1)*sign;
1888 AddNtoC(AC.cbufnum,*term,term,7);
1911int CodeFactors(SBYTE *tokens)
1914 EXPRESSIONS e = Expressions + AR.CurExpr;
1915 int nfactor = 1, nparenthesis, i, last = 0, error = 0;
1916 SBYTE *t, *startobject, *tt, *s1, *out, *outtokens;
1917 WORD nexp, subexp = 0, power, pow, x2, powfactor, first;
1922 while ( *t != TENDOFIT ) {
1923 if ( *t >= 0 ) {
while ( *t >= 0 ) t++;
continue; }
1924 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
1925 nparenthesis = 0; t++;
1926 while ( nparenthesis >= 0 ) {
1927 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
1928 else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
1933 else if ( ( *t == TPLUS || *t == TMINUS ) && ( t > tokens )
1934 && ( t[-1] != TPLUS && t[-1] != TMINUS ) ) {
1935 if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
1936 || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
1937 subexp = CodeGenerator(tokens);
1938 if ( subexp < 0 ) error = -1;
1939 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
1940 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
1943 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
1944 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
1945 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(SUBBUF),
"subexpbuffers");
1947 subexpbuffers[insubexpbuffers].subexpnum = subexp;
1948 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
1949 subexp = insubexpbuffers++;
1951 *t++ = TSYMBOL; *t++ = FACTORSYMBOL;
1952 *t++ = TMULTIPLY; *t++ = TSUBEXP;
1953 PUTNUMBER128(t,subexp)
1956 e->vflags |= ISFACTORIZED;
1960 else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && t > tokens ) {
1963 else if ( *t == TEXPRESSION ) {
1965 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
1966 if ( *t == LBRACE )
continue;
1967 if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) != 0 ) {
1968 nfactor += AS.OldNumFactors[nexp];
1973 else if ( *t == TDOLLAR ) {
1975 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
1976 if ( *t == LBRACE )
continue;
1977 if ( Dollars[nexp].nfactors > 0 ) {
1978 nfactor += Dollars[nexp].nfactors;
1989 outtokens = (SBYTE *)Malloc1(((t-tokens)+(nfactor+2)*25)*
sizeof(SBYTE),
"CodeFactors");
1991 t = tokens; first = 1; powfactor = 1;
1992 while ( *t == TPLUS || *t == TMINUS ) {
if ( *t == TMINUS ) first = -first; t++; }
1994 *out++ = TMINUS; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
1995 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
1998 startobject = t; power = 1;
1999 while ( *t != TENDOFIT ) {
2000 if ( *t >= 0 ) {
while ( *t >= 0 ) t++;
continue; }
2001 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) {
2002 nparenthesis = 0; t++;
2003 while ( nparenthesis >= 0 ) {
2004 if ( *t == LPARENTHESIS || *t == LBRACE || *t == TSETOPEN || *t == TFUNOPEN ) nparenthesis++;
2005 else if ( *t == RPARENTHESIS || *t == RBRACE || *t == TSETCLOSE || *t == TFUNCLOSE ) nparenthesis--;
2010 else if ( ( *t == TMULTIPLY || *t == TDIVIDE ) && ( t > tokens ) ) {
2011 if ( t[-1] >= 0 || t[-1] == RPARENTHESIS || t[-1] == RBRACE
2012 || t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
2014 if ( startobject ) {
2016 if ( power < 0 ) { *out++ = TNUMBER; *out++ = 1; *out++ = TDIVIDE; }
2018 while ( s1 < t ) *out++ = *s1++;
2019 *out++ = TMULTIPLY; *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2020 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2023 if ( last ) { startobject = 0;
break; }
2025 if ( *t == TDIVIDE ) power = -1;
2026 if ( *t == TMULTIPLY ) power = 1;
2029 else if ( *t == TPOWER ) {
2032 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2033 if ( *tt == TMINUS ) pow = -pow;
2036 if ( *tt == TSYMBOL ) {
2037 tt++;
while ( *tt >= 0 ) tt++;
2040 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2045 power = power*pow*x2;
2046 if ( power < 0 ) { pow = -power; power = -1; }
2047 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2048 else { pow = power; power = 1; }
2051 subexp = GenerateFactors(pow,1);
2052 if ( subexp < 0 ) { error = -1; subexp = 0; }
2053 *out++ = TSUBEXP; PUTNUMBER128(out,subexp);
2055 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2056 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2058 if ( power > 0 ) *out++ = TMULTIPLY;
2059 else *out++ = TDIVIDE;
2060 s1 = startobject;
while ( s1 < t ) *out++ = *s1++;
2061 startobject = 0; t = tt;
continue;
2063 else if ( *t == TEXPRESSION ) {
2066 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
2067 if ( *t == LBRACE )
continue;
2068 if ( *t == LPARENTHESIS ) {
2069 nparenthesis = 0; t++;
2070 while ( nparenthesis >= 0 ) {
2071 if ( *t == LPARENTHESIS ) nparenthesis++;
2072 else if ( *t == RPARENTHESIS ) nparenthesis--;
2076 if ( ( AS.Oldvflags[nexp] & ISFACTORIZED ) == 0 )
continue;
2077 if ( *t == TPOWER ) {
2080 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2081 if ( *tt == TMINUS ) pow = -pow;
2084 if ( *tt != TNUMBER ) {
2085 MesPrint(
"Internal problems(1) in CodeFactors");
2088 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2094 power = power*pow*x2;
2095 if ( power < 0 ) { pow = -power; power = -1; }
2096 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2097 else { pow = power; power = 1; }
2100 subexp = GenerateFactors(pow,AS.OldNumFactors[nexp]);
2101 if ( subexp < 0 ) { error = -1; subexp = 0; }
2102 *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
2107 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2109 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,i)
2113 powfactor += AS.OldNumFactors[nexp]*pow;
2115 while ( s1 < t ) *out++ = *s1++;
2116 startobject = 0; t = tt;
continue;
2119 tt = t; pow = 1; x2 = 1;
goto dopower;
2122 else if ( *t == TDOLLAR ) {
2125 nexp = 0;
while ( *t >= 0 ) { nexp = nexp*128 + *t++; }
2126 if ( *t == LBRACE )
continue;
2127 if ( Dollars[nexp].nfactors == 0 )
continue;
2128 if ( *t == TPOWER ) {
2131 while ( ( *tt == TMINUS ) || ( *tt == TPLUS ) ) {
2132 if ( *tt == TMINUS ) pow = -pow;
2135 if ( *tt != TNUMBER ) {
2136 MesPrint(
"Internal problems(2) in CodeFactors");
2139 tt++; x2 = 0;
while ( *tt >= 0 ) { x2 = 100*x2 + *tt++; }
2145 power = power*pow*x2;
2146 if ( power < 0 ) { pow = -power; power = -1; }
2147 else if ( power == 0 ) { t = tt; startobject = tt;
continue; }
2148 else { pow = power; power = 1; }
2150 subexp = GenerateFactors(pow,1);
2151 if ( subexp < 0 ) { error = -1; subexp = 0; }
2153 for ( i = 1; i <= Dollars[nexp].nfactors; i++ ) {
2154 s1 = startobject; *out++ = TPLUS;
2155 while ( s1 < t ) *out++ = *s1++;
2156 *out++ = LBRACE; *out++ = TNUMBER; PUTNUMBER128(out,i)
2159 *out++ = TSYMBOL; *out++ = FACTORSYMBOL;
2160 *out++ = TPOWER; *out++ = TNUMBER; PUTNUMBER100(out,powfactor)
2163 *out++ = TSUBEXP; PUTNUMBER128(out,subexp)
2166 startobject = 0; t = tt;
continue;
2169 tt = t; pow = 1; x2 = 1;
goto dopowerd;
2174 if ( last == 0 ) { last = 1;
goto dolast; }
2176 e->numfactors = powfactor-1;
2177 e->vflags |= ISFACTORIZED;
2178 subexp = CodeGenerator(outtokens);
2179 if ( subexp < 0 ) error = -1;
2180 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
2181 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
2184 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
2185 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
2186 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(SUBBUF),
"subexpbuffers");
2188 subexpbuffers[insubexpbuffers].subexpnum = subexp;
2189 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
2190 subexp = insubexpbuffers++;
2191 M_free(outtokens,
"CodeFactors");
2193 *s1++ = TSUBEXP; PUTNUMBER128(s1,subexp); *s1++ = TENDOFIT;
2194 if ( error < 0 )
return(-1);
2195 else return(subexp);
2208WORD GenerateFactors(WORD n,WORD inc)
2213 SBYTE *tokenbuffer = (SBYTE *)Malloc1(8*n*
sizeof(SBYTE),
"GenerateFactors");
2215 *s++ = TNUMBER; *s++ = 1;
2216 for ( i = inc; i < n*inc; i += inc ) {
2217 *s++ = TPLUS; *s++ = TSYMBOL; *s++ = FACTORSYMBOL;
2219 *s++ = TPOWER; *s++ = TNUMBER;
2224 subexp = CodeGenerator(tokenbuffer);
2225 if ( subexp < 0 ) error = -1;
2226 M_free(tokenbuffer,
"GenerateFactors");
2227 if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
2228 MesPrint(
"&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
2231 if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
2232 DoubleBuffer((
void **)((VOID *)(&subexpbuffers))
2233 ,(
void **)((VOID *)(&topsubexpbuffers)),
sizeof(SUBBUF),
"subexpbuffers");
2235 subexpbuffers[insubexpbuffers].subexpnum = subexp;
2236 subexpbuffers[insubexpbuffers].buffernum = AC.cbufnum;
2237 subexp = insubexpbuffers++;
2238 if ( error < 0 )
return(error);
struct FuNcTiOn * FUNCTIONS
struct ReNuMbEr * RENUMBER