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 ) {
222 MesPrint(
"!>(1) Expression %d has problems in scratchfile",i);
229 SeekScratch(AR.outfile,&position);
230 e->onfile = position;
231 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
232 AR.DeferFlag = AC.ComDefer;
237 for ( j = 0; j < *t; j++ ) term[j] = t[j];
239 AN.ninterms++; dd = AN.deferskipped;
240 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
241 if ( GetMoreFromMem(term,&t) ) {
245 AT.WorkPointer = term + *term;
246 AN.RepPoint = AT.RepCount + 1;
247 AN.IndDum = AM.IndDum;
248 AR.CurDum = ReNumber(BHEAD term);
249 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
251 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
252 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
254 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
261 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
262 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
263 else e->vflags |= ISZERO;
264 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
265 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
266 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
274 switch ( e->status ) {
275 case UNHIDELEXPRESSION:
276 case UNHIDEGEXPRESSION:
279 if ( PF.me == MASTER ) SetScratch(AR.hidefile,&(e->onfile));
281 SetScratch(AR.hidefile,&(e->onfile));
282 AR.InHiBuf = AR.hidefile->POfull-AR.hidefile->POfill;
284 MesPrint(
"Hidefile: onfile: %15p, POposition: %15p, filesize: %15p",&(e->onfile)
285 ,&(AR.hidefile->POposition),&(AR.hidefile->filesize));
286 MesPrint(
"Set hidefile to buffer position %l/%l; AR.InHiBuf = %l"
287 ,(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD)
288 ,(AR.hidefile->POfull-AR.hidefile->PObuffer)*
sizeof(WORD)
293 curfile = AR.hidefile;
295 case INTOHIDELEXPRESSION:
296 case INTOHIDEGEXPRESSION:
303 SetEndHScratch(AR.hidefile,&position);
305 case LOCALEXPRESSION:
306 case GLOBALEXPRESSION:
310 if( ( PF.me == MASTER ) || (PF.mkSlaveInfile) )
312 SetScratch(AR.infile,&(e->onfile));
318 MesPrint(
"Error in PF_Processor");
322 if ( AC.mparallelflag != PARALLELFLAG ){
327 if ( GetTerm(BHEAD term) <= 0 ) {
329 MesPrint(
"Error condition 1a");
333 MesPrint(
"!>(2) Expression %d has problems in scratchfile(process)",i);
340 fromspectator = -term[5];
341 PUTZERO(AM.SpectatorFiles[fromspectator-1].readpos);
342 term[5] = AC.cbufnum;
344 else fromspectator = 0;
345 if ( AR.outtohide ) {
346 SeekScratch(AR.hidefile,&position);
347 e->onfile = position;
348 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
351 SeekScratch(AR.outfile,&position);
352 e->onfile = position;
353 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
355 AR.DeferFlag = AC.ComDefer;
357 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
359 AT.BrackBuf = AM.BracketFactors;
360 AT.bracketindexflag = 1;
362 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
364 if ( AS.MultiThreaded && AC.mparallelflag == PARALLELFLAG ) {
365 if ( ThreadsProcessor(e,LastExpression,fromspectator) ) {
367 MesPrint(
"!>Error in ThreadsProcessor");
371 if ( AR.outtohide ) {
372 AR.outfile = oldoutfile;
373 AR.hidefile->POfull = AR.hidefile->POfill;
380 AR.MaxDum = AM.IndDum;
383 if ( fromspectator ) size = GetFromSpectator(term,fromspectator-1);
384 else size = GetTerm(BHEAD term);
385 if ( size <= 0 )
break;
386 SeekScratch(curfile,&position);
387 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
391 AN.ninterms++; dd = AN.deferskipped;
392 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)(
sizeof(WORD)))) ) {
393 if ( GetMoreTerms(term) < 0 ) {
396 SeekScratch(curfile,&position);
398 AT.WorkPointer = term + *term;
399 AN.RepPoint = AT.RepCount + 1;
400 if ( AR.DeferFlag ) {
401 AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
402 AR.CurDum = AN.IndDum;
405 AN.IndDum = AM.IndDum;
406 AR.CurDum = ReNumber(BHEAD term);
408 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
410 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
411 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
413 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
414 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
415 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
416 PolyFunClean(BHEAD term);
423 SetScratch(curfile,&position);
424 if ( AR.GetFile == 2 ) {
425 AR.InHiBuf = (curfile->POfull-curfile->PObuffer)
426 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
429 AR.InInBuf = (curfile->POfull-curfile->PObuffer)
430 -DIFBASE(position,curfile->POposition)/
sizeof(WORD);
434 if ( LastExpression ) {
436 if ( AR.infile->handle >= 0 ) {
437 CloseFile(AR.infile->handle);
438 AR.infile->handle = -1;
439 remove(AR.infile->name);
440 PUTZERO(AR.infile->POposition);
442 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
444 if ( AR.outtohide ) AR.outfile = AR.hidefile;
445 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
goto ProcErr;
446 if ( AR.outtohide ) {
447 AR.outfile = oldoutfile;
448 AR.hidefile->POfull = AR.hidefile->POfill;
450 e->numdummies = AR.MaxDum - AM.IndDum;
453 AR.BracketOn = oldBracketOn;
454 AT.BrackBuf = oldBrackBuf;
455 if ( ( e->vflags & TOBEFACTORED ) != 0 ) {
458 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
459 && ( ( e->vflags & ISFACTORIZED ) != 0 ) ) {
462 AT.bracketindexflag = oldbracketindexflag;
463 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
464 else e->vflags |= ISZERO;
465 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
466 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
467 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
475 if ( e->status == INTOHIDELEXPRESSION ||
476 e->status == INTOHIDEGEXPRESSION ) {
481 case SKIPLEXPRESSION:
482 case SKIPGEXPRESSION:
487 if ( PF.me != MASTER )
break;
490 SetScratch(AR.infile,&(e->onfile));
491 if ( GetTerm(BHEAD term) <= 0 ) {
493 MesPrint(
"Error condition 1b");
497 MesPrint(
"!>(3) Expression %d has problems in scratchfile",i);
504 SeekScratch(AR.outfile,&position);
505 e->onfile = position;
506 *AM.S0->sBuffer = 0; firstterm = -1;
508 WORD *oldipointer = AR.CompressPointer;
509 WORD *comprtop = AR.ComprTop;
510 AR.ComprTop = AM.S0->sTop;
511 AR.CompressPointer = AM.S0->sBuffer;
512 if ( firstterm > 0 ) {
513 if (
PutOut(BHEAD term,&position,AR.outfile,1) < 0 )
goto ProcErr;
515 else if ( firstterm < 0 ) {
516 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
goto ProcErr;
520 if (
PutOut(BHEAD term,&position,AR.outfile,-1) < 0 )
goto ProcErr;
523 AR.CompressPointer = oldipointer;
524 AR.ComprTop = comprtop;
525 }
while ( GetTerm(BHEAD term) );
526 if (
FlushOut(&position,AR.outfile,1) )
goto ProcErr;
529 case HIDELEXPRESSION:
530 case HIDEGEXPRESSION:
532 if ( PF.me != MASTER )
break;
535 SetScratch(AR.infile,&(e->onfile));
536 if ( GetTerm(BHEAD term) <= 0 ) {
538 MesPrint(
"Error condition 1c");
542 MesPrint(
"!>(4) Expression %d has problems in scratchfile",i);
549 SetEndHScratch(AR.hidefile,&position);
550 e->onfile = position;
552 if ( AR.hidefile->handle >= 0 ) {
556 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
557 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
558 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
559 MesPrint(
"Processor Hide1: filesize(th) = %12p, filesize(ex) = %12p",&(position),
561 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
564 *AM.S0->sBuffer = 0; firstterm = -1;
565 cbo = cpo = AM.S0->sBuffer;
567 WORD *oldipointer = AR.CompressPointer;
568 WORD *oldibuffer = AR.CompressBuffer;
569 WORD *comprtop = AR.ComprTop;
570 AR.ComprTop = AM.S0->sTop;
571 AR.CompressPointer = cpo;
572 AR.CompressBuffer = cbo;
573 if ( firstterm > 0 ) {
574 if (
PutOut(BHEAD term,&position,AR.hidefile,1) < 0 )
goto ProcErr;
576 else if ( firstterm < 0 ) {
577 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
goto ProcErr;
581 if (
PutOut(BHEAD term,&position,AR.hidefile,-1) < 0 )
goto ProcErr;
584 cpo = AR.CompressPointer;
585 cbo = AR.CompressBuffer;
586 AR.CompressPointer = oldipointer;
587 AR.CompressBuffer = oldibuffer;
588 AR.ComprTop = comprtop;
589 }
while ( GetTerm(BHEAD term) );
591 if ( AR.hidefile->handle >= 0 ) {
595 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
596 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
597 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
598 MesPrint(
"Processor Hide2: filesize(th) = %12p, filesize(ex) = %12p",&(position),
600 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
603 if (
FlushOut(&position,AR.hidefile,1) )
goto ProcErr;
604 AR.hidefile->POfull = AR.hidefile->POfill;
606 if ( AR.hidefile->handle >= 0 ) {
610 SeekFile(AR.hidefile->handle,&pos,SEEK_CUR);
611 SeekFile(AR.hidefile->handle,&possize,SEEK_END);
612 SeekFile(AR.hidefile->handle,&pos,SEEK_SET);
613 MesPrint(
"Processor Hide3: filesize(th) = %12p, filesize(ex) = %12p",&(position),
615 MesPrint(
" in buffer: %l",(AR.hidefile->POfill-AR.hidefile->PObuffer)*
sizeof(WORD));
626 if ( e->status == HIDELEXPRESSION ) {
627 e->status = HIDDENLEXPRESSION;
628 AS.OldOnFile[i] = e->onfile;
629 AS.OldNumFactors[i] = Expressions[i].numfactors;
631 if ( e->status == HIDEGEXPRESSION ) {
632 e->status = HIDDENGEXPRESSION;
633 AS.OldOnFile[i] = e->onfile;
634 AS.OldNumFactors[i] = Expressions[i].numfactors;
641 case DROPPEDEXPRESSION:
642 case DROPLEXPRESSION:
643 case DROPGEXPRESSION:
644 case DROPHLEXPRESSION:
645 case DROPHGEXPRESSION:
646 case STOREDEXPRESSION:
647 case HIDDENLEXPRESSION:
648 case HIDDENGEXPRESSION:
649 case SPECTATOREXPRESSION:
657 AT.WorkPointer = term;
659 MesPrint(
"Status at the end of Processor (HideLevel = %d)",AC.HideLevel);
660 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) );
661 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) );
662 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));
663 for ( i = 0; i < NumExpressions; i++ ) {
670 AT.WorkPointer = term;
671 if ( AM.tracebackflag ) MesCall(
"Processor");
2183 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2184 WORD *u, *v, *w, *from, *to,
2185 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2189 m = r - ABS(*r) + 1;
2192 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2195 if ( ( term + AR.TePos ) == t ) {
2197 while ( from < t ) *m++ = *from++;
2199 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2202 *m++ = t[1] + 4 + ARGHEAD;
2208 while ( t < v ) *m++ = *t++;
2214 while ( t < r ) *m++ = *t++;
2215 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2216 MLOCK(ErrorMessageLock);
2217 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2218 MUNLOCK(ErrorMessageLock);
2221 *termout = WORDDIF(m,termout);
2225 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec <= 0 )
2226 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2231 oldncmod = AN.ncmod;
2233 if ( *t > 0 && t[1] ) {
2234 WORD oldsorttype = AR.SortType;
2237 if ( ( AN.ncmod != 0 )
2238 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2239 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2243 LONG copy = t - from;
2244 const LONG size = t - u;
2245 NCOPY(m, from, copy);
2249 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2251 AR.SortType = SORTHIGHFIRST;
2260 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2262 AN.ncmod = oldncmod;
2272 if (
EndSort(BHEAD m,1) < 0 ) {
2273 AN.ncmod = oldncmod;
2276 AR.PolyFun = oldPolyFun;
2277 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2278 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2279 AR.SortType = oldsorttype;
2281 while ( *m ) m += *m;
2282 *to = WORDDIF(m,to);
2284 if ( ToFast(to,to) ) {
2285 if ( *to <= -FUNCTION ) m = to+1;
2288 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2291 while ( t < r ) *m++ = *t++;
2292 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2293 MLOCK(ErrorMessageLock);
2294 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2295 MUNLOCK(ErrorMessageLock);
2298 *termout = WORDDIF(m,termout);
2299 AR.DeferFlag = olddefer;
2300 AN.ncmod = oldncmod;
2303 else if ( *t == -DOLLAREXPRESSION ) {
2304 if ( AR.Eside == LHSIDE ) {
2306 AC.lhdollarflag = 1;
2314 int nummodopt, dtype = -1;
2315 if ( AS.MultiThreaded ) {
2316 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2317 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2319 if ( nummodopt < NumModOptdollars ) {
2320 dtype = ModOptdollars[nummodopt].type;
2321 if ( DollarLocalCopy(dtype) ) {
2322 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2325 LOCK(d->pthreadslock);
2330 oldncmod = AN.ncmod;
2331 if ( ( AN.ncmod != 0 )
2332 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2333 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2336 LONG copy = t - from;
2337 const LONG size = t - u;
2338 NCOPY(m, from, copy);
2341 switch ( d->type ) {
2343 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2344 *m++ = -SNUMBER; *m++ = d->index;
2346 else { *m++ = -INDEX; *m++ = d->index; }
2349 *m++ = -SNUMBER; *m++ = 0;
break;
2351 if ( d->where[0] == 4 &&
2352 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2354 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2355 else *m++ = -d->where[1];
2365 to = m; r = d->where;
2369 i = *r; NCOPY(m,r,i)
2372 if ( ToFast(to,to) ) {
2373 if ( *to <= -FUNCTION ) m = to+1;
2376 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2385 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2390 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2391 AR.PolyFun = oldPolyFun;
2392 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2400 while ( *m ) m += *m;
2402 if ( ToFast(to,to) ) {
2403 if ( *to <= -FUNCTION ) m = to+1;
2408 w[1] = w[1] - 2 + (m-to);
2411 to = m; r = d->where;
2413 *m++ = i+4+ARGHEAD; *m++ = 1;
2416 while ( --i >= 0 ) *m++ = *r++;
2417 *m++ = 1; *m++ = 1; *m++ = 3;
2418 if ( ToFast(to,to) ) {
2419 if ( *to <= -FUNCTION ) m = to+1;
2422 w[1] = w[1] - 2 + (m-to);
2425 to = m; r = d->where;
2428 *m++ = *r++; *m++ = 1; r++;
2429 while ( --i >= 0 ) *m++ = *r++;
2431 else if ( *r <= -FUNCTION ) *m++ = *r++;
2432 else { *m++ = *r++; *m++ = *r++; }
2433 w[1] = w[1] - 2 + (m-to);
2436 to = m; r = d->where;
2439 while ( --i >= 0 ) {
2441 *m++ = -VECTOR; *m++ = *r++;
2443 else if ( *r >= AM.OffsetIndex ) {
2444 *m++ = -INDEX; *m++ = *r++;
2446 else { *m++ = -SNUMBER; *m++ = *r++; }
2454 *m++ = *r++; *m++ = 1; r++;
2455 while ( --i >= 0 ) *m++ = *r++;
2457 else if ( *r <= -FUNCTION ) *m++ = *r++;
2458 else { *m++ = *r++; *m++ = *r++; }
2461 w[1] = w[1] - 2 + (m-to);
2465 MLOCK(ErrorMessageLock);
2466 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2467 AC.dollarnames->namebuffer+d->name);
2468 MUNLOCK(ErrorMessageLock);
2470 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2475 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2479 while ( t < r ) *m++ = *t++;
2480 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2481 MLOCK(ErrorMessageLock);
2482 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2483 MUNLOCK(ErrorMessageLock);
2486 *termout = WORDDIF(m,termout);
2487 AR.DeferFlag = olddefer;
2488 AN.ncmod = oldncmod;
2492 else if ( *t == -TERMSINBRACKET ) {
2493 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2502 LONG copy = t - from;
2503 const LONG size = t - u;
2504 NCOPY(m, from, copy);
2506 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2507 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2510 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2512 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2513 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2518 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2519 *m++ = 6; *m++ = numterms & WORDMASK;
2520 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2525 while ( from < r ) *m++ = *from++;
2526 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2527 MLOCK(ErrorMessageLock);
2528 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2529 MUNLOCK(ErrorMessageLock);
2532 *termout = WORDDIF(m,termout);
2539 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec > 0 )
2540 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2541 u = t; v = t + t[1];
2544 if ( *t == FUNNYDOLLAR ) {
2545 if ( AR.Eside != LHSIDE ) {
2548 int nummodopt, dtype = -1;
2549 if ( AS.MultiThreaded ) {
2550 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2551 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2553 if ( nummodopt < NumModOptdollars ) {
2554 dtype = ModOptdollars[nummodopt].type;
2555 if ( DollarLocalCopy(dtype) ) {
2556 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2559 LOCK(d->pthreadslock);
2564 oldncmod = AN.ncmod;
2565 if ( ( AN.ncmod != 0 )
2566 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2567 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2569 LONG copy = t - from;
2570 const LONG size = t - u;
2571 NCOPY(m, from, copy);
2574 switch ( d->type ) {
2576 *m++ = d->index;
break;
2581 if ( d->where[0] == 4 && d->where[4] == 0
2582 && d->where[3] == 3 && d->where[2] == 1
2583 && d->where[1] < AM.OffsetIndex ) {
2589 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2591 MLOCK(ErrorMessageLock);
2592 MesPrint(
"$%s has wrong type for tensor substitution",
2593 AC.dollarnames->namebuffer+d->name);
2594 MUNLOCK(ErrorMessageLock);
2595 AN.ncmod = oldncmod;
2600 if ( d->where[0] == -INDEX ) {
2601 *m++ = d->where[1];
break;
2603 else if ( d->where[0] == -VECTOR ) {
2604 *m++ = d->where[1];
break;
2606 else if ( d->where[0] == -MINVECTOR ) {
2611 else if ( d->where[0] == -SNUMBER ) {
2612 if ( d->where[1] >= 0
2613 && d->where[1] < AM.OffsetIndex ) {
2614 *m++ = d->where[1];
break;
2619 if ( d->where[0] > 0 ) {
2620 r = d->where; i = *r++;
2621 while ( --i >= 0 ) *m++ = *r++;
2626 if ( *r == -INDEX ) {
2627 *m++ = r[1]; r += 2;
continue;
2629 else if ( *r == -VECTOR ) {
2630 *m++ = r[1]; r += 2;
continue;
2632 else if ( *r == -MINVECTOR ) {
2633 *m++ = r[1]; r += 2;
2634 sign = -sign;
continue;
2636 else if ( *r == -SNUMBER ) {
2638 && r[1] < AM.OffsetIndex ) {
2639 *m++ = r[1]; r += 2;
continue;
2648 if ( *r == INDEX && r[1] == 3 ) {
2651 else goto wrongtype;
2655 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2657 MLOCK(ErrorMessageLock);
2658 MesPrint(
"$%s is undefined in tensor substitution",
2659 AC.dollarnames->namebuffer+d->name);
2660 MUNLOCK(ErrorMessageLock);
2661 AN.ncmod = oldncmod;
2665 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2667 w[1] = w[1] - 2 + (m-to);
2670 while ( from < term ) *m++ = *from++;
2671 if ( sign < 0 ) m[-1] = -m[-1];
2672 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2673 MLOCK(ErrorMessageLock);
2674 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2675 MUNLOCK(ErrorMessageLock);
2678 *termout = m - termout;
2679 AN.ncmod = oldncmod;
2683 AC.lhdollarflag = 1;
2693 MLOCK(ErrorMessageLock);
2694 MesPrint(
"!>Internal error in InFunction: Function not encountered.");
2695 if ( AM.tracebackflag ) {
2696 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2697 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2699 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2703 while ( --i >= 0 ) {
2704 TalToLine((UWORD)(*termout++));
2705 TokenToLine((UBYTE *)
" ");
2709 MesCall(
"InFunction");
2711 MUNLOCK(ErrorMessageLock);
2716 MLOCK(ErrorMessageLock);
2717 MesCall(
"InFunction");
2718 MUNLOCK(ErrorMessageLock);
2722 MLOCK(ErrorMessageLock);
2723 MesCall(
"InFunction");
2724 MUNLOCK(ErrorMessageLock);
3278 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3279 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, extractbuff;
3281 int *RepSto = AN.RepPoint, iscopy = 0;
3282 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3283 LONG posisub, oldcpointer, oldacpointer;
3285 WORD numfac[5], idfunctionflag;
3287 int nummodopt, dtype = -1, id;
3289 oldtoprhs = CC->numrhs;
3290 oldcpointer = CC->Pointer - CC->Buffer;
3291 oldatoprhs = CCC->numrhs;
3292 oldacpointer = CCC->Pointer - CCC->Buffer;
3294 if ( ( replac = TestSub(BHEAD term,level) ) == 0 ) {
3295 if ( applyflag ) { TableReset(); applyflag = 0; }
3304 AN.PolyNormFlag = 0;
3305 AN.idfunctionflag = 0;
3306 if ( ( ret = Normalize(BHEAD term) ) != 0 ) {
3308 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3313 idfunctionflag = AN.idfunctionflag;
3314 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3316 if ( AN.PolyNormFlag ) {
3317 if ( AN.PolyFunTodo == 0 ) {
3318 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3319 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3322 WORD oldPolyFunExp = AR.PolyFunExp;
3324 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3325 AT.WorkPointer = term+*term;
3326 AR.PolyFunExp = oldPolyFunExp;
3327 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3328 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3329 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3330 AT.WorkPointer = term+*term;
3331 if ( AN.PolyNormFlag ) {
3332 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3333 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3334 AT.WorkPointer = term+*term;
3339 if ( idfunctionflag > 0 ) {
3340 if ( TakeIDfunction(BHEAD term) ) {
3341 AT.WorkPointer = term + *term;
3345 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3346 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3349 if ( level > AR.Cnumlhs ) {
3350 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3352 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3358 if (
Deferred(BHEAD term,level) )
goto GenCall;
3362 if ( AN.ncmod != 0 ) {
3363 if ( Modulus(term) )
goto GenCall;
3364 if ( !*term )
goto Return0;
3366 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3367 WORD olddummies = AN.IndDum;
3368 AN.IndDum = AM.IndDum;
3369 ReNumber(BHEAD term);
3370 Normalize(BHEAD term);
3371 AN.IndDum = olddummies;
3372 if ( !*term )
goto Return0;
3373 olddummies = DetCurDum(BHEAD term);
3374 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3376 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3377 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3379 else if ( AR.PolyFun > 0 ) {
3380 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3382 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3383 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3384 termout = AT.WorkPointer;
3385 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3386 if ( PutBracket(BHEAD term) )
return(-1);
3387 AN.RepPoint = RepSto;
3388 *AT.WorkPointer = 0;
3390 AT.WorkPointer = termout;
3391 CC->numrhs = oldtoprhs;
3392 CC->Pointer = CC->Buffer + oldcpointer;
3393 CCC->numrhs = oldatoprhs;
3394 CCC->Pointer = CCC->Buffer + oldacpointer;
3398 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3399 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3400 *AT.WorkPointer = 0;
3401 AN.RepPoint = RepSto;
3403 CC->numrhs = oldtoprhs;
3404 CC->Pointer = CC->Buffer + oldcpointer;
3405 CCC->numrhs = oldatoprhs;
3406 CCC->Pointer = CCC->Buffer + oldacpointer;
3410 i = C->
lhs[level][0];
3411 if ( i >= TYPECOUNT ) {
3417 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3418 AT.WorkPointer = term + *term;
3423 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3426 level = AC.Labels[C->
lhs[level][2]];
3429 AT.WorkPointer = term + *term;
3439 WORD ic, jc, *ifcode, *jfcode;
3440 jfcode = C->
lhs[level]; jc = jfcode[1];
3441 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3442 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3443 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3444 level = C->
lhs[level][2];
3445 if ( C->
lhs[level][0] != TYPEELIF )
break;
3447 AT.WorkPointer = ifcode;
3450 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3451 level = C->
lhs[level][2];
3452 if ( C->
lhs[level][0] != TYPEELIF )
break;
3458 level = C->
lhs[level][2];
3459 }
while ( C->
lhs[level][0] == TYPEELIF );
3463 level = C->
lhs[level][2];
3467 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3468 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3469 WORD theindex = C->
lhs[level][2];
3470 if ( theindex < 0 ) {
3473 theindex = -theindex;
3474 d = Dollars + theindex;
3475 if ( AS.MultiThreaded ) {
3476 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3477 if ( theindex == ModOptdollars[nummodopt].number )
break;
3479 if ( nummodopt < NumModOptdollars ) {
3480 ddtype = ModOptdollars[nummodopt].type;
3481 if ( DollarLocalCopy(ddtype) ) {
3482 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3485 LOCK(d->pthreadslock);
3490 theindex = -theindex;
3491 d = Dollars + theindex;
3494 if ( d->type != DOLINDEX
3495 || d->index < AM.OffsetIndex
3496 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3497 MLOCK(ErrorMessageLock);
3498 MesPrint(
"$%s should have been an index"
3499 ,AC.dollarnames->namebuffer+d->name);
3500 AN.currentTerm = term;
3501 MesPrint(
"Current term: %t");
3502 AN.listinprint = printscratch;
3503 printscratch[0] = DOLLAREXPRESSION;
3504 printscratch[1] = theindex;
3506 ,AC.dollarnames->namebuffer+d->name);
3507 MUNLOCK(ErrorMessageLock);
3509 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3513 theindex = d->index;
3515 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3518 cp[1] = SUBEXPSIZE+4;
3523 i = C->
lhs[level][1] - 3;
3525 AR.CompressPointer = cp;
3526 while ( --i >= 0 ) {
3528 termout = AT.WorkPointer;
3529 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3533 while ( --jlhs >= 0 ) {
3534 if ( *m++ != *termout++ )
break;
3537 termout = AT.WorkPointer;
3538 AT.WorkPointer = termout + *termout;
3539 if (
Generator(BHEAD termout,level) )
goto GenCall;
3540 AT.WorkPointer = termout;
3543 AR.CompressPointer = op;
3547 AR.CompressPointer = op;
3552 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3558 AR.CurDum = DetCurDum(BHEAD term);
3559 i = C->
lhs[level][1]-2;
3560 wp = C->
lhs[level] + 2;
3561 cp[1] = SUBEXPSIZE+4*i;
3563 while ( --i >= 0 ) {
3565 if ( theindex < 0 ) {
3568 theindex = -theindex;
3569 d = Dollars + theindex;
3570 if ( AS.MultiThreaded ) {
3571 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3572 if ( theindex == ModOptdollars[nummodopt].number )
break;
3574 if ( nummodopt < NumModOptdollars ) {
3575 ddtype = ModOptdollars[nummodopt].type;
3576 if ( DollarLocalCopy(ddtype) ) {
3577 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3580 LOCK(d->pthreadslock);
3585 theindex = -theindex;
3586 d = Dollars + theindex;
3588 if ( d->type != DOLINDEX
3589 || d->index < AM.OffsetIndex
3590 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3591 MLOCK(ErrorMessageLock);
3592 MesPrint(
"$%s should have been an index"
3593 ,AC.dollarnames->namebuffer+d->name);
3594 AN.currentTerm = term;
3595 MesPrint(
"Current term: %t");
3596 AN.listinprint = printscratch;
3597 printscratch[0] = DOLLAREXPRESSION;
3598 printscratch[1] = theindex;
3600 ,AC.dollarnames->namebuffer+d->name);
3601 MUNLOCK(ErrorMessageLock);
3603 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3607 theindex = d->index;
3609 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3615 *cp++ = ++AR.CurDum;
3617 ow = AT.WorkPointer;
3618 AR.CompressPointer = cp;
3619 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3620 AR.CompressPointer = op;
3622 WORD term_changed = 0;
3623 for ( j = 0; j < i; j++ ) {
3624 if ( term[j] != ow[j] ) term_changed = 1;
3628 if ( term_changed ) *AN.RepPoint = 1;
3629 AT.WorkPointer = ow;
3634 ReNumber(BHEAD term);
3638 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3640 AT.WorkPointer = term + *term;
3643 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3644 level = C->
lhs[level][2];
3645 if ( i > 0 )
goto ReStart;
3653 case TYPESPLITFIRSTARG:
3654 case TYPESPLITLASTARG:
3655 case TYPEARGTOEXTRASYMBOL:
3656 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3657 level = C->
lhs[level][2];
3662 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3663 if ( jjj > 0 )
goto ReStart;
3664 level = C->
lhs[level][2];
3667 if ( C->
lhs[level][2] > 0 ) {
3668 MLOCK(ErrorMessageLock);
3669 MesPrint(
"%s",C->
lhs[level]+3);
3670 MUNLOCK(ErrorMessageLock);
3678 AN.currentTerm = term;
3679 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3680 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3681 MLOCK(ErrorMessageLock);
3683 MesPrint((
char *)(C->
lhs[level]+5));
3685 MUNLOCK(ErrorMessageLock);
3690 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3691 AC.LogHandle = C->
lhs[level][2];
3692 MLOCK(ErrorMessageLock);
3693 oldFOflag = AM.FileOnlyFlag;
3694 oldPrintType = AO.PrintType;
3695 if ( AC.LogHandle >= 0 ) {
3696 AM.FileOnlyFlag = 1;
3697 AO.PrintType |= PRINTLFILE;
3699 AO.PrintType |= C->
lhs[level][3];
3700 AN.currentTerm = term;
3701 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3702 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3703 MesPrint((
char *)(C->
lhs[level]+5));
3704 AO.PrintType = oldPrintType;
3705 AM.FileOnlyFlag = oldFOflag;
3706 MUNLOCK(ErrorMessageLock);
3707 AC.LogHandle = oldLogHandle;
3711 j = C->
lhs[level][2];
3721 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3722 if ( AC.pfirstnum[ii] == j )
break;
3724 AC.inputnumbers[ii] = AN.ninterms;
3728 if ( AS.MultiThreaded ) {
3730 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3731 if ( AC.pfirstnum[ii] == j )
break;
3733 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3734 LOCK(AP.PreVarLock);
3735 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3736 a = C->
lhs[level]+4;
3737 if ( a[a[-1]] == 0 )
3738 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3741 ,(UBYTE *)(a+a[-1]+1),1);
3745 AC.inputnumbers[ii] = AN.inputnumber;
3747 UNLOCK(AP.PreVarLock);
3752 a = C->
lhs[level]+4;
3753 LOCK(AP.PreVarLock);
3754 if ( a[a[-1]] == 0 )
3755 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3758 ,(UBYTE *)(a+a[-1]+1),1);
3759 UNLOCK(AP.PreVarLock);
3763 AT.WorkPointer = term + *term;
3764 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3765 AT.WorkPointer = term + *term;
3766 if ( *term == 0 )
goto Return0;
3769 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3770 AT.WorkPointer = term + *term;
3773 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3774 WORD oldrepeat = *AN.RepPoint;
3780 AN.cTerm = AN.currentTerm = term;
3781 AT.WorkPointer = term + *term;
3782 *AT.WorkPointer++ = 0;
3783 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3784 AT.WorkPointer = term + *term;
3786 *AN.RepPoint = oldrepeat;
3787 AR.NoCompress = onc;
3788 AR.Eside = oldEside;
3792 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3793 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3794 AT.WorkPointer = term + *term;
3799 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3800 level = C->
lhs[level][2];
3803 ret = execterm(BHEAD term,level);
3804 AN.RepPoint = RepSto;
3806 CC->numrhs = oldtoprhs;
3807 CC->Pointer = CC->Buffer + oldcpointer;
3808 CCC->numrhs = oldatoprhs;
3809 CCC->Pointer = CCC->Buffer + oldacpointer;
3812 AT.WorkPointer = term + *term;
3813 AR.CurDum = DetCurDum(BHEAD term);
3815 case TYPEINEXPRESSION:
3816 {WORD *ll = C->
lhs[level];
3817 int numexprs = (int)(ll[1]-3);
3819 while ( numexprs-- >= 0 ) {
3820 if ( *ll == AR.CurExpr )
break;
3823 if ( numexprs < 0 ) level = C->
lhs[level][2];
3827 AT.WorkPointer = term + *term;
3828 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3830 AT.WorkPointer = term + *term;
3833 AT.WorkPointer = term + *term;
3834 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3836 AT.WorkPointer = term + *term;
3839 AT.WorkPointer = term + *term;
3840 if ( TestUse(term,level) )
goto GenCall;
3841 AT.WorkPointer = term + *term;
3844 AT.WorkPointer = term + *term;
3845 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3846 AT.WorkPointer = term + *term;
3850 AT.WorkPointer = term + *term;
3861 AT.WorkPointer = term + *term;
3862 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3863 AT.WorkPointer = term + *term;
3865 if ( *term == 0 )
goto Return0;
3866 if ( *term != lter ) *AN.RepPoint = 1;
3871 AT.WorkPointer = term + *term;
3872 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3873 AT.WorkPointer = term + *term;
3874 if ( *term != lter ) *AN.RepPoint = 1;
3878 AT.WorkPointer = term + *term;
3879 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3880 AT.WorkPointer = term + *term;
3882 case TYPEARGIMPLODE:
3883 AT.WorkPointer = term + *term;
3884 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3885 AT.WorkPointer = term + *term;
3887 case TYPEARGEXPLODE:
3888 AT.WorkPointer = term + *term;
3889 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3890 AT.WorkPointer = term + *term;
3892 case TYPEDENOMINATORS:
3893 if ( DenToFunction(term,C->
lhs[level][2]) )
goto ReStart;
3895 case TYPEDROPCOEFFICIENT:
3896 DropCoefficient(BHEAD term);
3899 AT.WorkPointer = term + *term;
3900 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3901 AT.WorkPointer = term + *term;
3902 if ( *term == 0 )
goto Return0;
3904 case TYPETOPOLYNOMIAL:
3905 AT.WorkPointer = term + *term;
3906 termout = AT.WorkPointer;
3907 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3908 if ( *termout == 0 )
goto Return0;
3909 i = termout[0]; t = term; NCOPY(t,termout,i);
3910 AT.WorkPointer = term + *term;
3912 case TYPEFROMPOLYNOMIAL:
3913 AT.WorkPointer = term + *term;
3914 termout = AT.WorkPointer;
3915 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3916 if ( *term == 0 )
goto Return0;
3917 i = termout[0]; t = term; NCOPY(t,termout,i);
3918 AT.WorkPointer = term + *term;
3921 level = TestDoLoop(BHEAD C->
lhs[level],level);
3922 if ( level < 0 )
goto GenCall;
3925 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3926 if ( level < 0 )
goto GenCall;
3928 case TYPEDROPSYMBOLS:
3929 DropSymbols(BHEAD term);
3932 AT.WorkPointer = term + *term;
3933 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3934 AT.WorkPointer = term + *term;
3939 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3941 case TYPETOSPECTATOR:
3942 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3944 case TYPECANONICALIZE:
3945 AT.WorkPointer = term + *term;
3946 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3947 AT.WorkPointer = term + *term;
3948 if ( *term == 0 )
goto Return0;
3951 AT.WorkPointer = term + *term;
3952 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3955 AT.WorkPointer = term + *term;
3956 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3958 case TYPESETUSERFLAG:
3959 Expressions[AR.CurExpr].uflags |= 1 << (C->
lhs[level][2]);
3961 case TYPECLEARUSERFLAG:
3962 Expressions[AR.CurExpr].uflags &= ~(1 << (C->
lhs[level][2]));
3965 AT.WorkPointer = term + *term;
3966 if ( AllLoops(BHEAD term,level) )
goto GenCall;
3969 AT.WorkPointer = term + *term;
3970 if ( AllPaths(BHEAD term,level) )
goto GenCall;
3974 AT.WorkPointer = term + *term;
3975 if ( C->
lhs[level][2] == MZV
3976 || C->
lhs[level][2] == EULER
3977 || C->
lhs[level][2] == MZVHALF
3978 || C->
lhs[level][2] == ALLMZVFUNCTIONS
3980 if ( EvaluateEuler(BHEAD term,level,C->
lhs[level][2]) )
goto GenCall;
3983 if ( EvaluateFun(BHEAD term,level,C->
lhs[level]) )
goto GenCall;
3998 AT.WorkPointer = term + *term;
3999 if ( ToFloat(BHEAD term,level) )
goto GenCall;
4002 AT.WorkPointer = term + *term;
4003 if ( ToRat(BHEAD term,level) )
goto GenCall;
4005 case TYPESTRICTROUNDING:
4006 AT.WorkPointer = term + *term;
4007 if ( StrictRounding(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
goto GenCall;
4010 AT.WorkPointer = term + *term;
4011 if ( Chop(BHEAD term,level) )
goto GenCall;
4020 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
4021 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
4022 if ( i > 0 ) replac = TestSub(BHEAD term,level);
4024 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
4029AutoGen: i = *AT.TMout;
4030 t = termout = AT.WorkPointer;
4031 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
4033 while ( --i >= 0 ) *t++ = *accum++;
4034 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
4035 AT.WorkPointer = termout;
4039 if ( applyflag ) { TableReset(); applyflag = 0; }
4042 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
4044 if ( AR.TePos >= 0 )
goto AutoGen;
4045 switch ( AN.TeInFun ) {
4047 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
4050 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
4053 if ( DoTableExpansion(term,level) )
goto GenCall;
4056 if ( FactorIn(BHEAD term,level) )
goto GenCall;
4059 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
4062 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
4065 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
4068 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
4071 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
4074 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
4077 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
4080 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
4083 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
4086 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
4089 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
4094 termout = AT.WorkPointer;
4095 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4096 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4097 if (
InFunction(BHEAD term,termout) )
goto GenCall;
4098 AT.WorkPointer = termout + *termout;
4101 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4102 AT.WorkPointer = termout;
4105 else if ( replac > 0 ) {
4109 power = -power; tepos = 0;
4111 extractbuff = AT.TMbuff;
4112 if ( extractbuff == AM.dbufnum ) {
4113 d = DolToTerms(BHEAD replac);
4114 if ( d && d->where != 0 ) {
4116 if ( AT.TMdolfac > 0 ) {
4117 if ( AT.TMdolfac == 1 ) {
4118 if ( d->nfactors ) {
4120 numfac[1] = d->nfactors;
4131 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
4132 MLOCK(ErrorMessageLock);
4133 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
4134 if ( d->nfactors == 1 )
4135 MesPrint(
"There is only one factor");
4137 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
4138 MUNLOCK(ErrorMessageLock);
4141 if ( d->nfactors > 1 ) {
4145 dd = Dollars + replac;
4148 int nummodopt, dtype = -1;
4149 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
4150 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4151 if ( replac == ModOptdollars[nummodopt].number )
break;
4153 if ( nummodopt < NumModOptdollars ) {
4154 dtype = ModOptdollars[nummodopt].type;
4155 if ( DollarLocalCopy(dtype) ) {
4156 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
4162 dsize = dd->factors[AT.TMdolfac-2].size;
4168 numfac[1] = d->factors[AT.TMdolfac-2].value;
4173 if ( numfac[1] < 0 ) {
4174 numfac[1] = -numfac[1];
4175 numfac[3] = -numfac[3];
4179 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
4180 (dsize+1)*
sizeof(WORD),
"Copy of factor");
4181 td1 = dd->factors[AT.TMdolfac-2].where;
4183 d->size = dsize; d->type = DOLTERMS;
4184 NCOPY(td2,td1,dsize);
4188 else if ( d->nfactors == 1 ) {
4189 StartBuf = d->where;
4192 MLOCK(ErrorMessageLock);
4193 if ( d->nfactors == 0 ) {
4194 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
4198 MesPrint(
"!>Internal error. Illegal number of factors for $-variable");
4201 MUNLOCK(ErrorMessageLock);
4206 else StartBuf = d->where;
4209 d = Dollars + replac;
4210 StartBuf = zeroDollar;
4213 i = DetCommu(d->where);
4215 if ( AS.MultiThreaded ) {
4216 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4217 if ( replac == ModOptdollars[nummodopt].number )
break;
4219 if ( nummodopt < NumModOptdollars ) {
4220 dtype = ModOptdollars[nummodopt].type;
4221 if ( dtype == MODMAX || dtype == MODMIN ) {
4222 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
4223 MLOCK(ErrorMessageLock);
4224 MesPrint(
"A dollar variable with modoption max or min can have only one term");
4225 MUNLOCK(ErrorMessageLock);
4229 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
4230 LOCK(d->pthreadslock);
4237 StartBuf = cbuf[extractbuff].Buffer;
4238 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
4239 i = (WORD)cbuf[extractbuff].CanCommu[replac];
4242 termout = AT.WorkPointer;
4243 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4244 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4245 while ( StartBuf[posisub] ) {
4246 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
4247 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
4248 if (
InsertTerm(BHEAD term,replac,extractbuff,
4249 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
4250 AT.WorkPointer = termout + *termout;
4253 posisub += StartBuf[posisub];
4265 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4266 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
4268 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4269 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4275 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4277 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4279 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4286 StartBuf = cbuf[extractbuff].Buffer;
4289 if ( extractbuff == AT.allbufnum ) {
4290 CBUF *Ce = cbuf + extractbuff;
4294 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4297 if ( d->nfactors > 1 ) {
4299 for ( j = 0; j < d->nfactors; j++ ) {
4300 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4302 M_free(d->factors,
"Dollar factors");
4304 M_free(d,
"Copy of dollar variable");
4307 AT.WorkPointer = termout;
4309 else if ( i <= 1 ) {
4311 WORD *same, *ow = AT.WorkPointer;
4312 LONG olpw = AT.posWorkPointer;
4314 WantAddLongs(power1);
4315 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4316 same = ++AT.WorkPointer;
4317 a = accum = ( AT.WorkPointer += power1+1 );
4318 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4319 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4320 AT.lWorkSpace[posit] = posisub;
4327 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4329 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4331 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4332 same[1] = *same + 1;
4333 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4334 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4340 i--; posit--; same--;
4343 termout = AT.WorkPointer = a;
4344 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4345 if ( AT.WorkPointer > AT.WorkTop )
4347 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4348 AT.WorkPointer = termout + *termout;
4352 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4354 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4355 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4356 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4361 if (
Generator(BHEAD termout,level) )
goto GenCall;
4363 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4365 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4366 StartBuf = cbuf[extractbuff].Buffer;
4367 i--; posit--; same--;
4371 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4374 if ( d->nfactors > 1 ) {
4376 for ( j = 0; j < d->nfactors; j++ ) {
4377 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4379 M_free(d->factors,
"Dollar factors");
4381 M_free(d,
"Copy of dollar variable");
4384 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4387 LONG posit, olw, olpw = AT.posWorkPointer;
4388 WantAddLongs(power);
4389 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4390 a = accum = AT.WorkPointer;
4391 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4392 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4393 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4399 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4401 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4402 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4406 AT.lWorkSpace[posit--] = posisub;
4410 termout = AT.WorkPointer = a;
4411 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4412 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4413 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4414 AT.WorkPointer = termout + *termout;
4418 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4419 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4421 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4426 if (
Generator(BHEAD termout,level) )
goto GenCall;
4428 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4430 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4431 StartBuf = cbuf[extractbuff].Buffer;
4436 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4439 if ( d->nfactors > 1 ) {
4441 for ( j = 0; j < d->nfactors; j++ ) {
4442 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4444 M_free(d->factors,
"Dollar factors");
4446 M_free(d,
"Copy of dollar variable");
4449 AT.WorkPointer = accum;
4450 AT.lWorkPointer = olw;
4451 AT.posWorkPointer = olpw;
4456 LONG position, olpw, opw, comprev, extra;
4458 WORD *Freeze, *aa, *dummies;
4462 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4464 SETSTARTPOS(firstpos);
4476 WantAddPointers(power+1);
4477 comprev = opw = AT.pWorkPointer;
4478 AT.pWorkPointer += power+1;
4479 WantAddPositions(power+1);
4480 position = olpw = AT.posWorkPointer;
4481 AT.posWorkPointer += power + 1;
4483 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4485 for ( i = 0; i < power; i++ ) {
4486 PUTZERO(AT.posWorkSpace[position]); position++;
4489 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4490 dummies = AT.WorkPointer;
4491 *dummies++ = AR.CurDum;
4492 AT.WorkPointer += power+2;
4493 accum = AT.WorkPointer;
4494 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4495 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4496 aa = AT.WorkPointer;
4498 i = 0; StartPos = AT.posWorkSpace[position];
4499 dummies[i] = AR.CurDum;
4502 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4503 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4504 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4505 if ( Expressions[replac].numdummies > 0 ) {
4506 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4508 if ( NOTSTARTPOS(firstpos) ) {
4509 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4510 firstpos = AT.posWorkSpace[position];
4521 i++; AT.posWorkSpace[++position] = StartPos;
4522 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4523 dummies[i] = AR.CurDum;
4526 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4527 AR.CurDum = dummies[i];
4531 termout = AT.WorkPointer = a;
4532 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4533 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4534 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4536 AT.WorkPointer = termout + *termout;
4540 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4542 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4547 if (
Generator(BHEAD termout,level) )
goto GenCall;
4550 AR.CurDum = dummies[i];
4553 AT.WorkPointer = aa;
4555 AT.WorkPointer = accum;
4556 AT.posWorkPointer = olpw;
4557 AT.pWorkPointer = opw;
4565 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4566 M_free(renumber->
symb.
lo,
"VarSpace");
4567 M_free(renumber,
"Renumber");
4571 aa = accum = AT.WorkPointer;
4572 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4574 *accum++ = -1; AT.WorkPointer++;
4575 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4576 AT.WorkPointer = aa;
4581 AN.RepPoint = RepSto;
4582 CC->numrhs = oldtoprhs;
4583 CC->Pointer = CC->Buffer + oldcpointer;
4584 CCC->numrhs = oldatoprhs;
4585 CCC->Pointer = CCC->Buffer + oldacpointer;
4589 if ( AM.tracebackflag ) {
4591 MLOCK(ErrorMessageLock);
4592 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4596 while ( --i >= 0 ) {
4597 TalToLine((UWORD)(*termout++));
4598 TokenToLine((UBYTE *)
" ");
4602 MesCall(
"Generator");
4603 MUNLOCK(ErrorMessageLock);
4605 CC->numrhs = oldtoprhs;
4606 CC->Pointer = CC->Buffer + oldcpointer;
4607 CCC->numrhs = oldatoprhs;
4608 CCC->Pointer = CCC->Buffer + oldacpointer;
4611 CC->numrhs = oldtoprhs;
4612 CC->Pointer = CC->Buffer + oldcpointer;
4613 CCC->numrhs = oldatoprhs;
4614 CCC->Pointer = CCC->Buffer + oldacpointer;
4615 MLOCK(ErrorMessageLock);
4617 MUNLOCK(ErrorMessageLock);
5397 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5398 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5399 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0;
5401 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5403 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5406 if ( *t != AR.PolyFun ) {
5408 if ( t == w ) { t += t[1]; w = t; }
5409 else { i = t[1]; NCOPY(w,t,i) }
5413 t2 = t + t[1]; t += FUNHEAD;
5415 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5416 else if ( *t != -SNUMBER )
goto NoLegal;
5419 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5420 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5421 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5422 pow1 += t[ARGHEAD+4];
5428 MLOCK(ErrorMessageLock);
5429 MesPrint(
"!>Illegal term with divergence in PolyRatFun");
5430 MesCall(
"PolyFunMul");
5431 MUNLOCK(ErrorMessageLock);
5436 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5437 else if ( *t != -SNUMBER )
goto NoLegal;
5440 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5441 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5442 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5443 pow1 -= t[ARGHEAD+4];
5447 if ( t == t2 ) pow += pow1;
5451 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5453 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5454 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5455 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5457 else if ( pow == 1 ) {
5458 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5460 else if ( pow < -1 ) {
5461 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5462 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5463 *w++ = 1; *w++ = 1; *w++ = 3;
5465 else if ( pow == -1 ) {
5466 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5469 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5472 *w++ = 1; *w++ = 1; *w++ = 3;
5474 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5478 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5479 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5480 WORD count1 = 0, count2 = 0, count3;
5481 WORD oldtype = AR.SortType;
5482 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5484 if ( *t == AR.PolyFun ) {
5485 if ( t[2] && dirty == 0 ) {
5490 if ( term[0] == 0 )
return(0);
5495 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5496 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5497 if ( count3 == 2 ) {
5499 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5502 AR.SortType = SORTHIGHFIRST;
5503 t2 = t + t[1]; tt2 = t+FUNHEAD;
5504 while ( tt2 < t2 ) {
5506 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5508 while ( tt1 < tt2 ) {
5509 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5510 AT.WorkPointer = ww;
5515 ww = w;
while ( *ww ) ww += *ww;
5516 if ( ww-w != *tt4-ARGHEAD ) {
5521 WORD *r1 = TermMalloc(
"PolyFunMul");
5522 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5523 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5524 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5525 i = ww-w; ww = w; NCOPY(r4,ww,i);
5526 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5527 *r1 = i = r4-r1; r4 = term; r3 = r1;
5529 t[1] += ii; t1 += ii; *tt4 += ii;
5531 TermFree(r1,
"PolyFunMul");
5534 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5539 else if ( *tt2 <= -FUNCTION ) tt2++;
5542 AR.SortType = oldtype;
5548 if ( count1 <= 1 ) {
goto checkaction; }
5549 if ( AR.PolyFunExp == 1 ) {
5550 t = term + *term; t -= ABS(t[-1]);
5551 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5554 AR.SortType = SORTHIGHFIRST;
5558 if ( *term == 0 )
return(retval);
5559 AR.SortType = oldtype;
5562 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5564 if ( *t == AR.PolyFun ) {
5565 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5566 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5567 if ( count3 == 2 ) {
5573 if ( count1 >= count2 ) {
5576 if ( *t == AR.PolyFun ) {
5579 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5582 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5591 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5593 if ( action ) retval = action;
5597 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5598 AT.WorkPointer = term + *term;
5599 GETSTOP(term,tstop);
5601 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5602 while ( t < tstop && *t == AR.PolyFun ) {
5603 if ( t[1] > FUNHEAD ) {
5604 if ( t[FUNHEAD] < 0 ) {
5605 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5606 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5607 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5614 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5619 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5622 while ( t < tstop && *t == AR.PolyFun ) {
5623 if ( t[1] > FUNHEAD ) {
5624 if ( t[FUNHEAD] < 0 ) {
5625 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5626 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5627 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5634 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5639 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5647 n1 = 1; arg1 = AT.WorkPointer;
5648 ToGeneral(t,arg1,1);
5649 AT.WorkPointer = arg1 + *arg1;
5653 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5654 while ( t < t1 ) { n1++; t += *t; }
5658 n2 = 1; arg2 = AT.WorkPointer;
5659 ToGeneral(t,arg2,1);
5660 AT.WorkPointer = arg2 + *arg2;
5664 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5665 while ( t < t2 ) { n2++; t += *t; }
5677 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5684 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5686 if ( minp1 > 0 ) minp1 = 0;
5688 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5689 if ( minp1 > 0 ) minp1 = 0;
5692 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5693 if ( t1[4] < minp1 ) minp1 = t1[4];
5697 MesPrint(
"!>Illegal term in expanded polyratfun.");
5704 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5706 if ( minp2 > 0 ) minp2 = 0;
5708 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5709 if ( minp2 > 0 ) minp2 = 0;
5712 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5713 if ( t2[4] < minp2 ) minp2 = t2[4];
5717 MesPrint(
"!>Illegal term in expanded polyratfun.");
5723 AR.PolyFunPow += minp1+minp2;
5725 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5726 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5731 while ( t < tt1 ) *m++ = *t++;
5734 while ( t < tt2 ) *m++ = *t++;
5735 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5740 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5741 l3 = REDLENG(m[-1]);
5745 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5747 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5749 if ( l4 == 0 )
continue;
5752 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5754 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5763 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5765 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5768 if ( l3 == 0 )
continue;
5778 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5779 AR.PolyFunPow = OldPolyFunPow;
5786 while ( *t ) t += *t;
5790 while ( t1 < fun1 ) *t++ = *t1++;
5793 *t++ = FUNHEAD+ARGHEAD+n1;
5800 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5801 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5802 else t2[FUNHEAD] = FUNHEAD+1;
5805 t1 = fun1 + fun1[1];
5806 while ( t1 < fun2 ) *t++ = *t1++;
5807 t1 = fun2 + fun2[1];
5809 while ( t1 < t2 ) *t++ = *t1++;
5810 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5811 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5812 MLOCK(ErrorMessageLock);
5813 MesPrint(
"Term too complex (%d words). MaxTermSize (%l words) is too small.", n1, AM.MaxTer/(LONG)
sizeof(WORD) );
5816 m = term; t = AT.WorkPointer;
5821 AT.WorkPointer = term + *term;
5822 if ( action && noac ) {
5823 if ( Normalize(BHEAD term) )
goto PolyCall;
5824 AT.WorkPointer = term + *term;
5828 MLOCK(ErrorMessageLock);
5830 AR.PolyFunPow = OldPolyFunPow;
5831 MesCall(
"PolyFunMul");
5832 MUNLOCK(ErrorMessageLock);