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");
2180 WORD *m, *t, *r, *rr, sign = 1, oldncmod;
2181 WORD *u, *v, *w, *from, *to,
2182 ipp, olddefer = AR.DeferFlag, oldPolyFun = AR.PolyFun, i, j;
2186 m = r - ABS(*r) + 1;
2189 if ( *t >= FUNCTION+WILDOFFSET ) ipp = *t - WILDOFFSET;
2192 if ( ( term + AR.TePos ) == t ) {
2194 while ( from < t ) *m++ = *from++;
2196 *m++ = t[1] + 4 + FUNHEAD + ARGHEAD;
2199 *m++ = t[1] + 4 + ARGHEAD;
2205 while ( t < v ) *m++ = *t++;
2211 while ( t < r ) *m++ = *t++;
2212 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2213 MLOCK(ErrorMessageLock);
2214 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2215 MUNLOCK(ErrorMessageLock);
2218 *termout = WORDDIF(m,termout);
2222 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec <= 0 )
2223 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2228 oldncmod = AN.ncmod;
2230 if ( *t > 0 && t[1] ) {
2231 WORD oldsorttype = AR.SortType;
2234 if ( ( AN.ncmod != 0 )
2235 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2236 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2240 LONG copy = t - from;
2241 const LONG size = t - u;
2242 NCOPY(m, from, copy);
2246 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2248 AR.SortType = SORTHIGHFIRST;
2257 if ( AT.WorkPointer < m+*m ) AT.WorkPointer = m + *m;
2259 AN.ncmod = oldncmod;
2269 if (
EndSort(BHEAD m,1) < 0 ) {
2270 AN.ncmod = oldncmod;
2273 AR.PolyFun = oldPolyFun;
2274 if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2275 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2276 AR.SortType = oldsorttype;
2278 while ( *m ) m += *m;
2279 *to = WORDDIF(m,to);
2281 if ( ToFast(to,to) ) {
2282 if ( *to <= -FUNCTION ) m = to+1;
2285 w[1] = WORDDIF(m,w) + WORDDIF(r,v);
2288 while ( t < r ) *m++ = *t++;
2289 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2290 MLOCK(ErrorMessageLock);
2291 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2292 MUNLOCK(ErrorMessageLock);
2295 *termout = WORDDIF(m,termout);
2296 AR.DeferFlag = olddefer;
2297 AN.ncmod = oldncmod;
2300 else if ( *t == -DOLLAREXPRESSION ) {
2301 if ( AR.Eside == LHSIDE ) {
2303 AC.lhdollarflag = 1;
2311 int nummodopt, dtype = -1;
2312 if ( AS.MultiThreaded ) {
2313 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2314 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2316 if ( nummodopt < NumModOptdollars ) {
2317 dtype = ModOptdollars[nummodopt].type;
2318 if ( DollarLocalCopy(dtype) ) {
2319 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2322 LOCK(d->pthreadslock);
2327 oldncmod = AN.ncmod;
2328 if ( ( AN.ncmod != 0 )
2329 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2330 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2333 LONG copy = t - from;
2334 const LONG size = t - u;
2335 NCOPY(m, from, copy);
2338 switch ( d->type ) {
2340 if ( d->index >= 0 && d->index < AM.OffsetIndex ) {
2341 *m++ = -SNUMBER; *m++ = d->index;
2343 else { *m++ = -INDEX; *m++ = d->index; }
2346 *m++ = -SNUMBER; *m++ = 0;
break;
2348 if ( d->where[0] == 4 &&
2349 ( d->where[1] & MAXPOSITIVE ) == d->where[1] ) {
2351 if ( d->where[3] >= 0 ) *m++ = d->where[1];
2352 else *m++ = -d->where[1];
2362 to = m; r = d->where;
2366 i = *r; NCOPY(m,r,i)
2369 if ( ToFast(to,to) ) {
2370 if ( *to <= -FUNCTION ) m = to+1;
2373 else if ( *u == AR.PolyFun && AR.PolyFunType == 2 ) {
2382 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2387 if (
EndSort(BHEAD to+ARGHEAD,1) < 0 )
goto InFunc;
2388 AR.PolyFun = oldPolyFun;
2389 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
2397 while ( *m ) m += *m;
2399 if ( ToFast(to,to) ) {
2400 if ( *to <= -FUNCTION ) m = to+1;
2405 w[1] = w[1] - 2 + (m-to);
2408 to = m; r = d->where;
2410 *m++ = i+4+ARGHEAD; *m++ = 1;
2413 while ( --i >= 0 ) *m++ = *r++;
2414 *m++ = 1; *m++ = 1; *m++ = 3;
2415 if ( ToFast(to,to) ) {
2416 if ( *to <= -FUNCTION ) m = to+1;
2419 w[1] = w[1] - 2 + (m-to);
2422 to = m; r = d->where;
2425 *m++ = *r++; *m++ = 1; r++;
2426 while ( --i >= 0 ) *m++ = *r++;
2428 else if ( *r <= -FUNCTION ) *m++ = *r++;
2429 else { *m++ = *r++; *m++ = *r++; }
2430 w[1] = w[1] - 2 + (m-to);
2433 to = m; r = d->where;
2436 while ( --i >= 0 ) {
2438 *m++ = -VECTOR; *m++ = *r++;
2440 else if ( *r >= AM.OffsetIndex ) {
2441 *m++ = -INDEX; *m++ = *r++;
2443 else { *m++ = -SNUMBER; *m++ = *r++; }
2451 *m++ = *r++; *m++ = 1; r++;
2452 while ( --i >= 0 ) *m++ = *r++;
2454 else if ( *r <= -FUNCTION ) *m++ = *r++;
2455 else { *m++ = *r++; *m++ = *r++; }
2458 w[1] = w[1] - 2 + (m-to);
2462 MLOCK(ErrorMessageLock);
2463 MesPrint(
"!!!Undefined $-variable: $%s!!!",
2464 AC.dollarnames->namebuffer+d->name);
2465 MUNLOCK(ErrorMessageLock);
2467 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2472 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2476 while ( t < r ) *m++ = *t++;
2477 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2478 MLOCK(ErrorMessageLock);
2479 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2480 MUNLOCK(ErrorMessageLock);
2483 *termout = WORDDIF(m,termout);
2484 AR.DeferFlag = olddefer;
2485 AN.ncmod = oldncmod;
2489 else if ( *t == -TERMSINBRACKET ) {
2490 if ( AC.ComDefer ) numterms = CountTerms1(BHEAD0);
2499 LONG copy = t - from;
2500 const LONG size = t - u;
2501 NCOPY(m, from, copy);
2503 if ( ( numterms & MAXPOSITIVE ) == numterms ) {
2504 *m++ = -SNUMBER; *m++ = numterms & MAXPOSITIVE;
2507 else if ( ( i = numterms >> BITSINWORD ) == 0 ) {
2509 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2510 *m++ = 4; *m++ = numterms & WORDMASK; *m++ = 1; *m++ = 3;
2515 for ( j = 1; j < ARGHEAD; j++ ) *m++ = 0;
2516 *m++ = 6; *m++ = numterms & WORDMASK;
2517 *m++ = i; *m++ = 1; *m++ = 0; *m++ = 5;
2522 while ( from < r ) *m++ = *from++;
2523 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2524 MLOCK(ErrorMessageLock);
2525 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2526 MUNLOCK(ErrorMessageLock);
2529 *termout = WORDDIF(m,termout);
2536 else if ( ( *t >= FUNCTION && functions[ipp-FUNCTION].spec > 0 )
2537 && ( t[2] & DIRTYFLAG ) == DIRTYFLAG ) {
2538 u = t; v = t + t[1];
2541 if ( *t == FUNNYDOLLAR ) {
2542 if ( AR.Eside != LHSIDE ) {
2545 int nummodopt, dtype = -1;
2546 if ( AS.MultiThreaded ) {
2547 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
2548 if ( t[1] == ModOptdollars[nummodopt].number )
break;
2550 if ( nummodopt < NumModOptdollars ) {
2551 dtype = ModOptdollars[nummodopt].type;
2552 if ( DollarLocalCopy(dtype) ) {
2553 d = ModOptdollars[nummodopt].dstruct+AT.identity;
2556 LOCK(d->pthreadslock);
2561 oldncmod = AN.ncmod;
2562 if ( ( AN.ncmod != 0 )
2563 && ( ( AC.modmode & ALSOFUNARGS ) == 0 )
2564 && ( *u != AR.PolyFun ) ) { AN.ncmod = 0; }
2566 LONG copy = t - from;
2567 const LONG size = t - u;
2568 NCOPY(m, from, copy);
2571 switch ( d->type ) {
2573 *m++ = d->index;
break;
2578 if ( d->where[0] == 4 && d->where[4] == 0
2579 && d->where[3] == 3 && d->where[2] == 1
2580 && d->where[1] < AM.OffsetIndex ) {
2586 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2588 MLOCK(ErrorMessageLock);
2589 MesPrint(
"$%s has wrong type for tensor substitution",
2590 AC.dollarnames->namebuffer+d->name);
2591 MUNLOCK(ErrorMessageLock);
2592 AN.ncmod = oldncmod;
2597 if ( d->where[0] == -INDEX ) {
2598 *m++ = d->where[1];
break;
2600 else if ( d->where[0] == -VECTOR ) {
2601 *m++ = d->where[1];
break;
2603 else if ( d->where[0] == -MINVECTOR ) {
2608 else if ( d->where[0] == -SNUMBER ) {
2609 if ( d->where[1] >= 0
2610 && d->where[1] < AM.OffsetIndex ) {
2611 *m++ = d->where[1];
break;
2616 if ( d->where[0] > 0 ) {
2617 r = d->where; i = *r++;
2618 while ( --i >= 0 ) *m++ = *r++;
2623 if ( *r == -INDEX ) {
2624 *m++ = r[1]; r += 2;
continue;
2626 else if ( *r == -VECTOR ) {
2627 *m++ = r[1]; r += 2;
continue;
2629 else if ( *r == -MINVECTOR ) {
2630 *m++ = r[1]; r += 2;
2631 sign = -sign;
continue;
2633 else if ( *r == -SNUMBER ) {
2635 && r[1] < AM.OffsetIndex ) {
2636 *m++ = r[1]; r += 2;
continue;
2645 if ( *r == INDEX && r[1] == 3 ) {
2648 else goto wrongtype;
2652 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2654 MLOCK(ErrorMessageLock);
2655 MesPrint(
"$%s is undefined in tensor substitution",
2656 AC.dollarnames->namebuffer+d->name);
2657 MUNLOCK(ErrorMessageLock);
2658 AN.ncmod = oldncmod;
2662 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
2664 w[1] = w[1] - 2 + (m-to);
2667 while ( from < term ) *m++ = *from++;
2668 if ( sign < 0 ) m[-1] = -m[-1];
2669 if ( (m-termout) > (LONG)(AM.MaxTer/
sizeof(WORD)) ) {
2670 MLOCK(ErrorMessageLock);
2671 MesPrint(
"Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/
sizeof(WORD));
2672 MUNLOCK(ErrorMessageLock);
2675 *termout = m - termout;
2676 AN.ncmod = oldncmod;
2680 AC.lhdollarflag = 1;
2690 MLOCK(ErrorMessageLock);
2691 MesPrint(
"!>Internal error in InFunction: Function not encountered.");
2692 if ( AM.tracebackflag ) {
2693 MesPrint(
"%w: AR.TePos = %d",AR.TePos);
2694 MesPrint(
"%w: AN.TeInFun = %d",AN.TeInFun);
2696 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer + AM.MaxTer;
2700 while ( --i >= 0 ) {
2701 TalToLine((UWORD)(*termout++));
2702 TokenToLine((UBYTE *)
" ");
2706 MesCall(
"InFunction");
2708 MUNLOCK(ErrorMessageLock);
2713 MLOCK(ErrorMessageLock);
2714 MesCall(
"InFunction");
2715 MUNLOCK(ErrorMessageLock);
2719 MLOCK(ErrorMessageLock);
2720 MesCall(
"InFunction");
2721 MUNLOCK(ErrorMessageLock);
3275 WORD replac, *accum, *termout, *t, i, j, tepos, applyflag = 0, *StartBuf;
3276 WORD *a, power, power1, DumNow = AR.CurDum, oldtoprhs, oldatoprhs, extractbuff;
3278 int *RepSto = AN.RepPoint, iscopy = 0;
3279 CBUF *C = cbuf+AM.rbufnum, *CC = cbuf + AT.ebufnum, *CCC = cbuf + AT.aebufnum;
3280 LONG posisub, oldcpointer, oldacpointer;
3282 WORD numfac[5], idfunctionflag;
3284 int nummodopt, dtype = -1, id;
3286 oldtoprhs = CC->numrhs;
3287 oldcpointer = CC->Pointer - CC->Buffer;
3288 oldatoprhs = CCC->numrhs;
3289 oldacpointer = CCC->Pointer - CCC->Buffer;
3291 if ( ( replac = TestSub(BHEAD term,level) ) == 0 ) {
3292 if ( applyflag ) { TableReset(); applyflag = 0; }
3301 AN.PolyNormFlag = 0;
3302 AN.idfunctionflag = 0;
3303 if ( ( ret = Normalize(BHEAD term) ) != 0 ) {
3305 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3310 idfunctionflag = AN.idfunctionflag;
3311 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3313 if ( AN.PolyNormFlag ) {
3314 if ( AN.PolyFunTodo == 0 ) {
3315 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3316 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3319 WORD oldPolyFunExp = AR.PolyFunExp;
3321 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3322 AT.WorkPointer = term+*term;
3323 AR.PolyFunExp = oldPolyFunExp;
3324 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3325 if ( Normalize(BHEAD term) < 0 )
goto GenCall;
3326 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3327 AT.WorkPointer = term+*term;
3328 if ( AN.PolyNormFlag ) {
3329 if (
PolyFunMul(BHEAD term) < 0 )
goto GenCall;
3330 if ( !*term ) { AN.PolyNormFlag = 0;
goto Return0; }
3331 AT.WorkPointer = term+*term;
3336 if ( idfunctionflag > 0 ) {
3337 if ( TakeIDfunction(BHEAD term) ) {
3338 AT.WorkPointer = term + *term;
3342 if ( AT.WorkPointer < (WORD *)(((UBYTE *)(term)) + AM.MaxTer) )
3343 AT.WorkPointer = (WORD *)(((UBYTE *)(term)) + AM.MaxTer);
3346 if ( level > AR.Cnumlhs ) {
3347 if ( AR.DeferFlag && AR.sLevel <= 0 ) {
3349 if ( PF.me != MASTER && AC.mparallelflag == PARALLELFLAG && PF.exprtodo < 0 ) {
3355 if (
Deferred(BHEAD term,level) )
goto GenCall;
3359 if ( AN.ncmod != 0 ) {
3360 if ( Modulus(term) )
goto GenCall;
3361 if ( !*term )
goto Return0;
3363 if ( AR.CurDum > AM.IndDum && AR.sLevel <= 0 ) {
3364 WORD olddummies = AN.IndDum;
3365 AN.IndDum = AM.IndDum;
3366 ReNumber(BHEAD term);
3367 Normalize(BHEAD term);
3368 AN.IndDum = olddummies;
3369 if ( !*term )
goto Return0;
3370 olddummies = DetCurDum(BHEAD term);
3371 if ( olddummies > AR.MaxDum ) AR.MaxDum = olddummies;
3373 if ( AR.PolyFun > 0 && ( AR.sLevel <= 0 || AN.FunSorts[AR.sLevel]->PolyFlag > 0 ) ) {
3374 if (
PrepPoly(BHEAD term,0) != 0 )
goto Return0;
3376 else if ( AR.PolyFun > 0 ) {
3377 if (
PrepPoly(BHEAD term,1) != 0 )
goto Return0;
3379 if ( AR.sLevel <= 0 && AR.BracketOn ) {
3380 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3381 termout = AT.WorkPointer;
3382 if ( AT.WorkPointer + *term + 3 > AT.WorkTop )
goto OverWork;
3383 if ( PutBracket(BHEAD term) )
return(-1);
3384 AN.RepPoint = RepSto;
3385 *AT.WorkPointer = 0;
3387 AT.WorkPointer = termout;
3388 CC->numrhs = oldtoprhs;
3389 CC->Pointer = CC->Buffer + oldcpointer;
3390 CCC->numrhs = oldatoprhs;
3391 CCC->Pointer = CCC->Buffer + oldacpointer;
3395 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
3396 if ( AT.WorkPointer >= AT.WorkTop )
goto OverWork;
3397 *AT.WorkPointer = 0;
3398 AN.RepPoint = RepSto;
3400 CC->numrhs = oldtoprhs;
3401 CC->Pointer = CC->Buffer + oldcpointer;
3402 CCC->numrhs = oldatoprhs;
3403 CCC->Pointer = CCC->Buffer + oldacpointer;
3407 i = C->
lhs[level][0];
3408 if ( i >= TYPECOUNT ) {
3414 if ( CountDo(term,C->
lhs[level]) < C->
lhs[level][2] ) {
3415 AT.WorkPointer = term + *term;
3420 if ( MultDo(BHEAD term,C->
lhs[level]) )
goto GenCall;
3423 level = AC.Labels[C->
lhs[level][2]];
3426 AT.WorkPointer = term + *term;
3436 WORD ic, jc, *ifcode, *jfcode;
3437 jfcode = C->
lhs[level]; jc = jfcode[1];
3438 ifcode = AT.WorkPointer; AT.WorkPointer += jc;
3439 for ( ic = 0; ic < jc; ic++ ) ifcode[ic] = jfcode[ic];
3440 while ( !DoIfStatement(BHEAD ifcode,term) ) {
3441 level = C->
lhs[level][2];
3442 if ( C->
lhs[level][0] != TYPEELIF )
break;
3444 AT.WorkPointer = ifcode;
3447 while ( !DoIfStatement(BHEAD C->
lhs[level],term) ) {
3448 level = C->
lhs[level][2];
3449 if ( C->
lhs[level][0] != TYPEELIF )
break;
3455 level = C->
lhs[level][2];
3456 }
while ( C->
lhs[level][0] == TYPEELIF );
3460 level = C->
lhs[level][2];
3464 WORD *cp = AR.CompressPointer, *op = AR.CompressPointer;
3465 WORD *tlhs = C->
lhs[level] + 3, *m, jlhs;
3466 WORD theindex = C->
lhs[level][2];
3467 if ( theindex < 0 ) {
3470 theindex = -theindex;
3471 d = Dollars + theindex;
3472 if ( AS.MultiThreaded ) {
3473 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3474 if ( theindex == ModOptdollars[nummodopt].number )
break;
3476 if ( nummodopt < NumModOptdollars ) {
3477 ddtype = ModOptdollars[nummodopt].type;
3478 if ( DollarLocalCopy(ddtype) ) {
3479 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3482 LOCK(d->pthreadslock);
3487 theindex = -theindex;
3488 d = Dollars + theindex;
3491 if ( d->type != DOLINDEX
3492 || d->index < AM.OffsetIndex
3493 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3494 MLOCK(ErrorMessageLock);
3495 MesPrint(
"$%s should have been an index"
3496 ,AC.dollarnames->namebuffer+d->name);
3497 AN.currentTerm = term;
3498 MesPrint(
"Current term: %t");
3499 AN.listinprint = printscratch;
3500 printscratch[0] = DOLLAREXPRESSION;
3501 printscratch[1] = theindex;
3503 ,AC.dollarnames->namebuffer+d->name);
3504 MUNLOCK(ErrorMessageLock);
3506 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3510 theindex = d->index;
3512 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3515 cp[1] = SUBEXPSIZE+4;
3520 i = C->
lhs[level][1] - 3;
3522 AR.CompressPointer = cp;
3523 while ( --i >= 0 ) {
3525 termout = AT.WorkPointer;
3526 if ( ( jlhs = WildFill(BHEAD termout,term,op)) < 0 )
3530 while ( --jlhs >= 0 ) {
3531 if ( *m++ != *termout++ )
break;
3534 termout = AT.WorkPointer;
3535 AT.WorkPointer = termout + *termout;
3536 if (
Generator(BHEAD termout,level) )
goto GenCall;
3537 AT.WorkPointer = termout;
3540 AR.CompressPointer = op;
3544 AR.CompressPointer = op;
3549 WORD *wp, *cp = AR.CompressPointer, *op = AR.CompressPointer;
3555 AR.CurDum = DetCurDum(BHEAD term);
3556 i = C->
lhs[level][1]-2;
3557 wp = C->
lhs[level] + 2;
3558 cp[1] = SUBEXPSIZE+4*i;
3560 while ( --i >= 0 ) {
3562 if ( theindex < 0 ) {
3565 theindex = -theindex;
3566 d = Dollars + theindex;
3567 if ( AS.MultiThreaded ) {
3568 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
3569 if ( theindex == ModOptdollars[nummodopt].number )
break;
3571 if ( nummodopt < NumModOptdollars ) {
3572 ddtype = ModOptdollars[nummodopt].type;
3573 if ( DollarLocalCopy(ddtype) ) {
3574 d = ModOptdollars[nummodopt].dstruct+AT.identity;
3577 LOCK(d->pthreadslock);
3582 theindex = -theindex;
3583 d = Dollars + theindex;
3585 if ( d->type != DOLINDEX
3586 || d->index < AM.OffsetIndex
3587 || d->index >= AM.OffsetIndex + WILDOFFSET ) {
3588 MLOCK(ErrorMessageLock);
3589 MesPrint(
"$%s should have been an index"
3590 ,AC.dollarnames->namebuffer+d->name);
3591 AN.currentTerm = term;
3592 MesPrint(
"Current term: %t");
3593 AN.listinprint = printscratch;
3594 printscratch[0] = DOLLAREXPRESSION;
3595 printscratch[1] = theindex;
3597 ,AC.dollarnames->namebuffer+d->name);
3598 MUNLOCK(ErrorMessageLock);
3600 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3604 theindex = d->index;
3606 if ( ddtype > 0 && ! DollarLocalCopy(ddtype) ) { UNLOCK(d->pthreadslock); }
3612 *cp++ = ++AR.CurDum;
3614 ow = AT.WorkPointer;
3615 AR.CompressPointer = cp;
3616 if ( WildFill(BHEAD ow,term,op) < 0 )
goto GenCall;
3617 AR.CompressPointer = op;
3619 WORD term_changed = 0;
3620 for ( j = 0; j < i; j++ ) {
3621 if ( term[j] != ow[j] ) term_changed = 1;
3625 if ( term_changed ) *AN.RepPoint = 1;
3626 AT.WorkPointer = ow;
3631 ReNumber(BHEAD term);
3635 if ( Chisholm(BHEAD term,level) )
goto GenCall;
3637 AT.WorkPointer = term + *term;
3640 if ( ( i = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3641 level = C->
lhs[level][2];
3642 if ( i > 0 )
goto ReStart;
3650 case TYPESPLITFIRSTARG:
3651 case TYPESPLITLASTARG:
3652 case TYPEARGTOEXTRASYMBOL:
3653 if ( execarg(BHEAD term,level) < 0 )
goto GenCall;
3654 level = C->
lhs[level][2];
3659 if ( ( jjj = execarg(BHEAD term,level) ) < 0 )
goto GenCall;
3660 if ( jjj > 0 )
goto ReStart;
3661 level = C->
lhs[level][2];
3664 if ( C->
lhs[level][2] > 0 ) {
3665 MLOCK(ErrorMessageLock);
3666 MesPrint(
"%s",C->
lhs[level]+3);
3667 MUNLOCK(ErrorMessageLock);
3675 AN.currentTerm = term;
3676 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3677 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3678 MLOCK(ErrorMessageLock);
3680 MesPrint((
char *)(C->
lhs[level]+5));
3682 MUNLOCK(ErrorMessageLock);
3687 WORD oldPrintType, oldLogHandle = AC.LogHandle;
3688 AC.LogHandle = C->
lhs[level][2];
3689 MLOCK(ErrorMessageLock);
3690 oldFOflag = AM.FileOnlyFlag;
3691 oldPrintType = AO.PrintType;
3692 if ( AC.LogHandle >= 0 ) {
3693 AM.FileOnlyFlag = 1;
3694 AO.PrintType |= PRINTLFILE;
3696 AO.PrintType |= C->
lhs[level][3];
3697 AN.currentTerm = term;
3698 AN.numlistinprint = (C->
lhs[level][1] - C->
lhs[level][4] - 5)/2;
3699 AN.listinprint = C->
lhs[level]+5+C->
lhs[level][4];
3700 MesPrint((
char *)(C->
lhs[level]+5));
3701 AO.PrintType = oldPrintType;
3702 AM.FileOnlyFlag = oldFOflag;
3703 MUNLOCK(ErrorMessageLock);
3704 AC.LogHandle = oldLogHandle;
3708 j = C->
lhs[level][2];
3718 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3719 if ( AC.pfirstnum[ii] == j )
break;
3721 AC.inputnumbers[ii] = AN.ninterms;
3725 if ( AS.MultiThreaded ) {
3727 for ( ii = 0; ii < AC.numpfirstnum; ii++ ) {
3728 if ( AC.pfirstnum[ii] == j )
break;
3730 if ( AN.inputnumber < AC.inputnumbers[ii] )
break;
3731 LOCK(AP.PreVarLock);
3732 if ( AN.inputnumber >= AC.inputnumbers[ii] ) {
3733 a = C->
lhs[level]+4;
3734 if ( a[a[-1]] == 0 )
3735 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3738 ,(UBYTE *)(a+a[-1]+1),1);
3742 AC.inputnumbers[ii] = AN.inputnumber;
3744 UNLOCK(AP.PreVarLock);
3749 a = C->
lhs[level]+4;
3750 LOCK(AP.PreVarLock);
3751 if ( a[a[-1]] == 0 )
3752 PutPreVar(PreVar[j].name,(UBYTE *)(a),0,1);
3755 ,(UBYTE *)(a+a[-1]+1),1);
3756 UNLOCK(AP.PreVarLock);
3760 AT.WorkPointer = term + *term;
3761 if ( FullRenumber(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3762 AT.WorkPointer = term + *term;
3763 if ( *term == 0 )
goto Return0;
3766 if ( TryDo(BHEAD term,C->
lhs[level],level) )
goto GenCall;
3767 AT.WorkPointer = term + *term;
3770 { WORD onc = AR.NoCompress, oldEside = AR.Eside;
3771 WORD oldrepeat = *AN.RepPoint;
3777 AN.cTerm = AN.currentTerm = term;
3778 AT.WorkPointer = term + *term;
3779 *AT.WorkPointer++ = 0;
3780 if ( AssignDollar(BHEAD term,level) )
goto GenCall;
3781 AT.WorkPointer = term + *term;
3783 *AN.RepPoint = oldrepeat;
3784 AR.NoCompress = onc;
3785 AR.Eside = oldEside;
3789 if ( Lus(term,C->
lhs[level][3],C->
lhs[level][4],
3790 C->
lhs[level][5],C->
lhs[level][6],C->
lhs[level][2]) ) {
3791 AT.WorkPointer = term + *term;
3796 if ( InsideDollar(BHEAD C->
lhs[level],level) < 0 )
goto GenCall;
3797 level = C->
lhs[level][2];
3800 ret = execterm(BHEAD term,level);
3801 AN.RepPoint = RepSto;
3803 CC->numrhs = oldtoprhs;
3804 CC->Pointer = CC->Buffer + oldcpointer;
3805 CCC->numrhs = oldatoprhs;
3806 CCC->Pointer = CCC->Buffer + oldacpointer;
3809 AT.WorkPointer = term + *term;
3810 AR.CurDum = DetCurDum(BHEAD term);
3812 case TYPEINEXPRESSION:
3813 {WORD *ll = C->
lhs[level];
3814 int numexprs = (int)(ll[1]-3);
3816 while ( numexprs-- >= 0 ) {
3817 if ( *ll == AR.CurExpr )
break;
3820 if ( numexprs < 0 ) level = C->
lhs[level][2];
3824 AT.WorkPointer = term + *term;
3825 if ( DoShuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3827 AT.WorkPointer = term + *term;
3830 AT.WorkPointer = term + *term;
3831 if ( DoStuffle(term,level,C->
lhs[level][2],C->
lhs[level][3]) )
3833 AT.WorkPointer = term + *term;
3836 AT.WorkPointer = term + *term;
3837 if ( TestUse(term,level) )
goto GenCall;
3838 AT.WorkPointer = term + *term;
3841 AT.WorkPointer = term + *term;
3842 if ( ApplyExec(term,C->
lhs[level][2],level) < C->
lhs[level][2] ) {
3843 AT.WorkPointer = term + *term;
3847 AT.WorkPointer = term + *term;
3858 AT.WorkPointer = term + *term;
3859 if ( ChainIn(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3860 AT.WorkPointer = term + *term;
3862 if ( *term == 0 )
goto Return0;
3863 if ( *term != lter ) *AN.RepPoint = 1;
3868 AT.WorkPointer = term + *term;
3869 if ( ChainOut(BHEAD term,C->
lhs[level][2]) )
goto GenCall;
3870 AT.WorkPointer = term + *term;
3871 if ( *term != lter ) *AN.RepPoint = 1;
3875 AT.WorkPointer = term + *term;
3876 if ( DollarFactorize(BHEAD C->
lhs[level][2]) )
goto GenCall;
3877 AT.WorkPointer = term + *term;
3879 case TYPEARGIMPLODE:
3880 AT.WorkPointer = term + *term;
3881 if ( ArgumentImplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3882 AT.WorkPointer = term + *term;
3884 case TYPEARGEXPLODE:
3885 AT.WorkPointer = term + *term;
3886 if ( ArgumentExplode(BHEAD term,C->
lhs[level]) )
goto GenCall;
3887 AT.WorkPointer = term + *term;
3889 case TYPEDENOMINATORS:
3890 if ( DenToFunction(term,C->
lhs[level][2]) )
goto ReStart;
3892 case TYPEDROPCOEFFICIENT:
3893 DropCoefficient(BHEAD term);
3896 AT.WorkPointer = term + *term;
3897 if ( RunTransform(BHEAD term,C->
lhs[level]+2) )
goto GenCall;
3898 AT.WorkPointer = term + *term;
3899 if ( *term == 0 )
goto Return0;
3901 case TYPETOPOLYNOMIAL:
3902 AT.WorkPointer = term + *term;
3903 termout = AT.WorkPointer;
3904 if ( ConvertToPoly(BHEAD term,termout,C->
lhs[level],0) < 0 )
goto GenCall;
3905 if ( *termout == 0 )
goto Return0;
3906 i = termout[0]; t = term; NCOPY(t,termout,i);
3907 AT.WorkPointer = term + *term;
3909 case TYPEFROMPOLYNOMIAL:
3910 AT.WorkPointer = term + *term;
3911 termout = AT.WorkPointer;
3912 if ( ConvertFromPoly(BHEAD term,termout,0,numxsymbol,0,0) < 0 )
goto GenCall;
3913 if ( *term == 0 )
goto Return0;
3914 i = termout[0]; t = term; NCOPY(t,termout,i);
3915 AT.WorkPointer = term + *term;
3918 level = TestDoLoop(BHEAD C->
lhs[level],level);
3919 if ( level < 0 )
goto GenCall;
3922 level = TestEndDoLoop(BHEAD C->
lhs[C->
lhs[level][2]],C->
lhs[level][2]);
3923 if ( level < 0 )
goto GenCall;
3925 case TYPEDROPSYMBOLS:
3926 DropSymbols(BHEAD term);
3929 AT.WorkPointer = term + *term;
3930 if ( PutInside(BHEAD term,C->
lhs[level]) < 0 )
goto GenCall;
3931 AT.WorkPointer = term + *term;
3936 if (
Generator(BHEAD term,level) < 0 )
goto GenCall;
3938 case TYPETOSPECTATOR:
3939 if ( PutInSpectator(term,C->
lhs[level][2]) < 0 )
goto GenCall;
3941 case TYPECANONICALIZE:
3942 AT.WorkPointer = term + *term;
3943 if ( DoCanonicalize(BHEAD term,C->
lhs[level]) )
goto GenCall;
3944 AT.WorkPointer = term + *term;
3945 if ( *term == 0 )
goto Return0;
3948 AT.WorkPointer = term + *term;
3949 if ( DoSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3952 AT.WorkPointer = term + *term;
3953 if ( DoEndSwitch(BHEAD term,C->
lhs[level]) )
goto GenCall;
3955 case TYPESETUSERFLAG:
3956 Expressions[AR.CurExpr].uflags |= 1 << (C->
lhs[level][2]);
3958 case TYPECLEARUSERFLAG:
3959 Expressions[AR.CurExpr].uflags &= ~(1 << (C->
lhs[level][2]));
3962 AT.WorkPointer = term + *term;
3963 if ( AllLoops(BHEAD term,level) )
goto GenCall;
3966 AT.WorkPointer = term + *term;
3967 if ( AllPaths(BHEAD term,level) )
goto GenCall;
3971 AT.WorkPointer = term + *term;
3972 if ( C->
lhs[level][2] == MZV
3973 || C->
lhs[level][2] == EULER
3974 || C->
lhs[level][2] == MZVHALF
3975 || C->
lhs[level][2] == ALLMZVFUNCTIONS
3977 if ( EvaluateEuler(BHEAD term,level,C->
lhs[level][2]) )
goto GenCall;
3980 if ( EvaluateFun(BHEAD term,level,C->
lhs[level]) )
goto GenCall;
3995 AT.WorkPointer = term + *term;
3996 if ( ToFloat(BHEAD term,level) )
goto GenCall;
3999 AT.WorkPointer = term + *term;
4000 if ( ToRat(BHEAD term,level) )
goto GenCall;
4002 case TYPESTRICTROUNDING:
4003 AT.WorkPointer = term + *term;
4004 if ( StrictRounding(BHEAD term,level,C->
lhs[level][2],C->
lhs[level][3]) )
goto GenCall;
4007 AT.WorkPointer = term + *term;
4008 if ( Chop(BHEAD term,level) )
goto GenCall;
4017 }
while ( ( i =
TestMatch(BHEAD term,&level) ) == 0 );
4018 if ( AT.WorkPointer < term + *term ) AT.WorkPointer = term + *term;
4019 if ( i > 0 ) replac = TestSub(BHEAD term,level);
4021 if ( replac >= 0 || AT.TMout[1] != SYMMETRIZE ) {
4026AutoGen: i = *AT.TMout;
4027 t = termout = AT.WorkPointer;
4028 if ( ( AT.WorkPointer += i ) > AT.WorkTop )
goto OverWork;
4030 while ( --i >= 0 ) *t++ = *accum++;
4031 if ( (*(FG.Operation[termout[1]]))(BHEAD term,termout,replac,level) )
goto GenCall;
4032 AT.WorkPointer = termout;
4036 if ( applyflag ) { TableReset(); applyflag = 0; }
4039 if ( AN.TeInFun < 0 && !AN.TeSuOut ) {
4041 if ( AR.TePos >= 0 )
goto AutoGen;
4042 switch ( AN.TeInFun ) {
4044 if ( DoDistrib(BHEAD term,level) )
goto GenCall;
4047 if ( DoDelta3(BHEAD term,level) )
goto GenCall;
4050 if ( DoTableExpansion(term,level) )
goto GenCall;
4053 if ( FactorIn(BHEAD term,level) )
goto GenCall;
4056 if ( FactorInExpr(BHEAD term,level) )
goto GenCall;
4059 if ( TermsInBracket(BHEAD term,level) < 0 )
goto GenCall;
4062 if ( ExtraSymFun(BHEAD term,level) < 0 )
goto GenCall;
4065 if ( GCDfunction(BHEAD term,level) < 0 )
goto GenCall;
4068 if ( DIVfunction(BHEAD term,level,0) < 0 )
goto GenCall;
4071 if ( DIVfunction(BHEAD term,level,1) < 0 )
goto GenCall;
4074 if ( DIVfunction(BHEAD term,level,2) < 0 )
goto GenCall;
4077 if ( DoPermutations(BHEAD term,level) )
goto GenCall;
4080 if ( DoPartitions(BHEAD term,level) )
goto GenCall;
4083 if ( DIVfunction(BHEAD term,level,3) < 0 )
goto GenCall;
4086 if ( GenDiagrams(BHEAD term,level) < 0 )
goto GenCall;
4091 termout = AT.WorkPointer;
4092 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4093 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4094 if (
InFunction(BHEAD term,termout) )
goto GenCall;
4095 AT.WorkPointer = termout + *termout;
4098 if ( *termout &&
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4099 AT.WorkPointer = termout;
4102 else if ( replac > 0 ) {
4106 power = -power; tepos = 0;
4108 extractbuff = AT.TMbuff;
4109 if ( extractbuff == AM.dbufnum ) {
4110 d = DolToTerms(BHEAD replac);
4111 if ( d && d->where != 0 ) {
4113 if ( AT.TMdolfac > 0 ) {
4114 if ( AT.TMdolfac == 1 ) {
4115 if ( d->nfactors ) {
4117 numfac[1] = d->nfactors;
4128 if ( (AT.TMdolfac-1) > d->nfactors && d->nfactors > 0 ) {
4129 MLOCK(ErrorMessageLock);
4130 MesPrint(
"Attempt to use an nonexisting factor %d of a $-variable",(WORD)(AT.TMdolfac-1));
4131 if ( d->nfactors == 1 )
4132 MesPrint(
"There is only one factor");
4134 MesPrint(
"There are only %d factors",(WORD)(d->nfactors));
4135 MUNLOCK(ErrorMessageLock);
4138 if ( d->nfactors > 1 ) {
4142 dd = Dollars + replac;
4145 int nummodopt, dtype = -1;
4146 if ( AS.MultiThreaded && ( AC.mparallelflag == PARALLELFLAG ) ) {
4147 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4148 if ( replac == ModOptdollars[nummodopt].number )
break;
4150 if ( nummodopt < NumModOptdollars ) {
4151 dtype = ModOptdollars[nummodopt].type;
4152 if ( DollarLocalCopy(dtype) ) {
4153 dd = ModOptdollars[nummodopt].dstruct+AT.identity;
4159 dsize = dd->factors[AT.TMdolfac-2].size;
4165 numfac[1] = d->factors[AT.TMdolfac-2].value;
4170 if ( numfac[1] < 0 ) {
4171 numfac[1] = -numfac[1];
4172 numfac[3] = -numfac[3];
4176 d->factors[AT.TMdolfac-2].where = td2 = (WORD *)Malloc1(
4177 (dsize+1)*
sizeof(WORD),
"Copy of factor");
4178 td1 = dd->factors[AT.TMdolfac-2].where;
4180 d->size = dsize; d->type = DOLTERMS;
4181 NCOPY(td2,td1,dsize);
4185 else if ( d->nfactors == 1 ) {
4186 StartBuf = d->where;
4189 MLOCK(ErrorMessageLock);
4190 if ( d->nfactors == 0 ) {
4191 MesPrint(
"Attempt to use factor %d of an unfactored $-variable",(WORD)(AT.TMdolfac-1));
4195 MesPrint(
"!>Internal error. Illegal number of factors for $-variable");
4198 MUNLOCK(ErrorMessageLock);
4203 else StartBuf = d->where;
4206 d = Dollars + replac;
4207 StartBuf = zeroDollar;
4210 i = DetCommu(d->where);
4212 if ( AS.MultiThreaded ) {
4213 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
4214 if ( replac == ModOptdollars[nummodopt].number )
break;
4216 if ( nummodopt < NumModOptdollars ) {
4217 dtype = ModOptdollars[nummodopt].type;
4218 if ( dtype == MODMAX || dtype == MODMIN ) {
4219 if ( StartBuf[0] && StartBuf[StartBuf[0]] ) {
4220 MLOCK(ErrorMessageLock);
4221 MesPrint(
"A dollar variable with modoption max or min can have only one term");
4222 MUNLOCK(ErrorMessageLock);
4226 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
4227 LOCK(d->pthreadslock);
4234 StartBuf = cbuf[extractbuff].Buffer;
4235 posisub = cbuf[extractbuff].rhs[replac] - StartBuf;
4236 i = (WORD)cbuf[extractbuff].CanCommu[replac];
4239 termout = AT.WorkPointer;
4240 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
4241 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4242 while ( StartBuf[posisub] ) {
4243 if ( extractbuff == AT.allbufnum ) WildDollars(BHEAD &(StartBuf[posisub]));
4244 AT.WorkPointer = (WORD *)(((UBYTE *)(termout)) + AM.MaxTer);
4245 if (
InsertTerm(BHEAD term,replac,extractbuff,
4246 &(StartBuf[posisub]),termout,tepos) < 0 )
goto GenCall;
4247 AT.WorkPointer = termout + *termout;
4250 posisub += StartBuf[posisub];
4262 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4263 if ( ( AS.Balancing && CC->numrhs == 0 ) && StartBuf[posisub] ) {
4265 if ( (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4266 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4272 if (
Generator(BHEAD termout,level) < 0 )
goto GenCall;
4274 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4276 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) ) {
4283 StartBuf = cbuf[extractbuff].Buffer;
4286 if ( extractbuff == AT.allbufnum ) {
4287 CBUF *Ce = cbuf + extractbuff;
4291 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4294 if ( d->nfactors > 1 ) {
4296 for ( j = 0; j < d->nfactors; j++ ) {
4297 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4299 M_free(d->factors,
"Dollar factors");
4301 M_free(d,
"Copy of dollar variable");
4304 AT.WorkPointer = termout;
4306 else if ( i <= 1 ) {
4308 WORD *same, *ow = AT.WorkPointer;
4309 LONG olpw = AT.posWorkPointer;
4311 WantAddLongs(power1);
4312 olw = posit = AT.lWorkPointer; AT.lWorkPointer += power1;
4313 same = ++AT.WorkPointer;
4314 a = accum = ( AT.WorkPointer += power1+1 );
4315 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4316 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4317 AT.lWorkSpace[posit] = posisub;
4324 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4326 &(StartBuf[AT.lWorkSpace[posit]]),i,*same) ) == 0 )
4328 AT.lWorkSpace[posit+1] = AT.lWorkSpace[posit];
4329 same[1] = *same + 1;
4330 if ( i > 1 && AT.lWorkSpace[posit] < AT.lWorkSpace[posit-1] ) *same = 1;
4331 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4337 i--; posit--; same--;
4340 termout = AT.WorkPointer = a;
4341 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4342 if ( AT.WorkPointer > AT.WorkTop )
4344 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4345 AT.WorkPointer = termout + *termout;
4349 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4351 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 )
4352 && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4353 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4358 if (
Generator(BHEAD termout,level) )
goto GenCall;
4360 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4362 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4363 StartBuf = cbuf[extractbuff].Buffer;
4364 i--; posit--; same--;
4368 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4371 if ( d->nfactors > 1 ) {
4373 for ( j = 0; j < d->nfactors; j++ ) {
4374 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4376 M_free(d->factors,
"Dollar factors");
4378 M_free(d,
"Copy of dollar variable");
4381 AT.WorkPointer = ow; AT.lWorkPointer = olw; AT.posWorkPointer = olpw;
4384 LONG posit, olw, olpw = AT.posWorkPointer;
4385 WantAddLongs(power);
4386 posit = olw = AT.lWorkPointer; AT.lWorkPointer += power;
4387 a = accum = AT.WorkPointer;
4388 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4389 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4390 for ( i = 0; i < power; i++ ) AT.lWorkSpace[posit++] = posisub;
4396 if ( StartBuf[AT.lWorkSpace[posit]] ) {
4398 &(StartBuf[AT.lWorkSpace[posit]]),1,1) ) == 0 )
goto GenCall;
4399 AT.lWorkSpace[posit] += StartBuf[AT.lWorkSpace[posit]];
4403 AT.lWorkSpace[posit--] = posisub;
4407 termout = AT.WorkPointer = a;
4408 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4409 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4410 if (
FiniTerm(BHEAD term,accum,termout,replac,tepos) )
goto GenCall;
4411 AT.WorkPointer = termout + *termout;
4415 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); }
4416 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4418 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4423 if (
Generator(BHEAD termout,level) )
goto GenCall;
4425 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { dtype = 0;
break; }
4427 if ( iscopy == 0 && ( extractbuff != AM.dbufnum ) )
4428 StartBuf = cbuf[extractbuff].Buffer;
4433 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) { UNLOCK(d->pthreadslock); dtype = 0; }
4436 if ( d->nfactors > 1 ) {
4438 for ( j = 0; j < d->nfactors; j++ ) {
4439 if ( d->factors[j].where ) M_free(d->factors[j].where,
"Copy of factor");
4441 M_free(d->factors,
"Dollar factors");
4443 M_free(d,
"Copy of dollar variable");
4446 AT.WorkPointer = accum;
4447 AT.lWorkPointer = olw;
4448 AT.posWorkPointer = olpw;
4453 LONG position, olpw, opw, comprev, extra;
4455 WORD *Freeze, *aa, *dummies;
4459 if ( Expressions[replac].status == STOREDEXPRESSION ) {
4461 SETSTARTPOS(firstpos);
4473 WantAddPointers(power+1);
4474 comprev = opw = AT.pWorkPointer;
4475 AT.pWorkPointer += power+1;
4476 WantAddPositions(power+1);
4477 position = olpw = AT.posWorkPointer;
4478 AT.posWorkPointer += power + 1;
4480 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4482 for ( i = 0; i < power; i++ ) {
4483 PUTZERO(AT.posWorkSpace[position]); position++;
4486 if ( ( renumber = GetTable(replac,&(AT.posWorkSpace[position]),1) ) == 0 )
goto GenCall;
4487 dummies = AT.WorkPointer;
4488 *dummies++ = AR.CurDum;
4489 AT.WorkPointer += power+2;
4490 accum = AT.WorkPointer;
4491 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4492 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4493 aa = AT.WorkPointer;
4495 i = 0; StartPos = AT.posWorkSpace[position];
4496 dummies[i] = AR.CurDum;
4499 AR.CompressPointer = AT.pWorkSpace[comprev-1];
4500 if ( ( extra =
PasteFile(BHEAD i,accum,&(AT.posWorkSpace[position])
4501 ,&a,renumber,Freeze,replac) ) < 0 )
goto GenCall;
4502 if ( Expressions[replac].numdummies > 0 ) {
4503 AR.CurDum = dummies[i] + Expressions[replac].numdummies;
4505 if ( NOTSTARTPOS(firstpos) ) {
4506 if ( ISMINPOS(firstpos) || ISEQUALPOS(firstpos,AT.posWorkSpace[position]) ) {
4507 firstpos = AT.posWorkSpace[position];
4518 i++; AT.posWorkSpace[++position] = StartPos;
4519 AT.pWorkSpace[comprev++] = AR.CompressPointer;
4520 dummies[i] = AR.CurDum;
4523 PUTZERO(AT.posWorkSpace[position]); position--; i--;
4524 AR.CurDum = dummies[i];
4528 termout = AT.WorkPointer = a;
4529 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2*AM.MaxTer);
4530 if ( AT.WorkPointer > AT.WorkTop )
goto OverWork;
4531 if (
FiniTerm(BHEAD term,accum,termout,replac,0) )
goto GenCall;
4533 AT.WorkPointer = termout + *termout;
4537 if ( ( AS.Balancing && CC->numrhs == 0 ) && ( i > 0 ) && (
id = ConditionalGetAvailableThread() ) >= 0 ) {
4539 if ( BalanceRunThread(BHEAD
id,termout,level) < 0 )
goto GenCall;
4544 if (
Generator(BHEAD termout,level) )
goto GenCall;
4547 AR.CurDum = dummies[i];
4550 AT.WorkPointer = aa;
4552 AT.WorkPointer = accum;
4553 AT.posWorkPointer = olpw;
4554 AT.pWorkPointer = opw;
4562 if ( renumber->
symb.
lo != AN.dummyrenumlist )
4563 M_free(renumber->
symb.
lo,
"VarSpace");
4564 M_free(renumber,
"Renumber");
4568 aa = accum = AT.WorkPointer;
4569 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + 2 * AM.MaxTer +
sizeof(WORD)) ) > AT.WorkTop )
4571 *accum++ = -1; AT.WorkPointer++;
4572 if (
DoOnePow(BHEAD term,power,replac,accum,aa,level,Freeze) )
goto GenCall;
4573 AT.WorkPointer = aa;
4578 AN.RepPoint = RepSto;
4579 CC->numrhs = oldtoprhs;
4580 CC->Pointer = CC->Buffer + oldcpointer;
4581 CCC->numrhs = oldatoprhs;
4582 CCC->Pointer = CCC->Buffer + oldacpointer;
4586 if ( AM.tracebackflag ) {
4588 MLOCK(ErrorMessageLock);
4589 AO.OutFill = AO.OutputLine = (UBYTE *)AT.WorkPointer;
4593 while ( --i >= 0 ) {
4594 TalToLine((UWORD)(*termout++));
4595 TokenToLine((UBYTE *)
" ");
4599 MesCall(
"Generator");
4600 MUNLOCK(ErrorMessageLock);
4602 CC->numrhs = oldtoprhs;
4603 CC->Pointer = CC->Buffer + oldcpointer;
4604 CCC->numrhs = oldatoprhs;
4605 CCC->Pointer = CCC->Buffer + oldacpointer;
4608 CC->numrhs = oldtoprhs;
4609 CC->Pointer = CC->Buffer + oldcpointer;
4610 CCC->numrhs = oldatoprhs;
4611 CCC->Pointer = CCC->Buffer + oldacpointer;
4612 MLOCK(ErrorMessageLock);
4614 MUNLOCK(ErrorMessageLock);
5394 WORD *t, *fun1, *fun2, *t1, *t2, *m, *w, *ww, *tt1, *tt2, *tt4, *arg1, *arg2;
5395 WORD *tstop, i, dirty = 0, OldPolyFunPow = AR.PolyFunPow, minp1, minp2;
5396 WORD n1, n2, i1, i2, l1, l2, l3, l4, action = 0, noac = 0;
5398 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 1 ) {
5400 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5403 if ( *t != AR.PolyFun ) {
5405 if ( t == w ) { t += t[1]; w = t; }
5406 else { i = t[1]; NCOPY(w,t,i) }
5410 t2 = t + t[1]; t += FUNHEAD;
5412 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1++;
5413 else if ( *t != -SNUMBER )
goto NoLegal;
5416 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5417 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5418 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5419 pow1 += t[ARGHEAD+4];
5425 MLOCK(ErrorMessageLock);
5426 MesPrint(
"!>Illegal term with divergence in PolyRatFun");
5427 MesCall(
"PolyFunMul");
5428 MUNLOCK(ErrorMessageLock);
5433 if ( *t == -SYMBOL && t[1] == AR.PolyFunVar ) pow1--;
5434 else if ( *t != -SNUMBER )
goto NoLegal;
5437 else if ( t[0] == ARGHEAD+8 && t[ARGHEAD] == 8
5438 && t[ARGHEAD+1] == SYMBOL && t[ARGHEAD+3] == AR.PolyFunVar
5439 && t[ARGHEAD+5] == 1 && t[ARGHEAD+6] == 1 && t[ARGHEAD+7] == 3 ) {
5440 pow1 -= t[ARGHEAD+4];
5444 if ( t == t2 ) pow += pow1;
5448 *w++ = AR.PolyFun; *w++ = 0; FILLFUN(w);
5450 *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5451 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = pow;
5452 *w++ = 1; *w++ = 1; *w++ = 3; *w++ = -SNUMBER; *w++ = 1;
5454 else if ( pow == 1 ) {
5455 *w++ = -SYMBOL; *w++ = AR.PolyFunVar; *w++ = -SNUMBER; *w++ = 1;
5457 else if ( pow < -1 ) {
5458 *w++ = -SNUMBER; *w++ = 1; *w++ = 8+ARGHEAD; *w++ = 0; FILLARG(w);
5459 *w++ = 8; *w++ = SYMBOL; *w++ = 4; *w++ = AR.PolyFunVar; *w++ = -pow;
5460 *w++ = 1; *w++ = 1; *w++ = 3;
5462 else if ( pow == -1 ) {
5463 *w++ = -SNUMBER; *w++ = 1; *w++ = -SYMBOL; *w++ = AR.PolyFunVar;
5466 *w++ = -SNUMBER; *w++ = 1; *w++ = -SNUMBER; *w++ = 1;
5469 *w++ = 1; *w++ = 1; *w++ = 3;
5471 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5475 if ( AR.PolyFunType == 2 && ( ( AR.PolyFunExp != 2 )
5476 || ( AR.PolyFunExp == 2 && AN.PolyNormFlag > 1 ) ) ) {
5477 WORD count1 = 0, count2 = 0, count3;
5478 WORD oldtype = AR.SortType;
5479 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5481 if ( *t == AR.PolyFun ) {
5482 if ( t[2] && dirty == 0 ) {
5487 if ( term[0] == 0 )
return(0);
5492 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5493 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5494 if ( count3 == 2 ) {
5496 if ( ( t[2] & MUSTCLEANPRF ) != 0 ) {
5499 AR.SortType = SORTHIGHFIRST;
5500 t2 = t + t[1]; tt2 = t+FUNHEAD;
5501 while ( tt2 < t2 ) {
5503 tt4 = tt2; tt1 = tt2 + ARGHEAD; tt2 += *tt2;
5505 while ( tt1 < tt2 ) {
5506 i = *tt1; ww = w; NCOPY(ww,tt1,i);
5507 AT.WorkPointer = ww;
5512 ww = w;
while ( *ww ) ww += *ww;
5513 if ( ww-w != *tt4-ARGHEAD ) {
5518 WORD *r1 = TermMalloc(
"PolyFunMul");
5519 WORD ii = (ww-w)-(*tt4-ARGHEAD);
5520 WORD *r2 = tt4+ARGHEAD, *r3, *r4 = r1;
5521 i = r2 - term; r3 = term; NCOPY(r4,r3,i);
5522 i = ww-w; ww = w; NCOPY(r4,ww,i);
5523 r3 = tt2; i = term+*term-tt2; NCOPY(r4,r3,i);
5524 *r1 = i = r4-r1; r4 = term; r3 = r1;
5526 t[1] += ii; t1 += ii; *tt4 += ii;
5528 TermFree(r1,
"PolyFunMul");
5531 i = ww-w; ww = w; tt1 = tt4+ARGHEAD;
5536 else if ( *tt2 <= -FUNCTION ) tt2++;
5539 AR.SortType = oldtype;
5545 if ( count1 <= 1 ) {
goto checkaction; }
5546 if ( AR.PolyFunExp == 1 ) {
5547 t = term + *term; t -= ABS(t[-1]);
5548 *t++ = 1; *t++ = 1; *t++ = 3; *term = t - term;
5551 AR.SortType = SORTHIGHFIRST;
5555 if ( *term == 0 )
return(retval);
5556 AR.SortType = oldtype;
5559 t = term + 1; t1 = term + *term; t1 -= ABS(t1[-1]);
5561 if ( *t == AR.PolyFun ) {
5562 t2 = t + t[1]; tt2 = t+FUNHEAD; count3 = 0;
5563 while ( tt2 < t2 ) { count3++; NEXTARG(tt2); }
5564 if ( count3 == 2 ) {
5570 if ( count1 >= count2 ) {
5573 if ( *t == AR.PolyFun ) {
5576 t2[2] |= (DIRTYFLAG|MUSTCLEANPRF);
5579 if ( *t2 > 0 ) t2[1] = DIRTYFLAG;
5588 if ( w > AT.WorkSpace && w < AT.WorkTop ) AT.WorkPointer = w;
5590 if ( action ) retval = action;
5594 if ( term >= AT.WorkSpace && term+*term < AT.WorkTop )
5595 AT.WorkPointer = term + *term;
5596 GETSTOP(term,tstop);
5598 while ( *t != AR.PolyFun && t < tstop ) t += t[1];
5599 while ( t < tstop && *t == AR.PolyFun ) {
5600 if ( t[1] > FUNHEAD ) {
5601 if ( t[FUNHEAD] < 0 ) {
5602 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5603 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5604 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5611 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5616 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5619 while ( t < tstop && *t == AR.PolyFun ) {
5620 if ( t[1] > FUNHEAD ) {
5621 if ( t[FUNHEAD] < 0 ) {
5622 if ( t[FUNHEAD] <= -FUNCTION && t[1] == FUNHEAD+1 )
break;
5623 if ( t[FUNHEAD] > -FUNCTION && t[1] == FUNHEAD+2 ) {
5624 if ( t[FUNHEAD] == -SNUMBER && t[FUNHEAD+1] == 0 ) {
5631 else if ( t[FUNHEAD] == t[1] - FUNHEAD )
break;
5636 if ( *t != AR.PolyFun || t >= tstop )
goto done;
5644 n1 = 1; arg1 = AT.WorkPointer;
5645 ToGeneral(t,arg1,1);
5646 AT.WorkPointer = arg1 + *arg1;
5650 n1 = 0; t1 = fun1 + fun1[1]; arg1 = t;
5651 while ( t < t1 ) { n1++; t += *t; }
5655 n2 = 1; arg2 = AT.WorkPointer;
5656 ToGeneral(t,arg2,1);
5657 AT.WorkPointer = arg2 + *arg2;
5661 n2 = 0; t2 = fun2 + fun2[1]; arg2 = t;
5662 while ( t < t2 ) { n2++; t += *t; }
5674 if ( AR.PolyFunType == 2 && AR.PolyFunExp == 2 ) {
5681 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5683 if ( minp1 > 0 ) minp1 = 0;
5685 else if ( ABS(t1[*t1-1]) == (*t1-1) ) {
5686 if ( minp1 > 0 ) minp1 = 0;
5689 if ( t1[1] == SYMBOL && t1[2] == 4 && t1[3] == AR.PolyFunVar ) {
5690 if ( t1[4] < minp1 ) minp1 = t1[4];
5694 MesPrint(
"!>Illegal term in expanded polyratfun.");
5701 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5703 if ( minp2 > 0 ) minp2 = 0;
5705 else if ( ABS(t2[*t2-1]) == (*t2-1) ) {
5706 if ( minp2 > 0 ) minp2 = 0;
5709 if ( t2[1] == SYMBOL && t2[2] == 4 && t2[3] == AR.PolyFunVar ) {
5710 if ( t2[4] < minp2 ) minp2 = t2[4];
5714 MesPrint(
"!>Illegal term in expanded polyratfun.");
5720 AR.PolyFunPow += minp1+minp2;
5722 for ( t1 = arg1, i1 = 0; i1 < n1; i1++, t1 += *t1 ) {
5723 for ( t2 = arg2, i2 = 0; i2 < n2; i2++, t2 += *t2 ) {
5728 while ( t < tt1 ) *m++ = *t++;
5731 while ( t < tt2 ) *m++ = *t++;
5732 *m++ = 1; *m++ = 1; *m++ = 3; *w = WORDDIF(m,w);
5737 if ( m[-1] != 3 || m[-2] != 1 || m[-3] != 1 ) {
5738 l3 = REDLENG(m[-1]);
5742 if ( MulRat(BHEAD (UWORD *)m,l3,(UWORD *)tt1,l1,(UWORD *)m,&l4) ) {
5744 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l4,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5746 if ( l4 == 0 )
continue;
5749 if ( MulRat(BHEAD (UWORD *)m,l4,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5751 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5760 if ( MulRat(BHEAD (UWORD *)tt1,l1,(UWORD *)tt2,l2,(UWORD *)m,&l3) ) {
5762 if ( AN.ncmod != 0 && TakeModulus((UWORD *)m,&l3,AC.cmod,AN.ncmod,UNPACK|AC.modmode) ) {
5765 if ( l3 == 0 )
continue;
5775 if (
EndSort(BHEAD w,0) < 0 )
goto PolyCall;
5776 AR.PolyFunPow = OldPolyFunPow;
5783 while ( *t ) t += *t;
5787 while ( t1 < fun1 ) *t++ = *t1++;
5790 *t++ = FUNHEAD+ARGHEAD+n1;
5797 if ( ToFast(t2+FUNHEAD,t2+FUNHEAD) ) {
5798 if ( t2[FUNHEAD] > -FUNCTION ) t2[1] = FUNHEAD+2;
5799 else t2[FUNHEAD] = FUNHEAD+1;
5802 t1 = fun1 + fun1[1];
5803 while ( t1 < fun2 ) *t++ = *t1++;
5804 t1 = fun2 + fun2[1];
5806 while ( t1 < t2 ) *t++ = *t1++;
5807 *AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
5808 if ( n1*((LONG)
sizeof(WORD)) > AM.MaxTer ) {
5809 MLOCK(ErrorMessageLock);
5810 MesPrint(
"Term too complex (%d words). MaxTermSize (%l words) is too small.", n1, AM.MaxTer/(LONG)
sizeof(WORD) );
5813 m = term; t = AT.WorkPointer;
5818 AT.WorkPointer = term + *term;
5819 if ( action && noac ) {
5820 if ( Normalize(BHEAD term) )
goto PolyCall;
5821 AT.WorkPointer = term + *term;
5825 MLOCK(ErrorMessageLock);
5827 AR.PolyFunPow = OldPolyFunPow;
5828 MesCall(
"PolyFunMul");
5829 MUNLOCK(ErrorMessageLock);