Fix for generating incorrect code for accessing arrays with three or more dimensions.

SVN r15 (trunk)
This commit is contained in:
Randy Heit 2006-02-25 03:54:30 +00:00
parent 56f3ff15d8
commit 23b23f3950
3 changed files with 12 additions and 8 deletions

View file

@ -16,7 +16,7 @@ endif
CFLAGS = -Os -Wall -W -march=pentium -mtune=athlon-4 -fomit-frame-pointer CFLAGS = -Os -Wall -W -march=pentium -mtune=athlon-4 -fomit-frame-pointer
LDFLAGS = -s LDFLAGS = -s
VERNUM = 136 VERNUM = 137
OBJS = \ OBJS = \
acc.o \ acc.o \

2
acc.c
View file

@ -22,7 +22,7 @@
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
#define VERSION_TEXT "1.36" #define VERSION_TEXT "1.37"
#define COPYRIGHT_YEARS_TEXT "1995" #define COPYRIGHT_YEARS_TEXT "1995"
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------

16
parse.c
View file

@ -882,7 +882,7 @@ static void OuterFunction(void)
static void OuterMapVar(boolean local) static void OuterMapVar(boolean local)
{ {
symbolNode_t *sym = NULL; symbolNode_t *sym = NULL;
int index; int index, i;
MS_Message(MSG_DEBUG, "---- %s ----\n", local ? "LeadingStaticVarDeclare" : "OuterMapVar"); MS_Message(MSG_DEBUG, "---- %s ----\n", local ? "LeadingStaticVarDeclare" : "OuterMapVar");
do do
@ -993,8 +993,6 @@ static void OuterMapVar(boolean local)
sym->info.array.size = size; sym->info.array.size = size;
if(ndim > 0) if(ndim > 0)
{ {
int i;
sym->info.array.dimensions[ndim-1] = 1; sym->info.array.dimensions[ndim-1] = 1;
for(i = ndim - 2; i >= 0; --i) for(i = ndim - 2; i >= 0; --i)
{ {
@ -1002,6 +1000,12 @@ static void OuterMapVar(boolean local)
sym->info.array.dimensions[i+1] * dims[i+1]; sym->info.array.dimensions[i+1] * dims[i+1];
} }
} }
MS_Message(MSG_DEBUG, " - with multipliers ");
for(i = 0; i < ndim; ++i)
{
MS_Message(MSG_DEBUG, "[%d]", sym->info.array.dimensions[i]);
}
MS_Message(MSG_DEBUG, "\n");
if(tk_Token == TK_ASSIGN) if(tk_Token == TK_ASSIGN)
{ {
InitializeArray(sym, dims, size); InitializeArray(sym, dims, size);
@ -3693,12 +3697,12 @@ static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices)
} }
} }
} }
if(i > 0) EvalExpression();
if(i < sym->info.array.ndim - 1)
{ {
PC_AppendPushVal(sym->info.array.dimensions[i-1]); PC_AppendPushVal(sym->info.array.dimensions[i]);
PC_AppendCmd(PCD_MULTIPLY); PC_AppendCmd(PCD_MULTIPLY);
} }
EvalExpression();
if(i > 0) if(i > 0)
{ {
PC_AppendCmd(PCD_ADD); PC_AppendCmd(PCD_ADD);