Skip to content

Commit

Permalink
Added id,all
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaseren committed Apr 11, 2016
1 parent 66a04da commit 00e5dd9
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 84 deletions.
4 changes: 2 additions & 2 deletions sources/argument.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
level = C->lhs[level][2];
goto SkipCount;
}
Note that there will be cases that extra space is needed.
Note that there will be cases in which extra space is needed.
In addition the compare with C->numlhs isn't very fine, because we
need to insert a different value (C->lhs[level][2]).
*/
Expand Down Expand Up @@ -1561,7 +1561,7 @@ nextterm: mm = mnext;
}
}
/*
#] Numerical factor :
#] Numerical factor :
*/
else {
oneterm:;
Expand Down
60 changes: 56 additions & 4 deletions sources/comexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ static struct id_options {
,{(UBYTE *)"ifnotmatch", SUBAFTERNOT ,0}
,{(UBYTE *)"disorder", SUBDISORDER ,0}
,{(UBYTE *)"select", SUBSELECT ,0}
,{(UBYTE *)"all", SUBALL ,0}
};

/*
#] Includes :
#] Includes :
#[ CoLocal :
*/

Expand Down Expand Up @@ -496,7 +497,7 @@ int CoIdExpression(UBYTE *inp, int type)
oldnumrhs, *ow, oldEside;
UBYTE *p, *pp, c;
CBUF *C = cbuf+AC.cbufnum;
LONG oldcpointer;
LONG oldcpointer, x;
FirstWork = OldWork = AT.WorkPointer;
/*
Don't forget to change in StudyPattern if we change/add_to the
Expand Down Expand Up @@ -669,6 +670,45 @@ findsets:;
OldWork[3] = GetLabel(inp);
*p++ = c; inp = p;
break;
case SUBALL:
x = 0;
if ( *pp == '(' ) {
while ( *inp >= '0' && *inp <= '9' ) x = 10*x+*inp++ - '0';
if ( *inp != ')' || inp+1 != p ) {
c = *p; *p = 0;
MesPrint("&Illegal ALL option in id-statement: ",pp);
*p++ = c;
error = 1;
continue;
}
pp = inp;
inp = pp+1;
}
/*
Note that the following statement limits x to
*/
if ( x > MAXPOSITIVE ) {
MesPrint("&Requested maximum number of matches %l in ALL option in id-statement is greater than %l ",x,MAXPOSITIVE);
error = 1;
}
OldWork[3] = x;
if ( type != TYPEIDNEW ) {
if ( type == TYPEIDOLD ) {
MesPrint("&Requested ALL option not allowed in idold/also statement.");
error = 1;
}
else if ( type == TYPEIF ) {
MesPrint("&Requested ALL option not allowed in if(match())");
error = 1;
}
else {
MesPrint("&ALL option only allowed in regular id-statement.");
error = 1;
}
}
p++; inp = p;
AC.idoption = opt;
break;
default:
if ( pp != p ) {
IllField: c = *p; *p = 0;
Expand Down Expand Up @@ -810,7 +850,7 @@ IllLeft:MesPrint("&Illegal LHS");
error = 1;
}
AC.DumNum = AM.IndDum;
OldWork[2] = ( OldWork[2] - ( OldWork[2] & SUBMASK ) ) | SUBALL;
OldWork[2] = ( OldWork[2] - ( OldWork[2] & SUBMASK ) ) | SUBVECTOR;
c1 = w[3];
/* We overwrite the LHS */
*w++ = INDTOIND;
Expand Down Expand Up @@ -920,14 +960,26 @@ IllLeft:MesPrint("&Illegal LHS");
Actual adding happens only now after numrhs insertion
*/
/* if ( !error ) */ { AddNtoL(OldWork[1],OldWork); }
if ( type == TYPEIDOLD ) {
if ( C->numlhs <= 1 ||
( C->lhs[C->numlhs-1][0] != TYPEIDNEW &&
C->lhs[C->numlhs-1][0] != TYPEIDOLD ) ) {
MesPrint("&Idold/also should follow an id/idnew statement.");
error = 1;
}
else if ( (C->lhs[C->numlhs-1][2] & SUBMASK) == SUBALL ) {
MesPrint("&Idold/also cannot follow an id,all statement.");
error = 1;
}
}
AllDone:
AC.lhdollarflag = 0;
AT.WorkPointer = FirstWork;
return(error);
}

