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 542 additions and 56 deletions.
2 changes: 1 addition & 1 deletion 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
56 changes: 54 additions & 2 deletions sources/comexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static struct id_options {
,{(UBYTE *)"ifnotmatch", SUBAFTERNOT ,0}
,{(UBYTE *)"disorder", SUBDISORDER ,0}
,{(UBYTE *)"select", SUBSELECT ,0}
,{(UBYTE *)"all", SUBALL ,0}
};

/*
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,6 +960,18 @@ 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;
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
1 change: 1 addition & 0 deletions sources/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ VOID TestDrop()
break;
default:
ClearBracketIndex(j);
e->bracketinfo = 0;
break;
}
if ( e->replace == NEWLYDEFINEDEXPRESSION ) e->replace = REGULAREXPRESSION;
Expand Down
2 changes: 2 additions & 0 deletions sources/fsizes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define WORKBUFFER 40000000
#define MAXTER 40000
#define HALFMAX 0x10000
#define MAXSUBEXPRESSIONS 0x1FFFFFF
#else
#define MAXPOWER 10000
#define MAXVARIABLES 8050
Expand All @@ -62,6 +63,7 @@
#define WORKBUFFER 10000000
#define MAXTER 10000
#define HALFMAX 0x100
#define MAXSUBEXPRESSIONS 0x3FFF
#endif
#define MAXENAME 16
#define MAXSAVEFUNCTION 16384
Expand Down
3 changes: 2 additions & 1 deletion sources/ftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,9 @@ typedef int (*TFUN1)();
#define SUBONCE 2
#define SUBONLY 3
#define SUBMANY 4
#define SUBALL 5
#define SUBVECTOR 5
#define SUBSELECT 6
#define SUBALL 7
#define SUBMASK 15
#define SUBDISORDER 16
#define SUBAFTER 32
Expand Down
24 changes: 15 additions & 9 deletions sources/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,8 @@ int ChainOut(PHEAD WORD *term, WORD funnum)
The ones with a minus sign in front have been implemented.
There are still a few considerations:
1: the dummy indices should be reset in multiple ?? matches.
2: currently we cannot have a match with multiple ?? if
first there is a match and later the assignment isn't right.
we cannot go back at the moment to continue searching.
Note: the argument wilds allows backtracking when multiple
?a,?b give a match that later turns out to be useless.
*/

WORD MatchFunction(PHEAD WORD *pattern, WORD *interm, WORD *wilds)
Expand Down Expand Up @@ -1761,6 +1758,10 @@ trythis:;
if ( *inter != SUBEXPRESSION && MatchFunction(BHEAD inpat,inter,&wilds) ) {
AN.terfirstcomm = Oterfirstcomm;
if ( wilds ) {
/*
Store wildcards to continue in MatchFunction if the current
wildcards do not work out.
*/
wildargs = AN.WildArgs;
wildeat = AN.WildEat;
for ( i = 0; i < wildargs; i++ ) wildargtaken[i] = AT.WildArgTaken[i];
Expand Down Expand Up @@ -1873,6 +1874,11 @@ trythis:;
AT.WorkPointer = OldWork;
return(0);
OnSuccess:
if ( AT.idallflag ) {
SubsInAll(BHEAD0);
AT.idallnum++;
if ( AT.idallmaxnum == 0 || AT.idallnum < AT.idallmaxnum ) goto NoMat;
}
AN.terfirstcomm = Oterfirstcomm;
AN.SignCheck = oldSignCheck;
/*
Expand All @@ -1888,8 +1894,7 @@ trythis:;
t = AN.terstart + AN.RepFunList[i];
if ( *m != *t ) {
if ( *m > *t ) continue;
jexch: AT.WorkPointer = OldWork;
return(1);
goto doesmatch;
}
if ( *m >= FUNCTION && functions[*m-FUNCTION].spec >=
TENSORFUNCTION ) {
Expand All @@ -1906,15 +1911,16 @@ jexch: AT.WorkPointer = OldWork;
}
while ( k > 0 && kk > 0 ) {
if ( *m < *t ) goto NextFor;
else if ( *m++ > *t++ ) goto jexch;
else if ( *m++ > *t++ ) goto doesmatch;
k--; kk--;
}
if ( k > 0 ) goto jexch;
if ( k > 0 ) goto doesmatch;
NextFor:;
}
SetStop = 1;
goto NoMat;
}
doesmatch:
AT.WorkPointer = OldWork;
return(1);
}
Expand Down
2 changes: 1 addition & 1 deletion sources/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ WORD HowMany(PHEAD WORD *ifcode, WORD *term)
case SUBMULTI :
RetVal = FindMulti(BHEAD term,m);
break;
case SUBALL :
case SUBVECTOR :
RetVal = 0;
for ( i = 0; i < *term; i++ ) ww[i] = term[i];
while ( ( power = FindAll(BHEAD ww,m,AR.Cnumlhs,ifcode) ) != 0 ) { RetVal += power; }
Expand Down

0 comments on commit 00e5dd9

Please sign in to comment.