53 if ( nametree->
namenode == 0 )
return(0);
60 else if ( i > 0 ) newnode = n->
right;
62 }
while ( newnode >= 0 );
71 int AddName(
NAMETREE *nametree, UBYTE *name, WORD type, WORD number,
int *nodenum)
75 LONG *c1,*c2, j, newsize;
76 int node, newnode, node3, r, rr = 0, i, retval = 0;
78 s = name; i = 1;
while ( *s ) { i++; s++; }
82 "new nametree in AddName");
84 "new namebuffer in AddName");
98 while ( *s ) *ss++ = *s++;
108 newnode = n->
left; r = -1;
111 newnode = n->
right; r = 1;
113 }
while ( newnode >= 0 );
119 if ( newsize > MAXINNAMETREE ) newsize = MAXINNAMETREE;
120 if ( nametree->
nodefill >= MAXINNAMETREE ) {
121 MesPrint(
"!!!More than %l names in one object",(LONG)MAXINNAMETREE);
125 "extra names in AddName");
126 c1 = (LONG *)nnn; c2 = (LONG *)nametree->
namenode;
128 while ( --i >= 0 ) *c1++ = *c2++;
129 M_free(nametree->
namenode,
"nametree->namenode");
134 *nodenum = newnode = nametree->
nodefill++;
137 if ( r < 0 ) n->
left = newnode;
else n->
right = newnode;
142 i = 1; s = name;
while ( *s ) { i++; s++; }
144 sss = (UBYTE *)Malloc1(2*nametree->
namesize,
145 "extra names in AddName");
147 while ( --j >= 0 ) *s++ = *ss++;
148 M_free(nametree->
namebuffer,
"nametree->namebuffer");
156 while ( *name ) *s++ = *name++;
161 while ( node >= 0 ) {
163 if ( newnode == n->
left ) rr = -1;
166 else if ( n->
balance == rr )
break;
171 if ( node < 0 )
return(retval);
208 if ( node == nn->
left ) nn->
left = node3;
209 else nn->
right = node3;
213 else if ( nn->
balance == rr ) {
225 if ( node == nnn->
left ) nnn->
left = newnode;
226 else nnn->
right = newnode;
233 MesPrint(
"We ran into an impossible case in AddName\n");
252 int GetName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
255 int node, newnode, i;
264 else if ( i > 0 ) newnode = n->
right;
269 }
while ( newnode >= 0 );
272 if ( s > name && s[-1] ==
'_' && nametree == AC.varnames ) {
276 if ( s == name+2 && ( *name ==
'd' || *name ==
'D' ) ) {
277 *number = DELTA-FUNCTION;
283 if ( s > name+2 && *name ==
'N' ) {
285 while ( FG.cTable[*t] == 1 ) i = 10*i + *t++ -
'0';
287 *number = i + AM.IndDum - AM.OffsetIndex;
300 else if ( i > 0 ) newnode = n->
right;
304 }
while ( newnode >= 0 );
311 t = name; u = AC.extrasym;
312 while ( *t == *u ) { t++; u++; }
313 if ( *u == 0 && *t != 0 ) {
315 while ( FG.cTable[*t] == 1 ) {
316 x = 10*x + (*t++ -
'0');
318 if ( *t ==
'_' && x > 0 && x <= cbuf[AM.sbufnum].numrhs ) {
319 *number = MAXVARIABLES-x;
325 if ( par != WITHAUTO || nametree == AC.autonames )
return(NAMENOTFOUND);
326 return(GetAutoName(name,number));
340 int GetLastExprName(UBYTE *name, WORD *number)
344 for ( i = NumExpressions; i > 0; i-- ) {
346 if ( StrCmp(AC.exprnames->namebuffer+e->name,name) == 0 ) {
362 int GetOName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
364 int retval = GetName(nametree,name,number,par);
366 case CVECTOR: *number += AM.OffsetVector;
break;
367 case CINDEX: *number += AM.OffsetIndex;
break;
368 case CFUNCTION: *number += FUNCTION;
break;
381 int GetAutoName(UBYTE *name, WORD *number)
385 if ( GetName(AC.exprnames,name,number,NOAUTO) != NAMENOTFOUND )
386 return(NAMENOTFOUND);
388 while ( *s ) { s++; }
389 if ( s[-1] ==
'_' ) {
390 return(NAMENOTFOUND);
394 type = GetName(AC.autonames,name,number,NOAUTO);
399 *number = AddSymbol(name,sym->minpower,sym->maxpower,sym->complex,sym->dimension);
403 *number = AddVector(name,vec->complex,vec->dimension);
407 *number = AddIndex(name,ind->dimension,ind->nmin4);
418 return(NAMENOTFOUND);
426 int GetVar(UBYTE *name, WORD *type, WORD *number,
int wantedtype,
int par)
430 if ( ( typ = GetName(AC.varnames,name,number,par) ) != wantedtype ) {
431 if ( typ != NAMENOTFOUND ) {
432 if ( wantedtype == -1 ) {
436 NameConflict(typ,name);
437 MakeDubious(AC.varnames,name,&funnum);
440 if ( ( typ = GetName(AC.exprnames,name,&funnum,par) ) != NAMENOTFOUND ) {
441 if ( typ == wantedtype || wantedtype == -1 ) {
442 *number = funnum; *type = typ;
return(1);
444 NameConflict(typ,name);
447 return(NAMENOTFOUND);
449 if ( typ == -1 ) {
return(0); }
459 WORD EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
463 return(AddSymbol(name,y,z,x,d));
466 return(AddIndex(name,x,z));
469 return(AddVector(name,x,d));
472 return(AddFunction(name,y,z,x,0,d,-1,-1));
475 AC.SetList.numtemp++;
476 return(AddSet(name,d));
479 return(AddExpression(name,x,y));
492 int GetDollar(UBYTE *name)
495 if ( GetName(AC.dollarnames,name,&number,NOAUTO) == NAMENOTFOUND )
return(-1);
508 DumpNode(nametree,nametree->
headnode,0);
517 VOID DumpNode(
NAMETREE *nametree, WORD node, WORD depth)
523 if ( n->
left >= 0 ) DumpNode(nametree,n->
left,depth+1);
524 for ( i = 0; i < depth; i++ ) printf(
" ");
526 printf(
"%s(%d): {%d}(%d)(%d)[%d]\n",
528 if ( n->
right >= 0 ) DumpNode(nametree,n->
right,depth+1);
536 int CompactifyTree(
NAMETREE *nametree,WORD par)
543 for ( i = 0, j = 0, k = 0, n = nametree->
namenode, ns = 0;
544 i < nametree->nodefill; i++, n++ ) {
545 if ( n->
type != CDELETE ) {
547 while ( *s ) { s++; ns++; }
552 if ( k == 0 )
return(0);
567 if ( j < 10 ) j = 10;
568 if ( ns < 100 ) ns = 100;
571 newtree.
namebuffer = (UBYTE *)Malloc1(2*ns,
"compactify namestree");
573 CopyTree(&newtree,nametree,nametree->
headnode,par);
575 LinkTree(&newtree,(WORD)0,newtree.
nodefill);
577 M_free(nametree->
namebuffer,
"nametree->namebuffer");
578 M_free(nametree->
namenode,
"nametree->namenode");
603 if ( n->
left >= 0 ) CopyTree(newtree,oldtree,n->
left,par);
604 if ( n->
type != CDELETE ) {
613 if ( par == AUTONAMES ) {
623 if ( par == AUTONAMES ) {
633 if ( par == AUTONAMES ) {
643 if ( par == AUTONAMES ) {
669 MesPrint(
"Illegal variable type in CopyTree: %d",n->
type);
675 while ( *t ) { *s++ = *t++; newtree->
namefill++; }
678 if ( n->
right >= 0 ) CopyTree(newtree,oldtree,n->
right,par);
686 VOID LinkTree(
NAMETREE *
tree, WORD offset, WORD numnodes)
691 int med,numleft,numright,medleft,medright;
694 numright = numnodes - med - 1;
695 medleft = numleft >> 1;
696 medright = ( numright >> 1 ) + med + 1;
698 tree->namenode[offset+med].
left = offset+medleft;
699 tree->namenode[offset+medleft].
parent = offset+med;
701 if ( numright > 0 ) {
702 tree->namenode[offset+med].
right = offset+medright;
703 tree->namenode[offset+medright].
parent = offset+med;
705 if ( numleft > 0 ) LinkTree(
tree,offset,numleft);
706 if ( numright > 0 ) LinkTree(
tree,offset+med+1,numright);
707 while ( numleft && numright ) { numleft >>= 1; numright >>= 1; }
708 if ( numleft )
tree->namenode[offset+med].balance = -1;
709 else if ( numright )
tree->namenode[offset+med].balance = 1;
741 M_free(n,
"nametree");
751 void ClearWildcardNames()
753 AC.NumWildcardNames = 0;
756 int AddWildcardName(UBYTE *name)
759 int size = 0, tocopy, i;
760 UBYTE *s = name, *t, *newbuffer;
761 while ( *s ) { s++; size++; }
762 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
764 while ( ( *s == *t ) && *s ) { s++; t++; }
765 if ( *s == 0 && *t == 0 )
return(i+1);
769 tocopy = t - AC.WildcardNames;
770 if ( tocopy + size + 1 > AC.WildcardBufferSize ) {
771 if ( AC.WildcardBufferSize == 0 ) {
772 AC.WildcardBufferSize = size+1;
773 if ( AC.WildcardBufferSize < 100 ) AC.WildcardBufferSize = 100;
775 else if ( size+1 >= AC.WildcardBufferSize ) {
776 AC.WildcardBufferSize += size+1;
779 AC.WildcardBufferSize *= 2;
781 newbuffer = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
783 if ( AC.WildcardNames ) {
784 s = AC.WildcardNames;
785 while ( tocopy > 0 ) { *t++ = *s++; tocopy--; }
786 M_free(AC.WildcardNames,
"AC.WildcardNames");
788 AC.WildcardNames = newbuffer;
789 M_free(AT.WildArgTaken,
"AT.WildArgTaken");
790 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
791 ,
"argument list names");
794 while ( *s ) *t++ = *s++;
796 AC.NumWildcardNames++;
797 return(AC.NumWildcardNames);
800 int GetWildcardName(UBYTE *name)
804 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
806 while ( ( *s == *t ) && *s ) { s++; t++; }
807 if ( *s == 0 && *t == 0 )
return(i+1);
822 int AddSymbol(UBYTE *name,
int minpow,
int maxpow,
int cplx,
int dim)
824 int nodenum, numsymbol = AC.Symbols->num;
827 bzero(sym,
sizeof(
struct SyMbOl));
828 sym->name = AddName(*AC.activenames,name,CSYMBOL,numsymbol,&nodenum);
829 sym->minpower = minpow;
830 sym->maxpower = maxpow;
836 sym->namesize = (s-name)+1;
848 int CoSymbol(UBYTE *s)
850 int type, error = 0, minpow, maxpow, cplx, sgn, dim;
852 UBYTE *name, *oldc, c, cc;
859 if ( ( s = SkipAName(s) ) == 0 ) {
860 IllForm: MesPrint(
"&Illegally formed name in symbol statement");
862 s = SkipField(name,0);
865 oldc = s; cc = c = *s; *s = 0;
866 if ( TestName(name) ) { *s = c;
goto IllForm; }
869 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
870 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
871 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
872 else if ( ( ( *s ==
'-' || *s ==
'+' || *s ==
'=' )
873 && ( s[1] >=
'0' && s[1] <=
'9' ) )
874 || ( *s >=
'0' && *s <=
'9' ) ) {
877 if ( *s ==
'-' ) { sgn = VARTYPEMINUS; s++; }
878 else if ( *s ==
'+' || *s ==
'=' ) { sgn = 0; s++; }
880 while ( s[1] >=
'0' && s[1] <=
'9' ) {
881 x = 10*x + (s[1] -
'0'); s++;
883 if ( x >= MAXPOWER || x <= 1 ) {
884 MesPrint(
"&Illegal value for root of unity %s",name);
890 cplx = VARTYPEROOTOFUNITY | sgn;
893 MesPrint(
"&Illegal specification for complexity of symbol %s",name);
903 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
905 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
906 ParseSignedNumber(dim,s)
907 if ( dim < -HALFMAX || dim > HALFMAX ) {
908 MesPrint(
"&Warning: dimension of %s (%d) out of range" 912 if ( *s !=
'}' )
goto IllDim;
916 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
924 if ( ( cplx & VARTYPEROOTOFUNITY ) == VARTYPEROOTOFUNITY ) {
925 MesPrint(
"&Root of unity property for %s cannot be combined with power restrictions",name);
929 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
930 ParseSignedNumber(minpow,s)
931 if ( minpow < -MAXPOWER ) {
934 MesPrint(
"&Warning: minimum power of %s corrected to %d" 944 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
945 ParseSignedNumber(maxpow,s)
946 if ( maxpow > MAXPOWER ) {
949 MesPrint(
"&Warning: maximum power of %s corrected to %d" 953 if ( *s !=
')' )
goto skippar;
956 if ( ( AC.AutoDeclareFlag == 0 &&
957 ( ( type = GetName(AC.exprnames,name,&numsymbol,NOAUTO) )
959 || ( ( type = GetName(*(AC.activenames),name,&numsymbol,NOAUTO) ) != NAMENOTFOUND ) ) {
960 if ( type != CSYMBOL ) error = NameConflict(type,name);
963 if ( ( numsymbol == AC.lPolyFunVar ) && ( AC.lPolyFunType > 0 )
964 && ( AC.lPolyFun != 0 ) && ( minpow > -MAXPOWER || maxpow < MAXPOWER ) ) {
965 MesPrint(
"&The symbol %s is used by power expansions in the PolyRatFun!",name);
969 sym->minpower = minpow;
970 sym->maxpower = maxpow;
975 AddSymbol(name,minpow,maxpow,cplx,dim);
978 eol:
while ( *s ==
',' ) s++;
990 int AddIndex(UBYTE *name,
int dim,
int dim4)
992 int nodenum, numindex = AC.Indices->num;
995 bzero(ind,
sizeof(
struct InDeX));
996 ind->name = AddName(*AC.activenames,name,CINDEX,numindex,&nodenum);
998 ind->dimension = dim;
1001 ind->node = nodenum;
1003 ind->namesize = (s-name)+1;
1014 int CoIndex(UBYTE *s)
1016 int type, error = 0, dim, dim4;
1018 UBYTE *name, *oldc, c;
1023 if ( ( s = SkipAName(s) ) == 0 ) {
1024 IllForm: MesPrint(
"&Illegally formed name in index statement");
1026 s = SkipField(name,0);
1029 oldc = s; c = *s; *s = 0;
1030 if ( TestName(name) ) { *s = c;
goto IllForm; }
1033 if ( ( s = DoDimension(s,&dim,&dim4) ) == 0 ) {
1036 s = SkipField(name,0);
1040 if ( ( AC.AutoDeclareFlag == 0 &&
1041 ( ( type = GetName(AC.exprnames,name,&numindex,NOAUTO) )
1043 || ( ( type = GetName(*(AC.activenames),name,&numindex,NOAUTO) ) != NAMENOTFOUND ) ) {
1044 if ( type != CINDEX ) error = NameConflict(type,name);
1046 indices[numindex].dimension = dim;
1047 indices[numindex].nmin4 = dim4;
1050 else AddIndex(name,dim,dim4);
1052 eol:
while ( *s ==
',' ) s++;
1062 UBYTE *DoDimension(UBYTE *s,
int *dim,
int *dim4)
1065 int type, error = 0;
1067 NAMETREE **oldtree = AC.activenames;
1068 *dim4 = -NMIN4SHIFT;
1069 if ( FG.cTable[*s] == 1 ) {
1072 #if ( BITSINWORD/8 < 4 ) 1073 if ( *dim >= (1 << (BITSINWORD-1)) )
goto illeg;
1078 else if ( ( (FG.cTable[*s] == 0 ) || ( *s ==
'[' ) )
1079 && ( s = SkipAName(s) ) != 0 ) {
1080 AC.activenames = &(AC.varnames);
1082 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1083 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1084 if ( type != CSYMBOL ) error = NameConflict(type,t);
1087 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1088 if ( *oldtree != AC.autonames && AC.WarnFlag )
1089 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1092 if ( ( *s = c ) ==
':' ) {
1095 if ( ( s = SkipAName(s) ) == 0 )
goto illeg;
1096 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1097 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1098 if ( type != CSYMBOL ) error = NameConflict(type,t);
1101 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1102 if ( *oldtree != AC.autonames && AC.WarnFlag )
1103 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1105 *dim4 = -numsymbol-NMIN4SHIFT;
1108 else if ( *s ==
'+' && FG.cTable[s[1]] == 1 ) {
1112 illeg: MesPrint(
"&Illegal dimension specification. Should be number >= 0, symbol or symbol:symbol");
1115 AC.activenames = oldtree;
1116 if ( error )
return(0);
1125 int CoDimension(UBYTE *s)
1127 s = DoDimension(s,&AC.lDefDim,&AC.lDefDim4);
1128 if ( s == 0 )
return(1);
1130 MesPrint(
"&Argument of dimension statement should be number >= 0, symbol or symbol:symbol");
1143 int AddVector(UBYTE *name,
int cplx,
int dim)
1145 int nodenum, numvector = AC.Vectors->num;
1148 bzero(v,
sizeof(
struct VeCtOr));
1149 v->name = AddName(*AC.activenames,name,CVECTOR,numvector,&nodenum);
1155 v->namesize = (s-name)+1;
1166 int CoVector(UBYTE *s)
1168 int type, error = 0, dim;
1170 UBYTE *name, c, *endname;
1174 if ( ( s = SkipAName(s) ) == 0 ) {
1175 IllForm: MesPrint(
"&Illegally formed name in vector statement");
1180 c = *s; *s = 0, endname = s;
1181 if ( TestName(name) ) { *s = c;
goto IllForm; }
1184 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1186 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1187 ParseSignedNumber(dim,s)
1188 if ( dim < -HALFMAX || dim > HALFMAX ) {
1189 MesPrint(
"&Warning: dimension of %s (%d) out of range" 1193 if ( *s !=
'}' )
goto IllDim;
1197 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1200 while ( *s ==
',' ) s++;
1204 if ( ( AC.AutoDeclareFlag == 0 &&
1205 ( ( type = GetName(AC.exprnames,name,&numvector,NOAUTO) )
1207 || ( ( type = GetName(*(AC.activenames),name,&numvector,NOAUTO) ) != NAMENOTFOUND ) ) {
1208 if ( type != CVECTOR ) error = NameConflict(type,name);
1210 else AddVector(name,0,dim);
1213 while ( *s ==
',' ) s++;
1225 int AddFunction(UBYTE *name,
int comm,
int istensor,
int cplx,
int symprop,
int dim,
int argmax,
int argmin)
1227 int nodenum, numfunction = AC.Functions->num;
1230 bzero(fun,
sizeof(
struct FuNcTiOn));
1231 fun->
name = AddName(*AC.activenames,name,CFUNCTION,numfunction,&nodenum);
1233 fun->
spec = istensor;
1237 fun->
node = nodenum;
1240 fun->dimension = dim;
1241 fun->maxnumargs = argmax;
1242 fun->minnumargs = argmin;
1245 return(numfunction);
1255 int CoCommuteInSet(UBYTE *s)
1257 UBYTE *name, *ss, c, *start = s;
1258 WORD number, type, *g, *gg;
1259 int error = 0, i, len = StrLen(s), len2 = 0;
1260 if ( AC.CommuteInSet != 0 ) {
1261 g = AC.CommuteInSet;
1262 while ( *g ) g += *g;
1263 len2 = g - AC.CommuteInSet;
1264 if ( len2+len+3 > AC.SizeCommuteInSet ) {
1265 gg = (WORD *)Malloc1((len2+len+3)*
sizeof(WORD),
"CommuteInSet");
1266 for ( i = 0; i < len2; i++ ) gg[i] = AC.CommuteInSet[i];
1268 M_free(AC.CommuteInSet,
"CommuteInSet");
1269 AC.CommuteInSet = gg;
1270 AC.SizeCommuteInSet = len+len2+3;
1271 g = AC.CommuteInSet+len2;
1275 AC.SizeCommuteInSet = len+2;
1276 g = AC.CommuteInSet = (WORD *)Malloc1((len+3)*
sizeof(WORD),
"CommuteInSet");
1282 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1284 if ( s - start >= len )
break;
1289 MesPrint(
"&There should be at least two noncommuting functions or tensors in a commuting statement.");
1292 else if ( *gg == 2 ) {
1293 gg[2] = gg[1]; gg[3] = 0; gg[0] = 3;
1300 MesPrint(
"&The CommuteInSet statement should have sets enclosed in {}.");
1312 if ( ( type = GetName(AC.varnames,name,&number,NOAUTO) ) != CFUNCTION ) {
1313 MesPrint(
"&%s is not a function or tensor",name);
1316 else if ( functions[number].commute == 0 ){
1317 MesPrint(
"&%s is not a noncommuting function or tensor",name);
1321 *g++ = number+FUNCTION;
1322 functions[number].flags |= COULDCOMMUTE;
1323 if ( number+FUNCTION >= GAMMA && number+FUNCTION <= GAMMASEVEN ) {
1324 functions[GAMMA-FUNCTION].flags |= COULDCOMMUTE;
1325 functions[GAMMAI-FUNCTION].flags |= COULDCOMMUTE;
1326 functions[GAMMAFIVE-FUNCTION].flags |= COULDCOMMUTE;
1327 functions[GAMMASIX-FUNCTION].flags |= COULDCOMMUTE;
1328 functions[GAMMASEVEN-FUNCTION].flags |= COULDCOMMUTE;
1345 int CoFunction(UBYTE *s,
int comm,
int istensor)
1347 int type, error = 0, cplx, symtype, dim, argmax, argmin;
1348 WORD numfunction, reverseorder = 0, addone;
1349 UBYTE *name, *oldc, *par, c, cc;
1351 symtype = cplx = 0, argmin = argmax = -1;
1354 if ( ( s = SkipAName(s) ) == 0 ) {
1355 IllForm: MesPrint(
"&Illegally formed function/tensor name");
1357 s = SkipField(name,0);
1360 oldc = s; cc = c = *s; *s = 0;
1361 if ( TestName(name) ) { *s = c;
goto IllForm; }
1364 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
1365 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
1366 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
1368 MesPrint(
"&Illegal specification for complexity of %s",name);
1378 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1380 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1381 ParseSignedNumber(dim,s)
1382 if ( dim < -HALFMAX || dim > HALFMAX ) {
1383 MesPrint(
"&Warning: dimension of %s (%d) out of range" 1387 if ( *s !=
'}' )
goto IllDim;
1391 IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1401 reverseorder = REVERSEORDER;
1408 while ( FG.cTable[*s] == 0 ) s++;
1412 MesPrint(
"&Illegal specification for symmetry of %s",name);
1418 if ( StrICont(par,(UBYTE *)
"symmetric") == 0 ) symtype = SYMMETRIC;
1419 else if ( StrICont(par,(UBYTE *)
"antisymmetric") == 0 ) symtype = ANTISYMMETRIC;
1420 else if ( ( StrICont(par,(UBYTE *)
"cyclesymmetric") == 0 )
1421 || ( StrICont(par,(UBYTE *)
"cyclic") == 0 ) ) symtype = CYCLESYMMETRIC;
1422 else if ( ( StrICont(par,(UBYTE *)
"rcyclesymmetric") == 0 )
1423 || ( StrICont(par,(UBYTE *)
"rcyclic") == 0 )
1424 || ( StrICont(par,(UBYTE *)
"reversecyclic") == 0 ) ) symtype = RCYCLESYMMETRIC;
1427 if ( *s !=
')' || ( s[1] && s[1] !=
',' && s[1] !=
'<' ) ) {
1428 Warning(
"&Excess information in symmetric properties currently ignored");
1432 symtype |= reverseorder;
1438 if ( *s ==
'=' ) { addone++; s++; }
1440 while ( FG.cTable[*s] == 1 ) { argmax = 10*argmax + *s++ -
'0'; }
1443 while ( FG.cTable[*s] == 0 ) s++;
1446 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1447 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1449 Warning(
"&Illegal information in number of arguments properties currently ignored");
1454 if ( argmax <= 0 ) {
1455 MesPrint(
"&Error: Cannot have fewer than 0 arguments for variable %s",name);
1462 if ( *s ==
'=' ) { addone = 0; s++; }
1464 while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ -
'0'; }
1467 while ( FG.cTable[*s] == 0 ) s++;
1470 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1471 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1473 Warning(
"&Illegal information in number of arguments properties currently ignored");
1480 if ( cc ==
'<' )
goto retry;
1481 if ( ( AC.AutoDeclareFlag == 0 &&
1482 ( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
1484 || ( ( type = GetName(*(AC.activenames),name,&numfunction,NOAUTO) ) != NAMENOTFOUND ) ) {
1485 if ( type != CFUNCTION ) error = NameConflict(type,name);
1490 if ( fun->
tabl != 0 ) {
1491 MesPrint(
"&Illegal attempt to change table into function");
1497 if ( istensor && fun->
spec == 0 ) {
1498 MesPrint(
"&Function %s changed to tensor",name);
1501 else if ( istensor == 0 && fun->
spec ) {
1502 MesPrint(
"&Tensor %s changed to function",name);
1505 fun->
spec = istensor;
1508 AC.SymChangeFlag = 1;
1510 fun->maxnumargs = argmax;
1511 fun->minnumargs = argmin;
1515 AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
1518 eol:
while ( *s ==
',' ) s++;
1523 int CoNFunction(UBYTE *s) {
return(CoFunction(s,1,0)); }
1524 int CoCFunction(UBYTE *s) {
return(CoFunction(s,0,0)); }
1525 int CoNTensor(UBYTE *s) {
return(CoFunction(s,1,2)); }
1526 int CoCTensor(UBYTE *s) {
return(CoFunction(s,0,2)); }
1558 static int nwarntab = 1;
1560 int DoTable(UBYTE *s,
int par)
1563 UBYTE *name, *p, *inp, c;
1564 int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
1565 int error = 0, ret, oldcbufnum, oldEside;
1566 WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;
1573 while ( *s ==
',' ) s++;
1576 if ( ( s = SkipAName(s) ) == 0 ) {
1577 IllForm: MesPrint(
"&Illegal name or option in table declaration");
1581 if ( TestName(name) ) { *s = c;
goto IllForm; }
1583 if ( *s ==
'(' )
break;
1585 MesPrint(
"&Illegal definition of table");
1592 if ( StrICmp(name,(UBYTE *)(
"check" )) == 0 ) checkflag = 1;
1593 else if ( StrICmp(name,(UBYTE *)(
"zero" )) == 0 ) checkflag = 2;
1594 else if ( StrICmp(name,(UBYTE *)(
"one" )) == 0 ) checkflag = 3;
1595 else if ( StrICmp(name,(UBYTE *)(
"strict")) == 0 ) rflag = 1;
1596 else if ( StrICmp(name,(UBYTE *)(
"relax" )) == 0 ) rflag = -1;
1597 else if ( StrICmp(name,(UBYTE *)(
"zerofill" )) == 0 ) { rflag = -2; checkflag = 2; }
1598 else if ( StrICmp(name,(UBYTE *)(
"onefill" )) == 0 ) { rflag = -3; checkflag = 3; }
1599 else if ( StrICmp(name,(UBYTE *)(
"sparse")) == 0 ) sparseflag |= 1;
1600 else if ( StrICmp(name,(UBYTE *)(
"base")) == 0 ) sparseflag |= 3;
1601 else if ( StrICmp(name,(UBYTE *)(
"tablebase")) == 0 ) sparseflag |= 3;
1603 MesPrint(
"&Illegal option in table definition: '%s'",name);
1607 while ( *s ==
',' ) s++;
1609 if ( name == s || *s == 0 ) {
1610 MesPrint(
"&Illegal name or option in table declaration");
1615 if ( checkflag == 1 ) rflag = 0;
1616 else if ( checkflag == 2 ) rflag = -2;
1617 else if ( checkflag == 3 ) rflag = -3;
1620 if ( ( ret = GetVar(name,&type,&funnum,CFUNCTION,NOAUTO) ) ==
1623 funnum = EntVar(CFUNCTION,name,0,1,0,0);
1625 else if ( par == 1 || par == 2 ) {
1626 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1629 else if ( ret <= 0 ) {
1630 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1636 Warning(
"Table now declares its (commuting) function.");
1637 Warning(
"Earlier definition in Function statement obsolete. Please remove.");
1643 MesPrint(
"&(N)(C)Tables should not be declared previously");
1646 if ( functions[funnum].spec > 0 ) {
1647 MesPrint(
"&Tensors cannot become tables");
1650 if ( functions[funnum].symmetric > 0 ) {
1651 MesPrint(
"&Functions with nontrivial symmetrization properties cannot become tables");
1654 if ( functions[funnum].tabl ) {
1655 MesPrint(
"&Redefinition of an existing table is not allowed.");
1658 functions[funnum].tabl = T = (
TABLES)Malloc1(
sizeof(
struct TaBlEs),
"table");
1678 if ( rflag > 0 ) AC.MustTestTable++;
1692 T->
argtail = strDup1(p,
"argtail");
1699 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1701 MesPrint(
"&First argument in a sparse table must be a number of dimensions");
1707 T->
flags = (WORD *)Malloc1(x*
sizeof(WORD),
"table flags");
1710 if ( *inp !=
')' ) inp++;
1720 if ( FG.cTable[*p] != 1 && *p !=
'+' && *p !=
'-' )
break;
1721 ParseSignedNumber(x,p)
1722 if ( FG.cTable[p[-1]] != 1 || *p !=
':' )
break;
1724 ParseSignedNumber(y,p)
1725 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1726 MesPrint(
"&Illegal dimension field in table declaration");
1730 flags1 = (WORD *)Malloc1((T->
numind+1)*
sizeof(WORD),
"table flags");
1731 for ( i = 0; i < T->
numind; i++ ) { mm1[i] = T->
mm[i]; flags1[i] = T->
flags[i]; }
1732 if ( T->
mm ) M_free(T->
mm,
"table dimensions");
1733 if ( T->
flags ) M_free(T->
flags,
"table flags");
1740 if ( *p ==
')' ) { inp = p;
break; }
1743 = (WORD *)Malloc1(TABLEEXTENSION*
sizeof(WORD)*(T->
totind),
"table pointers");
1745 for ( i = TABLEEXTENSION*T->
totind; i > 0; i-- ) *w++ = -1;
1746 for ( i = T->
numind-1, x = 1; i >= 0; i-- ) {
1756 OldWork = AT.WorkPointer;
1757 oldcbufnum = AC.cbufnum;
1759 C = cbuf+AC.cbufnum;
1761 oldnumlhs = C->numlhs;
1762 oldnumrhs = C->numrhs;
1764 while ( s >= name ) *--inp = *s--;
1767 *w++ = SUBEXPRESSION;
1775 AT.WorkPointer = w + 4*AM.MaxWildcards;
1776 if ( ( ret = CompileAlgebra(inp,LHSIDE,AC.ProtoType) ) < 0 ) {
1777 error = 1;
goto FinishUp;
1779 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
1793 OldWork[2] = C->numrhs;
1794 *w++ = 1; *w++ = 1; *w++ = 3;
1795 OldWork[-1] = w-OldWork+1;
1797 ww = C->
rhs[C->numrhs];
1798 for ( j = 0; j < *ww; j++ ) w[j] = ww[j];
1799 AT.WorkPointer = w+*w;
1800 if ( *ww == 0 || ww[*ww] != 0 ) {
1801 MesPrint(
"&Illegal table pattern definition");
1802 AC.lhdollarflag = 0;
1805 if ( error )
goto FinishUp;
1807 if (
NewSort(BHEAD0) ||
NewSort(BHEAD0) ) { error = 1;
goto FinishUp; }
1808 AN.RepPoint = AT.RepCount + 1;
1809 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
1810 AR.Cnumlhs = C->numlhs;
1811 functions[funnum].tabl = 0;
1813 functions[funnum].tabl = T;
1814 AR.Eside = oldEside;
1817 functions[funnum].tabl = T;
1818 AR.Eside = oldEside;
1821 if ( *w == 0 || *(w+*w) != 0 ) {
1822 MesPrint(
"&Irregular pattern in table definition");
1827 if ( AC.lhdollarflag ) {
1828 MesPrint(
"&Unexpanded dollar variables are not allowed in table definition");
1832 AT.WorkPointer = ww = w + *w;
1833 if ( ww[-1] != 3 || ww[-2] != 1 || ww[-3] != 1 ) {
1834 MesPrint(
"&Coefficient of pattern in table definition should be 1.");
1846 T->
prototypeSize = ((i+j)*
sizeof(WORD)+2*
sizeof(WORD *)) * AM.totalnumberofthreads;
1849 t = (WORD *)(T->
pattern + AM.totalnumberofthreads);
1850 for ( n = 0; n < AM.totalnumberofthreads; n++ ) {
1852 for ( k = 0; k < i; k++ ) *t++ = OldWork[k];
1857 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1859 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1860 for ( k = 0; k < j; k++ ) *t++ = *w++;
1863 for ( n = 1; n < AM.totalnumberofthreads; n++ ) {
1865 for ( i = 0; i < k; i++ ) *t++ = *tt++;
1872 for ( k = 0; k < i; k++ ) T->
prototype[k] = OldWork[k];
1876 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1878 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1879 for ( k = 0; k < j; k++ ) *t++ = *w++;
1886 C->numrhs = oldnumrhs;
1887 C->numlhs = oldnumlhs;
1897 tt = t + t[1]; t += SUBEXPSIZE;
1899 if ( *t == LOADDOLLAR ) {
1900 Warning(
"The use of $-variable assignments in tables disables parallel\ 1901 execution for the whole program.");
1902 AM.hparallelflag |= NOPARALLEL_TBLDOLLAR;
1903 AC.mparallelflag |= NOPARALLEL_TBLDOLLAR;
1909 AT.WorkPointer = OldWork - 1;
1910 AC.cbufnum = oldcbufnum;
1911 if ( T->
sparse ) ClearTableTree(T);
1912 if ( ( sparseflag & 2 ) != 0 ) {
1913 if ( T->
spare == 0 ) { SpareTable(T); }
1923 int CoTable(UBYTE *s)
1925 return(DoTable(s,2));
1933 int CoNTable(UBYTE *s)
1935 return(DoTable(s,0));
1943 int CoCTable(UBYTE *s)
1945 return(DoTable(s,1));
1953 void EmptyTable(
TABLES T)
1956 if ( T->
sparse ) ClearTableTree(T);
1974 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
1975 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
1988 for ( j = TABLEEXTENSION*T->
totind; j > 0; j-- ) *w++ = -1;
1997 int AddSet(UBYTE *name, WORD dim)
1999 int nodenum, numset = AC.SetList.num;
2000 SETS set = (
SETS)FromVarList(&AC.SetList);
2003 set->name = AddName(AC.varnames,name,CSET,numset,&nodenum);
2006 set->namesize = (s-name)+1;
2007 set->node = nodenum;
2015 set->last = AC.SetElementList.num;
2017 set->dimension = dim;
2029 int DoElements(UBYTE *s,
SETS set, UBYTE *name)
2031 int type, error = 0, x, sgn, i;
2035 if ( *s ==
',' ) { s++;
continue; }
2037 while ( *s ==
'-' || *s ==
'+' ) { sgn ^= 1; s++; }
2039 if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'[' ) {
2040 if ( ( s = SkipAName(s) ) == 0 ) {
2041 MesPrint(
"&Illegal name in set definition");
2045 if ( ( ( type = GetName(AC.exprnames,cname,&numset,NOAUTO) ) == NAMENOTFOUND )
2046 && ( ( type = GetOName(AC.varnames,cname,&numset,WITHAUTO) ) == NAMENOTFOUND ) ) {
2049 MesPrint(
"&%s has not been declared",cname);
2053 numset = AC.DubiousList.num;
2054 dv = (
DUBIOUSV)FromVarList(&AC.DubiousList);
2055 dv->name = AddName(AC.varnames,cname,CDUBIOUS,numset,&nodenum);
2057 set->type = type = CDUBIOUS;
2061 if ( set->type == -1 ) {
2062 if ( type == CSYMBOL ) {
2063 for ( i = set->first; i < set->last; i++ ) {
2064 SetElements[i] += 2*MAXPOWER;
2069 if ( set->type != type && set->type != CDUBIOUS
2070 && type != CDUBIOUS ) {
2071 if ( set->type != CNUMBER || ( type != CSYMBOL
2072 && type != CINDEX ) ) {
2074 "&%s has not the same type as the other members of the set" 2077 set->type = CDUBIOUS;
2080 if ( type == CSYMBOL ) {
2081 for ( i = set->first; i < set->last; i++ ) {
2082 SetElements[i] += 2*MAXPOWER;
2088 if ( set->dimension != MAXPOSITIVE ) {
2089 switch ( set->type ) {
2091 if ( symbols[numset].dimension != set->dimension ) {
2092 MesPrint(
"&Dimension check failed in set %s, symbol %s",
2093 VARNAME(Sets,(
set-Sets)),
2094 VARNAME(symbols,numset));
2096 set->dimension = MAXPOSITIVE;
2100 if ( vectors[numset-AM.OffsetVector].dimension != set->dimension ) {
2101 MesPrint(
"&Dimension check failed in set %s, vector %s",
2102 VARNAME(Sets,(
set-Sets)),
2103 VARNAME(vectors,(numset-AM.OffsetVector)));
2105 set->dimension = MAXPOSITIVE;
2109 if ( functions[numset-FUNCTION].dimension != set->dimension ) {
2110 MesPrint(
"&Dimension check failed in set %s, function %s",
2111 VARNAME(Sets,(
set-Sets)),
2112 VARNAME(functions,(numset-FUNCTION)));
2116 set->dimension = MAXPOSITIVE;
2120 if ( type != CVECTOR ) {
2121 MesPrint(
"&Illegal use of - sign in set. Can use only with vector or number");
2132 if ( name == 0 && *s ==
'?' ) {
2134 switch ( set->type ) {
2136 numset = -numset;
break;
2138 numset += WILDOFFSET;
break;
2140 numset |= WILDMASK;
break;
2142 numset |= WILDMASK;
break;
2149 e = (WORD *)FromVarList(&AC.SetElementList);
2153 else if ( FG.cTable[*s] == 1 ) {
2156 if ( x >= MAXPOWER || x <= -MAXPOWER ||
2157 ( set->type == CINDEX && ( x < 0 || x >= AM.OffsetIndex ) ) ) {
2158 MesPrint(
"&Illegal value for set element: %d",x);
2159 if ( AC.firstconstindex ) {
2160 MesPrint(
"&0 <= Fixed indices < ConstIndex(which is %d)",
2162 MesPrint(
"&For setting ConstIndex, read the chapter on the setup file");
2163 AC.firstconstindex = 0;
2171 if ( set->type == -1 ) {
2172 if ( x < 0 || x >= AM.OffsetIndex ) {
2173 for ( i = set->first; i < set->last; i++ ) {
2174 SetElements[i] += 2*MAXPOWER;
2176 set->type = CSYMBOL;
2178 else set->type = CNUMBER;
2180 else if ( set->type == CDUBIOUS ) {}
2181 else if ( set->type == CNUMBER && x < 0 ) {
2182 for ( i = set->first; i < set->last; i++ ) {
2183 SetElements[i] += 2*MAXPOWER;
2185 set->type = CSYMBOL;
2187 else if ( set->type != CSYMBOL && ( x < 0 ||
2188 ( set->type != CINDEX && set->type != CNUMBER ) ) ) {
2189 MesPrint(
"&Illegal mixture of element types in set");
2191 set->type = CDUBIOUS;
2196 e = (WORD *)FromVarList(&AC.SetElementList);
2198 if ( set->type == CSYMBOL ) *e = x + 2*MAXPOWER;
2203 MesPrint(
"&Illegal object in list of set elements");
2219 int type, error = 0;
2220 UBYTE *name, c, *ss;
2222 WORD numberofset, dim = MAXPOSITIVE;
2224 if ( ( s = SkipAName(s) ) == 0 ) {
2225 IllForm:MesPrint(
"&Illegal name for set");
2229 if ( TestName(name) )
goto IllForm;
2230 if ( ( ( type = GetName(AC.exprnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND )
2231 || ( ( type = GetName(AC.varnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND ) ) {
2232 if ( type != CSET ) NameConflict(type,name);
2234 MesPrint(
"&There is already a set with the name %s",name);
2239 numberofset = AddSet(name,0);
2240 set = Sets + numberofset;
2246 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
2248 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
2249 ParseSignedNumber(dim,s)
2250 if ( dim < -HALFMAX || dim > HALFMAX ) {
2251 MesPrint(
"&Warning: dimension of %s (%d) out of range" 2255 if ( *s !=
'}' )
goto IllDim;
2259 IllDim: MesPrint(
"&Error: Illegal dimension field for set %s",name);
2263 while ( *s ==
',' ) s++;
2266 numberofset = AddSet(name,dim);
2268 set = Sets + numberofset;
2270 MesPrint(
"&Proper syntax is `Set name:elements'");
2274 error = DoElements(s,
set,name);
2275 AC.SetList.numtemp = AC.SetList.num;
2276 AC.SetElementList.numtemp = AC.SetElementList.num;
2290 int DoTempSet(UBYTE *from, UBYTE *to)
2295 int setnum = AddSet(0,MAXPOSITIVE);
2296 SETS set = Sets + setnum, setp;
2301 while ( *from ==
',' ) from++;
2302 if ( *from ==
'<' || *from ==
'>' ) {
2304 set->first = 3*MAXPOWER;
2305 set->last = -3*MAXPOWER;
2306 while ( *from ==
'<' || *from ==
'>' ) {
2307 if ( *from ==
'<' ) {
2309 if ( *from ==
'=' ) { from++; j++; }
2313 if ( *from ==
'=' ) { from++; j--; }
2316 while ( *from ==
'-' || *from ==
'+' ) {
2317 if ( *from ==
'-' ) sgn = -sgn;
2320 ParseNumber(num,from)
2321 if ( *from && *from !=
',' ) {
2322 MesPrint(
"&Illegal number in ranged set definition");
2325 if ( sgn < 0 ) num = -num;
2326 if ( num >= MAXPOWER || num <= -MAXPOWER ) {
2327 Warning(
"Value in ranged set too big. Adjusted to infinity.");
2328 if ( num > 0 ) num = 3*MAXPOWER;
2329 else num = -3*MAXPOWER;
2331 else if ( j == 2 ) num += 2*MAXPOWER;
2332 else if ( j == -2 ) num -= 2*MAXPOWER;
2333 if ( j > 0 )
set->first = num;
2334 else set->last = num;
2335 while ( *from ==
',' ) from++;
2338 MesPrint(
"&Definition of ranged set contains illegal objects");
2342 else if ( DoElements(from,
set,(UBYTE *)0) != 0 ) {
2343 AC.SetElementList.num =
set->first;
2344 AC.SetList.num--; *to = c;
2351 num =
set->last -
set->first;
2352 for ( setp = Sets, i = 0; i < AC.SetList.num-1; i++, setp++ ) {
2353 if ( num != setp->last - setp->first )
continue;
2354 if ( set->type != setp->type )
continue;
2355 if ( set->type == CRANGE ) {
2356 if ( set->first == setp->first )
return(setp-Sets);
2359 e = SetElements +
set->first;
2360 ep = SetElements + setp->first;
2362 while ( --j >= 0 )
if ( *e++ != *ep++ )
break;
2364 AC.SetElementList.num =
set->first;
2366 return(setp - Sets);
2382 int CoAuto(UBYTE *inp)
2386 AC.Symbols = &(AC.AutoSymbolList);
2387 AC.Vectors = &(AC.AutoVectorList);
2388 AC.Indices = &(AC.AutoIndexList);
2389 AC.Functions = &(AC.AutoFunctionList);
2390 AC.activenames = &(AC.autonames);
2391 AC.AutoDeclareFlag = WITHAUTO;
2393 while ( *inp ==
',' ) inp++;
2394 retval = CompileStatement(inp);
2396 AC.AutoDeclareFlag = 0;
2397 AC.Symbols = &(AC.SymbolList);
2398 AC.Vectors = &(AC.VectorList);
2399 AC.Indices = &(AC.IndexList);
2400 AC.Functions = &(AC.FunctionList);
2401 AC.activenames = &(AC.varnames);
2412 int AddDollar(UBYTE *name, WORD type, WORD *start, LONG size)
2414 int nodenum, numdollar = AP.DollarList.num;
2417 dol->name = AddName(AC.dollarnames,name,CDOLLAR,numdollar,&nodenum);
2419 dol->node = nodenum;
2421 dol->numdummies = 0;
2423 dol->pthreadslockread = dummylock;
2424 dol->pthreadslockwrite = dummylock;
2430 if ( start && size > 0 ) {
2433 s = (WORD *)Malloc1((size+1)*
sizeof(WORD),
"$-variable contents");
2435 while ( --size >= 0 ) *s++ = *t++;
2438 else { dol->where = &(AM.dollarzero); dol->size = 0; }
2439 cbuf[AM.dbufnum].rhs[numdollar] = dol->where;
2440 cbuf[AM.dbufnum].CanCommu[numdollar] = 0;
2441 cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
2456 int ReplaceDollar(WORD number, WORD newtype, WORD *newstart, LONG newsize)
2459 DOLLARS dol = Dollars + number;
2462 dol->type = newtype;
2463 if ( dol->size == newsize && newsize > 0 && newstart ) {
2464 s = dol->where; t = newstart; i = newsize;
2465 while ( --i >= 0 ) {
if ( *s++ != *t++ )
break; }
2466 if ( i < 0 )
return(0);
2468 if ( dol->where && dol->where != &(dol->zero) ) {
2469 M_free(dol->where,
"dollar->where"); dol->where = &(dol->zero); dol->size = 0;
2471 if ( newstart && newsize > 0 ) {
2472 dol->size = newsize;
2474 s = (WORD *)Malloc1((newsize+1)*
sizeof(WORD),
"$-variable contents");
2475 t = newstart; i = newsize;
2476 while ( --i >= 0 ) *s++ = *t++;
2489 int AddDubious(UBYTE *name)
2491 int nodenum, numdubious = AC.DubiousList.num;
2493 dub->name = AddName(AC.varnames,name,CDUBIOUS,numdubious,&nodenum);
2494 dub->node = nodenum;
2503 int MakeDubious(
NAMETREE *nametree, UBYTE *name, WORD *number)
2506 int node, newnode, i;
2507 if ( nametree->
namenode == 0 )
return(-1);
2514 else if ( i > 0 ) newnode = n->
right;
2516 if ( n->
type != CDUBIOUS ) {
2517 int numdubious = AC.DubiousList.num;
2525 }
while ( newnode >= 0 );
2534 static char *nametype[] = {
"symbol",
"index",
"vector",
"function",
2535 "set",
"expression" };
2536 static char *plural[] = {
"",
"n",
"",
"",
"",
"n" };
2538 int NameConflict(
int type, UBYTE *name)
2540 if ( type == NAMENOTFOUND ) {
2541 MesPrint(
"&%s has not been declared",name);
2543 else if ( type != CDUBIOUS )
2544 MesPrint(
"&%s has been declared as a%s %s already" 2545 ,name,plural[type],nametype[type]);
2554 int AddExpression(UBYTE *name,
int x,
int y)
2556 int nodenum, numexpr = AC.ExpressionList.num;
2560 expr->printflag = y;
2561 PUTZERO(expr->onfile);
2562 PUTZERO(expr->size);
2565 expr->hidelevel = 0;
2567 expr->bracketinfo = expr->newbracketinfo = 0;
2569 expr->name = AddName(AC.exprnames,name,CEXPRESSION,numexpr,&nodenum);
2570 expr->node = nodenum;
2571 expr->replace = NEWLYDEFINEDEXPRESSION ;
2574 expr->namesize = (s-name)+1;
2577 expr->replace = REDEFINEDEXPRESSION;
2578 expr->name = AC.TransEname;
2583 expr->numdummies = 0;
2584 expr->numfactors = 0;
2596 int GetLabel(UBYTE *name)
2600 UBYTE **NewLabelNames;
2602 for ( i = 0; i < AC.NumLabels; i++ ) {
2603 if ( StrCmp(name,AC.LabelNames[i]) == 0 )
return(i);
2605 if ( AC.NumLabels >= AC.MaxLabels ) {
2606 newnum = 2*AC.MaxLabels;
2607 if ( newnum == 0 ) newnum = 10;
2608 if ( newnum > 32765 ) newnum = 32765;
2609 if ( newnum == AC.MaxLabels ) {
2610 MesPrint(
"&More than 32765 labels in one module. Please simplify.");
2613 NewLabelNames = (UBYTE **)Malloc1((
sizeof(UBYTE *)+
sizeof(
int))
2615 NewLabel = (
int *)(NewLabelNames+newnum);
2616 for ( i = 0; i< AC.MaxLabels; i++ ) {
2617 NewLabelNames[i] = AC.LabelNames[i];
2618 NewLabel[i] = AC.Labels[i];
2620 if ( AC.LabelNames ) M_free(AC.LabelNames,
"Labels");
2621 AC.LabelNames = NewLabelNames;
2622 AC.Labels = NewLabel;
2623 AC.MaxLabels = newnum;
2626 AC.LabelNames[i] = strDup1(name,
"Labels");
2641 void ResetVariables(
int par)
2647 AC.SetList.num = AC.SetList.numtemp;
2648 AC.SetElementList.num = AC.SetElementList.numtemp;
2651 for ( i = AC.SymbolList.numclear; i < AC.SymbolList.num; i++ )
2652 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2653 AC.SymbolList.num = AC.SymbolList.numglobal = AC.SymbolList.numclear;
2654 for ( i = AC.VectorList.numclear; i < AC.VectorList.num; i++ )
2655 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2656 AC.VectorList.num = AC.VectorList.numglobal = AC.VectorList.numclear;
2657 for ( i = AC.IndexList.numclear; i < AC.IndexList.num; i++ )
2658 AC.varnames->namenode[indices[i].node].type = CDELETE;
2659 AC.IndexList.num = AC.IndexList.numglobal = AC.IndexList.numclear;
2660 for ( i = AC.FunctionList.numclear; i < AC.FunctionList.num; i++ ) {
2661 AC.varnames->namenode[functions[i].node].type = CDELETE;
2662 if ( ( T = functions[i].tabl ) != 0 ) {
2665 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2666 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2678 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2679 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2693 AC.FunctionList.num = AC.FunctionList.numglobal = AC.FunctionList.numclear;
2694 for ( i = AC.SetList.numclear; i < AC.SetList.num; i++ ) {
2695 if ( Sets[i].node >= 0 )
2696 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2698 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal = AC.SetList.numclear;
2699 for ( i = AC.DubiousList.numclear; i < AC.DubiousList.num; i++ )
2700 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2701 AC.DubiousList.num = AC.DubiousList.numglobal = AC.DubiousList.numclear;
2702 AC.SetElementList.numtemp = AC.SetElementList.num =
2703 AC.SetElementList.numglobal = AC.SetElementList.numclear;
2704 CompactifyTree(AC.varnames,VARNAMES);
2705 AC.varnames->namefill = AC.varnames->globalnamefill = AC.varnames->clearnamefill;
2706 AC.varnames->nodefill = AC.varnames->globalnodefill = AC.varnames->clearnodefill;
2708 for ( i = AC.AutoSymbolList.numclear; i < AC.AutoSymbolList.num; i++ )
2709 AC.autonames->namenode[
2710 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2711 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal
2712 = AC.AutoSymbolList.numclear;
2713 for ( i = AC.AutoVectorList.numclear; i < AC.AutoVectorList.num; i++ )
2714 AC.autonames->namenode[
2715 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2716 AC.AutoVectorList.num = AC.AutoVectorList.numglobal
2717 = AC.AutoVectorList.numclear;
2718 for ( i = AC.AutoIndexList.numclear; i < AC.AutoIndexList.num; i++ )
2719 AC.autonames->namenode[
2720 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2721 AC.AutoIndexList.num = AC.AutoIndexList.numglobal
2722 = AC.AutoIndexList.numclear;
2723 for ( i = AC.AutoFunctionList.numclear; i < AC.AutoFunctionList.num; i++ ) {
2724 AC.autonames->namenode[
2725 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].node].type = CDELETE;
2726 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2729 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2730 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2738 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2739 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2750 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal
2751 = AC.AutoFunctionList.numclear;
2752 CompactifyTree(AC.autonames,AUTONAMES);
2753 AC.autonames->namefill = AC.autonames->globalnamefill
2754 = AC.autonames->clearnamefill;
2755 AC.autonames->nodefill = AC.autonames->globalnodefill
2756 = AC.autonames->clearnodefill;
2760 for ( i = AC.SymbolList.numglobal; i < AC.SymbolList.num; i++ )
2761 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2762 AC.SymbolList.num = AC.SymbolList.numglobal;
2763 for ( i = AC.VectorList.numglobal; i < AC.VectorList.num; i++ )
2764 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2765 AC.VectorList.num = AC.VectorList.numglobal;
2766 for ( i = AC.IndexList.numglobal; i < AC.IndexList.num; i++ )
2767 AC.varnames->namenode[indices[i].node].type = CDELETE;
2768 AC.IndexList.num = AC.IndexList.numglobal;
2769 for ( i = AC.FunctionList.numglobal; i < AC.FunctionList.num; i++ ) {
2770 AC.varnames->namenode[functions[i].node].type = CDELETE;
2771 if ( ( T = functions[i].tabl ) != 0 ) {
2774 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2775 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2787 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2788 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2806 for ( i = 0; i < AC.FunctionList.numglobal; i++ ) {
2813 if ( ( T = functions[i].tabl ) != 0 ) {
2821 #if TABLEEXTENSION == 2 2828 tp += TABLEEXTENSION;
2830 RedoTableTree(T,T->
totind);
2834 for ( j = 0, tp = TT->
tablepointers; j < TT->totind; j++ ) {
2836 #if TABLEEXTENSION == 2 2843 tp += TABLEEXTENSION;
2845 RedoTableTree(TT,TT->
totind);
2852 #if TABLEEXTENSION == 2 2868 AC.FunctionList.num = AC.FunctionList.numglobal;
2869 for ( i = AC.SetList.numglobal; i < AC.SetList.num; i++ ) {
2870 if ( Sets[i].node >= 0 )
2871 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2873 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal;
2874 for ( i = AC.DubiousList.numglobal; i < AC.DubiousList.num; i++ )
2875 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2876 AC.DubiousList.num = AC.DubiousList.numglobal;
2877 AC.SetElementList.numtemp = AC.SetElementList.num =
2878 AC.SetElementList.numglobal;
2879 CompactifyTree(AC.varnames,VARNAMES);
2880 AC.varnames->namefill = AC.varnames->globalnamefill;
2881 AC.varnames->nodefill = AC.varnames->globalnodefill;
2883 for ( i = AC.AutoSymbolList.numglobal; i < AC.AutoSymbolList.num; i++ )
2884 AC.autonames->namenode[
2885 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2886 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal;
2887 for ( i = AC.AutoVectorList.numglobal; i < AC.AutoVectorList.num; i++ )
2888 AC.autonames->namenode[
2889 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2890 AC.AutoVectorList.num = AC.AutoVectorList.numglobal;
2891 for ( i = AC.AutoIndexList.numglobal; i < AC.AutoIndexList.num; i++ )
2892 AC.autonames->namenode[
2893 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2894 AC.AutoIndexList.num = AC.AutoIndexList.numglobal;
2895 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
2896 AC.autonames->namenode[
2897 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].node].type = CDELETE;
2898 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2901 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2902 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2910 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2911 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2922 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal;
2924 CompactifyTree(AC.autonames,AUTONAMES);
2926 AC.autonames->namefill = AC.autonames->globalnamefill;
2927 AC.autonames->nodefill = AC.autonames->globalnodefill;
2937 void RemoveDollars()
2940 CBUF *C = cbuf + AM.dbufnum;
2941 int numdollar = AP.DollarList.num;
2942 if ( numdollar > 0 ) {
2943 while ( numdollar > AM.gcNumDollars ) {
2945 d = Dollars + numdollar;
2946 if ( d->where && d->where != &(d->zero) && d->where != &(AM.dollarzero) ) {
2947 M_free(d->where,
"dollar->where"); d->where = &(d->zero); d->size = 0;
2949 AC.dollarnames->namenode[d->node].type = CDELETE;
2951 AP.DollarList.num = AM.gcNumDollars;
2952 CompactifyTree(AC.dollarnames,DOLLARNAMES);
2954 C->numrhs = C->mnumrhs;
2955 C->numlhs = C->mnumlhs;
2964 void Globalize(
int par)
2969 AC.SymbolList.numclear = AC.SymbolList.num;
2970 AC.VectorList.numclear = AC.VectorList.num;
2971 AC.IndexList.numclear = AC.IndexList.num;
2972 AC.FunctionList.numclear = AC.FunctionList.num;
2973 AC.SetList.numclear = AC.SetList.num;
2974 AC.DubiousList.numclear = AC.DubiousList.num;
2975 AC.SetElementList.numclear = AC.SetElementList.num;
2976 AC.varnames->clearnamefill = AC.varnames->namefill;
2977 AC.varnames->clearnodefill = AC.varnames->nodefill;
2979 AC.AutoSymbolList.numclear = AC.AutoSymbolList.num;
2980 AC.AutoVectorList.numclear = AC.AutoVectorList.num;
2981 AC.AutoIndexList.numclear = AC.AutoIndexList.num;
2982 AC.AutoFunctionList.numclear = AC.AutoFunctionList.num;
2983 AC.autonames->clearnamefill = AC.autonames->namefill;
2984 AC.autonames->clearnodefill = AC.autonames->nodefill;
2987 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
2992 if ( functions[i].tabl ) {
2993 TABLES T = functions[i].tabl;
2998 #if TABLEEXTENSION == 2 3001 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3003 tp += TABLEEXTENSION;
3008 for ( j = 0, tp = TT->
tablepointers; j < TT->totind; j++ ) {
3010 #if TABLEEXTENSION == 2 3013 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3015 tp += TABLEEXTENSION;
3024 #if TABLEEXTENSION == 2 3027 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3035 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3036 if ( ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl )
3037 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->mdefined =
3038 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->defined;
3040 AC.SymbolList.numglobal = AC.SymbolList.num;
3041 AC.VectorList.numglobal = AC.VectorList.num;
3042 AC.IndexList.numglobal = AC.IndexList.num;
3043 AC.FunctionList.numglobal = AC.FunctionList.num;
3044 AC.SetList.numglobal = AC.SetList.num;
3045 AC.DubiousList.numglobal = AC.DubiousList.num;
3046 AC.SetElementList.numglobal = AC.SetElementList.num;
3047 AC.varnames->globalnamefill = AC.varnames->namefill;
3048 AC.varnames->globalnodefill = AC.varnames->nodefill;
3050 AC.AutoSymbolList.numglobal = AC.AutoSymbolList.num;
3051 AC.AutoVectorList.numglobal = AC.AutoVectorList.num;
3052 AC.AutoIndexList.numglobal = AC.AutoIndexList.num;
3053 AC.AutoFunctionList.numglobal = AC.AutoFunctionList.num;
3054 AC.autonames->globalnamefill = AC.autonames->namefill;
3055 AC.autonames->globalnodefill = AC.autonames->nodefill;
3063 int TestName(UBYTE *name)
3065 if ( *name ==
'[' ) {
3066 while ( *name ) name++;
3067 if ( name[-1] ==
']' )
return(0);
3071 if ( *name ==
'_' )
return(-1);
void AddPotModdollar(WORD)
WORD SortWild(WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
struct FuNcTiOn * FUNCTIONS
LONG EndSort(PHEAD WORD *, int)