/*
#] CoIdExpression :
#] CoIdExpression :
#[ CoMultiply :
*/

Expand Down
16 changes: 8 additions & 8 deletions sources/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ int CompileSubExpressions(SBYTE *tokens)
this minimum. Ignoring this might lead to really rare and
hard to find errors, years from now.
*/
if ( insubexpbuffers >= 0x3FFFFFL ) {
MesPrint("&More than 2^22 subexpressions inside one expression");
if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
Terminate(-1);
}
if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
Expand Down Expand Up @@ -1910,8 +1910,8 @@ int CodeFactors(SBYTE *tokens)
|| t[-1] == TSETCLOSE || t[-1] == TFUNCLOSE ) {
subexp = CodeGenerator(tokens);
if ( subexp < 0 ) error = -1;
if ( insubexpbuffers >= 0x3FFFFFL ) {
MesPrint("&More than 2^22 subexpressions inside one expression");
if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
Terminate(-1);
}
if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
Expand Down Expand Up @@ -2151,8 +2151,8 @@ int CodeFactors(SBYTE *tokens)
e->vflags |= ISFACTORIZED;
subexp = CodeGenerator(outtokens);
if ( subexp < 0 ) error = -1;
if ( insubexpbuffers >= 0x3FFFFFL ) {
MesPrint("&More than 2^22 subexpressions inside one expression");
if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
Terminate(-1);
}
if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
Expand Down Expand Up @@ -2198,8 +2198,8 @@ WORD GenerateFactors(WORD n,WORD inc)
subexp = CodeGenerator(tokenbuffer);
if ( subexp < 0 ) error = -1;
M_free(tokenbuffer,"GenerateFactors");
if ( insubexpbuffers >= 0x3FFFFFL ) {
MesPrint("&More than 2^22 subexpressions inside one expression");
if ( insubexpbuffers >= MAXSUBEXPRESSIONS ) {
MesPrint("&More than %d subexpressions inside one expression",(WORD)MAXSUBEXPRESSIONS);
Terminate(-1);
}
if ( subexpbuffers+insubexpbuffers >= topsubexpbuffers ) {
Expand Down
5 changes: 5 additions & 0 deletions sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ extern DOLLARS DolToTerms(PHEAD WORD);
extern WORD EvalDoLoopArg(PHEAD WORD *,WORD);
extern int SetExprCases(int,int,int);
extern int TestSelect(WORD *,WORD *);
extern VOID SubsInAll(PHEAD0);
extern VOID TransferBuffer(int,int,int);
extern int TakeIDfunction(PHEAD WORD *);
extern int MakeSetupAllocs(VOID);
extern int TryFileSetups(VOID);
Expand Down Expand Up @@ -1504,6 +1506,9 @@ extern VOID AddToSymbolList(PHEAD WORD);
extern int AddToListPoly(PHEAD0);
extern int InvPoly(PHEAD WORD *,WORD,WORD);

extern int ReadFromScratch(FILEHANDLE *,POSITION *,UBYTE *,POSITION *);
extern int AddToScratch(FILEHANDLE *,POSITION *,UBYTE *,POSITION *,int);

/*
#] Declarations :
*/
Expand Down
45 changes: 23 additions & 22 deletions sources/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
* You should have received a copy of the GNU General Public License along
* with FORM. If not, see <http://www.gnu.org/licenses/>.
*/
/* #] License : */
/* #] License : */
/*
#[ Includes : execute.c
*/

#include "form3.h"

/*
#] Includes :
#] Includes :
#[ DoExecute :
#[ CleanExpr :
Expand Down Expand Up @@ -196,7 +196,7 @@ WORD CleanExpr(WORD par)
}

/*
#] CleanExpr :
#] CleanExpr :
#[ PopVariables :
Pops the local variables from the tables.
Expand Down Expand Up @@ -366,7 +366,7 @@ WORD PopVariables()
}

/*
#] PopVariables :
#] PopVariables :
#[ MakeGlobal :
*/

Expand Down Expand Up @@ -462,7 +462,7 @@ VOID MakeGlobal()
}

/*
#] MakeGlobal :
#] MakeGlobal :
#[ TestDrop :
*/

Expand Down Expand Up @@ -532,14 +532,15 @@ VOID TestDrop()
break;
default:
ClearBracketIndex(j);
e->bracketinfo = 0;
break;
}
if ( e->replace == NEWLYDEFINEDEXPRESSION ) e->replace = REGULAREXPRESSION;
}
}

