From f710188c865edf7c182cea42f2f191e1556752c8 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 18 May 2015 23:52:55 +0200 Subject: [PATCH] Compiler: Ability to directly reference another address in a default argument (for arrays only) SM patch: https://github.com/alliedmodders/sourcemod/commit/d8d13f19204fc682a090e549ca1a286d4f9f8524 --- compiler/libpc300/sc1.c | 77 ++++++++++++++++++++++++++++------------- compiler/libpc300/sc3.c | 34 +++++++++--------- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index 8230118c..fc15e124 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -2190,15 +2190,19 @@ static int base; * * Global references: litidx (altered) */ -static void initials(int ident,int tag,cell *size,int dim[],int numdim, - constvalue *enumroot) +static void initials2(int ident,int tag,cell *size,int dim[],int numdim, + constvalue *enumroot, int eq_match_override, int curlit_override) { int ctag; cell tablesize; - int curlit=litidx; + int curlit=(curlit_override == -1) ? litidx : curlit_override; int err=0; - if (!matchtoken('=')) { + if (eq_match_override == -1) { + eq_match_override = matchtoken('='); + } + + if (!eq_match_override) { assert(ident!=iARRAY || numdim>0); if (ident==iARRAY && dim[numdim-1]==0) { /* declared as "myvar[];" which is senseless (note: this *does* make @@ -2248,7 +2252,7 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim, /* now initialize the sub-arrays */ memset(counteddim,0,sizeof counteddim); initarray(ident,tag,dim,numdim,0,curlit,counteddim,&lastdim,enumroot,&errorfound); - /* check the specified array dimensions with the initialler counts */ + /* check the specified array dimensions with the initializer counts */ for (idx=0; idx0); /* check whether to dump the default array */ assert(dataaddr!=NULL); if (sc_status==statWRITE && *dataaddr<0) { @@ -1784,7 +1782,7 @@ static void setdefarray(cell *string,cell size,cell array_sz,cell *dataaddr,int * does not modify the default value), directly pass the address of the * array in the data segment. */ - if (fconst) { + if (fconst || !string) { ldconst(*dataaddr,sPRI); } else { /* Generate the code: @@ -2162,20 +2160,22 @@ static int nesting=0; arg[argidx].defvalue.array.arraysize, &arg[argidx].defvalue.array.addr, (arg[argidx].usage & uCONST)!=0); - if ((arg[argidx].usage & uCONST)==0) { - heapalloc+=arg[argidx].defvalue.array.arraysize; - nest_stkusage+=arg[argidx].defvalue.array.arraysize; - } /* if */ - /* keep the lengths of all dimensions of a multi-dimensional default array */ - assert(arg[argidx].numdim>0); - if (arg[argidx].numdim==1) { - append_constval(&arrayszlst,arg[argidx].name,arg[argidx].defvalue.array.arraysize,0); - } else { - for (level=0; level0); + if (arg[argidx].numdim==1) { + append_constval(&arrayszlst,arg[argidx].name,arg[argidx].defvalue.array.arraysize,0); + } else { + for (level=0; level