From 34c711fffde694406a6d29ab56ad97bfd5acf69b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 9 Dec 2006 01:20:33 +0000 Subject: [PATCH] added size adjustment to dynamic strings --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40205 --- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc1.c | 11 ++++++++--- sourcepawn/compiler/sc4.c | 7 +++++++ sourcepawn/compiler/sc6.c | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 7f78fd4a..43d0ae15 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -626,6 +626,7 @@ SC_FUNC void char2addr(void); SC_FUNC void charalign(void); SC_FUNC void addconst(cell value); SC_FUNC void setheap_save(cell value); +SC_FUNC void stradjust(regid reg); /* Code generation functions for arithmetic operators. * diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index d5de9d8c..f221e6fe 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -2241,7 +2241,10 @@ static int declloc(int fstatic) if (numdim == sDIMEN_MAX) { error(53); /* exceeding maximum number of dimensions */ return (all_constant ? iARRAY : iREFARRAY); - } /* if */ + } else if (numdim) { /* if */ + /* If we have a dimension on the stack, push it */ + pushreg(sPRI); + } if (matchtoken(']')) { dim[numdim++] = 0; continue; @@ -2249,9 +2252,7 @@ static int declloc(int fstatic) dim_ident = doexpr2(TRUE,FALSE,FALSE,FALSE,&idxtag[numdim],&dim_sym,0,&dim_val); if (dim_ident == iVARIABLE || dim_ident == iEXPRESSION || dim_ident == iARRAYCELL) { all_constant = 0; - pushreg(sPRI); } else if (dim_ident == iCONSTEXPR) { - pushreg(sPRI); dim[numdim] = dim_val.constval; /* :TODO: :URGENT: Make sure this still works */ if (dim_sym && dim_sym->usage & uENUMROOT) @@ -2275,6 +2276,10 @@ static int declloc(int fstatic) ident = iARRAY; stgdel(_index, _code); } else { + if (tag == pc_tag_string && numdim && dim[numdim-1]) { + stradjust(sPRI); + } + pushreg(sPRI); memset(dim, 0, sizeof(int)*sDIMEN_MAX); ident = iREFARRAY; genarray(numdim, autozero); diff --git a/sourcepawn/compiler/sc4.c b/sourcepawn/compiler/sc4.c index 509b4e06..2f2f51c4 100644 --- a/sourcepawn/compiler/sc4.c +++ b/sourcepawn/compiler/sc4.c @@ -593,6 +593,13 @@ SC_FUNC void fillarray(symbol *sym,cell size,cell value) code_idx+=opcodes(2)+opargs(2); } +SC_FUNC void stradjust(regid reg) +{ + assert(reg==sPRI); + stgwrite("\tstradjust.pri\n"); + code_idx+=opcodes(1); +} + /* Instruction to get an immediate value into the primary or the alternate * register */ diff --git a/sourcepawn/compiler/sc6.c b/sourcepawn/compiler/sc6.c index fc3ae824..011028e4 100644 --- a/sourcepawn/compiler/sc6.c +++ b/sourcepawn/compiler/sc6.c @@ -602,6 +602,7 @@ static OPCODEC opcodelist[] = { { 15, "stor.pri", sIN_CSEG, parm1 }, { 18, "stor.s.alt", sIN_CSEG, parm1 }, { 17, "stor.s.pri", sIN_CSEG, parm1 }, + {164, "stradjust.pri", sIN_CSEG, parm0 }, { 24, "strb.i", sIN_CSEG, parm1 }, { 79, "sub", sIN_CSEG, parm0 }, { 80, "sub.alt", sIN_CSEG, parm0 },