67 WORD *term, *t, i, size;
71 WORD last, LastExpression, fromspectator;
73 CBUF *C = cbuf+AC.cbufnum;
75 CBUF *CC = cbuf+AT.ebufnum;
78 WORD oldBracketOn = AR.BracketOn;
79 WORD *oldBrackBuf = AT.BrackBuf;
80 WORD oldbracketindexflag = AT.bracketindexflag;
82 int OldMultiThreaded = AS.MultiThreaded, Oldmparallelflag = AC.mparallelflag;
84 if ( CC->numrhs > 0 || CC->numlhs > 0 ) {
86 w = CC->
rhs; i = CC->numrhs;
87 do { *w++ = 0; }
while ( --i > 0 );
90 w = CC->
lhs; i = CC->numlhs;
91 do { *w++ = 0; }
while ( --i > 0 );
93 CC->numlhs = CC->numrhs = 0;
94 ClearTree(AT.ebufnum);
98 if ( NumExpressions == 0 )
return(0);
100 AR.CompressPointer = AR.CompressBuffer;
101 AR.NoCompress = AC.NoCompress;
102 term = AT.WorkPointer;
103 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer) ) > AT.WorkTop ) {
109 if ( AC.CollectFun ) AR.DeferFlag = 0;
113 MesPrint(
"Status at the start of Processor (HideLevel = %d)",AC.HideLevel);
114 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.infile->name ,AR.infile->POfill -AR.infile->PObuffer ,AR.infile->POfull -AR.infile->PObuffer ,AR.infile->POsize/
sizeof(WORD) );
115 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.outfile->name ,AR.outfile->POfill -AR.outfile->PObuffer ,AR.outfile->POfull -AR.outfile->PObuffer ,AR.outfile->POsize/
sizeof(WORD) );
116 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.hidefile->name ,AR.hidefile->POfill-AR.hidefile->PObuffer,AR.hidefile->POfull-AR.hidefile->PObuffer,AR.hidefile->POsize/
sizeof(WORD));
117 for ( i = 0; i < NumExpressions; i++ ) {
127 for ( i = NumExpressions-1; i >= 0; i-- ) {
129 if ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION
130 || e->status == HIDELEXPRESSION || e->status == HIDEGEXPRESSION
131 || e->status == SKIPLEXPRESSION || e->status == SKIPGEXPRESSION
132 || e->status == UNHIDELEXPRESSION || e->status == UNHIDEGEXPRESSION
133 || e->status == INTOHIDELEXPRESSION || e->status == INTOHIDEGEXPRESSION
137 for ( i = NumExpressions-1; i >= 0; i-- ) {
138 AS.OldOnFile[i] = Expressions[i].onfile;
139 AS.OldNumFactors[i] = Expressions[i].numfactors;
141 AS.Oldvflags[i] = Expressions[i].vflags;
142 AS.Olduflags[i] = Expressions[i].uflags;
143 Expressions[i].vflags &= ~(ISUNMODIFIED|ISZERO);
151 if ( AC.partodoflag && AM.totalnumberofthreads > 1 ) {
152 AS.MultiThreaded = 1; AC.mparallelflag = PARALLELFLAG;
154 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
164 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
165 if ( InParallelProcessor() ) {
168 AS.MultiThreaded = OldMultiThreaded;
169 AC.mparallelflag = Oldmparallelflag;
173 if ( AC.RhsExprInModuleFlag && PF.rhsInParallel && (AC.mparallelflag == PARALLELFLAG || AC.partodoflag) ) {
179 if ( AC.partodoflag > 0 ) {
185 for ( i = 0; i < NumExpressions; i++ ) {
187 if ( AC.InnerTest ) {
188 if ( StrCmp(AC.TestValue,(UBYTE *)INNERTEST) == 0 ) {
189 MesPrint(
"Testing(Processor): value = %s",AC.TestValue);
195 if ( AC.partodoflag > 0 && e->partodo > 0 && AM.totalnumberofthreads > 2 ) {
201 if ( AC.partodoflag > 0 && e->partodo > 0 && PF.numtasks > 2 ) {
206 AS.CollectOverFlag = 0;
208 if ( i == last ) LastExpression = 1;
209 else LastExpression = 0;
219 SetScratch(AR.infile,&(e->onfile));
220 if ( GetTerm(BHEAD term) <= 0 ) {
221 MesPrint(
"(1) Expression %d has problems in scratchfile",i);
227 SeekScratch(AR.outfile,&position);
228 e->onfile = position;
229 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
230 AR.DeferFlag = AC.ComDefer;
235 for ( j = 0; j < *t; j++ ) term[j] = t[j];
237 AN.ninterms++; dd = AN.deferskipped;
238 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
239 if ( GetMoreFromMem(term,&t) ) {
243 AT.WorkPointer = term + *term;
244 AN.RepPoint = AT.RepCount + 1;
245 AN.IndDum = AM.IndDum;
246 AR.CurDum = ReNumber(BHEAD term);
247 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
249 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
250 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
252 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
259 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
260 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
261 else e->vflags |= ISZERO;
262 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
263 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
264 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
272 switch ( e->status ) {
273 case UNHIDELEXPRESSION:
274 case UNHIDEGEXPRESSION:
277 if ( PF.me == MASTER ) SetScratch(AR.hidefile,&(e->onfile));
279 SetScratch(AR.hidefile,&(e->onfile));
280 AR.InHiBuf = AR.hidefile->POfull-AR.hidefile->POfill;
282 MesPrint(
"Hidefile: onfile: %15p, POposition: %15p, filesize: %15p",&(e->onfile)
283 ,&(AR.hidefile->POposition),&(AR.hidefile->filesize));
284 MesPrint(
"Set hidefile to buffer position %l/%l; AR.InHiBuf = %l"
285 ,(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD)
286 ,(AR.hidefile->POfull-AR.hidefile->PObuffer)*
sizeof(WORD)
291 curfile = AR.hidefile;
293 case INTOHIDELEXPRESSION:
294 case INTOHIDEGEXPRESSION:
301 SetEndHScratch(AR.hidefile,&position);
303 case LOCALEXPRESSION:
304 case GLOBALEXPRESSION:
308 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
310 SetScratch(AR.infile,&(e->onfile));
316 MesPrint(
"Error in PF_Processor");
320 if ( AC.mparallelflag != PARALLELFLAG ){
325 if ( GetTerm(BHEAD term) <= 0 ) {
327 MesPrint(
"Error condition 1a");
330 MesPrint(
"(2) Expression %d has problems in scratchfile(process)",i);
336 fromspectator = -term[5];
337 PUTZERO(AM.SpectatorFiles[fromspectator-1].readpos);
338 term[5] = AC.cbufnum;
340 else fromspectator = 0;
341 if ( AR.outtohide ) {
342 SeekScratch(AR.hidefile,&position);
343 e->onfile = position;
344 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
347 SeekScratch(AR.outfile,&position);
348 e->onfile = position;
349 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
351 AR.DeferFlag = AC.ComDefer;
353 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
355 AT.BrackBuf = AM.BracketFactors;
356 AT.bracketindexflag = 1;
358 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
360 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
361 if ( ThreadsProcessor(e,LastExpression,fromspectator) ) {
362 MesPrint(
"Error in ThreadsProcessor");
365 if ( AR.outtohide ) {
366 AR.outfile = oldoutfile;
367 AR.hidefile->POfull = AR.hidefile->POfill;
374 AR.MaxDum = AM.IndDum;
377 if ( fromspectator ) size = GetFromSpectator(term,fromspectator-1);
378 else size = GetTerm(BHEAD term);
379 if ( size <= 0 )
break;
380 SeekScratch(curfile,&position);
381 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
385 AN.ninterms++; dd = AN.deferskipped;
386 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
387 if ( GetMoreTerms(term) < 0 ) {
390 SeekScratch(curfile,&position);
392 AT.WorkPointer = term + *term;
393 AN.RepPoint = AT.RepCount + 1;
394 if ( AR.DeferFlag ) {
395 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
396 AR.CurDum = AN.IndDum;
399 AN.IndDum = AM.IndDum;
400 AR.CurDum = ReNumber(BHEAD term);
402 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
404 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
405 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
407 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
408 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
409 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
410 PolyFunClean(BHEAD term);
417 SetScratch(curfile,&position);
418 if ( AR.GetFile == 2 ) {
419 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
420 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
423 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
424 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
428 if ( LastExpression ) {
430 if ( AR.infile->handle >= 0 ) {
431 CloseFile(AR.infile->handle);
432 AR.infile->handle = -1;
433 remove(AR.infile->name);
434 PUTZERO(AR.infile->POposition);
436 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
438 if ( AR.outtohide ) AR.outfile = AR.hidefile;
439 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
440 if ( AR.outtohide ) {
441 AR.outfile = oldoutfile;
442 AR.hidefile->POfull = AR.hidefile->POfill;
444 e->numdummies = AR.MaxDum - AM.IndDum;
447 AR.BracketOn = oldBracketOn;
448 AT.BrackBuf = oldBrackBuf;
449 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
452 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
453 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
456 AT.bracketindexflag = oldbracketindexflag;
457 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
458 else e->vflags |= ISZERO;
459 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
460 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
461 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
469 if ( e->status == INTOHIDELEXPRESSION ||
470 e->status == INTOHIDEGEXPRESSION ) {
475 case SKIPLEXPRESSION:
476 case SKIPGEXPRESSION:
481 if ( PF.me != MASTER )
break;
484 SetScratch(AR.infile,&(e->onfile));
485 if ( GetTerm(BHEAD term) <= 0 ) {
487 MesPrint(
"Error condition 1b");
490 MesPrint(
"(3) Expression %d has problems in scratchfile",i);
496 SeekScratch(AR.outfile,&position);
497 e->onfile = position;
498 *AM.S0->sBuffer = 0; firstterm = -1;
500 WORD *oldipointer = AR.CompressPointer;
501 WORD *comprtop = AR.ComprTop;
502 AR.ComprTop = AM.S0->sTop;
503 AR.CompressPointer = AM.S0->sBuffer;
504 if ( firstterm > 0 ) {
505 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
507 else if ( firstterm < 0 ) {
508 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
512 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
515 AR.CompressPointer = oldipointer;
516 AR.ComprTop = comprtop;
517 }
while ( GetTerm(BHEAD term) );
518 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
521 case HIDELEXPRESSION:
522 case HIDEGEXPRESSION:
524 if ( PF.me != MASTER )
break;
527 SetScratch(AR.infile,&(e->onfile));
528 if ( GetTerm(BHEAD term) <= 0 ) {
530 MesPrint(
"Error condition 1c");
533 MesPrint(
"(4) Expression %d has problems in scratchfile",i);
539 SetEndHScratch(AR.hidefile,&position);
540 e->onfile = position;
542 if ( AR.hidefile->handle >= 0 ) {
546 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
547 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
548 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
549 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
551 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
554 *AM.S0->sBuffer = 0; firstterm = -1;
555 cbo = cpo = AM.S0->sBuffer;
557 WORD *oldipointer = AR.CompressPointer;
558 WORD *oldibuffer = AR.CompressBuffer;
559 WORD *comprtop = AR.ComprTop;
560 AR.ComprTop = AM.S0->sTop;
561 AR.CompressPointer = cpo;
562 AR.CompressBuffer = cbo;
563 if ( firstterm > 0 ) {
564 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
566 else if ( firstterm < 0 ) {
567 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
571 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
574 cpo = AR.CompressPointer;
575 cbo = AR.CompressBuffer;
576 AR.CompressPointer = oldipointer;
577 AR.CompressBuffer = oldibuffer;
578 AR.ComprTop = comprtop;
579 }
while ( GetTerm(BHEAD term) );
581 if ( AR.hidefile->handle >= 0 ) {
585 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
586 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
587 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
588 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
590 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
593 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
594 AR.hidefile->POfull = AR.hidefile->POfill;
596 if ( AR.hidefile->handle >= 0 ) {
600 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
601 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
602 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
603 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
605 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
616 if ( e->status == HIDELEXPRESSION ) {
617 e->status = HIDDENLEXPRESSION;
618 AS.OldOnFile[i] = e->onfile;
619 AS.OldNumFactors[i] = Expressions[i].numfactors;
621 if ( e->status == HIDEGEXPRESSION ) {
622 e->status = HIDDENGEXPRESSION;
623 AS.OldOnFile[i] = e->onfile;
624 AS.OldNumFactors[i] = Expressions[i].numfactors;
631 case DROPPEDEXPRESSION:
632 case DROPLEXPRESSION:
633 case DROPGEXPRESSION:
634 case DROPHLEXPRESSION:
635 case DROPHGEXPRESSION:
636 case STOREDEXPRESSION:
637 case HIDDENLEXPRESSION:
638 case HIDDENGEXPRESSION:
639 case SPECTATOREXPRESSION:
647 AT.WorkPointer = term;
649 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
650 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.infile->name ,AR.infile->POfill -AR.infile->PObuffer ,AR.infile->POfull -AR.infile->PObuffer ,AR.infile->POsize/
sizeof(WORD) );
651 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.outfile->name ,AR.outfile->POfill -AR.outfile->PObuffer ,AR.outfile->POfull -AR.outfile->PObuffer ,AR.outfile->POsize/
sizeof(WORD) );
652 MesPrint(
"File %s POfill %l POfull %l POsize %l", AR.hidefile->name ,AR.hidefile->POfill-AR.hidefile->PObuffer,AR.hidefile->POfull-AR.hidefile->PObuffer,AR.hidefile->POsize/
sizeof(WORD));
653 for ( i = 0; i < NumExpressions; i++ ) {
660 AT.WorkPointer = term;
661 if ( AM.tracebackflag ) MesCall(
"Processor");
2169 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2170 WORD *u, *v, *w, *from, *to,
2171 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2175 m = r - ABS(*r) + 1;
2178 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2181 if ( ( term + AR.TePos ) == t ) {
2183 while ( from < t ) *m++ = *from++;
2185 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2188 *m++ = t[1] + 4 + ARGHEAD;
2194 while ( t < v ) *m++ = *t++;
2200 while ( t < r ) *m++ = *t++;
2201 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2202 MLOCK(ErrorMessageLock);
2203 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2204 MUNLOCK(ErrorMessageLock);
2207 *termout = WORDDIF(m,termout);
2211 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec <= 0 )
2212 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2217 oldncmod = AN.ncmod;
2219 if ( *t > 0 && t[1] ) {
2220 WORD oldsorttype = AR.SortType;
2223 if ( ( AN.ncmod != 0 )
2224 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2225 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2229 LONG copy = t - from;
2230 const LONG size = t - u;
2231 NCOPY(m, from, copy);
2235 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2237 AR.SortType = SORTHIGHFIRST;
2246 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2248 AN.ncmod = oldncmod;
2258 if (
EndSort(BHEAD m,1) < 0 ) {
2259 AN.ncmod = oldncmod;
2262 AR.PolyFun = oldPolyFun;
2263 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2264 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2265 AR.SortType = oldsorttype;
2267 while ( *m ) m += *m;
2268 *to = WORDDIF(m,to);
2270 if ( ToFast(to,to) ) {
2271 if ( *to <= -FUNCTION ) m = to+1;
2274 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2277 while ( t < r ) *m++ = *t++;
2278 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2279 MLOCK(ErrorMessageLock);
2280 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2281 MUNLOCK(ErrorMessageLock);
2284 *termout = WORDDIF(m,termout);
2285 AR.DeferFlag = olddefer;
2286 AN.ncmod = oldncmod;
2289 else if ( *t == -DOLLAREXPRESSION ) {
2290 if ( AR.Eside == LHSIDE ) {
2292 AC.lhdollarflag = 1;
2300 int nummodopt, dtype = -1;
2301 if ( AS.MultiThreaded ) {
2302 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2303 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2305 if ( nummodopt < NumModOptdollars ) {
2306 dtype = ModOptdollars[nummodopt].type;
2307 if ( DollarLocalCopy(dtype) ) {
2308 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2311 LOCK(d->pthreadslock);
2316 oldncmod = AN.ncmod;
2317 if ( ( AN.ncmod != 0 )
2318 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2319 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2322 LONG copy = t - from;
2323 const LONG size = t - u;
2324 NCOPY(m, from, copy);
2327 switch ( d->type ) {
2329 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2330 *m++ = -SNUMBER; *m++ = d->index;
2332 else { *m++ = -INDEX; *m++ = d->index; }
2335 *m++ = -SNUMBER; *m++ = 0;
break;
2337 if ( d->where[0] == 4 &&
2338 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2340 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2341 else *m++ = -d->where[1];
2351 to = m; r = d->where;
2355 i = *r; NCOPY(m,r,i)
2358 if ( ToFast(to,to) ) {
2359 if ( *to <= -FUNCTION ) m = to+1;
2362 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2371 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2376 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2377 AR.PolyFun = oldPolyFun;
2378 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2386 while ( *m ) m += *m;
2388 if ( ToFast(to,to) ) {
2389 if ( *to <= -FUNCTION ) m = to+1;
2394 w[1] = w[1] - 2 + (m-to);
2397 to = m; r = d->where;
2399 *m++ = i+4+ARGHEAD; *m++ = 1;
2402 while ( --i >= 0 ) *m++ = *r++;
2403 *m++ = 1; *m++ = 1; *m++ = 3;
2404 if ( ToFast(to,to) ) {
2405 if ( *to <= -FUNCTION ) m = to+1;
2408 w[1] = w[1] - 2 + (m-to);
2411 to = m; r = d->where;
2414 *m++ = *r++; *m++ = 1; r++;
2415 while ( --i >= 0 ) *m++ = *r++;
2417 else if ( *r <= -FUNCTION ) *m++ = *r++;
2418 else { *m++ = *r++; *m++ = *r++; }
2419 w[1] = w[1] - 2 + (m-to);
2422 to = m; r = d->where;
2425 while ( --i >= 0 ) {
2427 *m++ = -VECTOR; *m++ = *r++;
2429 else if ( *r >= AM.OffsetIndex ) {
2430 *m++ = -INDEX; *m++ = *r++;
2432 else { *m++ = -SNUMBER; *m++ = *r++; }
2440 *m++ = *r++; *m++ = 1; r++;
2441 while ( --i >= 0 ) *m++ = *r++;
2443 else if ( *r <= -FUNCTION ) *m++ = *r++;
2444 else { *m++ = *r++; *m++ = *r++; }
2447 w[1] = w[1] - 2 + (m-to);
2451 MLOCK(ErrorMessageLock);
2452 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2453 AC.dollarnames->namebuffer+d->name);
2454 MUNLOCK(ErrorMessageLock);
2456 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2461 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2465 while ( t < r ) *m++ = *t++;
2466 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2467 MLOCK(ErrorMessageLock);
2468 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2469 MUNLOCK(ErrorMessageLock);
2472 *termout = WORDDIF(m,termout);
2473 AR.DeferFlag = olddefer;
2474 AN.ncmod = oldncmod;
2478 else if ( *t == -TERMSINBRACKET ) {
2479 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2488 LONG copy = t - from;
2489 const LONG size = t - u;
2490 NCOPY(m, from, copy);
2492 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2493 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2496 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2498 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2499 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2504 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2505 *m++ = 6; *m++ = numterms & WORDMASK;
2506 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2511 while ( from < r ) *m++ = *from++;
2512 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2513 MLOCK(ErrorMessageLock);
2514 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2515 MUNLOCK(ErrorMessageLock);
2518 *termout = WORDDIF(m,termout);
2525 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec > 0 )
2526 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2527 u = t; v = t + t[1];
2530 if ( *t == FUNNYDOLLAR ) {
2531 if ( AR.Eside != LHSIDE ) {
2534 int nummodopt, dtype = -1;
2535 if ( AS.MultiThreaded ) {
2536 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2537 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2539 if ( nummodopt < NumModOptdollars ) {
2540 dtype = ModOptdollars[nummodopt].type;
2541 if ( DollarLocalCopy(dtype) ) {
2542 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2545 LOCK(d->pthreadslock);
2550 oldncmod = AN.ncmod;
2551 if ( ( AN.ncmod != 0 )
2552 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2553 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2555 LONG copy = t - from;
2556 const LONG size = t - u;
2557 NCOPY(m, from, copy);
2560 switch ( d->type ) {
2562 *m++ = d->index;
break;
2567 if ( d->where[0] == 4 && d->where[4] == 0
2568 && d->where[3] == 3 && d->where[2] == 1
2569 && d->where[1] < AM.OffsetIndex ) {
2575 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2577 MLOCK(ErrorMessageLock);
2578 MesPrint(
"$%s has wrong type for tensor substitution",
2579 AC.dollarnames->namebuffer+d->name);
2580 MUNLOCK(ErrorMessageLock);
2581 AN.ncmod = oldncmod;
2586 if ( d->where[0] == -INDEX ) {
2587 *m++ = d->where[1];
break;
2589 else if ( d->where[0] == -VECTOR ) {
2590 *m++ = d->where[1];
break;
2592 else if ( d->where[0] == -MINVECTOR ) {
2597 else if ( d->where[0] == -SNUMBER ) {
2598 if ( d->where[1] >= 0
2599 && d->where[1] < AM.OffsetIndex ) {
2600 *m++ = d->where[1];
break;
2605 if ( d->where[0] > 0 ) {
2606 r = d->where; i = *r++;
2607 while ( --i >= 0 ) *m++ = *r++;
2612 if ( *r == -INDEX ) {
2613 *m++ = r[1]; r += 2;
continue;
2615 else if ( *r == -VECTOR ) {
2616 *m++ = r[1]; r += 2;
continue;
2618 else if ( *r == -MINVECTOR ) {
2619 *m++ = r[1]; r += 2;
2620 sign = -sign;
continue;
2622 else if ( *r == -SNUMBER ) {
2624 && r[1] < AM.OffsetIndex ) {
2625 *m++ = r[1]; r += 2;
continue;
2634 if ( *r == INDEX && r[1] == 3 ) {
2637 else goto wrongtype;
2641 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2643 MLOCK(ErrorMessageLock);
2644 MesPrint(
"$%s is undefined in tensor substitution",
2645 AC.dollarnames->namebuffer+d->name);
2646 MUNLOCK(ErrorMessageLock);
2647 AN.ncmod = oldncmod;
2651 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2653 w[1] = w[1] - 2 + (m-to);
2656 while ( from < term ) *m++ = *from++;
2657 if ( sign < 0 ) m[-1] = -m[-1];
2658 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2659 MLOCK(ErrorMessageLock);
2660 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2661 MUNLOCK(ErrorMessageLock);
2664 *termout = m - termout;
2665 AN.ncmod = oldncmod;
2669 AC.lhdollarflag = 1;
2678 MLOCK(ErrorMessageLock);
2679 MesPrint(
"Internal error in InFunction: Function not encountered.");
2680 if ( AM.tracebackflag ) {
2681 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2682 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2684 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2688 while ( --i >= 0 ) {
2689 TalToLine((UWORD)(*termout++));
2690 TokenToLine((UBYTE *)
" ");
2694 MesCall(
"InFunction");
2696 MUNLOCK(ErrorMessageLock);
2700 MLOCK(ErrorMessageLock);
2701 MesCall(
"InFunction");
2702 MUNLOCK(ErrorMessageLock);
2706 MLOCK(ErrorMessageLock);
2707 MesCall(
"InFunction");
2708 MUNLOCK(ErrorMessageLock);
3258 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3259 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, extractbuff;
3261 int *RepSto = AN.RepPoint, iscopy = 0;
3262 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3263 LONG posisub, oldcpointer, oldacpointer;
3265 WORD numfac[5], idfunctionflag;
3267 int nummodopt, dtype = -1, id;
3269 oldtoprhs = CC->numrhs;
3270 oldcpointer = CC->Pointer - CC->Buffer;
3271 oldatoprhs = CCC->numrhs;
3272 oldacpointer = CCC->Pointer - CCC->Buffer;
3274 if ( ( replac = TestSub(BHEAD term,level) ) == 0 ) {
3275 if ( applyflag ) { TableReset(); applyflag = 0; }
3284 AN.PolyNormFlag = 0;
3285 AN.idfunctionflag = 0;
3286 if ( ( ret = Normalize(BHEAD term) ) != 0 ) {
3288 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3293 idfunctionflag = AN.idfunctionflag;
3294 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3296 if ( AN.PolyNormFlag ) {
3297 if ( AN.PolyFunTodo == 0 ) {
3298 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3299 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3302 WORD oldPolyFunExp = AR.PolyFunExp;
3304 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3305 AT.WorkPointer = term+*term;
3306 AR.PolyFunExp = oldPolyFunExp;
3307 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3308 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3309 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3310 AT.WorkPointer = term+*term;
3311 if ( AN.PolyNormFlag ) {
3312 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3313 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3314 AT.WorkPointer = term+*term;
3319 if ( idfunctionflag > 0 ) {
3320 if ( TakeIDfunction(BHEAD term) ) {
3321 AT.WorkPointer = term + *term;
3325 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3326 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3329 if ( level > AR.Cnumlhs ) {
3330 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3332 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3338 if (
Deferred(BHEAD term,level) )
goto GenCall;
3342 if ( AN.ncmod != 0 ) {
3343 if ( Modulus(term) )
goto GenCall;
3344 if ( !*term )
goto Return0;
3346 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3347 WORD olddummies = AN.IndDum;
3348 AN.IndDum = AM.IndDum;
3349 ReNumber(BHEAD term);
3350 Normalize(BHEAD term);
3351 AN.IndDum = olddummies;
3352 if ( !*term )
goto Return0;
3353 olddummies = DetCurDum(BHEAD term);
3354 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3356 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3357 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3359 else if ( AR.PolyFun > 0 ) {
3360 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3362 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3363 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3364 termout = AT.WorkPointer;
3365 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3366 if ( PutBracket(BHEAD term) )
return(-1);
3367 AN.RepPoint = RepSto;
3368 *AT.WorkPointer = 0;
3370 AT.WorkPointer = termout;
3371 CC->numrhs = oldtoprhs;
3372 CC->Pointer = CC->Buffer + oldcpointer;
3373 CCC->numrhs = oldatoprhs;
3374 CCC->Pointer = CCC->Buffer + oldacpointer;
3378 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3379 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3380 *AT.WorkPointer = 0;
3381 AN.RepPoint = RepSto;
3383 CC->numrhs = oldtoprhs;
3384 CC->Pointer = CC->Buffer + oldcpointer;
3385 CCC->numrhs = oldatoprhs;
3386 CCC->Pointer = CCC->Buffer + oldacpointer;
3390 i = C->
lhs[level][0];
3391 if ( i >= TYPECOUNT ) {
3397 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3398 AT.WorkPointer = term + *term;
3403 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3406 level = AC.Labels[C->
lhs[level][2]];
3409 AT.WorkPointer = term + *term;
3419 WORD ic, jc, *ifcode, *jfcode;
3420 jfcode = C->
lhs[level]; jc = jfcode[1];
3421 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3422 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3423 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3424 level = C->
lhs[level][2];
3425 if ( C->
lhs[level][0] != TYPEELIF )
break;
3427 AT.WorkPointer = ifcode;
3430 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3431 level = C->
lhs[level][2];
3432 if ( C->
lhs[level][0] != TYPEELIF )
break;
3438 level = C->
lhs[level][2];
3439 }
while ( C->
lhs[level][0] == TYPEELIF );
3443 level = C->
lhs[level][2];
3447 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3448 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3449 WORD theindex = C->
lhs[level][2];
3450 if ( theindex < 0 ) {
3453 theindex = -theindex;
3454 d = Dollars + theindex;
3455 if ( AS.MultiThreaded ) {
3456 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3457 if ( theindex == ModOptdollars[nummodopt].number )
break;
3459 if ( nummodopt < NumModOptdollars ) {
3460 ddtype = ModOptdollars[nummodopt].type;
3461 if ( DollarLocalCopy(ddtype) ) {
3462 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3465 LOCK(d->pthreadslock);
3470 theindex = -theindex;
3471 d = Dollars + theindex;
3474 if ( d->type != DOLINDEX
3475 || d->index < AM.OffsetIndex
3476 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3477 MLOCK(ErrorMessageLock);
3478 MesPrint(
"$%s should have been an index"
3479 ,AC.dollarnames->namebuffer+d->name);
3480 AN.currentTerm = term;
3481 MesPrint(
"Current term: %t");
3482 AN.listinprint = printscratch;
3483 printscratch[0] = DOLLAREXPRESSION;
3484 printscratch[1] = theindex;
3486 ,AC.dollarnames->namebuffer+d->name);
3487 MUNLOCK(ErrorMessageLock);
3489 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3493 theindex = d->index;
3495 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3498 cp[1] = SUBEXPSIZE+4;
3503 i = C->
lhs[level][1] - 3;
3505 AR.CompressPointer = cp;
3506 while ( --i >= 0 ) {
3508 termout = AT.WorkPointer;
3509 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3513 while ( --jlhs >= 0 ) {
3514 if ( *m++ != *termout++ )
break;
3517 termout = AT.WorkPointer;
3518 AT.WorkPointer = termout + *termout;
3519 if (
Generator(BHEAD termout,level) )
goto GenCall;
3520 AT.WorkPointer = termout;
3523 AR.CompressPointer = op;
3527 AR.CompressPointer = op;
3532 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3538 AR.CurDum = DetCurDum(BHEAD term);
3539 i = C->
lhs[level][1]-2;
3540 wp = C->
lhs[level] + 2;
3541 cp[1] = SUBEXPSIZE+4*i;
3543 while ( --i >= 0 ) {
3545 if ( theindex < 0 ) {
3548 theindex = -theindex;
3549 d = Dollars + theindex;
3550 if ( AS.MultiThreaded ) {
3551 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3552 if ( theindex == ModOptdollars[nummodopt].number )
break;
3554 if ( nummodopt < NumModOptdollars ) {
3555 ddtype = ModOptdollars[nummodopt].type;
3556 if ( DollarLocalCopy(ddtype) ) {
3557 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3560 LOCK(d->pthreadslock);
3565 theindex = -theindex;
3566 d = Dollars + theindex;
3568 if ( d->type != DOLINDEX
3569 || d->index < AM.OffsetIndex
3570 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3571 MLOCK(ErrorMessageLock);
3572 MesPrint(
"$%s should have been an index"
3573 ,AC.dollarnames->namebuffer+d->name);
3574 AN.currentTerm = term;
3575 MesPrint(
"Current term: %t");
3576 AN.listinprint = printscratch;
3577 printscratch[0] = DOLLAREXPRESSION;
3578 printscratch[1] = theindex;
3580 ,AC.dollarnames->namebuffer+d->name);
3581 MUNLOCK(ErrorMessageLock);
3583 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3587 theindex = d->index;
3589 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3595 *cp++ = ++AR.CurDum;
3597 ow = AT.WorkPointer;
3598 AR.CompressPointer = cp;
3599 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3600 AR.CompressPointer = op;
3602 WORD term_changed = 0;
3603 for ( j = 0; j < i; j++ ) {
3604 if ( term[j] != ow[j] ) term_changed = 1;
3608 if ( term_changed ) *AN.RepPoint = 1;
3609 AT.WorkPointer = ow;
3614 ReNumber(BHEAD term);
3618 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3620 AT.WorkPointer = term + *term;
3623 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3624 level = C->
lhs[level][2];
3625 if ( i > 0 )
goto ReStart;
3633 case TYPESPLITFIRSTARG:
3634 case TYPESPLITLASTARG:
3635 case TYPEARGTOEXTRASYMBOL:
3636 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3637 level = C->
lhs[level][2];
3642 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3643 if ( jjj > 0 )
goto ReStart;
3644 level = C->
lhs[level][2];
3647 if ( C->
lhs[level][2] > 0 ) {
3648 MLOCK(ErrorMessageLock);
3649 MesPrint(
"%s",C->
lhs[level]+3);
3650 MUNLOCK(ErrorMessageLock);
3658 AN.currentTerm = term;
3659 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3660 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3661 MLOCK(ErrorMessageLock);
3663 MesPrint((
char *)(C->
lhs[level]+5));
3665 MUNLOCK(ErrorMessageLock);
3670 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3671 AC.LogHandle = C->
lhs[level][2];
3672 MLOCK(ErrorMessageLock);
3673 oldFOflag = AM.FileOnlyFlag;
3674 oldPrintType = AO.PrintType;
3675 if ( AC.LogHandle >= 0 ) {
3676 AM.FileOnlyFlag = 1;
3677 AO.PrintType |= PRINTLFILE;
3679 AO.PrintType |= C->
lhs[level][3];
3680 AN.currentTerm = term;
3681 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3682 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3683 MesPrint((
char *)(C->
lhs[level]+5));
3684 AO.PrintType = oldPrintType;
3685 AM.FileOnlyFlag = oldFOflag;
3686 MUNLOCK(ErrorMessageLock);
3687 AC.LogHandle = oldLogHandle;
3691 j = C->
lhs[level][2];
3701 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3702 if ( AC.pfirstnum[ii] == j )
break;
3704 AC.inputnumbers[ii] = AN.ninterms;
3708 if ( AS.MultiThreaded ) {
3710 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3711 if ( AC.pfirstnum[ii] == j )
break;
3713 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3714 LOCK(AP.PreVarLock);
3715 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3716 a = C->
lhs[level]+4;
3717 if ( a[a[-1]] == 0 )
3718 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3721 ,(UBYTE *)(a+a[-1]+1),1);
3725 AC.inputnumbers[ii] = AN.inputnumber;
3727 UNLOCK(AP.PreVarLock);
3732 a = C->
lhs[level]+4;
3733 LOCK(AP.PreVarLock);
3734 if ( a[a[-1]] == 0 )
3735 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3738 ,(UBYTE *)(a+a[-1]+1),1);
3739 UNLOCK(AP.PreVarLock);
3743 AT.WorkPointer = term + *term;
3744 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3745 AT.WorkPointer = term + *term;
3746 if ( *term == 0 )
goto Return0;
3749 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3750 AT.WorkPointer = term + *term;
3753 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3754 WORD oldrepeat = *AN.RepPoint;
3760 AN.cTerm = AN.currentTerm = term;
3761 AT.WorkPointer = term + *term;
3762 *AT.WorkPointer++ = 0;
3763 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3764 AT.WorkPointer = term + *term;
3766 *AN.RepPoint = oldrepeat;
3767 AR.NoCompress = onc;
3768 AR.Eside = oldEside;
3772 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3773 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3774 AT.WorkPointer = term + *term;
3779 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3780 level = C->
lhs[level][2];
3783 ret = execterm(BHEAD term,level);
3784 AN.RepPoint = RepSto;
3786 CC->numrhs = oldtoprhs;
3787 CC->Pointer = CC->Buffer + oldcpointer;
3788 CCC->numrhs = oldatoprhs;
3789 CCC->Pointer = CCC->Buffer + oldacpointer;
3792 AT.WorkPointer = term + *term;
3793 AR.CurDum = DetCurDum(BHEAD term);
3795 case TYPEINEXPRESSION:
3796 {WORD *ll = C->
lhs[level];
3797 int numexprs = (int)(ll[1]-3);
3799 while ( numexprs-- >= 0 ) {
3800 if ( *ll == AR.CurExpr )
break;
3803 if ( numexprs < 0 ) level = C->
lhs[level][2];
3807 AT.WorkPointer = term + *term;
3808 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3810 AT.WorkPointer = term + *term;
3813 AT.WorkPointer = term + *term;
3814 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3816 AT.WorkPointer = term + *term;
3819 AT.WorkPointer = term + *term;
3820 if ( TestUse(term,level) )
goto GenCall;
3821 AT.WorkPointer = term + *term;
3824 AT.WorkPointer = term + *term;
3825 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3826 AT.WorkPointer = term + *term;
3830 AT.WorkPointer = term + *term;
3841 AT.WorkPointer = term + *term;
3842 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3843 AT.WorkPointer = term + *term;
3845 if ( *term == 0 )
goto Return0;
3846 if ( *term != lter ) *AN.RepPoint = 1;
3851 AT.WorkPointer = term + *term;
3852 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3853 AT.WorkPointer = term + *term;
3854 if ( *term != lter ) *AN.RepPoint = 1;
3858 AT.WorkPointer = term + *term;
3859 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3860 AT.WorkPointer = term + *term;
3862 case TYPEARGIMPLODE:
3863 AT.WorkPointer = term + *term;
3864 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3865 AT.WorkPointer = term + *term;
3867 case TYPEARGEXPLODE:
3868 AT.WorkPointer = term + *term;
3869 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3870 AT.WorkPointer = term + *term;
3872 case TYPEDENOMINATORS:
3873 if ( DenToFunction(term,C->
lhs[level][2]) )
goto ReStart;
3875 case TYPEDROPCOEFFICIENT:
3876 DropCoefficient(BHEAD term);
3879 AT.WorkPointer = term + *term;
3880 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3881 AT.WorkPointer = term + *term;
3882 if ( *term == 0 )
goto Return0;
3884 case TYPETOPOLYNOMIAL:
3885 AT.WorkPointer = term + *term;
3886 termout = AT.WorkPointer;
3887 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3888 if ( *termout == 0 )
goto Return0;
3889 i = termout[0]; t = term; NCOPY(t,termout,i);
3890 AT.WorkPointer = term + *term;
3892 case TYPEFROMPOLYNOMIAL:
3893 AT.WorkPointer = term + *term;
3894 termout = AT.WorkPointer;
3895 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3896 if ( *term == 0 )
goto Return0;
3897 i = termout[0]; t = term; NCOPY(t,termout,i);
3898 AT.WorkPointer = term + *term;
3901 level = TestDoLoop(BHEAD C->
lhs[level],level);
3902 if ( level < 0 )
goto GenCall;
3905 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3906 if ( level < 0 )
goto GenCall;
3908 case TYPEDROPSYMBOLS:
3909 DropSymbols(BHEAD term);
3912 AT.WorkPointer = term + *term;
3913 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3914 AT.WorkPointer = term + *term;
3919 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3921 case TYPETOSPECTATOR:
3922 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3924 case TYPECANONICALIZE:
3925 AT.WorkPointer = term + *term;
3926 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3927 AT.WorkPointer = term + *term;
3928 if ( *term == 0 )
goto Return0;
3931 AT.WorkPointer = term + *term;
3932 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3935 AT.WorkPointer = term + *term;
3936 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3938 case TYPESETUSERFLAG:
3939 Expressions[AR.CurExpr].uflags |= 1 << (C->
lhs[level][2]);
3941 case TYPECLEARUSERFLAG:
3942 Expressions[AR.CurExpr].uflags &= ~(1 << (C->
lhs[level][2]));
3945 AT.WorkPointer = term + *term;
3946 if ( AllLoops(BHEAD term,level) )
goto GenCall;
3949 AT.WorkPointer = term + *term;
3950 if ( AllPaths(BHEAD term,level) )
goto GenCall;
3954 AT.WorkPointer = term + *term;
3955 if ( C->
lhs[level][2] == MZV
3956 || C->
lhs[level][2] == EULER
3957 || C->
lhs[level][2] == MZVHALF
3958 || C->
lhs[level][2] == ALLMZVFUNCTIONS
3960 if ( EvaluateEuler(BHEAD term,level,C->
lhs[level][2]) )
goto GenCall;
3963 if ( EvaluateFun(BHEAD term,level,C->
lhs[level]) )
goto GenCall;
3978 AT.WorkPointer = term + *term;
3979 if ( ToFloat(BHEAD term,level) )
goto GenCall;
3982 AT.WorkPointer = term + *term;
3983 if ( ToRat(BHEAD term,level) )
goto GenCall;
3985 case TYPESTRICTROUNDING:
3986 AT.WorkPointer = term + *term;
3987 if ( StrictRounding(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
goto GenCall;
3990 AT.WorkPointer = term + *term;
3991 if ( Chop(BHEAD term,level) )
goto GenCall;
4000 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
4001 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
4002 if ( i > 0 ) replac = TestSub(BHEAD term,level);
4004 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
4009AutoGen: i = *AT.TMout;
4010 t = termout = AT.WorkPointer;
4011 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
4013 while ( --i >= 0 ) *t++ = *accum++;
4014 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
4015 AT.WorkPointer = termout;
4019 if ( applyflag ) { TableReset(); applyflag = 0; }
4022 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
4024 if ( AR.TePos >= 0 )
goto AutoGen;
4025 switch ( AN.TeInFun ) {
4027 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
4030 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
4033 if ( DoTableExpansion(term,level) )
goto GenCall;
4036 if ( FactorIn(BHEAD term,level) )
goto GenCall;
4039 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
4042 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
4045 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
4048 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
4051 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
4054 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
4057 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
4060 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
4063 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
4066 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
4069 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
4074 termout = AT.WorkPointer;
4075 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4076 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4077 if (
InFunction(BHEAD term,termout) )
goto GenCall;
4078 AT.WorkPointer = termout + *termout;
4081 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4082 AT.WorkPointer = termout;
4085 else if ( replac > 0 ) {
4089 power = -power; tepos = 0;
4091 extractbuff = AT.TMbuff;
4092 if ( extractbuff == AM.dbufnum ) {
4093 d = DolToTerms(BHEAD replac);
4094 if ( d && d->where != 0 ) {
4096 if ( AT.TMdolfac > 0 ) {
4097 if ( AT.TMdolfac == 1 ) {
4098 if ( d->nfactors ) {
4100 numfac[1] = d->nfactors;
4111 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
4112 MLOCK(ErrorMessageLock);
4113 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
4114 if ( d->nfactors == 1 )
4115 MesPrint(
"There is only one factor");
4117 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
4118 MUNLOCK(ErrorMessageLock);
4121 if ( d->nfactors > 1 ) {
4125 dd = Dollars + replac;
4128 int nummodopt, dtype = -1;
4129 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
4130 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4131 if ( replac == ModOptdollars[nummodopt].number )
break;
4133 if ( nummodopt < NumModOptdollars ) {
4134 dtype = ModOptdollars[nummodopt].type;
4135 if ( DollarLocalCopy(dtype) ) {
4136 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
4142 dsize = dd->factors[AT.TMdolfac-2].size;
4148 numfac[1] = d->factors[AT.TMdolfac-2].value;
4153 if ( numfac[1] < 0 ) {
4154 numfac[1] = -numfac[1];
4155 numfac[3] = -numfac[3];
4159 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
4160 (dsize+1)*
sizeof(WORD),
"Copy of factor");
4161 td1 = dd->factors[AT.TMdolfac-2].where;
4163 d->size = dsize; d->type = DOLTERMS;
4164 NCOPY(td2,td1,dsize);
4168 else if ( d->nfactors == 1 ) {
4169 StartBuf = d->where;
4172 MLOCK(ErrorMessageLock);
4173 if ( d->nfactors == 0 ) {
4174 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
4177 MesPrint(
"Internal error. Illegal number of factors for $-variable");
4179 MUNLOCK(ErrorMessageLock);
4184 else StartBuf = d->where;
4187 d = Dollars + replac;
4188 StartBuf = zeroDollar;
4191 i = DetCommu(d->where);
4193 if ( AS.MultiThreaded ) {
4194 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4195 if ( replac == ModOptdollars[nummodopt].number )
break;
4197 if ( nummodopt < NumModOptdollars ) {
4198 dtype = ModOptdollars[nummodopt].type;
4199 if ( dtype == MODMAX || dtype == MODMIN ) {
4200 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
4201 MLOCK(ErrorMessageLock);
4202 MesPrint(
"A dollar variable with modoption max or min can have only one term");
4203 MUNLOCK(ErrorMessageLock);
4207 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
4208 LOCK(d->pthreadslock);
4215 StartBuf = cbuf[extractbuff].Buffer;
4216 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
4217 i = (WORD)cbuf[extractbuff].CanCommu[replac];
4220 termout = AT.WorkPointer;
4221 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4222 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4223 while ( StartBuf[posisub] ) {
4224 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
4225 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
4226 if (
InsertTerm(BHEAD term,replac,extractbuff,
4227 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
4228 AT.WorkPointer = termout + *termout;
4231 posisub += StartBuf[posisub];
4243 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4244 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
4246 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4247 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4253 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4255 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4257 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4264 StartBuf = cbuf[extractbuff].Buffer;
4267 if ( extractbuff == AT.allbufnum ) {
4268 CBUF *Ce = cbuf + extractbuff;
4272 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4275 if ( d->nfactors > 1 ) {
4277 for ( j = 0; j < d->nfactors; j++ ) {
4278 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4280 M_free(d->factors,
"Dollar factors");
4282 M_free(d,
"Copy of dollar variable");
4285 AT.WorkPointer = termout;
4287 else if ( i <= 1 ) {
4289 WORD *same, *ow = AT.WorkPointer;
4290 LONG olpw = AT.posWorkPointer;
4292 WantAddLongs(power1);
4293 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4294 same = ++AT.WorkPointer;
4295 a = accum = ( AT.WorkPointer += power1+1 );
4296 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4297 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4298 AT.lWorkSpace[posit] = posisub;
4305 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4307 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4309 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4310 same[1] = *same + 1;
4311 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4312 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4318 i--; posit--; same--;
4321 termout = AT.WorkPointer = a;
4322 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4323 if ( AT.WorkPointer > AT.WorkTop )
4325 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4326 AT.WorkPointer = termout + *termout;
4330 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4332 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4333 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4334 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4339 if (
Generator(BHEAD termout,level) )
goto GenCall;
4341 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4343 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4344 StartBuf = cbuf[extractbuff].Buffer;
4345 i--; posit--; same--;
4349 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4352 if ( d->nfactors > 1 ) {
4354 for ( j = 0; j < d->nfactors; j++ ) {
4355 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4357 M_free(d->factors,
"Dollar factors");
4359 M_free(d,
"Copy of dollar variable");
4362 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4365 LONG posit, olw, olpw = AT.posWorkPointer;
4366 WantAddLongs(power);
4367 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4368 a = accum = AT.WorkPointer;
4369 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4370 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4371 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4377 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4379 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4380 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4384 AT.lWorkSpace[posit--] = posisub;
4388 termout = AT.WorkPointer = a;
4389 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4390 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4391 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4392 AT.WorkPointer = termout + *termout;
4396 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4397 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4399 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4404 if (
Generator(BHEAD termout,level) )
goto GenCall;
4406 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4408 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4409 StartBuf = cbuf[extractbuff].Buffer;
4414 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4417 if ( d->nfactors > 1 ) {
4419 for ( j = 0; j < d->nfactors; j++ ) {
4420 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4422 M_free(d->factors,
"Dollar factors");
4424 M_free(d,
"Copy of dollar variable");
4427 AT.WorkPointer = accum;
4428 AT.lWorkPointer = olw;
4429 AT.posWorkPointer = olpw;
4434 LONG position, olpw, opw, comprev, extra;
4436 WORD *Freeze, *aa, *dummies;
4440 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4442 SETSTARTPOS(firstpos);
4454 WantAddPointers(power+1);
4455 comprev = opw = AT.pWorkPointer;
4456 AT.pWorkPointer += power+1;
4457 WantAddPositions(power+1);
4458 position = olpw = AT.posWorkPointer;
4459 AT.posWorkPointer += power + 1;
4461 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4463 for ( i = 0; i < power; i++ ) {
4464 PUTZERO(AT.posWorkSpace[position]); position++;
4467 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4468 dummies = AT.WorkPointer;
4469 *dummies++ = AR.CurDum;
4470 AT.WorkPointer += power+2;
4471 accum = AT.WorkPointer;
4472 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4473 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4474 aa = AT.WorkPointer;
4476 i = 0; StartPos = AT.posWorkSpace[position];
4477 dummies[i] = AR.CurDum;
4480 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4481 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4482 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4483 if ( Expressions[replac].numdummies > 0 ) {
4484 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4486 if ( NOTSTARTPOS(firstpos) ) {
4487 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4488 firstpos = AT.posWorkSpace[position];
4499 i++; AT.posWorkSpace[++position] = StartPos;
4500 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4501 dummies[i] = AR.CurDum;
4504 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4505 AR.CurDum = dummies[i];
4509 termout = AT.WorkPointer = a;
4510 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4511 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4512 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4514 AT.WorkPointer = termout + *termout;
4518 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4520 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4525 if (
Generator(BHEAD termout,level) )
goto GenCall;
4528 AR.CurDum = dummies[i];
4531 AT.WorkPointer = aa;
4533 AT.WorkPointer = accum;
4534 AT.posWorkPointer = olpw;
4535 AT.pWorkPointer = opw;
4543 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4544 M_free(renumber->
symb.
lo,
"VarSpace");
4545 M_free(renumber,
"Renumber");
4549 aa = accum = AT.WorkPointer;
4550 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4552 *accum++ = -1; AT.WorkPointer++;
4553 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4554 AT.WorkPointer = aa;
4559 AN.RepPoint = RepSto;
4560 CC->numrhs = oldtoprhs;
4561 CC->Pointer = CC->Buffer + oldcpointer;
4562 CCC->numrhs = oldatoprhs;
4563 CCC->Pointer = CCC->Buffer + oldacpointer;
4567 if ( AM.tracebackflag ) {
4569 MLOCK(ErrorMessageLock);
4570 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4574 while ( --i >= 0 ) {
4575 TalToLine((UWORD)(*termout++));
4576 TokenToLine((UBYTE *)
" ");
4580 MesCall(
"Generator");
4581 MUNLOCK(ErrorMessageLock);
4583 CC->numrhs = oldtoprhs;
4584 CC->Pointer = CC->Buffer + oldcpointer;
4585 CCC->numrhs = oldatoprhs;
4586 CCC->Pointer = CCC->Buffer + oldacpointer;
4589 CC->numrhs = oldtoprhs;
4590 CC->Pointer = CC->Buffer + oldcpointer;
4591 CCC->numrhs = oldatoprhs;
4592 CCC->Pointer = CCC->Buffer + oldacpointer;
4593 MLOCK(ErrorMessageLock);
4595 MUNLOCK(ErrorMessageLock);
5371 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5372 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5373 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0;
5375 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5377 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5380 if ( *t != AR.PolyFun ) {
5382 if ( t == w ) { t += t[1]; w = t; }
5383 else { i = t[1]; NCOPY(w,t,i) }
5387 t2 = t + t[1]; t += FUNHEAD;
5389 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5390 else if ( *t != -SNUMBER )
goto NoLegal;
5393 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5394 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5395 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5396 pow1 += t[ARGHEAD+4];
5401 MLOCK(ErrorMessageLock);
5402 MesPrint(
"Illegal term with divergence in PolyRatFun");
5403 MesCall(
"PolyFunMul");
5404 MUNLOCK(ErrorMessageLock);
5408 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5409 else if ( *t != -SNUMBER )
goto NoLegal;
5412 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5413 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5414 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5415 pow1 -= t[ARGHEAD+4];
5419 if ( t == t2 ) pow += pow1;
5423 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5425 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5426 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5427 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5429 else if ( pow == 1 ) {
5430 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5432 else if ( pow < -1 ) {
5433 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5434 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5435 *w++ = 1; *w++ = 1; *w++ = 3;
5437 else if ( pow == -1 ) {
5438 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5441 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5444 *w++ = 1; *w++ = 1; *w++ = 3;
5446 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5450 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5451 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5452 WORD count1 = 0, count2 = 0, count3;
5453 WORD oldtype = AR.SortType;
5454 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5456 if ( *t == AR.PolyFun ) {
5457 if ( t[2] && dirty == 0 ) {
5462 if ( term[0] == 0 )
return(0);
5467 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5468 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5469 if ( count3 == 2 ) {
5471 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5474 AR.SortType = SORTHIGHFIRST;
5475 t2 = t + t[1]; tt2 = t+FUNHEAD;
5476 while ( tt2 < t2 ) {
5478 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5480 while ( tt1 < tt2 ) {
5481 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5482 AT.WorkPointer = ww;
5487 ww = w;
while ( *ww ) ww += *ww;
5488 if ( ww-w != *tt4-ARGHEAD ) {
5493 WORD *r1 = TermMalloc(
"PolyFunMul");
5494 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5495 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5496 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5497 i = ww-w; ww = w; NCOPY(r4,ww,i);
5498 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5499 *r1 = i = r4-r1; r4 = term; r3 = r1;
5501 t[1] += ii; t1 += ii; *tt4 += ii;
5503 TermFree(r1,
"PolyFunMul");
5506 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5511 else if ( *tt2 <= -FUNCTION ) tt2++;
5514 AR.SortType = oldtype;
5520 if ( count1 <= 1 ) {
goto checkaction; }
5521 if ( AR.PolyFunExp == 1 ) {
5522 t = term + *term; t -= ABS(t[-1]);
5523 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5526 AR.SortType = SORTHIGHFIRST;
5530 if ( *term == 0 )
return(retval);
5531 AR.SortType = oldtype;
5534 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5536 if ( *t == AR.PolyFun ) {
5537 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5538 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5539 if ( count3 == 2 ) {
5545 if ( count1 >= count2 ) {
5548 if ( *t == AR.PolyFun ) {
5551 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5554 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5563 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5565 if ( action ) retval = action;
5569 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5570 AT.WorkPointer = term + *term;
5571 GETSTOP(term,tstop);
5573 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5574 while ( t < tstop && *t == AR.PolyFun ) {
5575 if ( t[1] > FUNHEAD ) {
5576 if ( t[FUNHEAD] < 0 ) {
5577 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5578 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5579 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5586 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5591 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5594 while ( t < tstop && *t == AR.PolyFun ) {
5595 if ( t[1] > FUNHEAD ) {
5596 if ( t[FUNHEAD] < 0 ) {
5597 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5598 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5599 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5606 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5611 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5619 n1 = 1; arg1 = AT.WorkPointer;
5620 ToGeneral(t,arg1,1);
5621 AT.WorkPointer = arg1 + *arg1;
5625 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5626 while ( t < t1 ) { n1++; t += *t; }
5630 n2 = 1; arg2 = AT.WorkPointer;
5631 ToGeneral(t,arg2,1);
5632 AT.WorkPointer = arg2 + *arg2;
5636 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5637 while ( t < t2 ) { n2++; t += *t; }
5649 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5656 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5658 if ( minp1 > 0 ) minp1 = 0;
5660 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5661 if ( minp1 > 0 ) minp1 = 0;
5664 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5665 if ( t1[4] < minp1 ) minp1 = t1[4];
5668 MesPrint(
"Illegal term in expanded polyratfun.");
5674 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5676 if ( minp2 > 0 ) minp2 = 0;
5678 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5679 if ( minp2 > 0 ) minp2 = 0;
5682 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5683 if ( t2[4] < minp2 ) minp2 = t2[4];
5686 MesPrint(
"Illegal term in expanded polyratfun.");
5691 AR.PolyFunPow += minp1+minp2;
5693 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5694 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5699 while ( t < tt1 ) *m++ = *t++;
5702 while ( t < tt2 ) *m++ = *t++;
5703 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5708 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5709 l3 = REDLENG(m[-1]);
5713 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5715 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5717 if ( l4 == 0 )
continue;
5720 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5722 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5731 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5733 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5736 if ( l3 == 0 )
continue;
5746 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5747 AR.PolyFunPow = OldPolyFunPow;
5754 while ( *t ) t += *t;
5758 while ( t1 < fun1 ) *t++ = *t1++;
5761 *t++ = FUNHEAD+ARGHEAD+n1;
5768 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5769 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5770 else t2[FUNHEAD] = FUNHEAD+1;
5773 t1 = fun1 + fun1[1];
5774 while ( t1 < fun2 ) *t++ = *t1++;
5775 t1 = fun2 + fun2[1];
5777 while ( t1 < t2 ) *t++ = *t1++;
5778 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5779 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5780 MLOCK(ErrorMessageLock);
5781 MesPrint(
"Term too complex (%d words). MaxTermSize (%l words) is too small.", n1, AM.MaxTer/(LONG)
sizeof(WORD) );
5784 m = term; t = AT.WorkPointer;
5789 AT.WorkPointer = term + *term;
5790 if ( action && noac ) {
5791 if ( Normalize(BHEAD term) )
goto PolyCall;
5792 AT.WorkPointer = term + *term;
5796 MLOCK(ErrorMessageLock);
5798 AR.PolyFunPow = OldPolyFunPow;
5799 MesCall(
"PolyFunMul");
5800 MUNLOCK(ErrorMessageLock);