53 if ( nametree->
namenode == 0 )
return(0);
60 else if ( i > 0 ) newnode = n->
right;
62 }
while ( newnode >= 0 );
71 int AddName(
NAMETREE *nametree, UBYTE *name, WORD type, WORD number,
int *nodenum)
75 LONG *c1,*c2, j, newsize;
76 int node, newnode, node3, r, rr = 0, i, retval = 0;
78 s = name; i = 1;
while ( *s ) { i++; s++; }
82 "new nametree in AddName");
84 "new namebuffer in AddName");
98 while ( *s ) *ss++ = *s++;
108 newnode = n->
left; r = -1;
111 newnode = n->
right; r = 1;
113 }
while ( newnode >= 0 );
119 if ( newsize > MAXINNAMETREE ) newsize = MAXINNAMETREE;
120 if ( nametree->
nodefill >= MAXINNAMETREE ) {
121 MesPrint(
"!!!More than %l names in one object",(LONG)MAXINNAMETREE);
125 "extra names in AddName");
126 c1 = (LONG *)nnn; c2 = (LONG *)nametree->
namenode;
128 while ( --i >= 0 ) *c1++ = *c2++;
129 M_free(nametree->
namenode,
"nametree->namenode");
134 *nodenum = newnode = nametree->
nodefill++;
137 if ( r < 0 ) n->
left = newnode;
else n->
right = newnode;
142 i = 1; s = name;
while ( *s ) { i++; s++; }
144 sss = (UBYTE *)Malloc1(2*nametree->
namesize,
145 "extra names in AddName");
147 while ( --j >= 0 ) *s++ = *ss++;
148 M_free(nametree->
namebuffer,
"nametree->namebuffer");
156 while ( *name ) *s++ = *name++;
161 while ( node >= 0 ) {
163 if ( newnode == n->
left ) rr = -1;
166 else if ( n->
balance == rr )
break;
171 if ( node < 0 )
return(retval);
208 if ( node == nn->
left ) nn->
left = node3;
209 else nn->
right = node3;
213 else if ( nn->
balance == rr ) {
225 if ( node == nnn->
left ) nnn->
left = newnode;
226 else nnn->
right = newnode;
233 MesPrint(
"We ran into an impossible case in AddName\n");
252 int GetName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
255 int node, newnode, i;
264 else if ( i > 0 ) newnode = n->
right;
269 }
while ( newnode >= 0 );
272 if ( s > name && s[-1] ==
'_' && nametree == AC.varnames ) {
276 if ( s == name+2 && ( *name ==
'd' || *name ==
'D' ) ) {
277 *number = DELTA-FUNCTION;
283 if ( s > name+2 && *name ==
'N' ) {
285 while ( FG.cTable[*t] == 1 ) i = 10*i + *t++ -
'0';
287 *number = i + AM.IndDum - AM.OffsetIndex;
300 else if ( i > 0 ) newnode = n->
right;
304 }
while ( newnode >= 0 );
311 t = name; u = AC.extrasym;
312 while ( *t == *u ) { t++; u++; }
313 if ( *u == 0 && *t != 0 ) {
315 while ( FG.cTable[*t] == 1 ) {
316 x = 10*x + (*t++ -
'0');
318 if ( *t ==
'_' && x > 0 && x <= cbuf[AM.sbufnum].numrhs ) {
319 *number = MAXVARIABLES-x;
325 if ( par != WITHAUTO || nametree == AC.autonames )
return(NAMENOTFOUND);
326 return(GetAutoName(name,number));
340 UBYTE *GetFunction(UBYTE *s,WORD *funnum)
346 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
348 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
352 MesPrint(
"&%s is undefined",s);
353 numfun = AddDollar(s+1,DOLINDEX,&one,1);
360 if ( ( ( type = GetName(AC.varnames,s,&numfun,WITHAUTO) ) != CFUNCTION )
361 || ( functions[numfun].spec != 0 ) ) {
362 MesPrint(
"&%s should be a regular function",s);
365 if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
366 AddFunction(s,0,0,0,0,0,-1,-1);
371 *funnum = numfun+FUNCTION;
386 UBYTE *GetNumber(UBYTE *s,WORD *num)
391 while ( *s ==
'+' ) s++;
393 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
395 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
399 MesPrint(
"&%s is undefined",s);
400 numfun = AddDollar(s+1,DOLINDEX,&one,1);
404 else if ( *s >=
'0' && *s <=
'9' ) {
405 ULONG x = *s++ -
'0';
406 while ( *s >=
'0' && *s <=
'9' ) { x = 10*x + (*s++-
'0'); }
408 if ( x >= MAXPOSITIVE )
goto illegal;
413 if ( *s ==
'-' ) { s++; }
414 if ( *s >=
'0' && *s <=
'9' ) {
while ( *s >=
'0' && *s <=
'9' ) s++; t1 = s; }
415 else { t1 = SkipAName(s); }
418 MesPrint(
"&Illegal option in Canonicalize statement. Should be a nonnegative number or $ variable.");
436 int GetLastExprName(UBYTE *name, WORD *number)
440 for ( i = NumExpressions; i > 0; i-- ) {
442 if ( StrCmp(AC.exprnames->namebuffer+e->name,name) == 0 ) {
458 int GetOName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
460 int retval = GetName(nametree,name,number,par);
462 case CVECTOR: *number += AM.OffsetVector;
break;
463 case CINDEX: *number += AM.OffsetIndex;
break;
464 case CFUNCTION: *number += FUNCTION;
break;
477 int GetAutoName(UBYTE *name, WORD *number)
481 if ( GetName(AC.exprnames,name,number,NOAUTO) != NAMENOTFOUND )
482 return(NAMENOTFOUND);
484 while ( *s ) { s++; }
485 if ( s[-1] ==
'_' ) {
486 return(NAMENOTFOUND);
490 type = GetName(AC.autonames,name,number,NOAUTO);
495 *number = AddSymbol(name,sym->minpower,sym->maxpower,sym->complex,sym->dimension);
499 *number = AddVector(name,vec->complex,vec->dimension);
503 *number = AddIndex(name,ind->dimension,ind->nmin4);
514 return(NAMENOTFOUND);
522 int GetVar(UBYTE *name, WORD *type, WORD *number,
int wantedtype,
int par)
526 if ( ( typ = GetName(AC.varnames,name,number,par) ) != wantedtype ) {
527 if ( typ != NAMENOTFOUND ) {
528 if ( wantedtype == -1 ) {
532 NameConflict(typ,name);
533 MakeDubious(AC.varnames,name,&funnum);
536 if ( ( typ = GetName(AC.exprnames,name,&funnum,par) ) != NAMENOTFOUND ) {
537 if ( typ == wantedtype || wantedtype == -1 ) {
538 *number = funnum; *type = typ;
return(1);
540 NameConflict(typ,name);
543 return(NAMENOTFOUND);
545 if ( typ == -1 ) {
return(0); }
555 WORD EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
559 return(AddSymbol(name,y,z,x,d));
562 return(AddIndex(name,x,z));
565 return(AddVector(name,x,d));
568 return(AddFunction(name,y,z,x,0,d,-1,-1));
571 AC.SetList.numtemp++;
572 return(AddSet(name,d));
575 return(AddExpression(name,x,y));
588 int GetDollar(UBYTE *name)
591 if ( GetName(AC.dollarnames,name,&number,NOAUTO) == NAMENOTFOUND )
return(-1);
604 DumpNode(nametree,nametree->
headnode,0);
613 VOID DumpNode(
NAMETREE *nametree, WORD node, WORD depth)
619 if ( n->
left >= 0 ) DumpNode(nametree,n->
left,depth+1);
620 for ( i = 0; i < depth; i++ ) printf(
" ");
622 printf(
"%s(%d): {%d}(%d)(%d)[%d]\n",
624 if ( n->
right >= 0 ) DumpNode(nametree,n->
right,depth+1);
632 int CompactifyTree(
NAMETREE *nametree,WORD par)
639 for ( i = 0, j = 0, k = 0, n = nametree->
namenode, ns = 0;
640 i < nametree->nodefill; i++, n++ ) {
641 if ( n->
type != CDELETE ) {
643 while ( *s ) { s++; ns++; }
648 if ( k == 0 )
return(0);
663 if ( j < 10 ) j = 10;
664 if ( ns < 100 ) ns = 100;
667 newtree.
namebuffer = (UBYTE *)Malloc1(2*ns,
"compactify namestree");
669 CopyTree(&newtree,nametree,nametree->
headnode,par);
671 LinkTree(&newtree,(WORD)0,newtree.
nodefill);
673 M_free(nametree->
namebuffer,
"nametree->namebuffer");
674 M_free(nametree->
namenode,
"nametree->namenode");
699 if ( n->
left >= 0 ) CopyTree(newtree,oldtree,n->
left,par);
700 if ( n->
type != CDELETE ) {
709 if ( par == AUTONAMES ) {
719 if ( par == AUTONAMES ) {
729 if ( par == AUTONAMES ) {
739 if ( par == AUTONAMES ) {
765 MesPrint(
"Illegal variable type in CopyTree: %d",n->
type);
771 while ( *t ) { *s++ = *t++; newtree->
namefill++; }
774 if ( n->
right >= 0 ) CopyTree(newtree,oldtree,n->
right,par);
782 VOID LinkTree(
NAMETREE *
tree, WORD offset, WORD numnodes)
787 int med,numleft,numright,medleft,medright;
790 numright = numnodes - med - 1;
791 medleft = numleft >> 1;
792 medright = ( numright >> 1 ) + med + 1;
797 if ( numright > 0 ) {
801 if ( numleft > 0 ) LinkTree(tree,offset,numleft);
802 if ( numright > 0 ) LinkTree(tree,offset+med+1,numright);
803 while ( numleft && numright ) { numleft >>= 1; numright >>= 1; }
837 M_free(n,
"nametree");
847 void ClearWildcardNames()
849 AC.NumWildcardNames = 0;
852 int AddWildcardName(UBYTE *name)
855 int size = 0, tocopy, i;
856 UBYTE *s = name, *t, *newbuffer;
857 while ( *s ) { s++; size++; }
858 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
860 while ( ( *s == *t ) && *s ) { s++; t++; }
861 if ( *s == 0 && *t == 0 )
return(i+1);
865 tocopy = t - AC.WildcardNames;
866 if ( tocopy + size + 1 > AC.WildcardBufferSize ) {
867 if ( AC.WildcardBufferSize == 0 ) {
868 AC.WildcardBufferSize = size+1;
869 if ( AC.WildcardBufferSize < 100 ) AC.WildcardBufferSize = 100;
871 else if ( size+1 >= AC.WildcardBufferSize ) {
872 AC.WildcardBufferSize += size+1;
875 AC.WildcardBufferSize *= 2;
877 newbuffer = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
879 if ( AC.WildcardNames ) {
880 s = AC.WildcardNames;
881 while ( tocopy > 0 ) { *t++ = *s++; tocopy--; }
882 M_free(AC.WildcardNames,
"AC.WildcardNames");
884 AC.WildcardNames = newbuffer;
885 M_free(AT.WildArgTaken,
"AT.WildArgTaken");
886 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
887 ,
"argument list names");
890 while ( *s ) *t++ = *s++;
892 AC.NumWildcardNames++;
893 return(AC.NumWildcardNames);
896 int GetWildcardName(UBYTE *name)
900 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
902 while ( ( *s == *t ) && *s ) { s++; t++; }
903 if ( *s == 0 && *t == 0 )
return(i+1);
918 int AddSymbol(UBYTE *name,
int minpow,
int maxpow,
int cplx,
int dim)
920 int nodenum, numsymbol = AC.Symbols->num;
923 bzero(sym,
sizeof(
struct SyMbOl));
924 sym->name = AddName(*AC.activenames,name,CSYMBOL,numsymbol,&nodenum);
925 sym->minpower = minpow;
926 sym->maxpower = maxpow;
932 sym->namesize = (s-name)+1;
944 int CoSymbol(UBYTE *s)
946 int type, error = 0, minpow, maxpow, cplx, sgn, dim;
948 UBYTE *name, *oldc, c, cc;
955 if ( ( s = SkipAName(s) ) == 0 ) {
956 IllForm: MesPrint(
"&Illegally formed name in symbol statement");
958 s = SkipField(name,0);
961 oldc = s; cc = c = *s; *s = 0;
962 if ( TestName(name) ) { *s = c;
goto IllForm; }
965 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
966 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
967 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
968 else if ( ( ( *s ==
'-' || *s ==
'+' || *s ==
'=' )
969 && ( s[1] >=
'0' && s[1] <=
'9' ) )
970 || ( *s >=
'0' && *s <=
'9' ) ) {
973 if ( *s ==
'-' ) { sgn = VARTYPEMINUS; s++; }
974 else if ( *s ==
'+' || *s ==
'=' ) { sgn = 0; s++; }
976 while ( s[1] >=
'0' && s[1] <=
'9' ) {
977 x = 10*x + (s[1] -
'0'); s++;
979 if ( x >= MAXPOWER || x <= 1 ) {
980 MesPrint(
"&Illegal value for root of unity %s",name);
986 cplx = VARTYPEROOTOFUNITY | sgn;
989 MesPrint(
"&Illegal specification for complexity of symbol %s",name);
999 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1001 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1002 ParseSignedNumber(dim,s)
1003 if ( dim < -HALFMAX || dim > HALFMAX ) {
1004 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1008 if ( *s !=
'}' )
goto IllDim;
1012 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1020 if ( ( cplx & VARTYPEROOTOFUNITY ) == VARTYPEROOTOFUNITY ) {
1021 MesPrint(
"&Root of unity property for %s cannot be combined with power restrictions",name);
1025 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1026 ParseSignedNumber(minpow,s)
1027 if ( minpow < -MAXPOWER ) {
1030 MesPrint(
"&Warning: minimum power of %s corrected to %d"
1040 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1041 ParseSignedNumber(maxpow,s)
1042 if ( maxpow > MAXPOWER ) {
1045 MesPrint(
"&Warning: maximum power of %s corrected to %d"
1049 if ( *s !=
')' )
goto skippar;
1052 if ( ( AC.AutoDeclareFlag == 0 &&
1053 ( ( type = GetName(AC.exprnames,name,&numsymbol,NOAUTO) )
1055 || ( ( type = GetName(*(AC.activenames),name,&numsymbol,NOAUTO) ) != NAMENOTFOUND ) ) {
1056 if ( type != CSYMBOL ) error = NameConflict(type,name);
1059 if ( ( numsymbol == AC.lPolyFunVar ) && ( AC.lPolyFunType > 0 )
1060 && ( AC.lPolyFun != 0 ) && ( minpow > -MAXPOWER || maxpow < MAXPOWER ) ) {
1061 MesPrint(
"&The symbol %s is used by power expansions in the PolyRatFun!",name);
1064 sym->complex = cplx;
1065 sym->minpower = minpow;
1066 sym->maxpower = maxpow;
1067 sym->dimension= dim;
1071 AddSymbol(name,minpow,maxpow,cplx,dim);
1074 eol:
while ( *s ==
',' ) s++;
1086 int AddIndex(UBYTE *name,
int dim,
int dim4)
1088 int nodenum, numindex = AC.Indices->num;
1091 bzero(ind,
sizeof(
struct InDeX));
1092 ind->name = AddName(*AC.activenames,name,CINDEX,numindex,&nodenum);
1094 ind->dimension = dim;
1097 ind->node = nodenum;
1099 ind->namesize = (s-name)+1;
1110 int CoIndex(UBYTE *s)
1112 int type, error = 0, dim, dim4;
1114 UBYTE *name, *oldc, c;
1119 if ( ( s = SkipAName(s) ) == 0 ) {
1120 IllForm: MesPrint(
"&Illegally formed name in index statement");
1122 s = SkipField(name,0);
1125 oldc = s; c = *s; *s = 0;
1126 if ( TestName(name) ) { *s = c;
goto IllForm; }
1129 if ( ( s = DoDimension(s,&dim,&dim4) ) == 0 ) {
1132 s = SkipField(name,0);
1136 if ( ( AC.AutoDeclareFlag == 0 &&
1137 ( ( type = GetName(AC.exprnames,name,&numindex,NOAUTO) )
1139 || ( ( type = GetName(*(AC.activenames),name,&numindex,NOAUTO) ) != NAMENOTFOUND ) ) {
1140 if ( type != CINDEX ) error = NameConflict(type,name);
1142 indices[numindex].dimension = dim;
1143 indices[numindex].nmin4 = dim4;
1146 else AddIndex(name,dim,dim4);
1148 eol:
while ( *s ==
',' ) s++;
1158 UBYTE *DoDimension(UBYTE *s,
int *dim,
int *dim4)
1161 int type, error = 0;
1163 NAMETREE **oldtree = AC.activenames;
1164 *dim4 = -NMIN4SHIFT;
1165 if ( FG.cTable[*s] == 1 ) {
1168 #if ( BITSINWORD/8 < 4 )
1169 if ( *dim >= (1 << (BITSINWORD-1)) )
goto illeg;
1174 else if ( ( (FG.cTable[*s] == 0 ) || ( *s ==
'[' ) )
1175 && ( s = SkipAName(s) ) != 0 ) {
1176 AC.activenames = &(AC.varnames);
1178 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1179 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1180 if ( type != CSYMBOL ) error = NameConflict(type,t);
1183 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1184 if ( *oldtree != AC.autonames && AC.WarnFlag )
1185 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1188 if ( ( *s = c ) ==
':' ) {
1191 if ( ( s = SkipAName(s) ) == 0 )
goto illeg;
1192 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1193 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1194 if ( type != CSYMBOL ) error = NameConflict(type,t);
1197 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1198 if ( *oldtree != AC.autonames && AC.WarnFlag )
1199 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1201 *dim4 = -numsymbol-NMIN4SHIFT;
1204 else if ( *s ==
'+' && FG.cTable[s[1]] == 1 ) {
1208 illeg: MesPrint(
"&Illegal dimension specification. Should be number >= 0, symbol or symbol:symbol");
1211 AC.activenames = oldtree;
1212 if ( error )
return(0);
1221 int CoDimension(UBYTE *s)
1223 s = DoDimension(s,&AC.lDefDim,&AC.lDefDim4);
1224 if ( s == 0 )
return(1);
1226 MesPrint(
"&Argument of dimension statement should be number >= 0, symbol or symbol:symbol");
1239 int AddVector(UBYTE *name,
int cplx,
int dim)
1241 int nodenum, numvector = AC.Vectors->num;
1244 bzero(v,
sizeof(
struct VeCtOr));
1245 v->name = AddName(*AC.activenames,name,CVECTOR,numvector,&nodenum);
1251 v->namesize = (s-name)+1;
1262 int CoVector(UBYTE *s)
1264 int type, error = 0, dim;
1266 UBYTE *name, c, *endname;
1270 if ( ( s = SkipAName(s) ) == 0 ) {
1271 IllForm: MesPrint(
"&Illegally formed name in vector statement");
1276 c = *s; *s = 0, endname = s;
1277 if ( TestName(name) ) { *s = c;
goto IllForm; }
1280 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1282 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1283 ParseSignedNumber(dim,s)
1284 if ( dim < -HALFMAX || dim > HALFMAX ) {
1285 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1289 if ( *s !=
'}' )
goto IllDim;
1293 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1296 while ( *s ==
',' ) s++;
1300 if ( ( AC.AutoDeclareFlag == 0 &&
1301 ( ( type = GetName(AC.exprnames,name,&numvector,NOAUTO) )
1303 || ( ( type = GetName(*(AC.activenames),name,&numvector,NOAUTO) ) != NAMENOTFOUND ) ) {
1304 if ( type != CVECTOR ) error = NameConflict(type,name);
1306 else AddVector(name,0,dim);
1309 while ( *s ==
',' ) s++;
1321 int AddFunction(UBYTE *name,
int comm,
int istensor,
int cplx,
int symprop,
int dim,
int argmax,
int argmin)
1323 int nodenum, numfunction = AC.Functions->num;
1326 bzero(fun,
sizeof(
struct FuNcTiOn));
1327 fun->
name = AddName(*AC.activenames,name,CFUNCTION,numfunction,&nodenum);
1329 fun->
spec = istensor;
1333 fun->
node = nodenum;
1336 fun->dimension = dim;
1337 fun->maxnumargs = argmax;
1338 fun->minnumargs = argmin;
1341 return(numfunction);
1351 int CoCommuteInSet(UBYTE *s)
1353 UBYTE *name, *ss, c, *start = s;
1354 WORD number, type, *g, *gg;
1355 int error = 0, i, len = StrLen(s), len2 = 0;
1356 if ( AC.CommuteInSet != 0 ) {
1357 g = AC.CommuteInSet;
1358 while ( *g ) g += *g;
1359 len2 = g - AC.CommuteInSet;
1360 if ( len2+len+3 > AC.SizeCommuteInSet ) {
1361 gg = (WORD *)Malloc1((len2+len+3)*
sizeof(WORD),
"CommuteInSet");
1362 for ( i = 0; i < len2; i++ ) gg[i] = AC.CommuteInSet[i];
1364 M_free(AC.CommuteInSet,
"CommuteInSet");
1365 AC.CommuteInSet = gg;
1366 AC.SizeCommuteInSet = len+len2+3;
1367 g = AC.CommuteInSet+len2;
1371 AC.SizeCommuteInSet = len+2;
1372 g = AC.CommuteInSet = (WORD *)Malloc1((len+3)*
sizeof(WORD),
"CommuteInSet");
1378 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1380 if ( s - start >= len )
break;
1385 MesPrint(
"&There should be at least two noncommuting functions or tensors in a commuting statement.");
1388 else if ( *gg == 2 ) {
1389 gg[2] = gg[1]; gg[3] = 0; gg[0] = 3;
1396 MesPrint(
"&The CommuteInSet statement should have sets enclosed in {}.");
1408 if ( ( type = GetName(AC.varnames,name,&number,NOAUTO) ) != CFUNCTION ) {
1409 MesPrint(
"&%s is not a function or tensor",name);
1412 else if ( functions[number].commute == 0 ){
1413 MesPrint(
"&%s is not a noncommuting function or tensor",name);
1417 *g++ = number+FUNCTION;
1418 functions[number].flags |= COULDCOMMUTE;
1419 if ( number+FUNCTION >= GAMMA && number+FUNCTION <= GAMMASEVEN ) {
1420 functions[GAMMA-FUNCTION].flags |= COULDCOMMUTE;
1421 functions[GAMMAI-FUNCTION].flags |= COULDCOMMUTE;
1422 functions[GAMMAFIVE-FUNCTION].flags |= COULDCOMMUTE;
1423 functions[GAMMASIX-FUNCTION].flags |= COULDCOMMUTE;
1424 functions[GAMMASEVEN-FUNCTION].flags |= COULDCOMMUTE;
1441 int CoFunction(UBYTE *s,
int comm,
int istensor)
1443 int type, error = 0, cplx, symtype, dim, argmax, argmin;
1444 WORD numfunction, reverseorder = 0, addone;
1445 UBYTE *name, *oldc, *par, c, cc;
1447 symtype = cplx = 0, argmin = argmax = -1;
1450 if ( ( s = SkipAName(s) ) == 0 ) {
1451 IllForm: MesPrint(
"&Illegally formed function/tensor name");
1453 s = SkipField(name,0);
1456 oldc = s; cc = c = *s; *s = 0;
1457 if ( TestName(name) ) { *s = c;
goto IllForm; }
1460 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
1461 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
1462 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
1464 MesPrint(
"&Illegal specification for complexity of %s",name);
1474 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1476 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1477 ParseSignedNumber(dim,s)
1478 if ( dim < -HALFMAX || dim > HALFMAX ) {
1479 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1483 if ( *s !=
'}' )
goto IllDim;
1487 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1497 reverseorder = REVERSEORDER;
1504 while ( FG.cTable[*s] == 0 ) s++;
1508 MesPrint(
"&Illegal specification for symmetry of %s",name);
1514 if ( StrICont(par,(UBYTE *)
"symmetric") == 0 ) symtype = SYMMETRIC;
1515 else if ( StrICont(par,(UBYTE *)
"antisymmetric") == 0 ) symtype = ANTISYMMETRIC;
1516 else if ( ( StrICont(par,(UBYTE *)
"cyclesymmetric") == 0 )
1517 || ( StrICont(par,(UBYTE *)
"cyclic") == 0 ) ) symtype = CYCLESYMMETRIC;
1518 else if ( ( StrICont(par,(UBYTE *)
"rcyclesymmetric") == 0 )
1519 || ( StrICont(par,(UBYTE *)
"rcyclic") == 0 )
1520 || ( StrICont(par,(UBYTE *)
"reversecyclic") == 0 ) ) symtype = RCYCLESYMMETRIC;
1523 if ( *s !=
')' || ( s[1] && s[1] !=
',' && s[1] !=
'<' ) ) {
1524 Warning(
"&Excess information in symmetric properties currently ignored");
1528 symtype |= reverseorder;
1534 if ( *s ==
'=' ) { addone++; s++; }
1536 while ( FG.cTable[*s] == 1 ) { argmax = 10*argmax + *s++ -
'0'; }
1539 while ( FG.cTable[*s] == 0 ) s++;
1542 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1543 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1545 Warning(
"&Illegal information in number of arguments properties currently ignored");
1550 if ( argmax <= 0 ) {
1551 MesPrint(
"&Error: Cannot have fewer than 0 arguments for variable %s",name);
1558 if ( *s ==
'=' ) { addone = 0; s++; }
1560 while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ -
'0'; }
1563 while ( FG.cTable[*s] == 0 ) s++;
1566 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1567 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1569 Warning(
"&Illegal information in number of arguments properties currently ignored");
1576 if ( cc ==
'<' )
goto retry;
1577 if ( ( AC.AutoDeclareFlag == 0 &&
1578 ( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
1580 || ( ( type = GetName(*(AC.activenames),name,&numfunction,NOAUTO) ) != NAMENOTFOUND ) ) {
1581 if ( type != CFUNCTION ) error = NameConflict(type,name);
1586 if ( fun->
tabl != 0 ) {
1587 MesPrint(
"&Illegal attempt to change table into function");
1593 if ( istensor && fun->
spec == 0 ) {
1594 MesPrint(
"&Function %s changed to tensor",name);
1597 else if ( istensor == 0 && fun->
spec ) {
1598 MesPrint(
"&Tensor %s changed to function",name);
1601 fun->
spec = istensor;
1604 AC.SymChangeFlag = 1;
1606 fun->maxnumargs = argmax;
1607 fun->minnumargs = argmin;
1611 AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
1614 eol:
while ( *s ==
',' ) s++;
1619 int CoNFunction(UBYTE *s) {
return(CoFunction(s,1,0)); }
1620 int CoCFunction(UBYTE *s) {
return(CoFunction(s,0,0)); }
1621 int CoNTensor(UBYTE *s) {
return(CoFunction(s,1,2)); }
1622 int CoCTensor(UBYTE *s) {
return(CoFunction(s,0,2)); }
1654 static int nwarntab = 1;
1656 int DoTable(UBYTE *s,
int par)
1659 UBYTE *name, *p, *inp, c;
1660 int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
1661 int error = 0, ret, oldcbufnum, oldEside;
1662 WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;
1669 while ( *s ==
',' ) s++;
1672 if ( ( s = SkipAName(s) ) == 0 ) {
1673 IllForm: MesPrint(
"&Illegal name or option in table declaration");
1677 if ( TestName(name) ) { *s = c;
goto IllForm; }
1679 if ( *s ==
'(' )
break;
1681 MesPrint(
"&Illegal definition of table");
1688 if ( StrICmp(name,(UBYTE *)(
"check" )) == 0 ) checkflag = 1;
1689 else if ( StrICmp(name,(UBYTE *)(
"zero" )) == 0 ) checkflag = 2;
1690 else if ( StrICmp(name,(UBYTE *)(
"one" )) == 0 ) checkflag = 3;
1691 else if ( StrICmp(name,(UBYTE *)(
"strict")) == 0 ) rflag = 1;
1692 else if ( StrICmp(name,(UBYTE *)(
"relax" )) == 0 ) rflag = -1;
1693 else if ( StrICmp(name,(UBYTE *)(
"zerofill" )) == 0 ) { rflag = -2; checkflag = 2; }
1694 else if ( StrICmp(name,(UBYTE *)(
"onefill" )) == 0 ) { rflag = -3; checkflag = 3; }
1695 else if ( StrICmp(name,(UBYTE *)(
"sparse")) == 0 ) sparseflag |= 1;
1696 else if ( StrICmp(name,(UBYTE *)(
"base")) == 0 ) sparseflag |= 3;
1697 else if ( StrICmp(name,(UBYTE *)(
"tablebase")) == 0 ) sparseflag |= 3;
1699 MesPrint(
"&Illegal option in table definition: '%s'",name);
1703 while ( *s ==
',' ) s++;
1705 if ( name == s || *s == 0 ) {
1706 MesPrint(
"&Illegal name or option in table declaration");
1711 if ( checkflag == 1 ) rflag = 0;
1712 else if ( checkflag == 2 ) rflag = -2;
1713 else if ( checkflag == 3 ) rflag = -3;
1716 if ( ( ret = GetVar(name,&type,&funnum,CFUNCTION,NOAUTO) ) ==
1719 funnum = EntVar(CFUNCTION,name,0,1,0,0);
1721 else if ( par == 1 || par == 2 ) {
1722 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1725 else if ( ret <= 0 ) {
1726 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1732 Warning(
"Table now declares its (commuting) function.");
1733 Warning(
"Earlier definition in Function statement obsolete. Please remove.");
1739 MesPrint(
"&(N)(C)Tables should not be declared previously");
1742 if ( functions[funnum].spec > 0 ) {
1743 MesPrint(
"&Tensors cannot become tables");
1746 if ( functions[funnum].symmetric > 0 ) {
1747 MesPrint(
"&Functions with nontrivial symmetrization properties cannot become tables");
1750 if ( functions[funnum].tabl ) {
1751 MesPrint(
"&Redefinition of an existing table is not allowed.");
1754 functions[funnum].tabl = T = (
TABLES)Malloc1(
sizeof(
struct TaBlEs),
"table");
1774 if ( rflag > 0 ) AC.MustTestTable++;
1788 T->argtail = strDup1(p,"argtail");
1795 if ( FG.cTable[p[-1]] != 1 || ( *p != ',' && *p != ')' ) ) {
1797 MesPrint(
"&First argument in a sparse table must be a number of dimensions");
1803 T->
flags = (WORD *)Malloc1(x*
sizeof(WORD),
"table flags");
1806 if ( *inp !=
')' ) inp++;
1816 if ( FG.cTable[*p] != 1 && *p !=
'+' && *p !=
'-' )
break;
1817 ParseSignedNumber(x,p)
1818 if ( FG.cTable[p[-1]] != 1 || *p != ':' ) break;
1820 ParseSignedNumber(y,p)
1821 if ( FG.cTable[p[-1]] != 1 || ( *p != ',' && *p != ')' ) ) {
1822 MesPrint(
"&Illegal dimension field in table declaration");
1826 flags1 = (WORD *)Malloc1((T->
numind+1)*
sizeof(WORD),
"table flags");
1827 for ( i = 0; i < T->
numind; i++ ) { mm1[i] = T->
mm[i]; flags1[i] = T->
flags[i]; }
1828 if ( T->
mm ) M_free(T->
mm,
"table dimensions");
1829 if ( T->
flags ) M_free(T->
flags,
"table flags");
1836 if ( *p ==
')' ) { inp = p;
break; }
1839 = (WORD *)Malloc1(TABLEEXTENSION*
sizeof(WORD)*(T->
totind),
"table pointers");
1841 for ( i = TABLEEXTENSION*T->
totind; i > 0; i-- ) *w++ = -1;
1842 for ( i = T->
numind-1, x = 1; i >= 0; i-- ) {
1852 OldWork = AT.WorkPointer;
1853 oldcbufnum = AC.cbufnum;
1855 C = cbuf+AC.cbufnum;
1857 oldnumlhs = C->numlhs;
1858 oldnumrhs = C->numrhs;
1860 while ( s >= name ) *--inp = *s--;
1863 *w++ = SUBEXPRESSION;
1871 AT.WorkPointer = w + 4*AM.MaxWildcards;
1872 if ( ( ret = CompileAlgebra(inp,LHSIDE,AC.ProtoType) ) < 0 ) {
1873 error = 1;
goto FinishUp;
1875 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
1889 OldWork[2] = C->numrhs;
1890 *w++ = 1; *w++ = 1; *w++ = 3;
1891 OldWork[-1] = w-OldWork+1;
1893 ww = C->
rhs[C->numrhs];
1894 for ( j = 0; j < *ww; j++ ) w[j] = ww[j];
1895 AT.WorkPointer = w+*w;
1896 if ( *ww == 0 || ww[*ww] != 0 ) {
1897 MesPrint(
"&Illegal table pattern definition");
1898 AC.lhdollarflag = 0;
1901 if ( error )
goto FinishUp;
1903 if (
NewSort(BHEAD0) ||
NewSort(BHEAD0) ) { error = 1;
goto FinishUp; }
1904 AN.RepPoint = AT.RepCount + 1;
1905 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
1906 AR.Cnumlhs = C->numlhs;
1907 functions[funnum].tabl = 0;
1909 functions[funnum].tabl = T;
1910 AR.Eside = oldEside;
1913 functions[funnum].tabl = T;
1914 AR.Eside = oldEside;
1917 if ( *w == 0 || *(w+*w) != 0 ) {
1918 MesPrint(
"&Irregular pattern in table definition");
1923 if ( AC.lhdollarflag ) {
1924 MesPrint(
"&Unexpanded dollar variables are not allowed in table definition");
1928 AT.WorkPointer = ww = w + *w;
1929 if ( ww[-1] != 3 || ww[-2] != 1 || ww[-3] != 1 ) {
1930 MesPrint(
"&Coefficient of pattern in table definition should be 1.");
1942 T->
prototypeSize = ((i+j)*
sizeof(WORD)+2*
sizeof(WORD *)) * AM.totalnumberofthreads;
1945 t = (WORD *)(T->
pattern + AM.totalnumberofthreads);
1946 for ( n = 0; n < AM.totalnumberofthreads; n++ ) {
1948 for ( k = 0; k < i; k++ ) *t++ = OldWork[k];
1953 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1955 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1956 for ( k = 0; k < j; k++ ) *t++ = *w++;
1959 for ( n = 1; n < AM.totalnumberofthreads; n++ ) {
1961 for ( i = 0; i < k; i++ ) *t++ = *tt++;
1968 for ( k = 0; k < i; k++ ) T->
prototype[k] = OldWork[k];
1972 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1974 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1975 for ( k = 0; k < j; k++ ) *t++ = *w++;
1982 C->numrhs = oldnumrhs;
1983 C->numlhs = oldnumlhs;
1993 tt = t + t[1]; t += SUBEXPSIZE;
1995 if ( *t == LOADDOLLAR ) {
1996 Warning(
"The use of $-variable assignments in tables disables parallel\
1997 execution for the whole program.");
1998 AM.hparallelflag |= NOPARALLEL_TBLDOLLAR;
1999 AC.mparallelflag |= NOPARALLEL_TBLDOLLAR;
2005 AT.WorkPointer = OldWork - 1;
2006 AC.cbufnum = oldcbufnum;
2007 if ( T->
sparse ) ClearTableTree(T);
2008 if ( ( sparseflag & 2 ) != 0 ) {
2009 if ( T->
spare == 0 ) { SpareTable(T); }
2019 int CoTable(UBYTE *s)
2021 return(DoTable(s,2));
2029 int CoNTable(UBYTE *s)
2031 return(DoTable(s,0));
2039 int CoCTable(UBYTE *s)
2041 return(DoTable(s,1));
2049 void EmptyTable(
TABLES T)
2052 if ( T->
sparse ) ClearTableTree(T);
2070 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2071 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2084 for ( j = TABLEEXTENSION*T->
totind; j > 0; j-- ) *w++ = -1;
2093 int AddSet(UBYTE *name, WORD dim)
2095 int nodenum, numset = AC.SetList.num;
2096 SETS set = (
SETS)FromVarList(&AC.SetList);
2099 set->name = AddName(AC.varnames,name,CSET,numset,&nodenum);
2102 set->namesize = (s-name)+1;
2103 set->node = nodenum;
2111 set->last = AC.SetElementList.num;
2113 set->dimension = dim;
2126 int DoElements(UBYTE *s,
SETS set, UBYTE *name)
2128 int type, error = 0, x, sgn, i;
2132 if ( *s ==
',' ) { s++;
continue; }
2134 while ( *s ==
'-' || *s ==
'+' ) { sgn ^= 1; s++; }
2136 if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'[' ) {
2137 if ( ( s = SkipAName(s) ) == 0 ) {
2138 MesPrint(
"&Illegal name in set definition");
2142 if ( ( ( type = GetName(AC.exprnames,cname,&numset,NOAUTO) ) == NAMENOTFOUND )
2143 && ( ( type = GetOName(AC.varnames,cname,&numset,WITHAUTO) ) == NAMENOTFOUND ) ) {
2146 MesPrint(
"&%s has not been declared",cname);
2150 numset = AC.DubiousList.num;
2151 dv = (
DUBIOUSV)FromVarList(&AC.DubiousList);
2152 dv->name = AddName(AC.varnames,cname,CDUBIOUS,numset,&nodenum);
2154 set->type = type = CDUBIOUS;
2158 if ( set->type == -1 ) {
2159 if ( type == CSYMBOL ) {
2160 for ( i = set->first; i < set->last; i++ ) {
2161 SetElements[i] += 2*MAXPOWER;
2166 if ( set->type != type && set->type != CDUBIOUS
2167 && type != CDUBIOUS ) {
2168 if ( set->type != CNUMBER || ( type != CSYMBOL
2169 && type != CINDEX ) ) {
2171 "&%s has not the same type as the other members of the set"
2174 set->type = CDUBIOUS;
2177 if ( type == CSYMBOL ) {
2178 for ( i = set->first; i < set->last; i++ ) {
2179 SetElements[i] += 2*MAXPOWER;
2185 if ( set->dimension != MAXPOSITIVE ) {
2186 switch ( set->type ) {
2188 if ( symbols[numset].dimension != set->dimension ) {
2189 MesPrint(
"&Dimension check failed in set %s, symbol %s",
2190 VARNAME(Sets,(set-Sets)),
2191 VARNAME(symbols,numset));
2193 set->dimension = MAXPOSITIVE;
2197 if ( vectors[numset-AM.OffsetVector].dimension != set->dimension ) {
2198 MesPrint(
"&Dimension check failed in set %s, vector %s",
2199 VARNAME(Sets,(set-Sets)),
2200 VARNAME(vectors,(numset-AM.OffsetVector)));
2202 set->dimension = MAXPOSITIVE;
2206 if ( functions[numset-FUNCTION].dimension != set->dimension ) {
2207 MesPrint(
"&Dimension check failed in set %s, function %s",
2208 VARNAME(Sets,(set-Sets)),
2209 VARNAME(functions,(numset-FUNCTION)));
2213 set->dimension = MAXPOSITIVE;
2217 if ( type != CVECTOR ) {
2218 MesPrint(
"&Illegal use of - sign in set. Can use only with vector or number");
2229 if ( name == 0 && *s ==
'?' ) {
2231 switch ( set->type ) {
2233 numset = -numset;
break;
2235 numset += WILDOFFSET;
break;
2237 numset |= WILDMASK;
break;
2239 numset |= WILDMASK;
break;
2246 e = (WORD *)FromVarList(&AC.SetElementList);
2250 else if ( FG.cTable[*s] == 1 ) {
2253 if ( x >= MAXPOWER || x <= -MAXPOWER ||
2254 ( set->type == CINDEX && ( x < 0 || x >= AM.OffsetIndex ) ) ) {
2255 MesPrint(
"&Illegal value for set element: %d",x);
2256 if ( AC.firstconstindex ) {
2257 MesPrint(
"&0 <= Fixed indices < ConstIndex(which is %d)",
2259 MesPrint(
"&For setting ConstIndex, read the chapter on the setup file");
2260 AC.firstconstindex = 0;
2268 if ( set->type == -1 ) {
2269 if ( x < 0 || x >= AM.OffsetIndex ) {
2270 for ( i = set->first; i < set->last; i++ ) {
2271 SetElements[i] += 2*MAXPOWER;
2273 set->type = CSYMBOL;
2275 else set->type = CNUMBER;
2277 else if ( set->type == CDUBIOUS ) {}
2278 else if ( set->type == CNUMBER && x < 0 ) {
2279 for ( i = set->first; i < set->last; i++ ) {
2280 SetElements[i] += 2*MAXPOWER;
2282 set->type = CSYMBOL;
2284 else if ( set->type != CSYMBOL && ( x < 0 ||
2285 ( set->type != CINDEX && set->type != CNUMBER ) ) ) {
2286 MesPrint(
"&Illegal mixture of element types in set");
2288 set->type = CDUBIOUS;
2293 e = (WORD *)FromVarList(&AC.SetElementList);
2295 if ( set->type == CSYMBOL ) *e = x + 2*MAXPOWER;
2300 MesPrint(
"&Illegal object in list of set elements");
2304 if ( error == 0 && ( ( set->flags & ORDEREDSET ) == ORDEREDSET ) ) {
2311 SimpleSplitMerge(SetElements+set->first,set->last-set->first);
2325 int type, error = 0, ordered = 0;
2326 UBYTE *name, c, *ss;
2328 WORD numberofset, dim = MAXPOSITIVE;
2330 if ( ( s = SkipAName(s) ) == 0 ) {
2331 IllForm:MesPrint(
"&Illegal name for set");
2335 if ( TestName(name) )
goto IllForm;
2336 if ( ( ( type = GetName(AC.exprnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND )
2337 || ( ( type = GetName(AC.varnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND ) ) {
2338 if ( type != CSET ) NameConflict(type,name);
2340 MesPrint(
"&There is already a set with the name %s",name);
2345 numberofset = AddSet(name,0);
2346 set = Sets + numberofset;
2353 while ( *s !=
',' && *s !=
')' && *s ) s++;
2355 if ( StrICont(sss,(UBYTE *)
"ordered") == 0 ) {
2356 ordered = ORDEREDSET;
2359 MesPrint(
"&Error: Illegal option in set definition: %s",sss);
2364 MesPrint(
"&Error: Currently only one option allowed in set definition.");
2366 while ( *s && *s !=
')' ) s++;
2372 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
2374 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
2375 ParseSignedNumber(dim,s)
2376 if ( dim < -HALFMAX || dim > HALFMAX ) {
2377 MesPrint(
"&Warning: dimension of %s (%d) out of range"
2381 if ( *s !=
'}' )
goto IllDim;
2385 IllDim: MesPrint(
"&Error: Illegal dimension field for set %s",name);
2389 while ( *s ==
',' ) s++;
2392 numberofset = AddSet(name,dim);
2394 set = Sets + numberofset;
2395 set->flags |= ordered;
2397 MesPrint(
"&Proper syntax is `Set name:elements'");
2401 error = DoElements(s,set,name);
2402 AC.SetList.numtemp = AC.SetList.num;
2403 AC.SetElementList.numtemp = AC.SetElementList.num;
2417 int DoTempSet(UBYTE *from, UBYTE *to)
2422 int setnum = AddSet(0,MAXPOSITIVE);
2423 SETS set = Sets + setnum, setp;
2428 while ( *from ==
',' ) from++;
2429 if ( *from ==
'<' || *from ==
'>' ) {
2431 set->first = 3*MAXPOWER;
2432 set->last = -3*MAXPOWER;
2433 while ( *from ==
'<' || *from ==
'>' ) {
2434 if ( *from ==
'<' ) {
2436 if ( *from ==
'=' ) { from++; j++; }
2440 if ( *from ==
'=' ) { from++; j--; }
2443 while ( *from ==
'-' || *from ==
'+' ) {
2444 if ( *from ==
'-' ) sgn = -sgn;
2447 ParseNumber(num,from)
2448 if ( *from && *from != ',' ) {
2449 MesPrint(
"&Illegal number in ranged set definition");
2452 if ( sgn < 0 ) num = -num;
2453 if ( num >= MAXPOWER || num <= -MAXPOWER ) {
2454 Warning(
"Value in ranged set too big. Adjusted to infinity.");
2455 if ( num > 0 ) num = 3*MAXPOWER;
2456 else num = -3*MAXPOWER;
2458 else if ( j == 2 ) num += 2*MAXPOWER;
2459 else if ( j == -2 ) num -= 2*MAXPOWER;
2460 if ( j > 0 ) set->first = num;
2461 else set->last = num;
2462 while ( *from ==
',' ) from++;
2465 MesPrint(
"&Definition of ranged set contains illegal objects");
2469 else if ( DoElements(from,set,(UBYTE *)0) != 0 ) {
2470 AC.SetElementList.num = set->first;
2471 AC.SetList.num--; *to = c;
2478 num = set->last - set->first;
2479 for ( setp = Sets, i = 0; i < AC.SetList.num-1; i++, setp++ ) {
2480 if ( num != setp->last - setp->first )
continue;
2481 if ( set->type != setp->type )
continue;
2482 if ( set->type == CRANGE ) {
2483 if ( set->first == setp->first )
return(setp-Sets);
2486 e = SetElements + set->first;
2487 ep = SetElements + setp->first;
2489 while ( --j >= 0 )
if ( *e++ != *ep++ )
break;
2491 AC.SetElementList.num = set->first;
2493 return(setp - Sets);
2509 int CoAuto(UBYTE *inp)
2513 AC.Symbols = &(AC.AutoSymbolList);
2514 AC.Vectors = &(AC.AutoVectorList);
2515 AC.Indices = &(AC.AutoIndexList);
2516 AC.Functions = &(AC.AutoFunctionList);
2517 AC.activenames = &(AC.autonames);
2518 AC.AutoDeclareFlag = WITHAUTO;
2520 while ( *inp ==
',' ) inp++;
2521 retval = CompileStatement(inp);
2523 AC.AutoDeclareFlag = 0;
2524 AC.Symbols = &(AC.SymbolList);
2525 AC.Vectors = &(AC.VectorList);
2526 AC.Indices = &(AC.IndexList);
2527 AC.Functions = &(AC.FunctionList);
2528 AC.activenames = &(AC.varnames);
2539 int AddDollar(UBYTE *name, WORD type, WORD *start, LONG size)
2541 int nodenum, numdollar = AP.DollarList.num;
2544 dol->name = AddName(AC.dollarnames,name,CDOLLAR,numdollar,&nodenum);
2546 dol->node = nodenum;
2548 dol->numdummies = 0;
2550 dol->pthreadslockread = dummylock;
2551 dol->pthreadslockwrite = dummylock;
2557 if ( start && size > 0 ) {
2560 s = (WORD *)Malloc1((size+1)*
sizeof(WORD),
"$-variable contents");
2562 while ( --size >= 0 ) *s++ = *t++;
2565 else { dol->where = &(AM.dollarzero); dol->size = 0; }
2566 cbuf[AM.dbufnum].rhs[numdollar] = dol->where;
2567 cbuf[AM.dbufnum].CanCommu[numdollar] = 0;
2568 cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
2583 int ReplaceDollar(WORD number, WORD newtype, WORD *newstart, LONG newsize)
2586 DOLLARS dol = Dollars + number;
2589 dol->type = newtype;
2590 if ( dol->size == newsize && newsize > 0 && newstart ) {
2591 s = dol->where; t = newstart; i = newsize;
2592 while ( --i >= 0 ) {
if ( *s++ != *t++ )
break; }
2593 if ( i < 0 )
return(0);
2595 if ( dol->where && dol->where != &(dol->zero) ) {
2596 M_free(dol->where,
"dollar->where"); dol->where = &(dol->zero); dol->size = 0;
2598 if ( newstart && newsize > 0 ) {
2599 dol->size = newsize;
2601 s = (WORD *)Malloc1((newsize+1)*
sizeof(WORD),
"$-variable contents");
2602 t = newstart; i = newsize;
2603 while ( --i >= 0 ) *s++ = *t++;
2616 int AddDubious(UBYTE *name)
2618 int nodenum, numdubious = AC.DubiousList.num;
2620 dub->name = AddName(AC.varnames,name,CDUBIOUS,numdubious,&nodenum);
2621 dub->node = nodenum;
2630 int MakeDubious(
NAMETREE *nametree, UBYTE *name, WORD *number)
2633 int node, newnode, i;
2634 if ( nametree->
namenode == 0 )
return(-1);
2641 else if ( i > 0 ) newnode = n->
right;
2643 if ( n->
type != CDUBIOUS ) {
2644 int numdubious = AC.DubiousList.num;
2652 }
while ( newnode >= 0 );
2661 static char *nametype[] = {
"symbol",
"index",
"vector",
"function",
2662 "set",
"expression" };
2663 static char *plural[] = {
"",
"n",
"",
"",
"",
"n" };
2665 int NameConflict(
int type, UBYTE *name)
2667 if ( type == NAMENOTFOUND ) {
2668 MesPrint(
"&%s has not been declared",name);
2670 else if ( type != CDUBIOUS )
2671 MesPrint(
"&%s has been declared as a%s %s already"
2672 ,name,plural[type],nametype[type]);
2681 int AddExpression(UBYTE *name,
int x,
int y)
2683 int nodenum, numexpr = AC.ExpressionList.num;
2687 expr->printflag = y;
2688 PUTZERO(expr->onfile);
2689 PUTZERO(expr->size);
2692 expr->hidelevel = 0;
2694 expr->bracketinfo = expr->newbracketinfo = 0;
2696 expr->name = AddName(AC.exprnames,name,CEXPRESSION,numexpr,&nodenum);
2697 expr->node = nodenum;
2698 expr->replace = NEWLYDEFINEDEXPRESSION ;
2701 expr->namesize = (s-name)+1;
2704 expr->replace = REDEFINEDEXPRESSION;
2705 expr->name = AC.TransEname;
2710 expr->numdummies = 0;
2711 expr->numfactors = 0;
2723 int GetLabel(UBYTE *name)
2727 UBYTE **NewLabelNames;
2729 for ( i = 0; i < AC.NumLabels; i++ ) {
2730 if ( StrCmp(name,AC.LabelNames[i]) == 0 )
return(i);
2732 if ( AC.NumLabels >= AC.MaxLabels ) {
2733 newnum = 2*AC.MaxLabels;
2734 if ( newnum == 0 ) newnum = 10;
2735 if ( newnum > 32765 ) newnum = 32765;
2736 if ( newnum == AC.MaxLabels ) {
2737 MesPrint(
"&More than 32765 labels in one module. Please simplify.");
2740 NewLabelNames = (UBYTE **)Malloc1((
sizeof(UBYTE *)+
sizeof(
int))
2742 NewLabel = (
int *)(NewLabelNames+newnum);
2743 for ( i = 0; i< AC.MaxLabels; i++ ) {
2744 NewLabelNames[i] = AC.LabelNames[i];
2745 NewLabel[i] = AC.Labels[i];
2747 if ( AC.LabelNames ) M_free(AC.LabelNames,
"Labels");
2748 AC.LabelNames = NewLabelNames;
2749 AC.Labels = NewLabel;
2750 AC.MaxLabels = newnum;
2753 AC.LabelNames[i] = strDup1(name,
"Labels");
2768 void ResetVariables(
int par)
2774 AC.SetList.num = AC.SetList.numtemp;
2775 AC.SetElementList.num = AC.SetElementList.numtemp;
2778 for ( i = AC.SymbolList.numclear; i < AC.SymbolList.num; i++ )
2779 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2780 AC.SymbolList.num = AC.SymbolList.numglobal = AC.SymbolList.numclear;
2781 for ( i = AC.VectorList.numclear; i < AC.VectorList.num; i++ )
2782 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2783 AC.VectorList.num = AC.VectorList.numglobal = AC.VectorList.numclear;
2784 for ( i = AC.IndexList.numclear; i < AC.IndexList.num; i++ )
2785 AC.varnames->namenode[indices[i].node].type = CDELETE;
2786 AC.IndexList.num = AC.IndexList.numglobal = AC.IndexList.numclear;
2787 for ( i = AC.FunctionList.numclear; i < AC.FunctionList.num; i++ ) {
2788 AC.varnames->namenode[functions[i].node].type = CDELETE;
2789 if ( ( T = functions[i].tabl ) != 0 ) {
2792 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2793 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2805 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2806 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2820 AC.FunctionList.num = AC.FunctionList.numglobal = AC.FunctionList.numclear;
2821 for ( i = AC.SetList.numclear; i < AC.SetList.num; i++ ) {
2822 if ( Sets[i].node >= 0 )
2823 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2825 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal = AC.SetList.numclear;
2826 for ( i = AC.DubiousList.numclear; i < AC.DubiousList.num; i++ )
2827 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2828 AC.DubiousList.num = AC.DubiousList.numglobal = AC.DubiousList.numclear;
2829 AC.SetElementList.numtemp = AC.SetElementList.num =
2830 AC.SetElementList.numglobal = AC.SetElementList.numclear;
2831 CompactifyTree(AC.varnames,VARNAMES);
2832 AC.varnames->namefill = AC.varnames->globalnamefill = AC.varnames->clearnamefill;
2833 AC.varnames->nodefill = AC.varnames->globalnodefill = AC.varnames->clearnodefill;
2835 for ( i = AC.AutoSymbolList.numclear; i < AC.AutoSymbolList.num; i++ )
2836 AC.autonames->namenode[
2837 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2838 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal
2839 = AC.AutoSymbolList.numclear;
2840 for ( i = AC.AutoVectorList.numclear; i < AC.AutoVectorList.num; i++ )
2841 AC.autonames->namenode[
2842 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2843 AC.AutoVectorList.num = AC.AutoVectorList.numglobal
2844 = AC.AutoVectorList.numclear;
2845 for ( i = AC.AutoIndexList.numclear; i < AC.AutoIndexList.num; i++ )
2846 AC.autonames->namenode[
2847 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2848 AC.AutoIndexList.num = AC.AutoIndexList.numglobal
2849 = AC.AutoIndexList.numclear;
2850 for ( i = AC.AutoFunctionList.numclear; i < AC.AutoFunctionList.num; i++ ) {
2851 AC.autonames->namenode[
2852 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].node].type = CDELETE;
2853 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2856 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2857 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2865 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2866 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2877 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal
2878 = AC.AutoFunctionList.numclear;
2879 CompactifyTree(AC.autonames,AUTONAMES);
2880 AC.autonames->namefill = AC.autonames->globalnamefill
2881 = AC.autonames->clearnamefill;
2882 AC.autonames->nodefill = AC.autonames->globalnodefill
2883 = AC.autonames->clearnodefill;
2887 for ( i = AC.SymbolList.numglobal; i < AC.SymbolList.num; i++ )
2888 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2889 AC.SymbolList.num = AC.SymbolList.numglobal;
2890 for ( i = AC.VectorList.numglobal; i < AC.VectorList.num; i++ )
2891 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2892 AC.VectorList.num = AC.VectorList.numglobal;
2893 for ( i = AC.IndexList.numglobal; i < AC.IndexList.num; i++ )
2894 AC.varnames->namenode[indices[i].node].type = CDELETE;
2895 AC.IndexList.num = AC.IndexList.numglobal;
2896 for ( i = AC.FunctionList.numglobal; i < AC.FunctionList.num; i++ ) {
2897 AC.varnames->namenode[functions[i].node].type = CDELETE;
2898 if ( ( T = functions[i].tabl ) != 0 ) {
2901 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2902 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2914 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2915 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2933 for ( i = 0; i < AC.FunctionList.numglobal; i++ ) {
2940 if ( ( T = functions[i].tabl ) != 0 ) {
2948 #if TABLEEXTENSION == 2
2955 tp += TABLEEXTENSION;
2957 RedoTableTree(T,T->
totind);
2961 for ( j = 0, tp = TT->
tablepointers; j < TT->totind; j++ ) {
2963 #if TABLEEXTENSION == 2
2970 tp += TABLEEXTENSION;
2972 RedoTableTree(TT,TT->
totind);
2979 #if TABLEEXTENSION == 2
2995 AC.FunctionList.num = AC.FunctionList.numglobal;
2996 for ( i = AC.SetList.numglobal; i < AC.SetList.num; i++ ) {
2997 if ( Sets[i].node >= 0 )
2998 AC.varnames->namenode[Sets[i].node].type = CDELETE;
3000 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal;
3001 for ( i = AC.DubiousList.numglobal; i < AC.DubiousList.num; i++ )
3002 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
3003 AC.DubiousList.num = AC.DubiousList.numglobal;
3004 AC.SetElementList.numtemp = AC.SetElementList.num =
3005 AC.SetElementList.numglobal;
3006 CompactifyTree(AC.varnames,VARNAMES);
3007 AC.varnames->namefill = AC.varnames->globalnamefill;
3008 AC.varnames->nodefill = AC.varnames->globalnodefill;
3010 for ( i = AC.AutoSymbolList.numglobal; i < AC.AutoSymbolList.num; i++ )
3011 AC.autonames->namenode[
3012 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
3013 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal;
3014 for ( i = AC.AutoVectorList.numglobal; i < AC.AutoVectorList.num; i++ )
3015 AC.autonames->namenode[
3016 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
3017 AC.AutoVectorList.num = AC.AutoVectorList.numglobal;
3018 for ( i = AC.AutoIndexList.numglobal; i < AC.AutoIndexList.num; i++ )
3019 AC.autonames->namenode[
3020 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
3021 AC.AutoIndexList.num = AC.AutoIndexList.numglobal;
3022 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3023 AC.autonames->namenode[
3024 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].node].type = CDELETE;
3025 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
3028 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
3029 if ( T->
flags ) M_free(T->
flags,
"tableflags");
3037 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
3038 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
3049 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal;
3051 CompactifyTree(AC.autonames,AUTONAMES);
3053 AC.autonames->namefill = AC.autonames->globalnamefill;
3054 AC.autonames->nodefill = AC.autonames->globalnodefill;
3064 void RemoveDollars()
3067 CBUF *C = cbuf + AM.dbufnum;
3068 int numdollar = AP.DollarList.num;
3069 if ( numdollar > 0 ) {
3070 while ( numdollar > AM.gcNumDollars ) {
3072 d = Dollars + numdollar;
3073 if ( d->where && d->where != &(d->zero) && d->where != &(AM.dollarzero) ) {
3074 M_free(d->where,
"dollar->where"); d->where = &(d->zero); d->size = 0;
3076 AC.dollarnames->namenode[d->node].type = CDELETE;
3078 AP.DollarList.num = AM.gcNumDollars;
3079 CompactifyTree(AC.dollarnames,DOLLARNAMES);
3081 C->numrhs = C->mnumrhs;
3082 C->numlhs = C->mnumlhs;
3091 void Globalize(
int par)
3096 AC.SymbolList.numclear = AC.SymbolList.num;
3097 AC.VectorList.numclear = AC.VectorList.num;
3098 AC.IndexList.numclear = AC.IndexList.num;
3099 AC.FunctionList.numclear = AC.FunctionList.num;
3100 AC.SetList.numclear = AC.SetList.num;
3101 AC.DubiousList.numclear = AC.DubiousList.num;
3102 AC.SetElementList.numclear = AC.SetElementList.num;
3103 AC.varnames->clearnamefill = AC.varnames->namefill;
3104 AC.varnames->clearnodefill = AC.varnames->nodefill;
3106 AC.AutoSymbolList.numclear = AC.AutoSymbolList.num;
3107 AC.AutoVectorList.numclear = AC.AutoVectorList.num;
3108 AC.AutoIndexList.numclear = AC.AutoIndexList.num;
3109 AC.AutoFunctionList.numclear = AC.AutoFunctionList.num;
3110 AC.autonames->clearnamefill = AC.autonames->namefill;
3111 AC.autonames->clearnodefill = AC.autonames->nodefill;
3114 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
3119 if ( functions[i].tabl ) {
3120 TABLES T = functions[i].tabl;
3125 #if TABLEEXTENSION == 2
3128 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3130 tp += TABLEEXTENSION;
3135 for ( j = 0, tp = TT->
tablepointers; j < TT->totind; j++ ) {
3137 #if TABLEEXTENSION == 2
3140 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3142 tp += TABLEEXTENSION;
3151 #if TABLEEXTENSION == 2
3154 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3162 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3163 if ( ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl )
3164 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->mdefined =
3165 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->defined;
3167 AC.SymbolList.numglobal = AC.SymbolList.num;
3168 AC.VectorList.numglobal = AC.VectorList.num;
3169 AC.IndexList.numglobal = AC.IndexList.num;
3170 AC.FunctionList.numglobal = AC.FunctionList.num;
3171 AC.SetList.numglobal = AC.SetList.num;
3172 AC.DubiousList.numglobal = AC.DubiousList.num;
3173 AC.SetElementList.numglobal = AC.SetElementList.num;
3174 AC.varnames->globalnamefill = AC.varnames->namefill;
3175 AC.varnames->globalnodefill = AC.varnames->nodefill;
3177 AC.AutoSymbolList.numglobal = AC.AutoSymbolList.num;
3178 AC.AutoVectorList.numglobal = AC.AutoVectorList.num;
3179 AC.AutoIndexList.numglobal = AC.AutoIndexList.num;
3180 AC.AutoFunctionList.numglobal = AC.AutoFunctionList.num;
3181 AC.autonames->globalnamefill = AC.autonames->namefill;
3182 AC.autonames->globalnodefill = AC.autonames->nodefill;
3190 int TestName(UBYTE *name)
3192 if ( *name ==
'[' ) {
3193 while ( *name ) name++;
3194 if ( name[-1] ==
']' )
return(0);
3198 if ( *name ==
'_' )
return(-1);
void AddPotModdollar(WORD)
WORD SortWild(WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
struct FuNcTiOn * FUNCTIONS
LONG EndSort(PHEAD WORD *, int)