53 if ( nametree->
namenode == 0 )
return(0);
60 else if ( i > 0 ) newnode = n->
right;
62 }
while ( newnode >= 0 );
71int 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);
209 else nn->
right = node3;
213 else if ( nn->
balance == rr ) {
226 else nnn->
right = newnode;
233 MesPrint(
"We ran into an impossible case in AddName\n");
252int GetName(
NAMETREE *nametree, UBYTE *namein, WORD *number,
int par)
255 int node, newnode, i;
256 UBYTE *s, *t, *u, *name;
266 else if ( i > 0 ) newnode = n->
right;
271 }
while ( newnode >= 0 );
274 if ( s > name && s[-1] ==
'_' && nametree == AC.varnames ) {
278 if ( s == name+2 && ( *name ==
'd' || *name ==
'D' ) ) {
279 *number = DELTA-FUNCTION;
285 if ( s > name+2 && *name ==
'N' ) {
287 while ( FG.cTable[*t] == 1 ) i = 10*i + *t++ -
'0';
289 *number = i + AM.IndDum - AM.OffsetIndex;
302 else if ( i > 0 ) newnode = n->
right;
306 }
while ( newnode >= 0 );
313 t = name; u = AC.extrasym;
314 while ( *t == *u ) { t++; u++; }
315 if ( *u == 0 && *t != 0 ) {
317 while ( FG.cTable[*t] == 1 ) {
318 x = 10*x + (*t++ -
'0');
320 if ( *t ==
'_' && x > 0 && x <= cbuf[AM.sbufnum].numrhs ) {
321 *number = MAXVARIABLES-x;
327 if ( par != WITHAUTO || nametree == AC.autonames )
return(NAMENOTFOUND);
328 return(GetAutoName(name,number));
342UBYTE *GetFunction(UBYTE *s,WORD *funnum)
348 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
350 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
354 MesPrint(
"&%s is undefined",s);
355 numfun = AddDollar(s+1,DOLINDEX,&one,1);
362 if ( ( ( type = GetName(AC.varnames,s,&numfun,WITHAUTO) ) != CFUNCTION )
363 || ( functions[numfun].spec > 0 ) ) {
364 MesPrint(
"&%s should be a regular function",s);
367 if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
368 AddFunction(s,0,0,0,0,0,-1,-1);
373 *funnum = numfun+FUNCTION;
388UBYTE *GetNumber(UBYTE *s,WORD *num)
393 while ( *s ==
'+' ) s++;
395 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
397 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
401 MesPrint(
"&%s is undefined",s);
402 numfun = AddDollar(s+1,DOLINDEX,&one,1);
406 else if ( *s >=
'0' && *s <=
'9' ) {
407 ULONG x = *s++ -
'0';
408 while ( *s >=
'0' && *s <=
'9' ) { x = 10*x + (*s++-
'0'); }
410 if ( x >= MAXPOSITIVE )
goto illegal;
415 if ( *s ==
'-' ) { s++; }
416 if ( *s >=
'0' && *s <=
'9' ) {
while ( *s >=
'0' && *s <=
'9' ) s++; t1 = s; }
420 MesPrint(
"&Illegal option in Canonicalize statement. Should be a nonnegative number or $ variable.");
438int GetLastExprName(UBYTE *name, WORD *number)
442 for ( i = NumExpressions; i > 0; i-- ) {
444 if ( StrCmp(AC.exprnames->namebuffer+e->name,name) == 0 ) {
460int GetOName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
462 int retval = GetName(nametree,name,number,par);
464 case CVECTOR: *number += AM.OffsetVector;
break;
465 case CINDEX: *number += AM.OffsetIndex;
break;
466 case CFUNCTION: *number += FUNCTION;
break;
479int GetAutoName(UBYTE *name, WORD *number)
483 if ( GetName(AC.exprnames,name,number,NOAUTO) != NAMENOTFOUND )
484 return(NAMENOTFOUND);
486 while ( *s ) { s++; }
487 if ( s[-1] ==
'_' ) {
488 return(NAMENOTFOUND);
492 type = GetName(AC.autonames,name,number,NOAUTO);
497 *number = AddSymbol(name,sym->minpower,sym->maxpower,sym->complex,sym->dimension);
501 *number = AddVector(name,vec->complex,vec->dimension);
505 *number = AddIndex(name,ind->dimension,ind->nmin4);
516 return(NAMENOTFOUND);
524int GetVar(UBYTE *name, WORD *type, WORD *number,
int wantedtype,
int par)
528 if ( ( typ = GetName(AC.varnames,name,number,par) ) != wantedtype ) {
529 if ( typ != NAMENOTFOUND ) {
530 if ( wantedtype == -1 ) {
534 NameConflict(typ,name);
535 MakeDubious(AC.varnames,name,&funnum);
538 if ( ( typ = GetName(AC.exprnames,name,&funnum,par) ) != NAMENOTFOUND ) {
539 if ( typ == wantedtype || wantedtype == -1 ) {
540 *number = funnum; *type = typ;
return(1);
542 NameConflict(typ,name);
545 return(NAMENOTFOUND);
547 if ( typ == -1 ) {
return(0); }
557int EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
561 return(AddSymbol(name,y,z,x,d));
564 return(AddIndex(name,x,z));
567 return(AddVector(name,x,d));
570 return(AddFunction(name,y,z,x,0,d,-1,-1));
573 AC.SetList.numtemp++;
574 return(AddSet(name,d));
577 return(AddExpression(name,x,y));
590int GetDollar(UBYTE *name)
593 if ( GetName(AC.dollarnames,name,&number,NOAUTO) == NAMENOTFOUND )
return(-1);
606 DumpNode(nametree,nametree->
headnode,0);
621 if ( n->
left >= 0 ) DumpNode(nametree,n->
left,depth+1);
622 for ( i = 0; i < depth; i++ ) printf(
" ");
624 printf(
"%s(%d): {%d}(%d)(%d)[%d]\n",
626 if ( n->
right >= 0 ) DumpNode(nametree,n->
right,depth+1);
634int CompactifyTree(
NAMETREE *nametree,WORD par)
641 for ( i = 0, j = 0, k = 0, n = nametree->
namenode, ns = 0;
642 i < nametree->
nodefill; i++, n++ ) {
643 if ( n->
type != CDELETE ) {
645 while ( *s ) { s++; ns++; }
650 if ( k == 0 )
return(0);
665 if ( j < 10 ) j = 10;
666 if ( ns < 100 ) ns = 100;
669 newtree.
namebuffer = (UBYTE *)Malloc1(2*ns,
"compactify namestree");
671 CopyTree(&newtree,nametree,nametree->
headnode,par);
673 LinkTree(&newtree,(WORD)0,newtree.
nodefill);
675 M_free(nametree->
namebuffer,
"nametree->namebuffer");
676 M_free(nametree->
namenode,
"nametree->namenode");
701 if ( n->
left >= 0 ) CopyTree(newtree,oldtree,n->
left,par);
702 if ( n->
type != CDELETE ) {
711 if ( par == AUTONAMES ) {
721 if ( par == AUTONAMES ) {
731 if ( par == AUTONAMES ) {
741 if ( par == AUTONAMES ) {
767 MesPrint(
"Illegal variable type in CopyTree: %d",n->
type);
773 while ( *t ) { *s++ = *t++; newtree->
namefill++; }
776 if ( n->
right >= 0 ) CopyTree(newtree,oldtree,n->
right,par);
784void LinkTree(
NAMETREE *
tree, WORD offset, WORD numnodes)
789 int med,numleft,numright,medleft,medright;
792 numright = numnodes - med - 1;
793 medleft = numleft >> 1;
794 medright = ( numright >> 1 ) + med + 1;
796 tree->namenode[offset+med].
left = offset+medleft;
797 tree->namenode[offset+medleft].
parent = offset+med;
799 if ( numright > 0 ) {
800 tree->namenode[offset+med].
right = offset+medright;
801 tree->namenode[offset+medright].
parent = offset+med;
803 if ( numleft > 0 ) LinkTree(
tree,offset,numleft);
804 if ( numright > 0 ) LinkTree(
tree,offset+med+1,numright);
805 while ( numleft && numright ) { numleft >>= 1; numright >>= 1; }
806 if ( numleft )
tree->namenode[offset+med].balance = -1;
807 else if ( numright )
tree->namenode[offset+med].balance = 1;
839 M_free(n,
"nametree");
849void ClearWildcardNames(
void)
851 AC.NumWildcardNames = 0;
854int AddWildcardName(UBYTE *name)
857 int size = 0, tocopy, i;
858 UBYTE *s = name, *t, *newbuffer;
859 while ( *s ) { s++; size++; }
860 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
862 while ( ( *s == *t ) && *s ) { s++; t++; }
863 if ( *s == 0 && *t == 0 )
return(i+1);
867 tocopy = t - AC.WildcardNames;
868 if ( tocopy + size + 1 > AC.WildcardBufferSize ) {
869 if ( AC.WildcardBufferSize == 0 ) {
870 AC.WildcardBufferSize = size+1;
871 if ( AC.WildcardBufferSize < 100 ) AC.WildcardBufferSize = 100;
873 else if ( size+1 >= AC.WildcardBufferSize ) {
874 AC.WildcardBufferSize += size+1;
877 AC.WildcardBufferSize *= 2;
879 newbuffer = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
881 if ( AC.WildcardNames ) {
882 s = AC.WildcardNames;
883 while ( tocopy > 0 ) { *t++ = *s++; tocopy--; }
884 M_free(AC.WildcardNames,
"AC.WildcardNames");
886 AC.WildcardNames = newbuffer;
887 M_free(AT.WildArgTaken,
"AT.WildArgTaken");
888 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
889 ,
"argument list names");
892 while ( *s ) *t++ = *s++;
894 AC.NumWildcardNames++;
895 return(AC.NumWildcardNames);
898int GetWildcardName(UBYTE *name)
902 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
904 while ( ( *s == *t ) && *s ) { s++; t++; }
905 if ( *s == 0 && *t == 0 )
return(i+1);
920int AddSymbol(UBYTE *name,
int minpow,
int maxpow,
int cplx,
int dim)
922 int nodenum, numsymbol = AC.Symbols->num;
925 bzero(sym,
sizeof(
struct SyMbOl));
926 sym->name = AddName(*AC.activenames,name,CSYMBOL,numsymbol,&nodenum);
927 sym->minpower = minpow;
928 sym->maxpower = maxpow;
934 sym->namesize = (s-name)+1;
946int CoSymbol(UBYTE *s)
948 int type, error = 0, minpow, maxpow, cplx, sgn, dim;
950 UBYTE *name, *oldc, c, cc;
958IllForm: MesPrint(
"&Illegally formed name in symbol statement");
963 oldc = s; cc = c = *s; *s = 0;
964 if ( TestName(name) ) { *s = c;
goto IllForm; }
967 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
968 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
969 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
970 else if ( ( ( *s ==
'-' || *s ==
'+' || *s ==
'=' )
971 && ( s[1] >=
'0' && s[1] <=
'9' ) )
972 || ( *s >=
'0' && *s <=
'9' ) ) {
975 if ( *s ==
'-' ) { sgn = VARTYPEMINUS; s++; }
976 else if ( *s ==
'+' || *s ==
'=' ) { sgn = 0; s++; }
978 while ( s[1] >=
'0' && s[1] <=
'9' ) {
979 x = 10*x + (s[1] -
'0'); s++;
981 if ( x >= MAXPOWER || x <= 1 ) {
982 MesPrint(
"&Illegal value for root of unity %s",name);
988 cplx = VARTYPEROOTOFUNITY | sgn;
991 MesPrint(
"&Illegal specification for complexity of symbol %s",name);
1001 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1003 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1004 ParseSignedNumber(dim,s)
1005 if ( dim < -HALFMAX || dim > HALFMAX ) {
1006 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1010 if ( *s !=
'}' )
goto IllDim;
1014IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1022 if ( ( cplx & VARTYPEROOTOFUNITY ) == VARTYPEROOTOFUNITY ) {
1023 MesPrint(
"&Root of unity property for %s cannot be combined with power restrictions",name);
1027 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1028 ParseSignedNumber(minpow,s)
1029 if ( minpow < -MAXPOWER ) {
1032 MesPrint(
"&Warning: minimum power of %s corrected to %d"
1042 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1043 ParseSignedNumber(maxpow,s)
1044 if ( maxpow > MAXPOWER ) {
1047 MesPrint(
"&Warning: maximum power of %s corrected to %d"
1051 if ( *s !=
')' )
goto skippar;
1054 if ( ( AC.AutoDeclareFlag == 0 &&
1055 ( ( type = GetName(AC.exprnames,name,&numsymbol,NOAUTO) )
1057 || ( ( type = GetName(*(AC.activenames),name,&numsymbol,NOAUTO) ) != NAMENOTFOUND ) ) {
1058 if ( type != CSYMBOL ) error = NameConflict(type,name);
1061 if ( ( numsymbol == AC.lPolyFunVar ) && ( AC.lPolyFunType > 0 )
1062 && ( AC.lPolyFun != 0 ) && ( minpow > -MAXPOWER || maxpow < MAXPOWER ) ) {
1063 MesPrint(
"&The symbol %s is used by power expansions in the PolyRatFun!",name);
1066 sym->complex = cplx;
1067 sym->minpower = minpow;
1068 sym->maxpower = maxpow;
1069 sym->dimension= dim;
1073 AddSymbol(name,minpow,maxpow,cplx,dim);
1076eol:
while ( *s ==
',' ) s++;
1088int AddIndex(UBYTE *name,
int dim,
int dim4)
1090 int nodenum, numindex = AC.Indices->num;
1093 bzero(ind,
sizeof(
struct InDeX));
1094 ind->name = AddName(*AC.activenames,name,CINDEX,numindex,&nodenum);
1096 ind->dimension = dim;
1099 ind->node = nodenum;
1101 ind->namesize = (s-name)+1;
1112int CoIndex(UBYTE *s)
1114 int type, error = 0, dim, dim4;
1116 UBYTE *name, *oldc, c;
1122IllForm: MesPrint(
"&Illegally formed name in index statement");
1127 oldc = s; c = *s; *s = 0;
1128 if ( TestName(name) ) { *s = c;
goto IllForm; }
1131 if ( ( s = DoDimension(s,&dim,&dim4) ) == 0 ) {
1138 if ( ( AC.AutoDeclareFlag == 0 &&
1139 ( ( type = GetName(AC.exprnames,name,&numindex,NOAUTO) )
1141 || ( ( type = GetName(*(AC.activenames),name,&numindex,NOAUTO) ) != NAMENOTFOUND ) ) {
1142 if ( type != CINDEX ) error = NameConflict(type,name);
1144 indices[numindex].dimension = dim;
1145 indices[numindex].nmin4 = dim4;
1148 else AddIndex(name,dim,dim4);
1150eol:
while ( *s ==
',' ) s++;
1160UBYTE *DoDimension(UBYTE *s,
int *dim,
int *dim4)
1163 int type, error = 0;
1165 NAMETREE **oldtree = AC.activenames;
1166 LIST* oldsymbols = AC.Symbols;
1167 *dim4 = -NMIN4SHIFT;
1168 if ( FG.cTable[*s] == 1 ) {
1171#if ( BITSINWORD/8 < 4 )
1172 if ( *dim >= (1 << (BITSINWORD-1)) )
goto illeg;
1177 else if ( ( (FG.cTable[*s] == 0 ) || ( *s ==
'[' ) )
1179 AC.activenames = &(AC.varnames);
1180 AC.Symbols = &(AC.SymbolList);
1182 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1183 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1184 if ( type != CSYMBOL ) error = NameConflict(type,t);
1187 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1189 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1192 if ( ( *s = c ) ==
':' ) {
1195 if ( ( s =
SkipAName(s) ) == 0 )
goto illeg;
1196 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1197 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1198 if ( type != CSYMBOL ) error = NameConflict(type,t);
1201 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1203 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1205 *dim4 = -numsymbol-NMIN4SHIFT;
1208 else if ( *s ==
'+' && FG.cTable[s[1]] == 1 ) {
1212illeg: MesPrint(
"&Illegal dimension specification. Should be number >= 0, symbol or symbol:symbol");
1215 AC.Symbols = oldsymbols;
1216 AC.activenames = oldtree;
1217 if ( error )
return(0);
1226int CoDimension(UBYTE *s)
1228 s = DoDimension(s,&AC.lDefDim,&AC.lDefDim4);
1229 if ( s == 0 )
return(1);
1231 MesPrint(
"&Argument of dimension statement should be number >= 0, symbol or symbol:symbol");
1244int AddVector(UBYTE *name,
int cplx,
int dim)
1246 int nodenum, numvector = AC.Vectors->num;
1249 bzero(v,
sizeof(
struct VeCtOr));
1250 v->name = AddName(*AC.activenames,name,CVECTOR,numvector,&nodenum);
1256 v->namesize = (s-name)+1;
1267int CoVector(UBYTE *s)
1269 int type, error = 0, dim;
1271 UBYTE *name, c, *endname;
1276IllForm: MesPrint(
"&Illegally formed name in vector statement");
1281 c = *s; *s = 0, endname = s;
1282 if ( TestName(name) ) { *s = c;
goto IllForm; }
1285 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1287 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1288 ParseSignedNumber(dim,s)
1289 if ( dim < -HALFMAX || dim > HALFMAX ) {
1290 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1294 if ( *s !=
'}' )
goto IllDim;
1298IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1301 while ( *s ==
',' ) s++;
1305 if ( ( AC.AutoDeclareFlag == 0 &&
1306 ( ( type = GetName(AC.exprnames,name,&numvector,NOAUTO) )
1308 || ( ( type = GetName(*(AC.activenames),name,&numvector,NOAUTO) ) != NAMENOTFOUND ) ) {
1309 if ( type != CVECTOR ) error = NameConflict(type,name);
1311 else AddVector(name,0,dim);
1314 while ( *s ==
',' ) s++;
1326int AddFunction(UBYTE *name,
int comm,
int istensor,
int cplx,
int symprop,
int dim,
int argmax,
int argmin)
1328 int nodenum, numfunction = AC.Functions->num;
1331 bzero(fun,
sizeof(
struct FuNcTiOn));
1332 fun->
name = AddName(*AC.activenames,name,CFUNCTION,numfunction,&nodenum);
1334 fun->
spec = istensor;
1338 fun->
node = nodenum;
1341 fun->dimension = dim;
1342 fun->maxnumargs = argmax;
1343 fun->minnumargs = argmin;
1346 return(numfunction);
1356int CoCommuteInSet(UBYTE *s)
1358 UBYTE *name, *ss, c, *start = s;
1359 WORD number, type, *g, *gg;
1360 int error = 0, i, len = StrLen(s), len2 = 0;
1361 if ( AC.CommuteInSet != 0 ) {
1362 g = AC.CommuteInSet;
1363 while ( *g ) g += *g;
1364 len2 = g - AC.CommuteInSet;
1365 if ( len2+len+3 > AC.SizeCommuteInSet ) {
1366 gg = (WORD *)Malloc1((len2+len+3)*
sizeof(WORD),
"CommuteInSet");
1367 for ( i = 0; i < len2; i++ ) gg[i] = AC.CommuteInSet[i];
1369 M_free(AC.CommuteInSet,
"CommuteInSet");
1370 AC.CommuteInSet = gg;
1371 AC.SizeCommuteInSet = len+len2+3;
1372 g = AC.CommuteInSet+len2;
1376 AC.SizeCommuteInSet = len+2;
1377 g = AC.CommuteInSet = (WORD *)Malloc1((len+3)*
sizeof(WORD),
"CommuteInSet");
1383 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1385 if ( s - start >= len )
break;
1390 MesPrint(
"&There should be at least two noncommuting functions or tensors in a commuting statement.");
1393 else if ( *gg == 2 ) {
1394 gg[2] = gg[1]; gg[3] = 0; gg[0] = 3;
1401 MesPrint(
"&The CommuteInSet statement should have sets enclosed in {}.");
1413 if ( ( type = GetName(AC.varnames,name,&number,NOAUTO) ) != CFUNCTION ) {
1414 MesPrint(
"&%s is not a function or tensor",name);
1417 else if ( functions[number].commute == 0 ){
1418 MesPrint(
"&%s is not a noncommuting function or tensor",name);
1422 *g++ = number+FUNCTION;
1423 functions[number].flags |= COULDCOMMUTE;
1424 if ( number+FUNCTION >= GAMMA && number+FUNCTION <= GAMMASEVEN ) {
1425 functions[GAMMA-FUNCTION].flags |= COULDCOMMUTE;
1426 functions[GAMMAI-FUNCTION].flags |= COULDCOMMUTE;
1427 functions[GAMMAFIVE-FUNCTION].flags |= COULDCOMMUTE;
1428 functions[GAMMASIX-FUNCTION].flags |= COULDCOMMUTE;
1429 functions[GAMMASEVEN-FUNCTION].flags |= COULDCOMMUTE;
1446int CoFunction(UBYTE *s,
int comm,
int istensor)
1448 int type, error = 0, cplx, symtype, dim, argmax, argmin;
1449 WORD numfunction, reverseorder = 0, addone;
1450 UBYTE *name, *oldc, *par, c, cc;
1452 symtype = cplx = 0, argmin = argmax = -1;
1456IllForm: MesPrint(
"&Illegally formed function/tensor name");
1461 oldc = s; cc = c = *s; *s = 0;
1462 if ( TestName(name) ) { *s = c;
goto IllForm; }
1465 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
1466 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
1467 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
1469 MesPrint(
"&Illegal specification for complexity of %s",name);
1479 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1481 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1482 ParseSignedNumber(dim,s)
1483 if ( dim < -HALFMAX || dim > HALFMAX ) {
1484 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1488 if ( *s !=
'}' )
goto IllDim;
1492IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1502 reverseorder = REVERSEORDER;
1509 while ( FG.cTable[*s] == 0 ) s++;
1513 MesPrint(
"&Illegal specification for symmetry of %s",name);
1519 if ( StrICont(par,(UBYTE *)
"symmetric") == 0 ) symtype = SYMMETRIC;
1520 else if ( StrICont(par,(UBYTE *)
"antisymmetric") == 0 ) symtype = ANTISYMMETRIC;
1521 else if ( ( StrICont(par,(UBYTE *)
"cyclesymmetric") == 0 )
1522 || ( StrICont(par,(UBYTE *)
"cyclic") == 0 ) ) symtype = CYCLESYMMETRIC;
1523 else if ( ( StrICont(par,(UBYTE *)
"rcyclesymmetric") == 0 )
1524 || ( StrICont(par,(UBYTE *)
"rcyclic") == 0 )
1525 || ( StrICont(par,(UBYTE *)
"reversecyclic") == 0 ) ) symtype = RCYCLESYMMETRIC;
1528 if ( *s !=
')' || ( s[1] && s[1] !=
',' && s[1] !=
'<' ) ) {
1529 Warning(
"Excess information in symmetric properties currently ignored");
1533 symtype |= reverseorder;
1539 if ( *s ==
'=' ) { addone++; s++; }
1541 while ( FG.cTable[*s] == 1 ) { argmax = 10*argmax + *s++ -
'0'; }
1544 while ( FG.cTable[*s] == 0 ) s++;
1547 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1548 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1550 Warning(
"Illegal information in number of arguments properties currently ignored");
1554 if ( argmax <= 0 ) {
1555 MesPrint(
"&Error: Cannot have fewer than 0 arguments for variable %s",name);
1562 if ( *s ==
'=' ) { addone = 0; s++; }
1564 while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ -
'0'; }
1567 while ( FG.cTable[*s] == 0 ) s++;
1570 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1571 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1573 Warning(
"Illegal information in number of arguments properties currently ignored");
1579 if ( cc ==
'<' )
goto retry;
1580 if ( ( AC.AutoDeclareFlag == 0 &&
1581 ( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
1583 || ( ( type = GetName(*(AC.activenames),name,&numfunction,NOAUTO) ) != NAMENOTFOUND ) ) {
1584 if ( type != CFUNCTION ) error = NameConflict(type,name);
1589 if ( fun->
tabl != 0 ) {
1590 MesPrint(
"&Illegal attempt to change table into function");
1596 if ( istensor && fun->
spec == 0 ) {
1597 MesPrint(
"&Function %s changed to tensor",name);
1600 else if ( istensor == 0 && fun->
spec > 0 ) {
1601 MesPrint(
"&Tensor %s changed to function",name);
1604 else if ( fun->
spec == VERTEXFUNCTION ) {
1605 MesPrint(
"&Function or Tensor %s already declared as a Particle",name);
1608 fun->
spec = istensor;
1611 AC.SymChangeFlag = 1;
1613 fun->maxnumargs = argmax;
1614 fun->minnumargs = argmin;
1618 AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
1621eol:
while ( *s ==
',' ) s++;
1626int CoNFunction(UBYTE *s) {
return(CoFunction(s,1,0)); }
1627int CoCFunction(UBYTE *s) {
return(CoFunction(s,0,0)); }
1628int CoNTensor(UBYTE *s) {
return(CoFunction(s,1,2)); }
1629int CoCTensor(UBYTE *s) {
return(CoFunction(s,0,2)); }
1666static int nwarntab = 1;
1668int DoTable(UBYTE *s,
int par)
1671 UBYTE *name, *p, *inp, c;
1672 int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
1673 int error = 0, ret, oldcbufnum, oldEside;
1674 WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;
1681 while ( *s ==
',' ) s++;
1685IllForm: MesPrint(
"&Illegal name or option in table declaration");
1689 if ( TestName(name) ) { *s = c;
goto IllForm; }
1691 if ( *s ==
'(' )
break;
1693 MesPrint(
"&Illegal definition of table");
1700 if ( StrICmp(name,(UBYTE *)(
"check" )) == 0 ) checkflag = 1;
1701 else if ( StrICmp(name,(UBYTE *)(
"zero" )) == 0 ) checkflag = 2;
1702 else if ( StrICmp(name,(UBYTE *)(
"one" )) == 0 ) checkflag = 3;
1703 else if ( StrICmp(name,(UBYTE *)(
"strict")) == 0 ) rflag = 1;
1704 else if ( StrICmp(name,(UBYTE *)(
"relax" )) == 0 ) rflag = -1;
1705 else if ( StrICmp(name,(UBYTE *)(
"zerofill" )) == 0 ) { rflag = -2; checkflag = 2; }
1706 else if ( StrICmp(name,(UBYTE *)(
"onefill" )) == 0 ) { rflag = -3; checkflag = 3; }
1707 else if ( StrICmp(name,(UBYTE *)(
"sparse")) == 0 ) sparseflag |= 1;
1708 else if ( StrICmp(name,(UBYTE *)(
"base")) == 0 ) sparseflag |= 3;
1709 else if ( StrICmp(name,(UBYTE *)(
"tablebase")) == 0 ) sparseflag |= 3;
1711 MesPrint(
"&Illegal option in table definition: '%s'",name);
1715 while ( *s ==
',' ) s++;
1717 if ( name == s || *s == 0 ) {
1718 MesPrint(
"&Illegal name or option in table declaration");
1723 if ( checkflag == 1 ) rflag = 0;
1724 else if ( checkflag == 2 ) rflag = -2;
1725 else if ( checkflag == 3 ) rflag = -3;
1728 if ( ( ret = GetVar(name,&type,&funnum,CFUNCTION,NOAUTO) ) ==
1731 funnum = EntVar(CFUNCTION,name,0,1,0,0);
1733 else if ( par == 1 || par == 2 ) {
1734 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1737 else if ( ret <= 0 ) {
1738 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1744 Warning(
"Table now declares its (commuting) function.");
1745 Warning(
"Earlier definition in Function statement obsolete. Please remove.");
1751 MesPrint(
"&(N)(C)Tables should not be declared previously");
1754 if ( functions[funnum].spec > 0 ) {
1755 MesPrint(
"&Tensors cannot become tables");
1758 if ( functions[funnum].symmetric > 0 ) {
1759 MesPrint(
"&Functions with nontrivial symmetrization properties cannot become tables");
1762 if ( functions[funnum].tabl ) {
1763 MesPrint(
"&Redefinition of an existing table is not allowed.");
1766 functions[funnum].tabl = T = (
TABLES)Malloc1(
sizeof(
struct TaBlEs),
"table");
1786 if ( rflag > 0 ) AC.MustTestTable++;
1800 T->
argtail = strDup1(p,
"argtail");
1809 if ( *p ==
'=' ) { inc++; p++; }
1814 while ( *p <=
'9' && *p >=
'0' ) x = 10*x + (*p++-
'0');
1817 MesPrint(
"&Maximum number of dimensions in *-table should be at least one.");
1824 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1826 MesPrint(
"&First argument in a sparse table must be a number of dimensions");
1832 T->
mm = (
MINMAX *)Malloc1(ABS(x)*
sizeof(
MINMAX),
"table dimensions");
1833 T->
flags = (WORD *)Malloc1(ABS(x)*
sizeof(WORD),
"table flags");
1836 if ( *inp !=
')' ) inp++;
1846 if ( FG.cTable[*p] != 1 && *p !=
'+' && *p !=
'-' )
break;
1847 ParseSignedNumber(x,p)
1848 if ( FG.cTable[p[-1]] != 1 || *p !=
':' )
break;
1850 ParseSignedNumber(y,p)
1851 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1852 MesPrint(
"&Illegal dimension field in table declaration");
1856 flags1 = (WORD *)Malloc1((T->
numind+1)*
sizeof(WORD),
"table flags");
1857 for ( i = 0; i < T->
numind; i++ ) { mm1[i] = T->
mm[i]; flags1[i] = T->
flags[i]; }
1858 if ( T->
mm ) M_free(T->
mm,
"table dimensions");
1859 if ( T->
flags ) M_free(T->
flags,
"table flags");
1866 if ( *p ==
')' ) { inp = p;
break; }
1869 = (WORD *)Malloc1(TABLEEXTENSION*
sizeof(WORD)*(T->
totind),
"table pointers");
1871 for ( i = TABLEEXTENSION*T->
totind; i > 0; i-- ) *w++ = -1;
1872 for ( i = T->
numind-1, x = 1; i >= 0; i-- ) {
1882 OldWork = AT.WorkPointer;
1883 oldcbufnum = AC.cbufnum;
1885 C = cbuf+AC.cbufnum;
1887 oldnumlhs = C->numlhs;
1888 oldnumrhs = C->numrhs;
1890 while ( s >= name ) *--inp = *s--;
1893 *w++ = SUBEXPRESSION;
1901 AT.WorkPointer = w + 4*AM.MaxWildcards;
1902 if ( ( ret = CompileAlgebra(inp,LHSIDE,AC.ProtoType) ) < 0 ) {
1903 error = 1;
goto FinishUp;
1905 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
1919 OldWork[2] = C->numrhs;
1920 *w++ = 1; *w++ = 1; *w++ = 3;
1921 OldWork[-1] = w-OldWork+1;
1923 ww = C->
rhs[C->numrhs];
1924 for ( j = 0; j < *ww; j++ ) w[j] = ww[j];
1925 AT.WorkPointer = w+*w;
1926 if ( *ww == 0 || ww[*ww] != 0 ) {
1927 MesPrint(
"&Illegal table pattern definition");
1928 AC.lhdollarflag = 0;
1931 if ( error )
goto FinishUp;
1933 if (
NewSort(BHEAD0) ||
NewSort(BHEAD0) ) { error = 1;
goto FinishUp; }
1934 AN.RepPoint = AT.RepCount + 1;
1935 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
1936 AR.Cnumlhs = C->numlhs;
1937 functions[funnum].tabl = 0;
1939 functions[funnum].tabl = T;
1940 AR.Eside = oldEside;
1943 functions[funnum].tabl = T;
1944 AR.Eside = oldEside;
1947 if ( *w == 0 || *(w+*w) != 0 ) {
1948 MesPrint(
"&Irregular pattern in table definition");
1953 if ( AC.lhdollarflag ) {
1954 MesPrint(
"&Unexpanded dollar variables are not allowed in table definition");
1958 AT.WorkPointer = ww = w + *w;
1959 if ( ww[-1] != 3 || ww[-2] != 1 || ww[-3] != 1 ) {
1960 MesPrint(
"&Coefficient of pattern in table definition should be 1.");
1969 j = *w + ABS(T->
numind)*2-3;
1972 T->
prototypeSize = ((i+j)*
sizeof(WORD)+2*
sizeof(WORD *)) * AM.totalnumberofthreads;
1975 t = (WORD *)(T->
pattern + AM.totalnumberofthreads);
1976 for ( n = 0; n < AM.totalnumberofthreads; n++ ) {
1978 for ( k = 0; k < i; k++ ) *t++ = OldWork[k];
1982 w[1] += ABS(T->
numind)*2;
1983 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1985 for ( k = 0; k < ABS(T->
numind); k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1986 for ( k = 0; k < j; k++ ) *t++ = *w++;
1989 for ( n = 1; n < AM.totalnumberofthreads; n++ ) {
1991 for ( i = 0; i < k; i++ ) *t++ = *tt++;
1998 for ( k = 0; k < i; k++ ) T->
prototype[k] = OldWork[k];
2001 w[1] += ABS(T->
numind)*2;
2002 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
2004 for ( k = 0; k < ABS(T->
numind); k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
2005 for ( k = 0; k < j; k++ ) *t++ = *w++;
2012 C->numrhs = oldnumrhs;
2013 C->numlhs = oldnumlhs;
2023 tt = t + t[1]; t += SUBEXPSIZE;
2025 if ( *t == LOADDOLLAR ) {
2026 Warning(
"The use of $-variable assignments in tables disables parallel\
2027 execution for the whole program.");
2028 AM.hparallelflag |= NOPARALLEL_TBLDOLLAR;
2029 AC.mparallelflag |= NOPARALLEL_TBLDOLLAR;
2035 AT.WorkPointer = OldWork - 1;
2036 AC.cbufnum = oldcbufnum;
2038 if ( T->
sparse ) ClearTableTree(T);
2039 if ( ( sparseflag & 2 ) != 0 ) {
2040 if ( T->
spare == 0 ) { SpareTable(T); }
2050int CoTable(UBYTE *s)
2052 return(DoTable(s,2));
2060int CoNTable(UBYTE *s)
2062 return(DoTable(s,0));
2070int CoCTable(UBYTE *s)
2072 return(DoTable(s,1));
2083 if ( T->
sparse ) ClearTableTree(T);
2101 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2102 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2115 for ( j = TABLEEXTENSION*T->
totind; j > 0; j-- ) *w++ = -1;
2124int AddSet(UBYTE *name, WORD dim)
2126 int nodenum, numset = AC.SetList.num;
2127 SETS set = (
SETS)FromVarList(&AC.SetList);
2130 set->name = AddName(AC.varnames,name,CSET,numset,&nodenum);
2133 set->namesize = (s-name)+1;
2134 set->node = nodenum;
2142 set->last = AC.SetElementList.num;
2144 set->dimension = dim;
2157int DoElements(UBYTE *s,
SETS set, UBYTE *name)
2159 int type, error = 0, x, sgn, i;
2163 if ( *s ==
',' ) { s++;
continue; }
2165 while ( *s ==
'-' || *s ==
'+' ) {
2166 if ( *s ==
'-' ) sgn ^= 1;
2170 if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'[' ) {
2172 MesPrint(
"&Illegal name in set definition");
2176 if ( ( ( type = GetName(AC.exprnames,cname,&numset,NOAUTO) ) == NAMENOTFOUND )
2177 && ( ( type = GetOName(AC.varnames,cname,&numset,WITHAUTO) ) == NAMENOTFOUND ) ) {
2180 MesPrint(
"&%s has not been declared",cname);
2184 numset = AC.DubiousList.num;
2185 dv = (
DUBIOUSV)FromVarList(&AC.DubiousList);
2186 dv->name = AddName(AC.varnames,cname,CDUBIOUS,numset,&nodenum);
2188 set->type = type = CDUBIOUS;
2192 if ( set->type == -1 ) {
2193 if ( type == CSYMBOL ) {
2194 for ( i = set->first; i < set->last; i++ ) {
2195 SetElements[i] += 2*MAXPOWER;
2200 if ( set->type != type && set->type != CDUBIOUS
2201 && type != CDUBIOUS ) {
2202 if ( set->type != CNUMBER || ( type != CSYMBOL
2203 && type != CINDEX ) ) {
2205 "&%s has not the same type as the other members of the set"
2208 set->type = CDUBIOUS;
2211 if ( type == CSYMBOL ) {
2212 for ( i = set->first; i < set->last; i++ ) {
2213 SetElements[i] += 2*MAXPOWER;
2219 if ( set->dimension != MAXPOSITIVE ) {
2220 switch ( set->type ) {
2222 if ( symbols[numset].dimension != set->dimension ) {
2223 MesPrint(
"&Dimension check failed in set %s, symbol %s",
2224 VARNAME(Sets,(set-Sets)),
2225 VARNAME(symbols,numset));
2227 set->dimension = MAXPOSITIVE;
2231 if ( vectors[numset-AM.OffsetVector].dimension != set->dimension ) {
2232 MesPrint(
"&Dimension check failed in set %s, vector %s",
2233 VARNAME(Sets,(set-Sets)),
2234 VARNAME(vectors,(numset-AM.OffsetVector)));
2236 set->dimension = MAXPOSITIVE;
2240 if ( functions[numset-FUNCTION].dimension != set->dimension ) {
2241 MesPrint(
"&Dimension check failed in set %s, function %s",
2242 VARNAME(Sets,(set-Sets)),
2243 VARNAME(functions,(numset-FUNCTION)));
2247 set->dimension = MAXPOSITIVE;
2251 if ( type != CVECTOR ) {
2252 MesPrint(
"&Illegal use of - sign in set. Can use only with vector or number");
2263 if ( name == 0 && *s ==
'?' ) {
2265 switch ( set->type ) {
2267 numset = -numset;
break;
2269 numset += WILDOFFSET;
break;
2271 numset |= WILDMASK;
break;
2273 numset |= WILDMASK;
break;
2280 e = (WORD *)FromVarList(&AC.SetElementList);
2284 else if ( FG.cTable[*s] == 1 ) {
2287 if ( x >= MAXPOWER || x <= -MAXPOWER ||
2288 ( set->type == CINDEX && ( x < 0 || x >= AM.OffsetIndex ) ) ) {
2289 MesPrint(
"&Illegal value for set element: %d",x);
2290 if ( AC.firstconstindex ) {
2291 MesPrint(
"&0 <= Fixed indices < ConstIndex(which is %d)",
2293 MesPrint(
"&For setting ConstIndex, read the chapter on the setup file");
2294 AC.firstconstindex = 0;
2302 if ( set->type == -1 ) {
2303 if ( x < 0 || x >= AM.OffsetIndex ) {
2304 for ( i = set->first; i < set->last; i++ ) {
2305 SetElements[i] += 2*MAXPOWER;
2307 set->type = CSYMBOL;
2309 else set->type = CNUMBER;
2311 else if ( set->type == CDUBIOUS ) {}
2312 else if ( set->type == CNUMBER && x < 0 ) {
2313 for ( i = set->first; i < set->last; i++ ) {
2314 SetElements[i] += 2*MAXPOWER;
2316 set->type = CSYMBOL;
2318 else if ( set->type != CSYMBOL && ( x < 0 ||
2319 ( set->type != CINDEX && set->type != CNUMBER ) ) ) {
2320 MesPrint(
"&Illegal mixture of element types in set");
2322 set->type = CDUBIOUS;
2327 e = (WORD *)FromVarList(&AC.SetElementList);
2329 if ( set->type == CSYMBOL ) *e = x + 2*MAXPOWER;
2334 MesPrint(
"&Illegal object in list of set elements");
2338 if ( error == 0 && ( ( set->flags & ORDEREDSET ) == ORDEREDSET ) ) {
2345 SimpleSplitMerge(SetElements+set->first,set->last-set->first);
2359 int type, error = 0, ordered = 0;
2360 UBYTE *name = s, c, *ss;
2362 WORD numberofset, dim = MAXPOSITIVE;
2369 while ( *ss && *ss !=
':' ) {
if ( *ss ==
'=' ) numeq++; ss++; }
2370 if ( *ss == 0 && numeq == 1 ) {
2371 while ( FG.cTable[*s] == 0 ) s++;
2372 ss = s; c = *s; *s = 0;
2375 MesPrint(
"&Proper syntax for value-set is `Set name = value'");
2379 while ( *s >=
'0' && *s <=
'9' ) x = 10*x + (*s++-
'0');
2380 if ( *s )
goto Proper;
2381 if ( StrICmp(name,(UBYTE *)
"maxweight") == 0 ) {
2384 else if ( StrICmp(name,(UBYTE *)
"defaultprecision") == 0 ) {
2385 AC.tDefaultPrecision = x;
2388 MesPrint(
"&Illegal subkey in value set: %s",name);
2396IllForm:MesPrint(
"&Illegal name for set");
2400 if ( TestName(name) )
goto IllForm;
2401 if ( ( ( type = GetName(AC.exprnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND )
2402 || ( ( type = GetName(AC.varnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND ) ) {
2403 if ( type != CSET ) NameConflict(type,name);
2405 MesPrint(
"&There is already a set with the name %s",name);
2410 numberofset = AddSet(name,0);
2411 set = Sets + numberofset;
2418 while ( *s !=
',' && *s !=
')' && *s ) s++;
2420 if ( StrICont(sss,(UBYTE *)
"ordered") == 0 ) {
2421 ordered = ORDEREDSET;
2424 MesPrint(
"&Error: Illegal option in set definition: %s",sss);
2429 MesPrint(
"&Error: Currently only one option allowed in set definition.");
2431 while ( *s && *s !=
')' ) s++;
2437 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
2439 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
2440 ParseSignedNumber(dim,s)
2441 if ( dim < -HALFMAX || dim > HALFMAX ) {
2442 MesPrint(
"&Warning: dimension of %s (%d) out of range"
2446 if ( *s !=
'}' )
goto IllDim;
2450IllDim: MesPrint(
"&Error: Illegal dimension field for set %s",name);
2454 while ( *s ==
',' ) s++;
2457 numberofset = AddSet(name,dim);
2459 set = Sets + numberofset;
2460 set->flags |= ordered;
2462 MesPrint(
"&Proper syntax is `Set name:elements'");
2466 error = DoElements(s,set,name);
2467 AC.SetList.numtemp = AC.SetList.num;
2468 AC.SetElementList.numtemp = AC.SetElementList.num;
2482int DoTempSet(UBYTE *from, UBYTE *to)
2487 int setnum = AddSet(0,MAXPOSITIVE);
2488 SETS set = Sets + setnum, setp;
2493 while ( *from ==
',' ) from++;
2494 if ( *from ==
'<' || *from ==
'>' ) {
2496 set->first = 3*MAXPOWER;
2497 set->last = -3*MAXPOWER;
2498 while ( *from ==
'<' || *from ==
'>' ) {
2499 if ( *from ==
'<' ) {
2501 if ( *from ==
'=' ) { from++; j++; }
2505 if ( *from ==
'=' ) { from++; j--; }
2508 while ( *from ==
'-' || *from ==
'+' ) {
2509 if ( *from ==
'-' ) sgn = -sgn;
2512 ParseNumber(num,from)
2513 if ( *from && *from !=
',' ) {
2514 MesPrint(
"&Illegal number in ranged set definition");
2517 if ( sgn < 0 ) num = -num;
2518 if ( num >= MAXPOWER || num <= -MAXPOWER ) {
2519 Warning(
"Value in ranged set too big. Adjusted to infinity.");
2520 if ( num > 0 ) num = 3*MAXPOWER;
2521 else num = -3*MAXPOWER;
2523 else if ( j == 2 ) num += 2*MAXPOWER;
2524 else if ( j == -2 ) num -= 2*MAXPOWER;
2525 if ( j > 0 ) set->first = num;
2526 else set->last = num;
2527 while ( *from ==
',' ) from++;
2530 MesPrint(
"&Definition of ranged set contains illegal objects");
2534 else if ( DoElements(from,set,(UBYTE *)0) != 0 ) {
2535 AC.SetElementList.num = set->first;
2536 AC.SetList.num--; *to = c;
2543 num = set->last - set->first;
2544 for ( setp = Sets, i = 0; i < AC.SetList.num-1; i++, setp++ ) {
2545 if ( num != setp->last - setp->first )
continue;
2546 if ( set->type != setp->type )
continue;
2547 if ( set->type == CRANGE ) {
2548 if ( set->first == setp->first )
return(setp-Sets);
2551 e = SetElements + set->first;
2552 ep = SetElements + setp->first;
2554 while ( --j >= 0 )
if ( *e++ != *ep++ )
break;
2556 AC.SetElementList.num = set->first;
2558 return(setp - Sets);
2574int CoAuto(UBYTE *inp)
2578 AC.Symbols = &(AC.AutoSymbolList);
2579 AC.Vectors = &(AC.AutoVectorList);
2580 AC.Indices = &(AC.AutoIndexList);
2581 AC.Functions = &(AC.AutoFunctionList);
2582 AC.activenames = &(AC.autonames);
2583 AC.AutoDeclareFlag = WITHAUTO;
2585 while ( *inp ==
',' ) inp++;
2586 retval = CompileStatement(inp);
2588 AC.AutoDeclareFlag = 0;
2589 AC.Symbols = &(AC.SymbolList);
2590 AC.Vectors = &(AC.VectorList);
2591 AC.Indices = &(AC.IndexList);
2592 AC.Functions = &(AC.FunctionList);
2593 AC.activenames = &(AC.varnames);
2604int AddDollar(UBYTE *name, WORD type, WORD *start, LONG size)
2606 int nodenum, numdollar = AP.DollarList.num;
2609 dol->name = AddName(AC.dollarnames,name,CDOLLAR,numdollar,&nodenum);
2611 dol->node = nodenum;
2613 dol->numdummies = 0;
2615 INIRECLOCK(dol->pthreadslock);
2621 if ( start && size > 0 ) {
2624 s = (WORD *)Malloc1((size+1)*
sizeof(WORD),
"$-variable contents");
2626 while ( --size >= 0 ) *s++ = *t++;
2629 else { dol->where = &(AM.dollarzero); dol->size = 0; }
2630 cbuf[AM.dbufnum].rhs[numdollar] = dol->where;
2631 cbuf[AM.dbufnum].CanCommu[numdollar] = 0;
2632 cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
2647int ReplaceDollar(WORD number, WORD newtype, WORD *newstart, LONG newsize)
2650 DOLLARS dol = Dollars + number;
2653 dol->type = newtype;
2654 if ( dol->size == newsize && newsize > 0 && newstart ) {
2655 s = dol->where; t = newstart; i = newsize;
2656 while ( --i >= 0 ) {
if ( *s++ != *t++ )
break; }
2657 if ( i < 0 )
return(0);
2659 if ( dol->where && dol->where != &(dol->zero) ) {
2660 M_free(dol->where,
"dollar->where"); dol->where = &(dol->zero); dol->size = 0;
2662 if ( newstart && newsize > 0 ) {
2663 dol->size = newsize;
2665 s = (WORD *)Malloc1((newsize+1)*
sizeof(WORD),
"$-variable contents");
2666 t = newstart; i = newsize;
2667 while ( --i >= 0 ) *s++ = *t++;
2680int AddDubious(UBYTE *name)
2682 int nodenum, numdubious = AC.DubiousList.num;
2684 dub->name = AddName(AC.varnames,name,CDUBIOUS,numdubious,&nodenum);
2685 dub->node = nodenum;
2694int MakeDubious(
NAMETREE *nametree, UBYTE *name, WORD *number)
2697 int node, newnode, i;
2698 if ( nametree->
namenode == 0 )
return(-1);
2705 else if ( i > 0 ) newnode = n->
right;
2707 if ( n->
type != CDUBIOUS ) {
2708 int numdubious = AC.DubiousList.num;
2716 }
while ( newnode >= 0 );
2725static char *nametype[] = {
"symbol",
"index",
"vector",
"function",
2726 "set",
"expression" };
2727static char *plural[] = {
"",
"n",
"",
"",
"",
"n" };
2729int NameConflict(
int type, UBYTE *name)
2731 if ( type == NAMENOTFOUND ) {
2732 MesPrint(
"&%s has not been declared",name);
2734 else if ( type != CDUBIOUS )
2735 MesPrint(
"&%s has been declared as a%s %s already"
2736 ,name,plural[type],nametype[type]);
2745int AddExpression(UBYTE *name,
int x,
int y)
2747 int nodenum, numexpr = AC.ExpressionList.num;
2751 expr->printflag = y;
2752 PUTZERO(expr->onfile);
2753 PUTZERO(expr->size);
2756 expr->hidelevel = 0;
2758 expr->bracketinfo = expr->newbracketinfo = 0;
2760 expr->name = AddName(AC.exprnames,name,CEXPRESSION,numexpr,&nodenum);
2761 expr->node = nodenum;
2762 expr->replace = NEWLYDEFINEDEXPRESSION ;
2765 expr->namesize = (s-name)+1;
2768 expr->replace = REDEFINEDEXPRESSION;
2769 expr->name = AC.TransEname;
2774 expr->numdummies = 0;
2775 expr->numfactors = 0;
2788int GetLabel(UBYTE *name)
2792 UBYTE **NewLabelNames;
2794 for ( i = 0; i < AC.NumLabels; i++ ) {
2795 if ( StrCmp(name,AC.LabelNames[i]) == 0 )
return(i);
2797 if ( AC.NumLabels >= AC.MaxLabels ) {
2798 newnum = 2*AC.MaxLabels;
2799 if ( newnum == 0 ) newnum = 10;
2800 if ( newnum > 32765 ) newnum = 32765;
2801 if ( newnum == AC.MaxLabels ) {
2802 MesPrint(
"&More than 32765 labels in one module. Please simplify.");
2805 NewLabelNames = (UBYTE **)Malloc1((
sizeof(UBYTE *)+
sizeof(
int))
2807 NewLabel = (
int *)(NewLabelNames+newnum);
2808 for ( i = 0; i< AC.MaxLabels; i++ ) {
2809 NewLabelNames[i] = AC.LabelNames[i];
2810 NewLabel[i] = AC.Labels[i];
2812 if ( AC.LabelNames ) M_free(AC.LabelNames,
"Labels");
2813 AC.LabelNames = NewLabelNames;
2814 AC.Labels = NewLabel;
2815 AC.MaxLabels = newnum;
2818 AC.LabelNames[i] = strDup1(name,
"Labels");
2833void ResetVariables(
int par)
2839 AC.SetList.num = AC.SetList.numtemp;
2840 AC.SetElementList.num = AC.SetElementList.numtemp;
2843 for ( i = AC.SymbolList.numclear; i < AC.SymbolList.num; i++ )
2844 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2845 AC.SymbolList.num = AC.SymbolList.numglobal = AC.SymbolList.numclear;
2846 for ( i = AC.VectorList.numclear; i < AC.VectorList.num; i++ )
2847 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2848 AC.VectorList.num = AC.VectorList.numglobal = AC.VectorList.numclear;
2849 for ( i = AC.IndexList.numclear; i < AC.IndexList.num; i++ )
2850 AC.varnames->namenode[indices[i].node].type = CDELETE;
2851 AC.IndexList.num = AC.IndexList.numglobal = AC.IndexList.numclear;
2852 for ( i = AC.FunctionList.numclear; i < AC.FunctionList.num; i++ ) {
2853 AC.varnames->namenode[functions[i].node].type = CDELETE;
2854 if ( ( T = functions[i].tabl ) != 0 ) {
2857 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2858 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2870 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2871 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2885 AC.FunctionList.num = AC.FunctionList.numglobal = AC.FunctionList.numclear;
2886 for ( i = AC.SetList.numclear; i < AC.SetList.num; i++ ) {
2887 if ( Sets[i].
node >= 0 )
2888 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2890 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal = AC.SetList.numclear;
2891 for ( i = AC.DubiousList.numclear; i < AC.DubiousList.num; i++ )
2892 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2893 AC.DubiousList.num = AC.DubiousList.numglobal = AC.DubiousList.numclear;
2894 AC.SetElementList.numtemp = AC.SetElementList.num =
2895 AC.SetElementList.numglobal = AC.SetElementList.numclear;
2896 CompactifyTree(AC.varnames,VARNAMES);
2897 AC.varnames->namefill = AC.varnames->globalnamefill = AC.varnames->clearnamefill;
2898 AC.varnames->nodefill = AC.varnames->globalnodefill = AC.varnames->clearnodefill;
2900 for ( i = AC.AutoSymbolList.numclear; i < AC.AutoSymbolList.num; i++ )
2901 AC.autonames->namenode[
2902 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2903 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal
2904 = AC.AutoSymbolList.numclear;
2905 for ( i = AC.AutoVectorList.numclear; i < AC.AutoVectorList.num; i++ )
2906 AC.autonames->namenode[
2907 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2908 AC.AutoVectorList.num = AC.AutoVectorList.numglobal
2909 = AC.AutoVectorList.numclear;
2910 for ( i = AC.AutoIndexList.numclear; i < AC.AutoIndexList.num; i++ )
2911 AC.autonames->namenode[
2912 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2913 AC.AutoIndexList.num = AC.AutoIndexList.numglobal
2914 = AC.AutoIndexList.numclear;
2915 for ( i = AC.AutoFunctionList.numclear; i < AC.AutoFunctionList.num; i++ ) {
2916 AC.autonames->namenode[
2917 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
2918 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2921 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2922 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2930 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2931 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2942 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal
2943 = AC.AutoFunctionList.numclear;
2944 CompactifyTree(AC.autonames,AUTONAMES);
2945 AC.autonames->namefill = AC.autonames->globalnamefill
2946 = AC.autonames->clearnamefill;
2947 AC.autonames->nodefill = AC.autonames->globalnodefill
2948 = AC.autonames->clearnodefill;
2952 for ( i = AC.SymbolList.numglobal; i < AC.SymbolList.num; i++ )
2953 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2954 AC.SymbolList.num = AC.SymbolList.numglobal;
2955 for ( i = AC.VectorList.numglobal; i < AC.VectorList.num; i++ )
2956 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2957 AC.VectorList.num = AC.VectorList.numglobal;
2958 for ( i = AC.IndexList.numglobal; i < AC.IndexList.num; i++ )
2959 AC.varnames->namenode[indices[i].node].type = CDELETE;
2960 AC.IndexList.num = AC.IndexList.numglobal;
2961 for ( i = AC.FunctionList.numglobal; i < AC.FunctionList.num; i++ ) {
2962 AC.varnames->namenode[functions[i].node].type = CDELETE;
2963 if ( ( T = functions[i].tabl ) != 0 ) {
2966 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2967 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2979 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2980 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2998 for ( i = 0; i < AC.FunctionList.numglobal; i++ ) {
3005 if ( ( T = functions[i].tabl ) != 0 ) {
3013#if TABLEEXTENSION == 2
3020 tp += TABLEEXTENSION;
3022 RedoTableTree(T,T->
totind);
3028#if TABLEEXTENSION == 2
3035 tp += TABLEEXTENSION;
3037 RedoTableTree(TT,TT->
totind);
3044#if TABLEEXTENSION == 2
3060 AC.FunctionList.num = AC.FunctionList.numglobal;
3061 for ( i = AC.SetList.numglobal; i < AC.SetList.num; i++ ) {
3062 if ( Sets[i].
node >= 0 )
3063 AC.varnames->namenode[Sets[i].node].type = CDELETE;
3065 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal;
3066 for ( i = AC.DubiousList.numglobal; i < AC.DubiousList.num; i++ )
3067 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
3068 AC.DubiousList.num = AC.DubiousList.numglobal;
3069 AC.SetElementList.numtemp = AC.SetElementList.num =
3070 AC.SetElementList.numglobal;
3071 CompactifyTree(AC.varnames,VARNAMES);
3072 AC.varnames->namefill = AC.varnames->globalnamefill;
3073 AC.varnames->nodefill = AC.varnames->globalnodefill;
3075 for ( i = AC.AutoSymbolList.numglobal; i < AC.AutoSymbolList.num; i++ )
3076 AC.autonames->namenode[
3077 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
3078 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal;
3079 for ( i = AC.AutoVectorList.numglobal; i < AC.AutoVectorList.num; i++ )
3080 AC.autonames->namenode[
3081 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
3082 AC.AutoVectorList.num = AC.AutoVectorList.numglobal;
3083 for ( i = AC.AutoIndexList.numglobal; i < AC.AutoIndexList.num; i++ )
3084 AC.autonames->namenode[
3085 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
3086 AC.AutoIndexList.num = AC.AutoIndexList.numglobal;
3087 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3088 AC.autonames->namenode[
3089 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
3090 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
3093 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
3094 if ( T->
flags ) M_free(T->
flags,
"tableflags");
3102 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
3103 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
3114 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal;
3116 CompactifyTree(AC.autonames,AUTONAMES);
3118 AC.autonames->namefill = AC.autonames->globalnamefill;
3119 AC.autonames->nodefill = AC.autonames->globalnodefill;
3129void RemoveDollars(
void)
3132 CBUF *C = cbuf + AM.dbufnum;
3133 int numdollar = AP.DollarList.num;
3134 if ( numdollar > 0 ) {
3135 while ( numdollar > AM.gcNumDollars ) {
3137 d = Dollars + numdollar;
3138 if ( d->where && d->where != &(d->zero) && d->where != &(AM.dollarzero) ) {
3139 M_free(d->where,
"dollar->where"); d->where = &(d->zero); d->size = 0;
3141 AC.dollarnames->namenode[d->node].type = CDELETE;
3143 AP.DollarList.num = AM.gcNumDollars;
3144 CompactifyTree(AC.dollarnames,DOLLARNAMES);
3146 C->numrhs = C->mnumrhs;
3147 C->numlhs = C->mnumlhs;
3156void Globalize(
int par)
3161 AC.SymbolList.numclear = AC.SymbolList.num;
3162 AC.VectorList.numclear = AC.VectorList.num;
3163 AC.IndexList.numclear = AC.IndexList.num;
3164 AC.FunctionList.numclear = AC.FunctionList.num;
3165 AC.SetList.numclear = AC.SetList.num;
3166 AC.DubiousList.numclear = AC.DubiousList.num;
3167 AC.SetElementList.numclear = AC.SetElementList.num;
3168 AC.varnames->clearnamefill = AC.varnames->namefill;
3169 AC.varnames->clearnodefill = AC.varnames->nodefill;
3171 AC.AutoSymbolList.numclear = AC.AutoSymbolList.num;
3172 AC.AutoVectorList.numclear = AC.AutoVectorList.num;
3173 AC.AutoIndexList.numclear = AC.AutoIndexList.num;
3174 AC.AutoFunctionList.numclear = AC.AutoFunctionList.num;
3175 AC.autonames->clearnamefill = AC.autonames->namefill;
3176 AC.autonames->clearnodefill = AC.autonames->nodefill;
3179 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
3184 if ( functions[i].tabl ) {
3185 TABLES T = functions[i].tabl;
3190#if TABLEEXTENSION == 2
3193 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3195 tp += TABLEEXTENSION;
3202#if TABLEEXTENSION == 2
3205 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3207 tp += TABLEEXTENSION;
3216#if TABLEEXTENSION == 2
3219 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3227 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3228 if ( ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl )
3229 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->mdefined =
3230 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->defined;
3232 AC.SymbolList.numglobal = AC.SymbolList.num;
3233 AC.VectorList.numglobal = AC.VectorList.num;
3234 AC.IndexList.numglobal = AC.IndexList.num;
3235 AC.FunctionList.numglobal = AC.FunctionList.num;
3236 AC.SetList.numglobal = AC.SetList.num;
3237 AC.DubiousList.numglobal = AC.DubiousList.num;
3238 AC.SetElementList.numglobal = AC.SetElementList.num;
3239 AC.varnames->globalnamefill = AC.varnames->namefill;
3240 AC.varnames->globalnodefill = AC.varnames->nodefill;
3242 AC.AutoSymbolList.numglobal = AC.AutoSymbolList.num;
3243 AC.AutoVectorList.numglobal = AC.AutoVectorList.num;
3244 AC.AutoIndexList.numglobal = AC.AutoIndexList.num;
3245 AC.AutoFunctionList.numglobal = AC.AutoFunctionList.num;
3246 AC.autonames->globalnamefill = AC.autonames->namefill;
3247 AC.autonames->globalnodefill = AC.autonames->nodefill;
3255int TestName(UBYTE *name)
3257 if ( *name ==
'[' ) {
3258 while ( *name ) name++;
3259 if ( name[-1] ==
']' )
return(0);
3263 if ( *name ==
'_' )
return(-1);
3264 if ( *name ==
'$' )
return(-1);
UBYTE * SkipAName(UBYTE *s)
int SortWild(WORD *, WORD)
void AddPotModdollar(WORD)
LONG EndSort(PHEAD WORD *, int)
int Generator(PHEAD WORD *, WORD)
UBYTE * SkipField(UBYTE *, int)
void LowerSortLevel(void)
struct FuNcTiOn * FUNCTIONS