From fb615aaef10277c85a624c189b36818e36ebfc1d Mon Sep 17 00:00:00 2001 From: Vincent Herbet Date: Sat, 13 Oct 2018 15:05:04 +0200 Subject: [PATCH] Compiler: Increase the maximum number of array dimension (#584) * Compiler: Increase the maximum number of array dimension to 4 * Compiler: Fix array initialization --- compiler/libpc300/sc.h | 2 +- compiler/libpc300/sc1.c | 85 +++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/compiler/libpc300/sc.h b/compiler/libpc300/sc.h index 82a7616d..46107475 100755 --- a/compiler/libpc300/sc.h +++ b/compiler/libpc300/sc.h @@ -54,7 +54,7 @@ #define CTRL_CHAR '^' /* default control 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 sCOMP_STACK 32 /* maximum nesting of #if .. #endif sections */ #define sDEF_LITMAX 500 /* initial size of the literal pool, in "cells" */ diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index 8f5936c9..03d261e3 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -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)); } -static cell adjust_indirectiontables(int dim[],int numdim,int cur,cell increment, - int startlit,constvalue *lastdim,int *skipdim) +static void adjust_indirectiontables(int dim[],int numdim,int startlit, + constvalue *lastdim,int *skipdim) { static int base; - int d; + int cur; + int i,d; cell accum; + cell size; - assert(cur>=0 && cur=0); - assert(cur>0 && startlit==-1 || startlit>=0 && startlit<=litidx); - if (cur==0) - base=startlit; - if (cur==numdim-1) - return 0; - /* 2 or more dimensions left, fill in an indirection vector */ - assert(dim[cur]>0); - if (dim[cur+1]>0) { - for (d=0; dnext; d<*skipdim; d++,ld=ld->next) { - assert(ld!=NULL); - } /* for */ - for (d=0; dname,NULL,16)==d); - litq[base++]=(dim[cur]+accum+increment) * sizeof(cell); - accum+=ld->value-1; - *skipdim+=1; - ld=ld->next; - } /* for */ - } /* if */ - /* create the indirection tables for the lower level */ - if (cur+2=0 && startlit<=litidx); + base=startlit; + size=1; + for (cur=0; cur0) { + for (i=0; inext; d<*skipdim; d++,ld=ld->next) { + assert(ld!=NULL); + } /* for */ + for (d=0; dname,NULL,16)==d); + litq[base++]=(size*dim[cur]+accum) * sizeof(cell); + accum+=ld->value-1; + *skipdim+=1; + ld=ld->next; + } /* for */ + } /* for */ + } /* if */ + size*=dim[cur]; + } /* for */ } /* 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--) litadd(0); 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 */ return; } /* 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 */ 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 */ } /* if */ } /* if */