54 static KEYWORD ModuleWords[] = {
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}
62 static 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}
76 int 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)
85 t = EndOfToken(s); c = *t; *t = 0;
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");
143 int CoModuleOption(UBYTE *s)
147 int error = 0, polyflag = 0;
148 AC.origin = FROMMODULEOPTION;
153 option = FindKeyWord(s,ModuleOptions,
154 sizeof(ModuleOptions)/
sizeof(KEYWORD));
157 *t = c; t++; s = SkipAName(t);
162 MesPrint(
"@Unrecognized module option: %s",s);
171 if ( (option->func)(t) ) error = 1;
173 if ( StrCmp((UBYTE *)(option->name),(UBYTE *)("polyfun")) == 0
174 || StrCmp((UBYTE *)(option->name),(UBYTE *)("polyratfun")) == 0 ) {
178 if ( option->flags > 0 )
return(error);
182 while ( *tt ==
',' ) tt++;
183 if ( *tt !=
'$' )
break;
186 if ( *t ==
')' )
break;
187 if ( *t ==
'(' ) SKIPBRA3(t)
188 else if ( *t == '{
' ) SKIPBRA2(t) 189 else if ( *t == '[
' ) SKIPBRA1(t) 193 } while ( *s == ',
' ); 195 MesPrint("@Unrecognized module option: %s",s); 205 To be called from a .instruction. 206 Only recognizes polyfun. The newer ones should be via the 207 ModuleOption statement. 210 int CoModOption(UBYTE *s) 214 AC.origin = FROMPOINTINSTRUCTION; 219 if ( StrICmp(s,(UBYTE *)"polyfun") == 0 ) { 222 if ( DoPolyfun(t) ) error = 1; 224 else if ( StrICmp(s,(UBYTE *)"polyratfun") == 0 ) { 227 if ( DoPolyratfun(t) ) error = 1; 230 MesPrint("@Unrecognized module option in .instruction: %s",s); 235 if ( *t == ',
' || *t == ')
' ) break; 236 if ( *t == '(
' ) SKIPBRA3(t) 237 else if ( *t == '{
' ) SKIPBRA2(t) 238 else if ( *t == '[
' ) SKIPBRA1(t) 242 } while ( *s == ',
' ); 244 MesPrint("@Unrecognized module option in .instruction: %s",s); 255 VOID SetSpecialMode(int moduletype, int specialtype) 257 DUMMYUSE(moduletype); DUMMYUSE(specialtype); 272 int ExecModule(int moduletype) 274 return(DoExecute(moduletype,0)); 291 Remark 27-oct-2005 by JV 292 This routine (and CleanUp in startup.c) may still need some work: 293 What to do with preprocessor variables 294 What to do with files we write to 301 while ( AC.CurrentStream->previous >= 0 ) 302 AC.CurrentStream = CloseStream(AC.CurrentStream); 303 AP.PreSwitchLevel = AP.PreIfLevel = 0; 305 for ( j = NumProcedures-1; j >= 0; j-- ) { 306 if ( Procedures[j].name ) M_free(Procedures[j].name,"name of procedure"); 307 if ( Procedures[j].p.buffer ) M_free(Procedures[j].p.buffer,"buffer of procedure"); 311 while ( NumPre > AP.gNumPre ) { 313 M_free(PreVar[NumPre].name,"PreVar[NumPre].name"); 314 PreVar[NumPre].name = PreVar[NumPre].value = 0; 318 for ( j = 0; j < NumExpressions; j++ ) { 319 AC.exprnames->namenode[Expressions[j].node].type = CDELETE; 323 CompactifyTree(AC.exprnames,EXPRNAMES); 325 for ( j = AO.NumDictionaries-1; j >= 0; j-- ) { 326 RemoveDictionary(AO.Dictionaries[j]); 327 M_free(AO.Dictionaries[j],"Dictionary"); 329 AO.NumDictionaries = AO.gNumDictionaries = 0; 330 M_free(AO.Dictionaries,"Dictionaries"); 332 AO.SizeDictionaries = 0; 333 AP.OpenDictionary = 0; 334 AO.CurrentDictionary = 0; 336 AP.ComChar = AP.cComChar; 337 if ( AP.procedureExtension ) M_free(AP.procedureExtension,"procedureextension"); 338 AP.procedureExtension = strDup1(AP.cprocedureExtension,"procedureextension"); 340 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag; 341 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols; 342 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] = 'Z
'; 343 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0; 344 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers; 345 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace; 346 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats; 347 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag; 348 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats; 349 AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag; 350 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag; 351 if ( AC.ThreadsFlag && AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1; 352 AC.ThreadBucketSize = AM.gThreadBucketSize = AM.ggThreadBucketSize; 353 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing; 354 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch; 355 AC.ShortStatsMax = AM.gShortStatsMax = AM.ggShortStatsMax; 356 AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0; 359 if ( DeleteStore(0) < 0 ) { 360 MesPrint("@Cannot restart the storage file"); 374 int DoPolyfun(UBYTE *s) 378 WORD funnum, eqsign = 0; 379 if ( AC.origin == FROMPOINTINSTRUCTION ) { 380 if ( *s == 0 || *s == ',
' || *s == ')
' ) { 381 AR.PolyFun = 0; AR.PolyFunType = 0; 385 MesPrint("@Proper use in point instructions is: PolyFun[=functionname]"); 392 AR.PolyFun = 0; AR.PolyFunType = 0; 395 if ( *s != '=
' && *s != ',
' ) { 396 MesPrint("@Proper use is: PolyFun[{ ,=}functionname]"); 399 if ( *s == '=
' ) eqsign = 1; 406 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) { 407 if ( AC.origin != FROMPOINTINSTRUCTION && eqsign == 0 ) { 408 AR.PolyFun = 0; AR.PolyFunType = 0; 411 MesPrint("@ %s is not a properly declared function",s); 415 if ( functions[funnum].spec != 0 || functions[funnum].commute != 0 ) { 416 MesPrint("@The PolyFun must be a regular commuting function!"); 420 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 1; 423 if ( *t && *t != ',
' && *t != ')
' ) { 425 MesPrint("@Improper ending of end-of-module instruction: %s",s); 437 int DoPolyratfun(UBYTE *s) 442 if ( AC.origin == FROMPOINTINSTRUCTION ) { 443 if ( *s == 0 || *s == ',
' || *s == ')
' ) { 444 AR.PolyFun = 0; AR.PolyFunType = 0; AR.PolyFunInv = 0; AR.PolyFunExp = 0; 448 MesPrint("@Proper use in point instructions is: PolyRatFun[=functionname[+functionname]]"); 454 AR.PolyFun = 0; AR.PolyFunType = 0; AR.PolyFunInv = 0; AR.PolyFunExp = 0; 457 if ( *s != '=
' && *s != ',
' ) { 458 MesPrint("@Proper use is: PolyRatFun[{ ,=}functionname[+functionname]]"); 467 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) { 469 MesPrint("@ %s is not a properly declared function",s); 473 if ( functions[funnum].spec != 0 || functions[funnum].commute != 0 ) { 475 MesPrint("@The PolyRatFun must be a regular commuting function!"); 479 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 2; 482 AC.PolyRatFunChanged = 1; 488 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) goto Error1; 489 if ( functions[funnum].spec != 0 || functions[funnum].commute != 0 ) goto Error2; 490 AR.PolyFunInv = funnum+FUNCTION; 494 if ( *t && *t != ',
' && *t != ')
' ) { 496 MesPrint("@Improper ending of end-of-module instruction: %s",s); 508 int DoNoParallel(UBYTE *s) 510 if ( *s == 0 || *s == ',
' || *s == ')
' ) { 511 AC.mparallelflag |= NOPARALLEL_USER; 514 MesPrint("@NoParallel should not have extra parameters"); 523 int DoParallel(UBYTE *s) 525 if ( *s == 0 || *s == ',
' || *s == ')
' ) { 526 AC.mparallelflag &= ~NOPARALLEL_USER; 529 MesPrint("@Parallel should not have extra parameters"); 538 int DoModSum(UBYTE *s) 540 while ( *s == ',
' ) s++; 542 MesPrint("@Module Sum should mention which $-variables"); 545 s = DoModDollar(s,MODSUM); 546 if ( s && *s != 0 && *s != ')
' ) { 547 MesPrint("@Irregular end of Sum option of Module statement"); 558 int DoModMax(UBYTE *s) 560 while ( *s == ',
' ) s++; 562 MesPrint("@Module Maximum should mention which $-variables"); 565 s = DoModDollar(s,MODMAX); 566 if ( s && *s != 0 ) { 567 MesPrint("@Irregular end of Maximum option of Module statement"); 578 int DoModMin(UBYTE *s) 580 while ( *s == ',
' ) s++; 582 MesPrint("@Module Minimum should mention which $-variables"); 585 s = DoModDollar(s,MODMIN); 586 if ( s && *s != 0 ) { 587 MesPrint("@Irregular end of Minimum option of Module statement"); 598 int DoModLocal(UBYTE *s) 600 while ( *s == ',
' ) s++; 602 MesPrint("@ModuleOption Local should mention which $-variables"); 605 s = DoModDollar(s,MODLOCAL); 606 if ( s && *s != 0 ) { 607 MesPrint("@Irregular end of Local option of ModuleOption statement"); 618 int DoProcessBucket(UBYTE *s) 621 while ( *s == ',
' || *s == '=
' ) s++; 623 if ( *s && *s != ' ' && *s != '\t
' ) { 624 MesPrint("&Numerical value expected for ProcessBucketSize"); 627 AC.mProcessBucketSize = x; 636 UBYTE * DoModDollar(UBYTE *s, int type) 641 while ( *s == '$
' ) { 643 Read the name of the dollar 648 if ( FG.cTable[*s] == 0 ) { 649 while ( FG.cTable[*s] == 0 || FG.cTable[*s] == 1 ) s++; 651 number = GetDollar(name); 653 number = AddDollar(s,0,0,0); 654 Warning("&Undefined $-variable in module statement"); 656 md = (MODOPTDOLLAR *)FromList(&AC.ModOptDolList); 660 if ( type == MODLOCAL ) { 662 DOLLARS dglobal, dlocal; 663 md->dstruct = (DOLLARS)Malloc1( 664 sizeof(struct DoLlArS)*AM.totalnumberofthreads,"Local DOLLARS"); 666 Now copy the global dollar into the local copies. 667 This can be nontrivial if the value needs an allocation. 668 We don't really need the locks.
670 dglobal = Dollars + number;
671 for ( j = 0; j < AM.totalnumberofthreads; j++ ) {
672 dlocal = md->dstruct + j;
673 dlocal->index = dglobal->index;
674 dlocal->node = dglobal->node;
675 dlocal->type = dglobal->type;
676 dlocal->name = dglobal->name;
677 dlocal->size = dglobal->size;
678 dlocal->where = dglobal->where;
679 if ( dlocal->size > 0 ) {
680 dlocal->where = (WORD *)Malloc1((dlocal->size+1)*
sizeof(WORD),
"Local dollar value");
681 for ( i = 0; i < dlocal->size; i++ )
682 dlocal->where[i] = dglobal->where[i];
683 dlocal->where[dlocal->size] = 0;
685 dlocal->pthreadslockread = dummylock;
686 dlocal->pthreadslockwrite = dummylock;
687 dlocal->nfactors = dglobal->nfactors;
688 if ( dglobal->nfactors > 1 ) {
691 dlocal->factors = (
FACDOLLAR *)Malloc1(dglobal->nfactors*
sizeof(
FACDOLLAR),
"Dollar factors");
692 for ( i = 0; i < dglobal->nfactors; i++ ) {
693 nsize = dglobal->factors[i].size;
694 dlocal->factors[i].type = DOLUNDEFINED;
695 dlocal->factors[i].value = dglobal->factors[i].value;
696 if ( ( dlocal->factors[i].size = nsize ) > 0 ) {
697 dlocal->factors[i].where = t = (WORD *)Malloc1(
sizeof(WORD)*(nsize+1),
"DollarCopyFactor");
698 m = dglobal->factors[i].where;
703 dlocal->factors[i].where = 0;
707 else { dlocal->factors = 0; }
717 MesPrint(
"&Illegal name for $-variable in module option");
718 while ( *s !=
',' && *s != 0 && *s !=
')' ) s++;
720 while ( *s ==
',' ) s++;
737 int DoinParallel(UBYTE *s)
739 return(DoInParallel(s,1));
747 int DonotinParallel(UBYTE *s)
749 return(DoInParallel(s,0));
759 int DoExecStatement()
763 if ( system((
char *)(AP.preStart)) )
return(-1);
766 Error0(
"External programs not implemented on this computer/system");
776 int DoPipeStatement()
780 if ( OpenStream(AP.preStart,PIPESTREAM,0,PRENOACTION) == 0 )
return(-1);
783 Error0(
"Pipes not implemented on this computer/system");