/*
#] TestDrop :
#] TestDrop :
#[ PutInVflags :
*/

Expand Down Expand Up @@ -587,7 +588,7 @@ restart:;
}

/*
#] PutInVflags :
#] PutInVflags :
#[ DoExecute :
*/

Expand Down Expand Up @@ -976,7 +977,7 @@ WORD DoExecute(WORD par, WORD skip)
}

/*
#] DoExecute :
#] DoExecute :
#[ PutBracket :
Routine uses the bracket info to split a term into two pieces:
Expand Down Expand Up @@ -1281,7 +1282,7 @@ nextdot:;
}

/*
#] PutBracket :
#] PutBracket :
#[ SpecialCleanup :
*/

Expand All @@ -1293,7 +1294,7 @@ VOID SpecialCleanup(PHEAD0)
}

/*
#] SpecialCleanup :
#] SpecialCleanup :
#[ SetMods :
*/

Expand All @@ -1311,7 +1312,7 @@ void SetMods()
#endif

/*
#] SetMods :
#] SetMods :
#[ UnSetMods :
*/

Expand All @@ -1326,7 +1327,7 @@ void UnSetMods()
#endif

/*
#] UnSetMods :
#] UnSetMods :
#] DoExecute :
#[ Expressions :
#[ ExchangeExpressions :
Expand Down Expand Up @@ -1402,7 +1403,7 @@ void ExchangeExpressions(int num1, int num2)
}

/*
#] ExchangeExpressions :
#] ExchangeExpressions :
#[ GetFirstBracket :
*/

Expand Down Expand Up @@ -1512,7 +1513,7 @@ int GetFirstBracket(WORD *term, int num)
}

/*
#] GetFirstBracket :
#] GetFirstBracket :
#[ GetFirstTerm :
*/

Expand Down Expand Up @@ -1607,7 +1608,7 @@ int GetFirstTerm(WORD *term, int num)
}

/*
#] GetFirstTerm :
#] GetFirstTerm :
#[ GetContent :
*/

Expand Down Expand Up @@ -1722,7 +1723,7 @@ int GetContent(WORD *content, int num)
}

/*
#] GetContent :
#] GetContent :
#[ CleanupTerm :
Removes noncommuting objects from the term
Expand All @@ -1748,7 +1749,7 @@ int CleanupTerm(WORD *term)
}

/*
#] CleanupTerm :
#] CleanupTerm :
#[ ContentMerge :
*/

Expand Down Expand Up @@ -1968,7 +1969,7 @@ WORD ContentMerge(PHEAD WORD *content, WORD *term)
}

/*
#] ContentMerge :
#] ContentMerge :
#[ TermsInExpression :
*/

Expand All @@ -1980,7 +1981,7 @@ LONG TermsInExpression(WORD num)
}

/*
#] TermsInExpression :
#] TermsInExpression :
#[ UpdatePositions :
*/

Expand Down Expand Up @@ -2031,7 +2032,7 @@ void UpdatePositions()
}

/*
#] UpdatePositions :
#] UpdatePositions :
#[ CountTerms1 : LONG CountTerms1()
Counts the terms in the current deferred bracket
Expand Down Expand Up @@ -2131,7 +2132,7 @@ Thatsit:;
}

/*
#] CountTerms1 :
#] CountTerms1 :
#[ TermsInBracket : LONG TermsInBracket(term,level)
The function TermsInBracket_()
Expand Down Expand Up @@ -2322,7 +2323,7 @@ IllBraReq:;
return(numterms);
}
/*
#] TermsInBracket : LONG TermsInBracket(term,level)
#] TermsInBracket : LONG TermsInBracket(term,level)
#] Expressions :
*/

Loading

0 comments on commit 00e5dd9

Please sign in to comment.