Compiler: Increase the maximum number of array dimension (#584)
* Compiler: Increase the maximum number of array dimension to 4 * Compiler: Fix array initialization
This commit is contained in:
parent
7f7d01fb8d
commit
fb615aaef1
|
@ -54,7 +54,7 @@
|
||||||
#define CTRL_CHAR '^' /* default control character */
|
#define CTRL_CHAR '^' /* default control character */
|
||||||
#define sCHARBITS 8 /* size of a packed character */
|
#define sCHARBITS 8 /* size of a packed character */
|
||||||
|
|
||||||
#define sDIMEN_MAX 3 /* maximum number of array dimensions */
|
#define sDIMEN_MAX 4 /* maximum number of array dimensions */
|
||||||
#define sLINEMAX 4095 /* input line length (in characters) */
|
#define sLINEMAX 4095 /* input line length (in characters) */
|
||||||
#define sCOMP_STACK 32 /* maximum nesting of #if .. #endif sections */
|
#define sCOMP_STACK 32 /* maximum nesting of #if .. #endif sections */
|
||||||
#define sDEF_LITMAX 500 /* initial size of the literal pool, in "cells" */
|
#define sDEF_LITMAX 500 /* initial size of the literal pool, in "cells" */
|
||||||
|
|
|
@ -2170,53 +2170,48 @@ static cell calc_arraysize(int dim[],int numdim,int cur)
|
||||||
return dim[cur]+(dim[cur]*calc_arraysize(dim,numdim,cur+1));
|
return dim[cur]+(dim[cur]*calc_arraysize(dim,numdim,cur+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell adjust_indirectiontables(int dim[],int numdim,int cur,cell increment,
|
static void adjust_indirectiontables(int dim[],int numdim,int startlit,
|
||||||
int startlit,constvalue *lastdim,int *skipdim)
|
constvalue *lastdim,int *skipdim)
|
||||||
{
|
{
|
||||||
static int base;
|
static int base;
|
||||||
int d;
|
int cur;
|
||||||
|
int i,d;
|
||||||
cell accum;
|
cell accum;
|
||||||
|
cell size;
|
||||||
|
|
||||||
assert(cur>=0 && cur<numdim);
|
assert(startlit==-1 || startlit>=0 && startlit<=litidx);
|
||||||
assert(increment>=0);
|
base=startlit;
|
||||||
assert(cur>0 && startlit==-1 || startlit>=0 && startlit<=litidx);
|
size=1;
|
||||||
if (cur==0)
|
for (cur=0; cur<numdim-1; cur++) {
|
||||||
base=startlit;
|
/* 2 or more dimensions left, fill in an indirection vector */
|
||||||
if (cur==numdim-1)
|
if (dim[cur+1]>0) {
|
||||||
return 0;
|
for (i=0; i<size; i++)
|
||||||
/* 2 or more dimensions left, fill in an indirection vector */
|
for (d=0; d<dim[cur]; d++)
|
||||||
assert(dim[cur]>0);
|
litq[base++]=(size*dim[cur]+(dim[cur+1]-1)*(dim[cur]*i+d)) * sizeof(cell);
|
||||||
if (dim[cur+1]>0) {
|
} else {
|
||||||
for (d=0; d<dim[cur]; d++)
|
/* final dimension is variable length */
|
||||||
litq[base++]=(dim[cur]+d*(dim[cur+1]-1)+increment) * sizeof(cell);
|
constvalue *ld;
|
||||||
accum=dim[cur]*(dim[cur+1]-1);
|
assert(dim[cur+1]==0);
|
||||||
} else {
|
assert(lastdim!=NULL);
|
||||||
/* final dimension is variable length */
|
assert(skipdim!=NULL);
|
||||||
constvalue *ld;
|
accum=0;
|
||||||
assert(dim[cur+1]==0);
|
for (i=0; i<size; i++) {
|
||||||
assert(lastdim!=NULL);
|
/* skip the final dimension sizes for all earlier major dimensions */
|
||||||
assert(skipdim!=NULL);
|
for (d=0,ld=lastdim->next; d<*skipdim; d++,ld=ld->next) {
|
||||||
accum=0;
|
assert(ld!=NULL);
|
||||||
/* skip the final dimension sizes for all earlier major dimensions */
|
} /* for */
|
||||||
for (d=0,ld=lastdim->next; d<*skipdim; d++,ld=ld->next) {
|
for (d=0; d<dim[cur]; d++) {
|
||||||
assert(ld!=NULL);
|
assert(ld!=NULL);
|
||||||
} /* for */
|
assert(strtol(ld->name,NULL,16)==d);
|
||||||
for (d=0; d<dim[cur]; d++) {
|
litq[base++]=(size*dim[cur]+accum) * sizeof(cell);
|
||||||
assert(ld!=NULL);
|
accum+=ld->value-1;
|
||||||
assert(strtol(ld->name,NULL,16)==d);
|
*skipdim+=1;
|
||||||
litq[base++]=(dim[cur]+accum+increment) * sizeof(cell);
|
ld=ld->next;
|
||||||
accum+=ld->value-1;
|
} /* for */
|
||||||
*skipdim+=1;
|
} /* for */
|
||||||
ld=ld->next;
|
} /* if */
|
||||||
} /* for */
|
size*=dim[cur];
|
||||||
} /* if */
|
} /* for */
|
||||||
/* create the indirection tables for the lower level */
|
|
||||||
if (cur+2<numdim) { /* are there at least 2 dimensions below this one? */
|
|
||||||
increment+=(dim[cur]-1)*dim[cur+1]; /* this many indirection tables follow */
|
|
||||||
for (d=0; d<dim[cur]; d++)
|
|
||||||
increment+=adjust_indirectiontables(dim,numdim,cur+1,increment,-1,lastdim,skipdim);
|
|
||||||
} /* if */
|
|
||||||
return accum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initials
|
/* initials
|
||||||
|
@ -2274,7 +2269,7 @@ static void initials2(int ident,int tag,cell *size,int dim[],int numdim,
|
||||||
for (tablesize=calc_arraysize(dim,numdim-1,0); tablesize>0; tablesize--)
|
for (tablesize=calc_arraysize(dim,numdim-1,0); tablesize>0; tablesize--)
|
||||||
litadd(0);
|
litadd(0);
|
||||||
if (dim[numdim-1]!=0) /* error 9 has already been given */
|
if (dim[numdim-1]!=0) /* error 9 has already been given */
|
||||||
adjust_indirectiontables(dim,numdim,0,0,curlit,NULL,NULL);
|
adjust_indirectiontables(dim,numdim,curlit,NULL,NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
return;
|
return;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -2340,7 +2335,7 @@ static void initials2(int ident,int tag,cell *size,int dim[],int numdim,
|
||||||
* of the array and we can properly adjust the indirection vectors
|
* of the array and we can properly adjust the indirection vectors
|
||||||
*/
|
*/
|
||||||
if (err==0)
|
if (err==0)
|
||||||
adjust_indirectiontables(dim,numdim,0,0,curlit,&lastdim,&skipdim);
|
adjust_indirectiontables(dim,numdim,curlit,&lastdim,&skipdim);
|
||||||
delete_consttable(&lastdim); /* clear list of minor dimension sizes */
|
delete_consttable(&lastdim); /* clear list of minor dimension sizes */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user