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;
234 MesPrint(
"!>We ran into an impossible case in AddName\n");
254int GetName(
NAMETREE *nametree, UBYTE *namein, WORD *number,
int par)
257 int node, newnode, i;
258 UBYTE *s, *t, *u, *name;
268 else if ( i > 0 ) newnode = n->
right;
273 }
while ( newnode >= 0 );
276 if ( s > name && s[-1] ==
'_' && nametree == AC.varnames ) {
280 if ( s == name+2 && ( *name ==
'd' || *name ==
'D' ) ) {
281 *number = DELTA-FUNCTION;
287 if ( s > name+2 && *name ==
'N' ) {
289 while ( FG.cTable[*t] == 1 ) i = 10*i + *t++ -
'0';
291 *number = i + AM.IndDum - AM.OffsetIndex;
304 else if ( i > 0 ) newnode = n->
right;
308 }
while ( newnode >= 0 );
315 t = name; u = AC.extrasym;
316 while ( *t == *u ) { t++; u++; }
317 if ( *u == 0 && *t != 0 ) {
319 while ( FG.cTable[*t] == 1 ) {
320 x = 10*x + (*t++ -
'0');
322 if ( *t ==
'_' && x > 0 && x <= cbuf[AM.sbufnum].numrhs ) {
323 *number = MAXVARIABLES-x;
329 if ( par != WITHAUTO || nametree == AC.autonames )
return(NAMENOTFOUND);
330 return(GetAutoName(name,number));
344UBYTE *GetFunction(UBYTE *s,WORD *funnum)
350 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
352 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
356 MesPrint(
"&%s is undefined",s);
357 numfun = AddDollar(s+1,DOLINDEX,&one,1);
364 if ( ( ( type = GetName(AC.varnames,s,&numfun,WITHAUTO) ) != CFUNCTION )
365 || ( functions[numfun].spec > 0 ) ) {
366 MesPrint(
"&%s should be a regular function",s);
369 if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
370 AddFunction(s,0,0,0,0,0,-1,-1);
375 *funnum = numfun+FUNCTION;
390UBYTE *GetNumber(UBYTE *s,WORD *num)
395 while ( *s ==
'+' ) s++;
397 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
399 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
403 MesPrint(
"&%s is undefined",s);
404 numfun = AddDollar(s+1,DOLINDEX,&one,1);
408 else if ( *s >=
'0' && *s <=
'9' ) {
409 ULONG x = *s++ -
'0';
410 while ( *s >=
'0' && *s <=
'9' ) { x = 10*x + (*s++-
'0'); }
412 if ( x >= MAXPOSITIVE )
goto illegal;
417 if ( *s ==
'-' ) { s++; }
418 if ( *s >=
'0' && *s <=
'9' ) {
while ( *s >=
'0' && *s <=
'9' ) s++; t1 = s; }
422 MesPrint(
"&Illegal option in Canonicalize statement. Should be a nonnegative number or $ variable.");
440int GetLastExprName(UBYTE *name, WORD *number)
444 for ( i = NumExpressions; i > 0; i-- ) {
446 if ( StrCmp(AC.exprnames->namebuffer+e->name,name) == 0 ) {
462int GetOName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
464 int retval = GetName(nametree,name,number,par);
466 case CVECTOR: *number += AM.OffsetVector;
break;
467 case CINDEX: *number += AM.OffsetIndex;
break;
468 case CFUNCTION: *number += FUNCTION;
break;
481int GetAutoName(UBYTE *name, WORD *number)
485 if ( GetName(AC.exprnames,name,number,NOAUTO) != NAMENOTFOUND )
486 return(NAMENOTFOUND);
488 while ( *s ) { s++; }
489 if ( s[-1] ==
'_' ) {
490 return(NAMENOTFOUND);
494 type = GetName(AC.autonames,name,number,NOAUTO);
499 *number = AddSymbol(name,sym->minpower,sym->maxpower,sym->complex,sym->dimension);
503 *number = AddVector(name,vec->complex,vec->dimension);
507 *number = AddIndex(name,ind->dimension,ind->nmin4);
518 return(NAMENOTFOUND);
526int GetVar(UBYTE *name, WORD *type, WORD *number,
int wantedtype,
int par)
530 if ( ( typ = GetName(AC.varnames,name,number,par) ) != wantedtype ) {
531 if ( typ != NAMENOTFOUND ) {
532 if ( wantedtype == -1 ) {
536 NameConflict(typ,name);
537 MakeDubious(AC.varnames,name,&funnum);
540 if ( ( typ = GetName(AC.exprnames,name,&funnum,par) ) != NAMENOTFOUND ) {
541 if ( typ == wantedtype || wantedtype == -1 ) {
542 *number = funnum; *type = typ;
return(1);
544 NameConflict(typ,name);
547 return(NAMENOTFOUND);
549 if ( typ == -1 ) {
return(0); }
559int EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
563 return(AddSymbol(name,y,z,x,d));
566 return(AddIndex(name,x,z));
569 return(AddVector(name,x,d));
572 return(AddFunction(name,y,z,x,0,d,-1,-1));
575 AC.SetList.numtemp++;
576 return(AddSet(name,d));
579 return(AddExpression(name,x,y));
592int GetDollar(UBYTE *name)
595 if ( GetName(AC.dollarnames,name,&number,NOAUTO) == NAMENOTFOUND )
return(-1);
608 DumpNode(nametree,nametree->
headnode,0);
623 if ( n->
left >= 0 ) DumpNode(nametree,n->
left,depth+1);
624 for ( i = 0; i < depth; i++ ) printf(
" ");
626 printf(
"%s(%d): {%d}(%d)(%d)[%d]\n",
628 if ( n->
right >= 0 ) DumpNode(nametree,n->
right,depth+1);
636int CompactifyTree(
NAMETREE *nametree,WORD par)
643 for ( i = 0, j = 0, k = 0, n = nametree->
namenode, ns = 0;
644 i < nametree->
nodefill; i++, n++ ) {
645 if ( n->
type != CDELETE ) {
647 while ( *s ) { s++; ns++; }
652 if ( k == 0 )
return(0);
667 if ( j < 10 ) j = 10;
668 if ( ns < 100 ) ns = 100;
671 newtree.
namebuffer = (UBYTE *)Malloc1(2*ns,
"compactify namestree");
673 CopyTree(&newtree,nametree,nametree->
headnode,par);
675 LinkTree(&newtree,(WORD)0,newtree.
nodefill);
677 M_free(nametree->
namebuffer,
"nametree->namebuffer");
678 M_free(nametree->
namenode,
"nametree->namenode");
703 if ( n->
left >= 0 ) CopyTree(newtree,oldtree,n->
left,par);
704 if ( n->
type != CDELETE ) {
713 if ( par == AUTONAMES ) {
723 if ( par == AUTONAMES ) {
733 if ( par == AUTONAMES ) {
743 if ( par == AUTONAMES ) {
770 MesPrint(
"!>Illegal variable type in CopyTree: %d",n->
type);
777 while ( *t ) { *s++ = *t++; newtree->
namefill++; }
780 if ( n->
right >= 0 ) CopyTree(newtree,oldtree,n->
right,par);
788void LinkTree(
NAMETREE *
tree, WORD offset, WORD numnodes)
793 int med,numleft,numright,medleft,medright;
796 numright = numnodes - med - 1;
797 medleft = numleft >> 1;
798 medright = ( numright >> 1 ) + med + 1;
800 tree->namenode[offset+med].
left = offset+medleft;
801 tree->namenode[offset+medleft].
parent = offset+med;
803 if ( numright > 0 ) {
804 tree->namenode[offset+med].
right = offset+medright;
805 tree->namenode[offset+medright].
parent = offset+med;
807 if ( numleft > 0 ) LinkTree(
tree,offset,numleft);
808 if ( numright > 0 ) LinkTree(
tree,offset+med+1,numright);
809 while ( numleft && numright ) { numleft >>= 1; numright >>= 1; }
810 if ( numleft )
tree->namenode[offset+med].balance = -1;
811 else if ( numright )
tree->namenode[offset+med].balance = 1;
843 M_free(n,
"nametree");
853void ClearWildcardNames(
void)
855 AC.NumWildcardNames = 0;
858int AddWildcardName(UBYTE *name)
861 int size = 0, tocopy, i;
862 UBYTE *s = name, *t, *newbuffer;
863 while ( *s ) { s++; size++; }
864 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
866 while ( ( *s == *t ) && *s ) { s++; t++; }
867 if ( *s == 0 && *t == 0 )
return(i+1);
871 tocopy = t - AC.WildcardNames;
872 if ( tocopy + size + 1 > AC.WildcardBufferSize ) {
873 if ( AC.WildcardBufferSize == 0 ) {
874 AC.WildcardBufferSize = size+1;
875 if ( AC.WildcardBufferSize < 100 ) AC.WildcardBufferSize = 100;
877 else if ( size+1 >= AC.WildcardBufferSize ) {
878 AC.WildcardBufferSize += size+1;
881 AC.WildcardBufferSize *= 2;
883 newbuffer = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
885 if ( AC.WildcardNames ) {
886 s = AC.WildcardNames;
887 while ( tocopy > 0 ) { *t++ = *s++; tocopy--; }
888 M_free(AC.WildcardNames,
"AC.WildcardNames");
890 AC.WildcardNames = newbuffer;
891 M_free(AT.WildArgTaken,
"AT.WildArgTaken");
892 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
893 ,
"argument list names");
896 while ( *s ) *t++ = *s++;
898 AC.NumWildcardNames++;
899 return(AC.NumWildcardNames);
902int GetWildcardName(UBYTE *name)
906 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
908 while ( ( *s == *t ) && *s ) { s++; t++; }
909 if ( *s == 0 && *t == 0 )
return(i+1);
924int AddSymbol(UBYTE *name,
int minpow,
int maxpow,
int cplx,
int dim)
926 int nodenum, numsymbol = AC.Symbols->num;
929 bzero(sym,
sizeof(
struct SyMbOl));
930 sym->name = AddName(*AC.activenames,name,CSYMBOL,numsymbol,&nodenum);
931 sym->minpower = minpow;
932 sym->maxpower = maxpow;
938 sym->namesize = (s-name)+1;
950int CoSymbol(UBYTE *s)
952 int type, error = 0, minpow, maxpow, cplx, sgn, dim;
954 UBYTE *name, *oldc, c, cc;
962IllForm: MesPrint(
"&Illegally formed name in symbol statement");
967 oldc = s; cc = c = *s; *s = 0;
968 if ( TestName(name) ) { *s = c;
goto IllForm; }
971 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
972 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
973 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
974 else if ( ( ( *s ==
'-' || *s ==
'+' || *s ==
'=' )
975 && ( s[1] >=
'0' && s[1] <=
'9' ) )
976 || ( *s >=
'0' && *s <=
'9' ) ) {
979 if ( *s ==
'-' ) { sgn = VARTYPEMINUS; s++; }
980 else if ( *s ==
'+' || *s ==
'=' ) { sgn = 0; s++; }
982 while ( s[1] >=
'0' && s[1] <=
'9' ) {
983 x = 10*x + (s[1] -
'0'); s++;
985 if ( x >= MAXPOWER || x <= 1 ) {
986 MesPrint(
"&Illegal value for root of unity %s",name);
992 cplx = VARTYPEROOTOFUNITY | sgn;
995 MesPrint(
"&Illegal specification for complexity of symbol %s",name);
1005 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1007 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1008 ParseSignedNumber(dim,s)
1009 if ( dim < -HALFMAX || dim > HALFMAX ) {
1010 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1014 if ( *s !=
'}' )
goto IllDim;
1018IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1026 if ( ( cplx & VARTYPEROOTOFUNITY ) == VARTYPEROOTOFUNITY ) {
1027 MesPrint(
"&Root of unity property for %s cannot be combined with power restrictions",name);
1031 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1032 ParseSignedNumber(minpow,s)
1033 if ( minpow < -MAXPOWER ) {
1036 MesPrint(
"&Warning: minimum power of %s corrected to %d"
1046 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1047 ParseSignedNumber(maxpow,s)
1048 if ( maxpow > MAXPOWER ) {
1051 MesPrint(
"&Warning: maximum power of %s corrected to %d"
1055 if ( *s !=
')' )
goto skippar;
1058 if ( ( AC.AutoDeclareFlag == 0 &&
1059 ( ( type = GetName(AC.exprnames,name,&numsymbol,NOAUTO) )
1061 || ( ( type = GetName(*(AC.activenames),name,&numsymbol,NOAUTO) ) != NAMENOTFOUND ) ) {
1062 if ( type != CSYMBOL ) error = NameConflict(type,name);
1065 if ( ( numsymbol == AC.lPolyFunVar ) && ( AC.lPolyFunType > 0 )
1066 && ( AC.lPolyFun != 0 ) && ( minpow > -MAXPOWER || maxpow < MAXPOWER ) ) {
1067 MesPrint(
"&The symbol %s is used by power expansions in the PolyRatFun!",name);
1070 sym->complex = cplx;
1071 sym->minpower = minpow;
1072 sym->maxpower = maxpow;
1073 sym->dimension= dim;
1077 AddSymbol(name,minpow,maxpow,cplx,dim);
1080eol:
while ( *s ==
',' ) s++;
1092int AddIndex(UBYTE *name,
int dim,
int dim4)
1094 int nodenum, numindex = AC.Indices->num;
1097 bzero(ind,
sizeof(
struct InDeX));
1098 ind->name = AddName(*AC.activenames,name,CINDEX,numindex,&nodenum);
1100 ind->dimension = dim;
1103 ind->node = nodenum;
1105 ind->namesize = (s-name)+1;
1116int CoIndex(UBYTE *s)
1118 int type, error = 0, dim, dim4;
1120 UBYTE *name, *oldc, c;
1126IllForm: MesPrint(
"&Illegally formed name in index statement");
1131 oldc = s; c = *s; *s = 0;
1132 if ( TestName(name) ) { *s = c;
goto IllForm; }
1135 if ( ( s = DoDimension(s,&dim,&dim4) ) == 0 ) {
1142 if ( ( AC.AutoDeclareFlag == 0 &&
1143 ( ( type = GetName(AC.exprnames,name,&numindex,NOAUTO) )
1145 || ( ( type = GetName(*(AC.activenames),name,&numindex,NOAUTO) ) != NAMENOTFOUND ) ) {
1146 if ( type != CINDEX ) error = NameConflict(type,name);
1148 indices[numindex].dimension = dim;
1149 indices[numindex].nmin4 = dim4;
1152 else AddIndex(name,dim,dim4);
1154eol:
while ( *s ==
',' ) s++;
1164UBYTE *DoDimension(UBYTE *s,
int *dim,
int *dim4)
1167 int type, error = 0;
1169 NAMETREE **oldtree = AC.activenames;
1170 LIST* oldsymbols = AC.Symbols;
1171 *dim4 = -NMIN4SHIFT;
1172 if ( FG.cTable[*s] == 1 ) {
1175#if ( BITSINWORD/8 < 4 )
1176 if ( *dim >= (1 << (BITSINWORD-1)) )
goto illeg;
1181 else if ( ( (FG.cTable[*s] == 0 ) || ( *s ==
'[' ) )
1183 AC.activenames = &(AC.varnames);
1184 AC.Symbols = &(AC.SymbolList);
1186 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1187 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1188 if ( type != CSYMBOL ) error = NameConflict(type,t);
1191 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1193 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1196 if ( ( *s = c ) ==
':' ) {
1199 if ( ( s =
SkipAName(s) ) == 0 )
goto illeg;
1200 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1201 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1202 if ( type != CSYMBOL ) error = NameConflict(type,t);
1205 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1207 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1209 *dim4 = -numsymbol-NMIN4SHIFT;
1212 else if ( *s ==
'+' && FG.cTable[s[1]] == 1 ) {
1216illeg: MesPrint(
"&Illegal dimension specification. Should be number >= 0, symbol or symbol:symbol");
1219 AC.Symbols = oldsymbols;
1220 AC.activenames = oldtree;
1221 if ( error )
return(0);
1230int CoDimension(UBYTE *s)
1232 s = DoDimension(s,&AC.lDefDim,&AC.lDefDim4);
1233 if ( s == 0 )
return(1);
1235 MesPrint(
"&Argument of dimension statement should be number >= 0, symbol or symbol:symbol");
1248int AddVector(UBYTE *name,
int cplx,
int dim)
1250 int nodenum, numvector = AC.Vectors->num;
1253 bzero(v,
sizeof(
struct VeCtOr));
1254 v->name = AddName(*AC.activenames,name,CVECTOR,numvector,&nodenum);
1260 v->namesize = (s-name)+1;
1271int CoVector(UBYTE *s)
1273 int type, error = 0, dim;
1275 UBYTE *name, c, *endname;
1280IllForm: MesPrint(
"&Illegally formed name in vector statement");
1285 c = *s; *s = 0, endname = s;
1286 if ( TestName(name) ) { *s = c;
goto IllForm; }
1289 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1291 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1292 ParseSignedNumber(dim,s)
1293 if ( dim < -HALFMAX || dim > HALFMAX ) {
1294 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1298 if ( *s !=
'}' )
goto IllDim;
1302IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1305 while ( *s ==
',' ) s++;
1309 if ( ( AC.AutoDeclareFlag == 0 &&
1310 ( ( type = GetName(AC.exprnames,name,&numvector,NOAUTO) )
1312 || ( ( type = GetName(*(AC.activenames),name,&numvector,NOAUTO) ) != NAMENOTFOUND ) ) {
1313 if ( type != CVECTOR ) error = NameConflict(type,name);
1315 else AddVector(name,0,dim);
1318 while ( *s ==
',' ) s++;
1330int AddFunction(UBYTE *name,
int comm,
int istensor,
int cplx,
int symprop,
int dim,
int argmax,
int argmin)
1332 int nodenum, numfunction = AC.Functions->num;
1335 bzero(fun,
sizeof(
struct FuNcTiOn));
1336 fun->
name = AddName(*AC.activenames,name,CFUNCTION,numfunction,&nodenum);
1338 fun->
spec = istensor;
1342 fun->
node = nodenum;
1345 fun->dimension = dim;
1346 fun->maxnumargs = argmax;
1347 fun->minnumargs = argmin;
1350 return(numfunction);
1360int CoCommuteInSet(UBYTE *s)
1362 UBYTE *name, *ss, c, *start = s;
1363 WORD number, type, *g, *gg;
1364 int error = 0, i, len = StrLen(s), len2 = 0;
1365 if ( AC.CommuteInSet != 0 ) {
1366 g = AC.CommuteInSet;
1367 while ( *g ) g += *g;
1368 len2 = g - AC.CommuteInSet;
1369 if ( len2+len+3 > AC.SizeCommuteInSet ) {
1370 gg = (WORD *)Malloc1((len2+len+3)*
sizeof(WORD),
"CommuteInSet");
1371 for ( i = 0; i < len2; i++ ) gg[i] = AC.CommuteInSet[i];
1373 M_free(AC.CommuteInSet,
"CommuteInSet");
1374 AC.CommuteInSet = gg;
1375 AC.SizeCommuteInSet = len+len2+3;
1376 g = AC.CommuteInSet+len2;
1380 AC.SizeCommuteInSet = len+2;
1381 g = AC.CommuteInSet = (WORD *)Malloc1((len+3)*
sizeof(WORD),
"CommuteInSet");
1387 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1389 if ( s - start >= len )
break;
1394 MesPrint(
"&There should be at least two noncommuting functions or tensors in a commuting statement.");
1397 else if ( *gg == 2 ) {
1398 gg[2] = gg[1]; gg[3] = 0; gg[0] = 3;
1405 MesPrint(
"&The CommuteInSet statement should have sets enclosed in {}.");
1417 if ( ( type = GetName(AC.varnames,name,&number,NOAUTO) ) != CFUNCTION ) {
1418 MesPrint(
"&%s is not a function or tensor",name);
1421 else if ( functions[number].commute == 0 ){
1422 MesPrint(
"&%s is not a noncommuting function or tensor",name);
1426 *g++ = number+FUNCTION;
1427 functions[number].flags |= COULDCOMMUTE;
1428 if ( number+FUNCTION >= GAMMA && number+FUNCTION <= GAMMASEVEN ) {
1429 functions[GAMMA-FUNCTION].flags |= COULDCOMMUTE;
1430 functions[GAMMAI-FUNCTION].flags |= COULDCOMMUTE;
1431 functions[GAMMAFIVE-FUNCTION].flags |= COULDCOMMUTE;
1432 functions[GAMMASIX-FUNCTION].flags |= COULDCOMMUTE;
1433 functions[GAMMASEVEN-FUNCTION].flags |= COULDCOMMUTE;
1450int CoFunction(UBYTE *s,
int comm,
int istensor)
1452 int type, error = 0, cplx, symtype, dim, argmax, argmin;
1453 WORD numfunction, reverseorder = 0, addone;
1454 UBYTE *name, *oldc, *par, c, cc;
1456 symtype = cplx = 0, argmin = argmax = -1;
1460IllForm: MesPrint(
"&Illegally formed function/tensor name");
1465 oldc = s; cc = c = *s; *s = 0;
1466 if ( TestName(name) ) { *s = c;
goto IllForm; }
1469 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
1470 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
1471 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
1473 MesPrint(
"&Illegal specification for complexity of %s",name);
1483 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1485 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1486 ParseSignedNumber(dim,s)
1487 if ( dim < -HALFMAX || dim > HALFMAX ) {
1488 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1492 if ( *s !=
'}' )
goto IllDim;
1496IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1506 reverseorder = REVERSEORDER;
1513 while ( FG.cTable[*s] == 0 ) s++;
1517 MesPrint(
"&Illegal specification for symmetry of %s",name);
1523 if ( StrICont(par,(UBYTE *)
"symmetric") == 0 ) symtype = SYMMETRIC;
1524 else if ( StrICont(par,(UBYTE *)
"antisymmetric") == 0 ) symtype = ANTISYMMETRIC;
1525 else if ( ( StrICont(par,(UBYTE *)
"cyclesymmetric") == 0 )
1526 || ( StrICont(par,(UBYTE *)
"cyclic") == 0 ) ) symtype = CYCLESYMMETRIC;
1527 else if ( ( StrICont(par,(UBYTE *)
"rcyclesymmetric") == 0 )
1528 || ( StrICont(par,(UBYTE *)
"rcyclic") == 0 )
1529 || ( StrICont(par,(UBYTE *)
"reversecyclic") == 0 ) ) symtype = RCYCLESYMMETRIC;
1532 if ( *s !=
')' || ( s[1] && s[1] !=
',' && s[1] !=
'<' ) ) {
1533 Warning(
"Excess information in symmetric properties currently ignored");
1537 symtype |= reverseorder;
1543 if ( *s ==
'=' ) { addone++; s++; }
1545 while ( FG.cTable[*s] == 1 ) { argmax = 10*argmax + *s++ -
'0'; }
1548 while ( FG.cTable[*s] == 0 ) s++;
1551 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1552 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1554 Warning(
"Illegal information in number of arguments properties currently ignored");
1558 if ( argmax <= 0 ) {
1559 MesPrint(
"&Error: Cannot have fewer than 0 arguments for variable %s",name);
1566 if ( *s ==
'=' ) { addone = 0; s++; }
1568 while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ -
'0'; }
1571 while ( FG.cTable[*s] == 0 ) s++;
1574 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1575 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1577 Warning(
"Illegal information in number of arguments properties currently ignored");
1583 if ( cc ==
'<' )
goto retry;
1584 if ( ( AC.AutoDeclareFlag == 0 &&
1585 ( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
1587 || ( ( type = GetName(*(AC.activenames),name,&numfunction,NOAUTO) ) != NAMENOTFOUND ) ) {
1588 if ( type != CFUNCTION ) error = NameConflict(type,name);
1593 if ( fun->
tabl != 0 ) {
1594 MesPrint(
"&Illegal attempt to change table into function");
1600 if ( istensor && fun->
spec == 0 ) {
1601 MesPrint(
"&Function %s changed to tensor",name);
1604 else if ( istensor == 0 && fun->
spec > 0 ) {
1605 MesPrint(
"&Tensor %s changed to function",name);
1608 else if ( fun->
spec == VERTEXFUNCTION ) {
1609 MesPrint(
"&Function or Tensor %s already declared as a Particle",name);
1612 fun->
spec = istensor;
1615 AC.SymChangeFlag = 1;
1617 fun->maxnumargs = argmax;
1618 fun->minnumargs = argmin;
1622 AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
1625eol:
while ( *s ==
',' ) s++;
1630int CoNFunction(UBYTE *s) {
return(CoFunction(s,1,0)); }
1631int CoCFunction(UBYTE *s) {
return(CoFunction(s,0,0)); }
1632int CoNTensor(UBYTE *s) {
return(CoFunction(s,1,2)); }
1633int CoCTensor(UBYTE *s) {
return(CoFunction(s,0,2)); }
1670static int nwarntab = 1;
1672int DoTable(UBYTE *s,
int par)
1675 UBYTE *name, *p, *inp, c;
1676 int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
1677 int error = 0, ret, oldcbufnum, oldEside;
1678 WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;
1685 while ( *s ==
',' ) s++;
1689IllForm: MesPrint(
"&Illegal name or option in table declaration");
1693 if ( TestName(name) ) { *s = c;
goto IllForm; }
1695 if ( *s ==
'(' )
break;
1697 MesPrint(
"&Illegal definition of table");
1704 if ( StrICmp(name,(UBYTE *)(
"check" )) == 0 ) checkflag = 1;
1705 else if ( StrICmp(name,(UBYTE *)(
"zero" )) == 0 ) checkflag = 2;
1706 else if ( StrICmp(name,(UBYTE *)(
"one" )) == 0 ) checkflag = 3;
1707 else if ( StrICmp(name,(UBYTE *)(
"strict")) == 0 ) rflag = 1;
1708 else if ( StrICmp(name,(UBYTE *)(
"relax" )) == 0 ) rflag = -1;
1709 else if ( StrICmp(name,(UBYTE *)(
"zerofill" )) == 0 ) { rflag = -2; checkflag = 2; }
1710 else if ( StrICmp(name,(UBYTE *)(
"onefill" )) == 0 ) { rflag = -3; checkflag = 3; }
1711 else if ( StrICmp(name,(UBYTE *)(
"sparse")) == 0 ) sparseflag |= 1;
1712 else if ( StrICmp(name,(UBYTE *)(
"base")) == 0 ) sparseflag |= 3;
1713 else if ( StrICmp(name,(UBYTE *)(
"tablebase")) == 0 ) sparseflag |= 3;
1715 MesPrint(
"&Illegal option in table definition: '%s'",name);
1719 while ( *s ==
',' ) s++;
1721 if ( name == s || *s == 0 ) {
1722 MesPrint(
"&Illegal name or option in table declaration");
1727 if ( checkflag == 1 ) rflag = 0;
1728 else if ( checkflag == 2 ) rflag = -2;
1729 else if ( checkflag == 3 ) rflag = -3;
1732 if ( ( ret = GetVar(name,&type,&funnum,CFUNCTION,NOAUTO) ) ==
1735 funnum = EntVar(CFUNCTION,name,0,1,0,0);
1737 else if ( par == 1 || par == 2 ) {
1738 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1741 else if ( ret <= 0 ) {
1742 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1748 Warning(
"Table now declares its (commuting) function.");
1749 Warning(
"Earlier definition in Function statement obsolete. Please remove.");
1755 MesPrint(
"&(N)(C)Tables should not be declared previously");
1758 if ( functions[funnum].spec > 0 ) {
1759 MesPrint(
"&Tensors cannot become tables");
1762 if ( functions[funnum].symmetric > 0 ) {
1763 MesPrint(
"&Functions with nontrivial symmetrization properties cannot become tables");
1766 if ( functions[funnum].tabl ) {
1767 MesPrint(
"&Redefinition of an existing table is not allowed.");
1770 functions[funnum].tabl = T = (
TABLES)Malloc1(
sizeof(
struct TaBlEs),
"table");
1790 if ( rflag > 0 ) AC.MustTestTable++;
1804 T->
argtail = strDup1(p,
"argtail");
1813 if ( *p ==
'=' ) { inc++; p++; }
1818 while ( *p <=
'9' && *p >=
'0' ) x = 10*x + (*p++-
'0');
1821 MesPrint(
"&Maximum number of dimensions in *-table should be at least one.");
1828 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1830 MesPrint(
"&First argument in a sparse table must be a number of dimensions");
1836 T->
mm = (
MINMAX *)Malloc1(ABS(x)*
sizeof(
MINMAX),
"table dimensions");
1837 T->
flags = (WORD *)Malloc1(ABS(x)*
sizeof(WORD),
"table flags");
1840 if ( *inp !=
')' ) inp++;
1850 if ( FG.cTable[*p] != 1 && *p !=
'+' && *p !=
'-' )
break;
1851 ParseSignedNumber(x,p)
1852 if ( FG.cTable[p[-1]] != 1 || *p !=
':' )
break;
1854 ParseSignedNumber(y,p)
1855 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1856 MesPrint(
"&Illegal dimension field in table declaration");
1860 flags1 = (WORD *)Malloc1((T->
numind+1)*
sizeof(WORD),
"table flags");
1861 for ( i = 0; i < T->
numind; i++ ) { mm1[i] = T->
mm[i]; flags1[i] = T->
flags[i]; }
1862 if ( T->
mm ) M_free(T->
mm,
"table dimensions");
1863 if ( T->
flags ) M_free(T->
flags,
"table flags");
1870 if ( *p ==
')' ) { inp = p;
break; }
1873 = (WORD *)Malloc1(TABLEEXTENSION*
sizeof(WORD)*(T->
totind),
"table pointers");
1875 for ( i = TABLEEXTENSION*T->
totind; i > 0; i-- ) *w++ = -1;
1876 for ( i = T->
numind-1, x = 1; i >= 0; i-- ) {
1886 OldWork = AT.WorkPointer;
1887 oldcbufnum = AC.cbufnum;
1889 C = cbuf+AC.cbufnum;
1891 oldnumlhs = C->numlhs;
1892 oldnumrhs = C->numrhs;
1894 while ( s >= name ) *--inp = *s--;
1897 *w++ = SUBEXPRESSION;
1905 AT.WorkPointer = w + 4*AM.MaxWildcards;
1906 if ( ( ret = CompileAlgebra(inp,LHSIDE,AC.ProtoType) ) < 0 ) {
1907 error = 1;
goto FinishUp;
1909 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
1923 OldWork[2] = C->numrhs;
1924 *w++ = 1; *w++ = 1; *w++ = 3;
1925 OldWork[-1] = w-OldWork+1;
1927 ww = C->
rhs[C->numrhs];
1928 for ( j = 0; j < *ww; j++ ) w[j] = ww[j];
1929 AT.WorkPointer = w+*w;
1930 if ( *ww == 0 || ww[*ww] != 0 ) {
1931 MesPrint(
"&Illegal table pattern definition");
1932 AC.lhdollarflag = 0;
1935 if ( error )
goto FinishUp;
1937 if (
NewSort(BHEAD0) ||
NewSort(BHEAD0) ) { error = 1;
goto FinishUp; }
1938 AN.RepPoint = AT.RepCount + 1;
1939 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
1940 AR.Cnumlhs = C->numlhs;
1941 functions[funnum].tabl = 0;
1943 functions[funnum].tabl = T;
1944 AR.Eside = oldEside;
1947 functions[funnum].tabl = T;
1948 AR.Eside = oldEside;
1951 if ( *w == 0 || *(w+*w) != 0 ) {
1952 MesPrint(
"&Irregular pattern in table definition");
1957 if ( AC.lhdollarflag ) {
1958 MesPrint(
"&Unexpanded dollar variables are not allowed in table definition");
1962 AT.WorkPointer = ww = w + *w;
1963 if ( ww[-1] != 3 || ww[-2] != 1 || ww[-3] != 1 ) {
1964 MesPrint(
"&Coefficient of pattern in table definition should be 1.");
1973 j = *w + ABS(T->
numind)*2-3;
1976 T->
prototypeSize = ((i+j)*
sizeof(WORD)+2*
sizeof(WORD *)) * AM.totalnumberofthreads;
1979 t = (WORD *)(T->
pattern + AM.totalnumberofthreads);
1980 for ( n = 0; n < AM.totalnumberofthreads; n++ ) {
1982 for ( k = 0; k < i; k++ ) *t++ = OldWork[k];
1986 w[1] += ABS(T->
numind)*2;
1987 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1989 for ( k = 0; k < ABS(T->
numind); k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1990 for ( k = 0; k < j; k++ ) *t++ = *w++;
1993 for ( n = 1; n < AM.totalnumberofthreads; n++ ) {
1995 for ( i = 0; i < k; i++ ) *t++ = *tt++;
2002 for ( k = 0; k < i; k++ ) T->
prototype[k] = OldWork[k];
2005 w[1] += ABS(T->
numind)*2;
2006 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
2008 for ( k = 0; k < ABS(T->
numind); k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
2009 for ( k = 0; k < j; k++ ) *t++ = *w++;
2016 C->numrhs = oldnumrhs;
2017 C->numlhs = oldnumlhs;
2027 tt = t + t[1]; t += SUBEXPSIZE;
2029 if ( *t == LOADDOLLAR ) {
2030 Warning(
"The use of $-variable assignments in tables disables parallel\
2031 execution for the whole program.");
2032 AM.hparallelflag |= NOPARALLEL_TBLDOLLAR;
2033 AC.mparallelflag |= NOPARALLEL_TBLDOLLAR;
2039 AT.WorkPointer = OldWork - 1;
2040 AC.cbufnum = oldcbufnum;
2042 if ( T->
sparse ) ClearTableTree(T);
2043 if ( ( sparseflag & 2 ) != 0 ) {
2044 if ( T->
spare == 0 ) { SpareTable(T); }
2054int CoTable(UBYTE *s)
2056 return(DoTable(s,2));
2064int CoNTable(UBYTE *s)
2066 return(DoTable(s,0));
2074int CoCTable(UBYTE *s)
2076 return(DoTable(s,1));
2087 if ( T->
sparse ) ClearTableTree(T);
2105 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2106 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2119 for ( j = TABLEEXTENSION*T->
totind; j > 0; j-- ) *w++ = -1;
2128int AddSet(UBYTE *name, WORD dim)
2130 int nodenum, numset = AC.SetList.num;
2131 SETS set = (
SETS)FromVarList(&AC.SetList);
2134 set->name = AddName(AC.varnames,name,CSET,numset,&nodenum);
2137 set->namesize = (s-name)+1;
2138 set->node = nodenum;
2146 set->last = AC.SetElementList.num;
2148 set->dimension = dim;
2161int DoElements(UBYTE *s,
SETS set, UBYTE *name)
2163 int type, error = 0, x, sgn, i;
2167 if ( *s ==
',' ) { s++;
continue; }
2169 while ( *s ==
'-' || *s ==
'+' ) {
2170 if ( *s ==
'-' ) sgn ^= 1;
2174 if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'[' ) {
2176 MesPrint(
"&Illegal name in set definition");
2180 if ( ( ( type = GetName(AC.exprnames,cname,&numset,NOAUTO) ) == NAMENOTFOUND )
2181 && ( ( type = GetOName(AC.varnames,cname,&numset,WITHAUTO) ) == NAMENOTFOUND ) ) {
2184 MesPrint(
"&%s has not been declared",cname);
2188 numset = AC.DubiousList.num;
2189 dv = (
DUBIOUSV)FromVarList(&AC.DubiousList);
2190 dv->name = AddName(AC.varnames,cname,CDUBIOUS,numset,&nodenum);
2192 set->type = type = CDUBIOUS;
2196 if ( set->type == -1 ) {
2197 if ( type == CSYMBOL ) {
2198 for ( i = set->first; i < set->last; i++ ) {
2199 SetElements[i] += 2*MAXPOWER;
2204 if ( set->type != type && set->type != CDUBIOUS
2205 && type != CDUBIOUS ) {
2206 if ( set->type != CNUMBER || ( type != CSYMBOL
2207 && type != CINDEX ) ) {
2209 "&%s has not the same type as the other members of the set"
2212 set->type = CDUBIOUS;
2215 if ( type == CSYMBOL ) {
2216 for ( i = set->first; i < set->last; i++ ) {
2217 SetElements[i] += 2*MAXPOWER;
2223 if ( set->dimension != MAXPOSITIVE ) {
2224 switch ( set->type ) {
2226 if ( symbols[numset].dimension != set->dimension ) {
2227 MesPrint(
"&Dimension check failed in set %s, symbol %s",
2228 VARNAME(Sets,(set-Sets)),
2229 VARNAME(symbols,numset));
2231 set->dimension = MAXPOSITIVE;
2235 if ( vectors[numset-AM.OffsetVector].dimension != set->dimension ) {
2236 MesPrint(
"&Dimension check failed in set %s, vector %s",
2237 VARNAME(Sets,(set-Sets)),
2238 VARNAME(vectors,(numset-AM.OffsetVector)));
2240 set->dimension = MAXPOSITIVE;
2244 if ( functions[numset-FUNCTION].dimension != set->dimension ) {
2245 MesPrint(
"&Dimension check failed in set %s, function %s",
2246 VARNAME(Sets,(set-Sets)),
2247 VARNAME(functions,(numset-FUNCTION)));
2251 set->dimension = MAXPOSITIVE;
2255 if ( type != CVECTOR ) {
2256 MesPrint(
"&Illegal use of - sign in set. Can use only with vector or number");
2267 if ( name == 0 && *s ==
'?' ) {
2269 switch ( set->type ) {
2271 numset = -numset;
break;
2273 numset += WILDOFFSET;
break;
2275 numset |= WILDMASK;
break;
2277 numset |= WILDMASK;
break;
2284 e = (WORD *)FromVarList(&AC.SetElementList);
2288 else if ( FG.cTable[*s] == 1 ) {
2291 if ( x >= MAXPOWER || x <= -MAXPOWER ||
2292 ( set->type == CINDEX && ( x < 0 || x >= AM.OffsetIndex ) ) ) {
2293 MesPrint(
"&Illegal value for set element: %d",x);
2294 if ( AC.firstconstindex ) {
2295 MesPrint(
"&0 <= Fixed indices < ConstIndex(which is %d)",
2297 MesPrint(
"&For setting ConstIndex, read the chapter on the setup file");
2298 AC.firstconstindex = 0;
2306 if ( set->type == -1 ) {
2307 if ( x < 0 || x >= AM.OffsetIndex ) {
2308 for ( i = set->first; i < set->last; i++ ) {
2309 SetElements[i] += 2*MAXPOWER;
2311 set->type = CSYMBOL;
2313 else set->type = CNUMBER;
2315 else if ( set->type == CDUBIOUS ) {}
2316 else if ( set->type == CNUMBER && x < 0 ) {
2317 for ( i = set->first; i < set->last; i++ ) {
2318 SetElements[i] += 2*MAXPOWER;
2320 set->type = CSYMBOL;
2322 else if ( set->type != CSYMBOL && ( x < 0 ||
2323 ( set->type != CINDEX && set->type != CNUMBER ) ) ) {
2324 MesPrint(
"&Illegal mixture of element types in set");
2326 set->type = CDUBIOUS;
2331 e = (WORD *)FromVarList(&AC.SetElementList);
2333 if ( set->type == CSYMBOL ) *e = x + 2*MAXPOWER;
2338 MesPrint(
"&Illegal object in list of set elements");
2342 if ( error == 0 && ( ( set->flags & ORDEREDSET ) == ORDEREDSET ) ) {
2349 SimpleSplitMerge(SetElements+set->first,set->last-set->first);
2363 int type, error = 0, ordered = 0;
2364 UBYTE *name = s, c, *ss;
2366 WORD numberofset, dim = MAXPOSITIVE;
2374 while ( *ss && *ss !=
':' ) {
if ( *ss ==
'=' ) numeq++; ss++; }
2375 if ( *ss == 0 && numeq == 1 ) {
2376 while ( FG.cTable[*s] == 0 ) s++;
2377 ss = s; c = *s; *s = 0;
2380 MesPrint(
"&Proper syntax for value-set is `Set name = value'");
2384 while ( *s >=
'0' && *s <=
'9' ) x = 10*x + (*s++-
'0');
2385 if ( *s )
goto Proper;
2386 if ( StrICmp(name,(UBYTE *)
"maxweight") == 0 ) {
2389 else if ( StrICmp(name,(UBYTE *)
"defaultprecision") == 0 ) {
2390 AC.tDefaultPrecision = x;
2393 MesPrint(
"&Illegal subkey in value set: %s",name);
2402IllForm:MesPrint(
"&Illegal name for set");
2406 if ( TestName(name) )
goto IllForm;
2407 if ( ( ( type = GetName(AC.exprnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND )
2408 || ( ( type = GetName(AC.varnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND ) ) {
2409 if ( type != CSET ) NameConflict(type,name);
2411 MesPrint(
"&There is already a set with the name %s",name);
2416 numberofset = AddSet(name,0);
2417 set = Sets + numberofset;
2424 while ( *s !=
',' && *s !=
')' && *s ) s++;
2426 if ( StrICont(sss,(UBYTE *)
"ordered") == 0 ) {
2427 ordered = ORDEREDSET;
2430 MesPrint(
"&Error: Illegal option in set definition: %s",sss);
2435 MesPrint(
"&Error: Currently only one option allowed in set definition.");
2437 while ( *s && *s !=
')' ) s++;
2443 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
2445 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
2446 ParseSignedNumber(dim,s)
2447 if ( dim < -HALFMAX || dim > HALFMAX ) {
2448 MesPrint(
"&Warning: dimension of %s (%d) out of range"
2452 if ( *s !=
'}' )
goto IllDim;
2456IllDim: MesPrint(
"&Error: Illegal dimension field for set %s",name);
2460 while ( *s ==
',' ) s++;
2463 numberofset = AddSet(name,dim);
2465 set = Sets + numberofset;
2466 set->flags |= ordered;
2468 MesPrint(
"&Proper syntax is `Set name:elements'");
2472 error = DoElements(s,set,name);
2473 AC.SetList.numtemp = AC.SetList.num;
2474 AC.SetElementList.numtemp = AC.SetElementList.num;
2488int DoTempSet(UBYTE *from, UBYTE *to)
2493 int setnum = AddSet(0,MAXPOSITIVE);
2494 SETS set = Sets + setnum, setp;
2499 while ( *from ==
',' ) from++;
2500 if ( *from ==
'<' || *from ==
'>' ) {
2502 set->first = 3*MAXPOWER;
2503 set->last = -3*MAXPOWER;
2504 while ( *from ==
'<' || *from ==
'>' ) {
2505 if ( *from ==
'<' ) {
2507 if ( *from ==
'=' ) { from++; j++; }
2511 if ( *from ==
'=' ) { from++; j--; }
2514 while ( *from ==
'-' || *from ==
'+' ) {
2515 if ( *from ==
'-' ) sgn = -sgn;
2518 ParseNumber(num,from)
2519 if ( *from && *from !=
',' ) {
2520 MesPrint(
"&Illegal number in ranged set definition");
2523 if ( sgn < 0 ) num = -num;
2524 if ( num >= MAXPOWER || num <= -MAXPOWER ) {
2525 Warning(
"Value in ranged set too big. Adjusted to infinity.");
2526 if ( num > 0 ) num = 3*MAXPOWER;
2527 else num = -3*MAXPOWER;
2529 else if ( j == 2 ) num += 2*MAXPOWER;
2530 else if ( j == -2 ) num -= 2*MAXPOWER;
2531 if ( j > 0 ) set->first = num;
2532 else set->last = num;
2533 while ( *from ==
',' ) from++;
2536 MesPrint(
"&Definition of ranged set contains illegal objects");
2540 else if ( DoElements(from,set,(UBYTE *)0) != 0 ) {
2541 AC.SetElementList.num = set->first;
2542 AC.SetList.num--; *to = c;
2549 num = set->last - set->first;
2550 for ( setp = Sets, i = 0; i < AC.SetList.num-1; i++, setp++ ) {
2551 if ( num != setp->last - setp->first )
continue;
2552 if ( set->type != setp->type )
continue;
2553 if ( set->type == CRANGE ) {
2554 if ( set->first == setp->first )
return(setp-Sets);
2557 e = SetElements + set->first;
2558 ep = SetElements + setp->first;
2560 while ( --j >= 0 )
if ( *e++ != *ep++ )
break;
2562 AC.SetElementList.num = set->first;
2564 return(setp - Sets);
2580int CoAuto(UBYTE *inp)
2584 AC.Symbols = &(AC.AutoSymbolList);
2585 AC.Vectors = &(AC.AutoVectorList);
2586 AC.Indices = &(AC.AutoIndexList);
2587 AC.Functions = &(AC.AutoFunctionList);
2588 AC.activenames = &(AC.autonames);
2589 AC.AutoDeclareFlag = WITHAUTO;
2591 while ( *inp ==
',' ) inp++;
2592 retval = CompileStatement(inp);
2594 AC.AutoDeclareFlag = 0;
2595 AC.Symbols = &(AC.SymbolList);
2596 AC.Vectors = &(AC.VectorList);
2597 AC.Indices = &(AC.IndexList);
2598 AC.Functions = &(AC.FunctionList);
2599 AC.activenames = &(AC.varnames);
2610int AddDollar(UBYTE *name, WORD type, WORD *start, LONG size)
2612 int nodenum, numdollar = AP.DollarList.num;
2615 dol->name = AddName(AC.dollarnames,name,CDOLLAR,numdollar,&nodenum);
2617 dol->node = nodenum;
2619 dol->numdummies = 0;
2621 INIRECLOCK(dol->pthreadslock);
2627 if ( start && size > 0 ) {
2630 s = (WORD *)Malloc1((size+1)*
sizeof(WORD),
"$-variable contents");
2632 while ( --size >= 0 ) *s++ = *t++;
2635 else { dol->where = &(AM.dollarzero); dol->size = 0; }
2636 cbuf[AM.dbufnum].rhs[numdollar] = dol->where;
2637 cbuf[AM.dbufnum].CanCommu[numdollar] = 0;
2638 cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
2653int ReplaceDollar(WORD number, WORD newtype, WORD *newstart, LONG newsize)
2656 DOLLARS dol = Dollars + number;
2659 dol->type = newtype;
2660 if ( dol->size == newsize && newsize > 0 && newstart ) {
2661 s = dol->where; t = newstart; i = newsize;
2662 while ( --i >= 0 ) {
if ( *s++ != *t++ )
break; }
2663 if ( i < 0 )
return(0);
2665 if ( dol->where && dol->where != &(dol->zero) ) {
2666 M_free(dol->where,
"dollar->where"); dol->where = &(dol->zero); dol->size = 0;
2668 if ( newstart && newsize > 0 ) {
2669 dol->size = newsize;
2671 s = (WORD *)Malloc1((newsize+1)*
sizeof(WORD),
"$-variable contents");
2672 t = newstart; i = newsize;
2673 while ( --i >= 0 ) *s++ = *t++;
2686int AddDubious(UBYTE *name)
2688 int nodenum, numdubious = AC.DubiousList.num;
2690 dub->name = AddName(AC.varnames,name,CDUBIOUS,numdubious,&nodenum);
2691 dub->node = nodenum;
2700int MakeDubious(
NAMETREE *nametree, UBYTE *name, WORD *number)
2703 int node, newnode, i;
2704 if ( nametree->
namenode == 0 )
return(-1);
2711 else if ( i > 0 ) newnode = n->
right;
2713 if ( n->
type != CDUBIOUS ) {
2714 int numdubious = AC.DubiousList.num;
2722 }
while ( newnode >= 0 );
2731static char *nametype[] = {
"symbol",
"index",
"vector",
"function",
2732 "set",
"expression" };
2733static char *plural[] = {
"",
"n",
"",
"",
"",
"n" };
2735int NameConflict(
int type, UBYTE *name)
2737 if ( type == NAMENOTFOUND ) {
2738 MesPrint(
"&%s has not been declared",name);
2740 else if ( type != CDUBIOUS )
2741 MesPrint(
"&%s has been declared as a%s %s already"
2742 ,name,plural[type],nametype[type]);
2751int AddExpression(UBYTE *name,
int x,
int y)
2753 int nodenum, numexpr = AC.ExpressionList.num;
2757 expr->printflag = y;
2758 PUTZERO(expr->onfile);
2759 PUTZERO(expr->size);
2762 expr->hidelevel = 0;
2764 expr->bracketinfo = expr->newbracketinfo = 0;
2766 expr->name = AddName(AC.exprnames,name,CEXPRESSION,numexpr,&nodenum);
2767 expr->node = nodenum;
2768 expr->replace = NEWLYDEFINEDEXPRESSION ;
2771 expr->namesize = (s-name)+1;
2774 expr->replace = REDEFINEDEXPRESSION;
2775 expr->name = AC.TransEname;
2780 expr->numdummies = 0;
2781 expr->numfactors = 0;
2794int GetLabel(UBYTE *name)
2798 UBYTE **NewLabelNames;
2800 for ( i = 0; i < AC.NumLabels; i++ ) {
2801 if ( StrCmp(name,AC.LabelNames[i]) == 0 )
return(i);
2803 if ( AC.NumLabels >= AC.MaxLabels ) {
2804 newnum = 2*AC.MaxLabels;
2805 if ( newnum == 0 ) newnum = 10;
2806 if ( newnum > 32765 ) newnum = 32765;
2807 if ( newnum == AC.MaxLabels ) {
2808 MesPrint(
"&More than 32765 labels in one module. Please simplify.");
2811 NewLabelNames = (UBYTE **)Malloc1((
sizeof(UBYTE *)+
sizeof(
int))
2813 NewLabel = (
int *)(NewLabelNames+newnum);
2814 for ( i = 0; i< AC.MaxLabels; i++ ) {
2815 NewLabelNames[i] = AC.LabelNames[i];
2816 NewLabel[i] = AC.Labels[i];
2818 if ( AC.LabelNames ) M_free(AC.LabelNames,
"Labels");
2819 AC.LabelNames = NewLabelNames;
2820 AC.Labels = NewLabel;
2821 AC.MaxLabels = newnum;
2824 AC.LabelNames[i] = strDup1(name,
"Labels");
2839void ResetVariables(
int par)
2845 AC.SetList.num = AC.SetList.numtemp;
2846 AC.SetElementList.num = AC.SetElementList.numtemp;
2849 for ( i = AC.SymbolList.numclear; i < AC.SymbolList.num; i++ )
2850 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2851 AC.SymbolList.num = AC.SymbolList.numglobal = AC.SymbolList.numclear;
2852 for ( i = AC.VectorList.numclear; i < AC.VectorList.num; i++ )
2853 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2854 AC.VectorList.num = AC.VectorList.numglobal = AC.VectorList.numclear;
2855 for ( i = AC.IndexList.numclear; i < AC.IndexList.num; i++ )
2856 AC.varnames->namenode[indices[i].node].type = CDELETE;
2857 AC.IndexList.num = AC.IndexList.numglobal = AC.IndexList.numclear;
2858 for ( i = AC.FunctionList.numclear; i < AC.FunctionList.num; i++ ) {
2859 AC.varnames->namenode[functions[i].node].type = CDELETE;
2860 if ( ( T = functions[i].tabl ) != 0 ) {
2863 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2864 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2876 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2877 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2891 AC.FunctionList.num = AC.FunctionList.numglobal = AC.FunctionList.numclear;
2892 for ( i = AC.SetList.numclear; i < AC.SetList.num; i++ ) {
2893 if ( Sets[i].
node >= 0 )
2894 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2896 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal = AC.SetList.numclear;
2897 for ( i = AC.DubiousList.numclear; i < AC.DubiousList.num; i++ )
2898 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2899 AC.DubiousList.num = AC.DubiousList.numglobal = AC.DubiousList.numclear;
2900 AC.SetElementList.numtemp = AC.SetElementList.num =
2901 AC.SetElementList.numglobal = AC.SetElementList.numclear;
2902 CompactifyTree(AC.varnames,VARNAMES);
2903 AC.varnames->namefill = AC.varnames->globalnamefill = AC.varnames->clearnamefill;
2904 AC.varnames->nodefill = AC.varnames->globalnodefill = AC.varnames->clearnodefill;
2906 for ( i = AC.AutoSymbolList.numclear; i < AC.AutoSymbolList.num; i++ )
2907 AC.autonames->namenode[
2908 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2909 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal
2910 = AC.AutoSymbolList.numclear;
2911 for ( i = AC.AutoVectorList.numclear; i < AC.AutoVectorList.num; i++ )
2912 AC.autonames->namenode[
2913 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2914 AC.AutoVectorList.num = AC.AutoVectorList.numglobal
2915 = AC.AutoVectorList.numclear;
2916 for ( i = AC.AutoIndexList.numclear; i < AC.AutoIndexList.num; i++ )
2917 AC.autonames->namenode[
2918 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2919 AC.AutoIndexList.num = AC.AutoIndexList.numglobal
2920 = AC.AutoIndexList.numclear;
2921 for ( i = AC.AutoFunctionList.numclear; i < AC.AutoFunctionList.num; i++ ) {
2922 AC.autonames->namenode[
2923 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
2924 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2927 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2928 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2936 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2937 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2948 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal
2949 = AC.AutoFunctionList.numclear;
2950 CompactifyTree(AC.autonames,AUTONAMES);
2951 AC.autonames->namefill = AC.autonames->globalnamefill
2952 = AC.autonames->clearnamefill;
2953 AC.autonames->nodefill = AC.autonames->globalnodefill
2954 = AC.autonames->clearnodefill;
2958 for ( i = AC.SymbolList.numglobal; i < AC.SymbolList.num; i++ )
2959 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2960 AC.SymbolList.num = AC.SymbolList.numglobal;
2961 for ( i = AC.VectorList.numglobal; i < AC.VectorList.num; i++ )
2962 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2963 AC.VectorList.num = AC.VectorList.numglobal;
2964 for ( i = AC.IndexList.numglobal; i < AC.IndexList.num; i++ )
2965 AC.varnames->namenode[indices[i].node].type = CDELETE;
2966 AC.IndexList.num = AC.IndexList.numglobal;
2967 for ( i = AC.FunctionList.numglobal; i < AC.FunctionList.num; i++ ) {
2968 AC.varnames->namenode[functions[i].node].type = CDELETE;
2969 if ( ( T = functions[i].tabl ) != 0 ) {
2972 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2973 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2985 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2986 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
3004 for ( i = 0; i < AC.FunctionList.numglobal; i++ ) {
3011 if ( ( T = functions[i].tabl ) != 0 ) {
3019#if TABLEEXTENSION == 2
3026 tp += TABLEEXTENSION;
3028 RedoTableTree(T,T->
totind);
3034#if TABLEEXTENSION == 2
3041 tp += TABLEEXTENSION;
3043 RedoTableTree(TT,TT->
totind);
3050#if TABLEEXTENSION == 2
3066 AC.FunctionList.num = AC.FunctionList.numglobal;
3067 for ( i = AC.SetList.numglobal; i < AC.SetList.num; i++ ) {
3068 if ( Sets[i].
node >= 0 )
3069 AC.varnames->namenode[Sets[i].node].type = CDELETE;
3071 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal;
3072 for ( i = AC.DubiousList.numglobal; i < AC.DubiousList.num; i++ )
3073 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
3074 AC.DubiousList.num = AC.DubiousList.numglobal;
3075 AC.SetElementList.numtemp = AC.SetElementList.num =
3076 AC.SetElementList.numglobal;
3077 CompactifyTree(AC.varnames,VARNAMES);
3078 AC.varnames->namefill = AC.varnames->globalnamefill;
3079 AC.varnames->nodefill = AC.varnames->globalnodefill;
3081 for ( i = AC.AutoSymbolList.numglobal; i < AC.AutoSymbolList.num; i++ )
3082 AC.autonames->namenode[
3083 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
3084 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal;
3085 for ( i = AC.AutoVectorList.numglobal; i < AC.AutoVectorList.num; i++ )
3086 AC.autonames->namenode[
3087 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
3088 AC.AutoVectorList.num = AC.AutoVectorList.numglobal;
3089 for ( i = AC.AutoIndexList.numglobal; i < AC.AutoIndexList.num; i++ )
3090 AC.autonames->namenode[
3091 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
3092 AC.AutoIndexList.num = AC.AutoIndexList.numglobal;
3093 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3094 AC.autonames->namenode[
3095 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
3096 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
3099 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
3100 if ( T->
flags ) M_free(T->
flags,
"tableflags");
3108 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
3109 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
3120 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal;
3122 CompactifyTree(AC.autonames,AUTONAMES);
3124 AC.autonames->namefill = AC.autonames->globalnamefill;
3125 AC.autonames->nodefill = AC.autonames->globalnodefill;
3135void RemoveDollars(
void)
3138 CBUF *C = cbuf + AM.dbufnum;
3139 int numdollar = AP.DollarList.num;
3140 if ( numdollar > 0 ) {
3141 while ( numdollar > AM.gcNumDollars ) {
3143 d = Dollars + numdollar;
3144 if ( d->where && d->where != &(d->zero) && d->where != &(AM.dollarzero) ) {
3145 M_free(d->where,
"dollar->where"); d->where = &(d->zero); d->size = 0;
3147 AC.dollarnames->namenode[d->node].type = CDELETE;
3149 AP.DollarList.num = AM.gcNumDollars;
3150 CompactifyTree(AC.dollarnames,DOLLARNAMES);
3152 C->numrhs = C->mnumrhs;
3153 C->numlhs = C->mnumlhs;
3162void Globalize(
int par)
3167 AC.SymbolList.numclear = AC.SymbolList.num;
3168 AC.VectorList.numclear = AC.VectorList.num;
3169 AC.IndexList.numclear = AC.IndexList.num;
3170 AC.FunctionList.numclear = AC.FunctionList.num;
3171 AC.SetList.numclear = AC.SetList.num;
3172 AC.DubiousList.numclear = AC.DubiousList.num;
3173 AC.SetElementList.numclear = AC.SetElementList.num;
3174 AC.varnames->clearnamefill = AC.varnames->namefill;
3175 AC.varnames->clearnodefill = AC.varnames->nodefill;
3177 AC.AutoSymbolList.numclear = AC.AutoSymbolList.num;
3178 AC.AutoVectorList.numclear = AC.AutoVectorList.num;
3179 AC.AutoIndexList.numclear = AC.AutoIndexList.num;
3180 AC.AutoFunctionList.numclear = AC.AutoFunctionList.num;
3181 AC.autonames->clearnamefill = AC.autonames->namefill;
3182 AC.autonames->clearnodefill = AC.autonames->nodefill;
3185 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
3190 if ( functions[i].tabl ) {
3191 TABLES T = functions[i].tabl;
3196#if TABLEEXTENSION == 2
3199 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3201 tp += TABLEEXTENSION;
3208#if TABLEEXTENSION == 2
3211 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3213 tp += TABLEEXTENSION;
3222#if TABLEEXTENSION == 2
3225 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3233 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3234 if ( ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl )
3235 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->mdefined =
3236 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->defined;
3238 AC.SymbolList.numglobal = AC.SymbolList.num;
3239 AC.VectorList.numglobal = AC.VectorList.num;
3240 AC.IndexList.numglobal = AC.IndexList.num;
3241 AC.FunctionList.numglobal = AC.FunctionList.num;
3242 AC.SetList.numglobal = AC.SetList.num;
3243 AC.DubiousList.numglobal = AC.DubiousList.num;
3244 AC.SetElementList.numglobal = AC.SetElementList.num;
3245 AC.varnames->globalnamefill = AC.varnames->namefill;
3246 AC.varnames->globalnodefill = AC.varnames->nodefill;
3248 AC.AutoSymbolList.numglobal = AC.AutoSymbolList.num;
3249 AC.AutoVectorList.numglobal = AC.AutoVectorList.num;
3250 AC.AutoIndexList.numglobal = AC.AutoIndexList.num;
3251 AC.AutoFunctionList.numglobal = AC.AutoFunctionList.num;
3252 AC.autonames->globalnamefill = AC.autonames->namefill;
3253 AC.autonames->globalnodefill = AC.autonames->nodefill;
3261int TestName(UBYTE *name)
3263 if ( *name ==
'[' ) {
3264 while ( *name ) name++;
3265 if ( name[-1] ==
']' )
return(0);
3269 if ( *name ==
'_' )
return(-1);
3270 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