55 {
"clear", (TFUN)0, CLEARMODULE, 0}
56 ,{
"end", (TFUN)0, ENDMODULE, 0}
57 ,{
"global", (TFUN)0, GLOBALMODULE, 0}
58 ,{
"sort", (TFUN)0, SORTMODULE, 0}
59 ,{
"store", (TFUN)0, STOREMODULE, 0}
62static KEYWORD ModuleOptions[] = {
63 {
"inparallel", DoinParallel, 1, 1}
64 ,{
"local", DoModLocal, MODLOCAL, 0}
65 ,{
"maximum", DoModMax, MODMAX, 0}
66 ,{
"minimum", DoModMin, MODMIN, 0}
67 ,{
"noparallel", DoNoParallel, NOPARALLEL_USER,0}
68 ,{
"notinparallel", DonotinParallel,0, 1}
69 ,{
"parallel", DoParallel, PARALLELFLAG, 0}
70 ,{
"polyfun", DoPolyfun, POLYFUN, 0}
71 ,{
"polyratfun", DoPolyratfun, POLYFUN, 0}
72 ,{
"processbucketsize", DoProcessBucket,0, 0}
73 ,{
"sum", DoModSum, MODSUM, 0}
76int ModuleInstruction(
int *moduletype,
int *specialtype)
80 int addit = 0, error = 0, i, j;
81 DUMMYUSE(specialtype);
83 AC.firstctypemessage = 0;
84 s = AP.preStart; SKIPBLANKS(s)
86 AC.origin = FROMPOINTINSTRUCTION;
87 key = FindKeyWord(AP.preStart,ModuleWords,
sizeof(ModuleWords)/
sizeof(
KEYWORD));
89 MesPrint(
"@Unrecognized module terminator: %s",s);
92 while ( StrCmp((UBYTE *)key->name,(UBYTE *)
"end") ) key++;
95 *moduletype = key->type;
100 MesPrint(
"@Improper options field in . instruction");
105 if ( CoModOption(s) ) error = 1;
113 while ( *t && *t !=
';' ) {
114 if ( *t ==
'\\' ) t++;
118 while ( u > s && u[-1] ==
' ' ) { u--; i--; }
119 if ( *u ==
'\\' ) { u++; i++; }
120 for ( j = COMMERCIALSIZE-1; j >= 0; j-- ) {
122 AC.Commercial[j] = *--u; i--;
123 if ( u > s && u[-1] ==
'\\' ) u--;
125 for ( ; j >= 0; j-- ) AC.Commercial[j] =
' ';
126 AC.Commercial[COMMERCIALSIZE] = 0;
129 if ( addit && *t !=
';' ) {
130 MesPrint(
"@Improper ending of . instruction");
143int CoModuleOption(UBYTE *s)
147 int error = 0, polyflag = 0;
148 AC.origin = FROMMODULEOPTION;
153 option = FindKeyWord(s,ModuleOptions,
154 sizeof(ModuleOptions)/
sizeof(
KEYWORD));
162 MesPrint(
"@Unrecognized module option: %s",s);
171 if ( (option->func)(t) ) error = 1;
173 if ( error )
return(error);
174 if ( StrCmp((UBYTE *)(option->name),(UBYTE *)(
"polyfun")) == 0
175 || StrCmp((UBYTE *)(option->name),(UBYTE *)(
"polyratfun")) == 0 ) {
181 if ( option->flags > 0 )
return(error);
185 while ( *tt ==
',' ) tt++;
186 if ( *tt !=
'$' )
break;
189 if ( *t ==
')' )
break;
190 if ( *t ==
'(' ) SKIPBRA3(t)
191 else if ( *t ==
'{' ) SKIPBRA2(t)
192 else if ( *t ==
'[' ) SKIPBRA1(t)
196 }
while ( *s ==
',' );
198 MesPrint(
"@Unrecognized module option: %s",s);
213int CoModOption(UBYTE *s)
217 AC.origin = FROMPOINTINSTRUCTION;
222 if ( StrICmp(s,(UBYTE *)
"polyfun") == 0 ) {
225 if ( DoPolyfun(t) ) error = 1;
227 else if ( StrICmp(s,(UBYTE *)
"polyratfun") == 0 ) {
230 if ( DoPolyratfun(t) ) error = 1;
233 MesPrint(
"@Unrecognized module option in .instruction: %s",s);
238 if ( *t ==
',' || *t ==
')' )
break;
239 if ( *t ==
'(' ) SKIPBRA3(t)
240 else if ( *t ==
'{' ) SKIPBRA2(t)
241 else if ( *t ==
'[' ) SKIPBRA1(t)
245 }
while ( *s ==
',' );
247 MesPrint(
"@Unrecognized module option in .instruction: %s",s);
258void SetSpecialMode(
int moduletype,
int specialtype)
260 DUMMYUSE(moduletype); DUMMYUSE(specialtype);
275int ExecModule(
int moduletype)
282 if ( ( AC.tMaxWeight != 0 && AC.tMaxWeight != AC.MaxWeight )
283 || ( AC.tDefaultPrecision != 0 && AC.tDefaultPrecision != AC.DefaultPrecision ) ) {
284 AC.DefaultPrecision = AC.tDefaultPrecision;
285 AC.tDefaultPrecision = 0;
286 AC.MaxWeight = AC.tMaxWeight;
292 return(DoExecute(moduletype,0));
315void FullCleanUp(
void)
319 while ( AC.CurrentStream->previous >= 0 )
320 AC.CurrentStream = CloseStream(AC.CurrentStream);
321 AP.PreSwitchLevel = AP.PreIfLevel = 0;
323 for ( j = NumProcedures-1; j >= 0; j-- ) {
324 if ( Procedures[j].name ) M_free(Procedures[j].name,
"name of procedure");
325 if ( Procedures[j].p.buffer ) M_free(Procedures[j].p.buffer,
"buffer of procedure");
329 while ( NumPre > AP.gNumPre ) {
331 M_free(PreVar[NumPre].name,
"PreVar[NumPre].name");
332 PreVar[NumPre].name = PreVar[NumPre].value = 0;
336 for ( j = 0; j < NumExpressions; j++ ) {
337 AC.exprnames->namenode[Expressions[j].node].type = CDELETE;
341 CompactifyTree(AC.exprnames,EXPRNAMES);
343 for ( j = AO.NumDictionaries-1; j >= 0; j-- ) {
344 RemoveDictionary(AO.Dictionaries[j]);
345 M_free(AO.Dictionaries[j],
"Dictionary");
347 AO.NumDictionaries = AO.gNumDictionaries = 0;
348 M_free(AO.Dictionaries,
"Dictionaries");
350 AO.SizeDictionaries = 0;
351 AP.OpenDictionary = 0;
352 AO.CurrentDictionary = 0;
354 AP.ComChar = AP.cComChar;
355 if ( AP.procedureExtension ) M_free(AP.procedureExtension,
"procedureextension");
356 AP.procedureExtension = strDup1(AP.cprocedureExtension,
"procedureextension");
358 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag;
359 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols;
360 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] =
'Z';
361 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
362 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers;
363 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace;
364 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats;
365 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag;
366 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats;
367 AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag;
368 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag;
369 if ( AC.ThreadsFlag && AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
370 AC.ThreadBucketSize = AM.gThreadBucketSize = AM.ggThreadBucketSize;
371 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing;
372 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch;
373 AC.ShortStatsMax = AM.gShortStatsMax = AM.ggShortStatsMax;
374 AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
376 AC.MaxWeight = AM.gMaxWeight = AM.ggMaxWeight;
377 AC.DefaultPrecision = AM.gDefaultPrecision = AM.ggDefaultPrecision;
381 if ( DeleteStore(0) < 0 ) {
382 MesPrint(
"@Cannot restart the storage file");
396int DoPolyfun(UBYTE *s)
400 WORD funnum, eqsign = 0;
401 if ( AC.origin == FROMPOINTINSTRUCTION ) {
402 if ( *s == 0 || *s ==
',' || *s ==
')' ) {
403 AR.PolyFun = 0; AR.PolyFunType = 0;
407 MesPrint(
"@Proper use in point instructions is: PolyFun[=functionname]");
414 AR.PolyFun = 0; AR.PolyFunType = 0;
417 if ( *s !=
'=' && *s !=
',' ) {
418 MesPrint(
"@Proper use is: PolyFun[{ ,=}functionname]");
421 if ( *s ==
'=' ) eqsign = 1;
428 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) {
429 if ( AC.origin != FROMPOINTINSTRUCTION && eqsign == 0 ) {
430 AR.PolyFun = 0; AR.PolyFunType = 0;
433 MesPrint(
"@ %s is not a properly declared function",s);
437 if ( functions[funnum].spec > 0 || functions[funnum].commute != 0 ) {
438 MesPrint(
"@The PolyFun must be a regular commuting function!");
442 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 1;
445 if ( *t && *t !=
',' && *t !=
')' ) {
447 MesPrint(
"@Improper ending of end-of-module instruction: %s",s);
459int DoPolyratfun(UBYTE *s)
464 if ( AC.origin == FROMPOINTINSTRUCTION ) {
465 if ( *s == 0 || *s ==
',' || *s ==
')' ) {
466 AR.PolyFun = 0; AR.PolyFunType = 0; AR.PolyFunInv = 0; AR.PolyFunExp = 0;
470 MesPrint(
"@Proper use in point instructions is: PolyRatFun[=functionname[+functionname]]");
476 AR.PolyFun = 0; AR.PolyFunType = 0; AR.PolyFunInv = 0; AR.PolyFunExp = 0;
479 if ( *s !=
'=' && *s !=
',' ) {
480 MesPrint(
"@Proper use is: PolyRatFun[{ ,=}functionname[+functionname]]");
489 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) {
491 MesPrint(
"@ %s is not a properly declared function",s);
495 if ( functions[funnum].spec > 0 || functions[funnum].commute != 0 ) {
497 MesPrint(
"@The PolyRatFun must be a regular commuting function!");
501 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 2;
504 AC.PolyRatFunChanged = 1;
510 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION )
goto Error1;
511 if ( functions[funnum].spec > 0 || functions[funnum].commute != 0 )
goto Error2;
512 AR.PolyFunInv = funnum+FUNCTION;
516 if ( *t && *t !=
',' && *t !=
')' ) {
518 MesPrint(
"@Improper ending of end-of-module instruction: %s",s);
530int DoNoParallel(UBYTE *s)
532 if ( *s == 0 || *s ==
',' || *s ==
')' ) {
533 AC.mparallelflag |= NOPARALLEL_USER;
536 MesPrint(
"@NoParallel should not have extra parameters");
545int DoParallel(UBYTE *s)
547 if ( *s == 0 || *s ==
',' || *s ==
')' ) {
548 AC.mparallelflag &= ~NOPARALLEL_USER;
551 MesPrint(
"@Parallel should not have extra parameters");
560int DoModSum(UBYTE *s)
562 while ( *s ==
',' ) s++;
564 MesPrint(
"@Module Sum should mention which $-variables");
567 s = DoModDollar(s,MODSUM);
568 if ( s && *s != 0 && *s !=
')' ) {
569 MesPrint(
"@Irregular end of Sum option of Module statement");
580int DoModMax(UBYTE *s)
582 while ( *s ==
',' ) s++;
584 MesPrint(
"@Module Maximum should mention which $-variables");
587 s = DoModDollar(s,MODMAX);
588 if ( s && *s != 0 ) {
589 MesPrint(
"@Irregular end of Maximum option of Module statement");
600int DoModMin(UBYTE *s)
602 while ( *s ==
',' ) s++;
604 MesPrint(
"@Module Minimum should mention which $-variables");
607 s = DoModDollar(s,MODMIN);
608 if ( s && *s != 0 ) {
609 MesPrint(
"@Irregular end of Minimum option of Module statement");
620int DoModLocal(UBYTE *s)
622 while ( *s ==
',' ) s++;
624 MesPrint(
"@ModuleOption Local should mention which $-variables");
627 s = DoModDollar(s,MODLOCAL);
628 if ( s && *s != 0 ) {
629 MesPrint(
"@Irregular end of Local option of ModuleOption statement");
640int DoProcessBucket(UBYTE *s)
643 while ( *s ==
',' || *s ==
'=' ) s++;
645 if ( *s && *s !=
' ' && *s !=
'\t' ) {
646 MesPrint(
"&Numerical value expected for ProcessBucketSize");
649 AC.mProcessBucketSize = x;
658UBYTE * DoModDollar(UBYTE *s,
int type)
664 while ( *s ==
'$' ) {
671 if ( FG.cTable[*s] == 0 ) {
672 while ( FG.cTable[*s] == 0 || FG.cTable[*s] == 1 ) s++;
674 number = GetDollar(name);
677 number = AddDollar(s,0,0,0);
678 s1 = strDup1((UBYTE *)
"Undefined $-variable in module option; option ignored: $",
"Undefined $-variable in ModuleOption");
679 s1 = AddToString(s1,name,0);
681 M_free(s1,
"Undefined $-variable in ModuleOption");
683 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
684 if ( number == ModOptdollars[nummodopt].number && type != ModOptdollars[nummodopt].type ) {
686 s1 = strDup1((UBYTE *)
"Conflicting module options for $-variable; later option ignored: $",
"Conflicting $-variable in ModuleOption");
687 s1 = AddToString(s1,name,0);
689 M_free(s1,
"Conflicting $-variable in ModuleOption");
697 if ( type == MODLOCAL ) {
700 md->dstruct = (
DOLLARS)Malloc1(
701 sizeof(
struct DoLlArS)*AM.totalnumberofthreads,
"Local DOLLARS");
707 dglobal = Dollars + number;
708 for ( j = 0; j < AM.totalnumberofthreads; j++ ) {
709 dlocal = md->dstruct + j;
710 dlocal->index = dglobal->index;
711 dlocal->node = dglobal->node;
712 dlocal->type = dglobal->type;
713 dlocal->name = dglobal->name;
714 dlocal->size = dglobal->size;
715 dlocal->where = dglobal->where;
716 if ( dlocal->size > 0 ) {
717 dlocal->where = (WORD *)Malloc1((dlocal->size+1)*
sizeof(WORD),
"Local dollar value");
718 for ( i = 0; i < dlocal->size; i++ )
719 dlocal->where[i] = dglobal->where[i];
720 dlocal->where[dlocal->size] = 0;
722 INIRECLOCK(dlocal->pthreadslock);
723 dlocal->nfactors = dglobal->nfactors;
724 if ( dglobal->nfactors > 1 ) {
727 dlocal->factors = (
FACDOLLAR *)Malloc1(dglobal->nfactors*
sizeof(
FACDOLLAR),
"Dollar factors");
728 for ( i = 0; i < dglobal->nfactors; i++ ) {
729 nsize = dglobal->factors[i].size;
730 dlocal->factors[i].type = DOLUNDEFINED;
731 dlocal->factors[i].value = dglobal->factors[i].value;
732 if ( ( dlocal->factors[i].size = nsize ) > 0 ) {
733 dlocal->factors[i].where = t = (WORD *)Malloc1(
sizeof(WORD)*(nsize+1),
"DollarCopyFactor");
734 m = dglobal->factors[i].where;
739 dlocal->factors[i].where = 0;
743 else { dlocal->factors = 0; }
753 MesPrint(
"&Illegal name for $-variable in module option");
754 while ( *s !=
',' && *s != 0 && *s !=
')' ) s++;
756 while ( *s ==
',' ) s++;
773int DoinParallel(UBYTE *s)
775 return(DoInParallel(s,1));
783int DonotinParallel(UBYTE *s)
785 return(DoInParallel(s,0));
795int DoExecStatement(
void)
799 if ( system((
char *)(AP.preStart)) )
return(-1);
802 Error0(
"External programs not implemented on this computer/system");
812int DoPipeStatement(
void)
816 if ( OpenStream(AP.preStart,PIPESTREAM,0,PRENOACTION) == 0 )
return(-1);
819 Error0(
"Pipes not implemented on this computer/system");
UBYTE * SkipAName(UBYTE *s)
UBYTE * EndOfToken(UBYTE *)