1.1 --- a/compiler-init/sc.h Sat Jul 15 03:05:56 2006 +0000
1.2 +++ b/compiler-init/sc.h Sat Jul 15 03:19:23 2006 +0000
1.3 @@ -283,7 +283,7 @@
1.4 */
1.5 #define tFIRST 256 /* value of first multi-character operator */
1.6 #define tMIDDLE 280 /* value of last multi-character operator */
1.7 -#define tLAST 325 /* value of last multi-character match-able token */
1.8 +#define tLAST 326 /* value of last multi-character match-able token */
1.9 /* multi-character operators */
1.10 #define taMULT 256 /* *= */
1.11 #define taDIV 257 /* /= */
1.12 @@ -329,44 +329,45 @@
1.13 #define tIF 296
1.14 #define tNATIVE 297
1.15 #define tNEW 298
1.16 -#define tOPERATOR 299
1.17 -#define tPUBLIC 300
1.18 -#define tRETURN 301
1.19 -#define tSIZEOF 302
1.20 -#define tSLEEP 303
1.21 -#define tSTATE 304
1.22 -#define tSTATIC 305
1.23 -#define tSTOCK 306
1.24 -#define tSWITCH 307
1.25 -#define tTAGOF 308
1.26 -#define tWHILE 309
1.27 +#define tDECL 299
1.28 +#define tOPERATOR 300
1.29 +#define tPUBLIC 301
1.30 +#define tRETURN 302
1.31 +#define tSIZEOF 303
1.32 +#define tSLEEP 304
1.33 +#define tSTATE 305
1.34 +#define tSTATIC 306
1.35 +#define tSTOCK 307
1.36 +#define tSWITCH 308
1.37 +#define tTAGOF 309
1.38 +#define tWHILE 310
1.39 /* compiler directives */
1.40 -#define tpASSERT 310 /* #assert */
1.41 -#define tpDEFINE 311
1.42 -#define tpELSE 312 /* #else */
1.43 -#define tpELSEIF 313 /* #elseif */
1.44 -#define tpEMIT 314
1.45 -#define tpENDIF 315
1.46 -#define tpENDINPUT 316
1.47 -#define tpENDSCRPT 317
1.48 -#define tpERROR 318
1.49 -#define tpFILE 319
1.50 -#define tpIF 320 /* #if */
1.51 -#define tINCLUDE 321
1.52 -#define tpLINE 322
1.53 -#define tpPRAGMA 323
1.54 -#define tpTRYINCLUDE 324
1.55 -#define tpUNDEF 325
1.56 +#define tpASSERT 311 /* #assert */
1.57 +#define tpDEFINE 312
1.58 +#define tpELSE 313 /* #else */
1.59 +#define tpELSEIF 314 /* #elseif */
1.60 +#define tpEMIT 315
1.61 +#define tpENDIF 316
1.62 +#define tpENDINPUT 317
1.63 +#define tpENDSCRPT 318
1.64 +#define tpERROR 319
1.65 +#define tpFILE 320
1.66 +#define tpIF 321 /* #if */
1.67 +#define tINCLUDE 322
1.68 +#define tpLINE 323
1.69 +#define tpPRAGMA 324
1.70 +#define tpTRYINCLUDE 325
1.71 +#define tpUNDEF 326
1.72 /* semicolon is a special case, because it can be optional */
1.73 -#define tTERM 326 /* semicolon or newline */
1.74 -#define tENDEXPR 327 /* forced end of expression */
1.75 +#define tTERM 327 /* semicolon or newline */
1.76 +#define tENDEXPR 328 /* forced end of expression */
1.77 /* other recognized tokens */
1.78 -#define tNUMBER 328 /* integer number */
1.79 -#define tRATIONAL 329 /* rational number */
1.80 -#define tSYMBOL 330
1.81 -#define tLABEL 331
1.82 -#define tSTRING 332
1.83 -#define tEXPR 333 /* for assigment to "lastst" only */
1.84 +#define tNUMBER 329 /* integer number */
1.85 +#define tRATIONAL 330 /* rational number */
1.86 +#define tSYMBOL 331
1.87 +#define tLABEL 332
1.88 +#define tSTRING 333
1.89 +#define tEXPR 334 /* for assigment to "lastst" only */
1.90
1.91 /* (reversed) evaluation of staging buffer */
1.92 #define sSTARTREORDER 0x01
2.1 --- a/compiler-init/sc1.c Sat Jul 15 03:05:56 2006 +0000
2.2 +++ b/compiler-init/sc1.c Sat Jul 15 03:19:23 2006 +0000
2.3 @@ -135,6 +135,7 @@
2.4 static void inst_datetime_defines(void);
2.5
2.6 static int norun = 0; /* the compiler never ran */
2.7 +static int autozero = 0; /* if 1 will zero out the variable, if 0 omit the zeroing */
2.8 static int lastst = 0; /* last executed statement type */
2.9 static int nestlevel = 0; /* number of active (open) compound statements */
2.10 static int rettype = 0; /* the type that a "return" expression should have */
2.11 @@ -1977,19 +1978,24 @@
2.12 int ctag = tag; /* set to "tag" by default */
2.13 int explicit_init=FALSE;/* is the variable explicitly initialized? */
2.14 if (matchtoken('=')) {
2.15 + if (!autozero)
2.16 + error(10);
2.17 doexpr(FALSE,FALSE,FALSE,FALSE,&ctag,NULL,TRUE);
2.18 explicit_init=TRUE;
2.19 } else {
2.20 - ldconst(0,sPRI); /* uninitialized variable, set to zero */
2.21 + if (autozero)
2.22 + ldconst(0,sPRI); /* uninitialized variable, set to zero */
2.23 } /* if */
2.24 - /* now try to save the value (still in PRI) in the variable */
2.25 - lval.sym=sym;
2.26 - lval.ident=iVARIABLE;
2.27 - lval.constval=0;
2.28 - lval.tag=tag;
2.29 - check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
2.30 - store(&lval);
2.31 - markexpr(sEXPR,NULL,0); /* full expression ends after the store */
2.32 + if (autozero) {
2.33 + /* now try to save the value (still in PRI) in the variable */
2.34 + lval.sym=sym;
2.35 + lval.ident=iVARIABLE;
2.36 + lval.constval=0;
2.37 + lval.tag=tag;
2.38 + check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
2.39 + store(&lval);
2.40 + markexpr(sEXPR,NULL,0); /* full expression ends after the store */
2.41 + }
2.42 assert(staging); /* end staging phase (optimize expression) */
2.43 stgout(staging_start);
2.44 stgset(FALSE);
2.45 @@ -2004,15 +2010,17 @@
2.46 assert(cur_lit>=0 && cur_lit<=litidx && litidx<=litmax);
2.47 assert(size>0 && size>=sym->dim.array.length);
2.48 assert(numdim>1 || size==sym->dim.array.length);
2.49 - /* final literal values that are zero make no sense to put in the literal
2.50 - * pool, because values get zero-initialized anyway; we check for this,
2.51 - * because users often explicitly initialize strings to ""
2.52 - */
2.53 - while (litidx>cur_lit && litq[litidx-1]==0)
2.54 - litidx--;
2.55 - /* if the array is not completely filled, set all values to zero first */
2.56 - if (litidx-cur_lit<size && (ucell)size<CELL_MAX)
2.57 - fillarray(sym,size*sizeof(cell),0);
2.58 + if (autozero) {
2.59 + /* final literal values that are zero make no sense to put in the literal
2.60 + * pool, because values get zero-initialized anyway; we check for this,
2.61 + * because users often explicitly initialize strings to ""
2.62 + */
2.63 + while (litidx>cur_lit && litq[litidx-1]==0)
2.64 + litidx--;
2.65 + /* if the array is not completely filled, set all values to zero first */
2.66 + if (litidx-cur_lit<size && (ucell)size<CELL_MAX)
2.67 + fillarray(sym,size*sizeof(cell),0);
2.68 + }
2.69 if (cur_lit<litidx) {
2.70 /* check whether the complete array is set to a single value; if
2.71 * it is, more compact code can be generated */
2.72 @@ -2264,12 +2272,12 @@
2.73 constvalue *enumroot,int *errorfound)
2.74 {
2.75 cell prev1=0,prev2=0;
2.76 - int ellips=FALSE;
2.77 + int ellips=FALSE,hadtoken=0;
2.78 int curlit=litidx;
2.79 int rtag,ctag;
2.80
2.81 assert(ident==iARRAY || ident==iREFARRAY);
2.82 - if (matchtoken('{')) {
2.83 + if ((hadtoken=matchtoken('{')) && autozero) {
2.84 constvalue *enumfield=(enumroot!=NULL) ? enumroot->next : NULL;
2.85 do {
2.86 int fieldlit=litidx;
2.87 @@ -2331,6 +2339,8 @@
2.88 } while (matchtoken(',')); /* do */
2.89 needtoken('}');
2.90 } else {
2.91 + if (hadtoken && !autozero)
2.92 + error(10);
2.93 init(ident,&ctag,errorfound);
2.94 if (!matchtag(tag,ctag,TRUE))
2.95 error(213); /* tagname mismatch */
2.96 @@ -4612,12 +4622,22 @@
2.97 break;
2.98 case tNEW:
2.99 if (allow_decl) {
2.100 + autozero=1;
2.101 declloc(FALSE);
2.102 lastst=tNEW;
2.103 } else {
2.104 error(3); /* declaration only valid in a block */
2.105 } /* if */
2.106 break;
2.107 + case tDECL:
2.108 + if (allow_decl) {
2.109 + autozero=0;
2.110 + declloc(FALSE);
2.111 + lastst=tDECL;
2.112 + } else {
2.113 + error(3); /* declaration only valid in a block */
2.114 + } /* if */
2.115 + break;
2.116 case tSTATIC:
2.117 if (allow_decl) {
2.118 declloc(TRUE);
2.119 @@ -4993,6 +5013,7 @@
2.120 * 'compound statement' level of it own.
2.121 */
2.122 nestlevel++;
2.123 + autozero=1;
2.124 declloc(FALSE); /* declare local variable */
2.125 } else {
2.126 doexpr(TRUE,TRUE,TRUE,TRUE,NULL,NULL,FALSE); /* expression 1 */
3.1 --- a/compiler-init/sc2.c Sat Jul 15 03:05:56 2006 +0000
3.2 +++ b/compiler-init/sc2.c Sat Jul 15 03:19:23 2006 +0000
3.3 @@ -1818,7 +1818,7 @@
3.4 "...", "..", "::",
3.5 "assert", "break", "case", "char", "const", "continue", "default",
3.6 "defined", "do", "else", "enum", "exit", "for", "forward", "goto",
3.7 - "if", "native", "new", "operator", "public", "return", "sizeof",
3.8 + "if", "native", "new", "decl", "operator", "public", "return", "sizeof",
3.9 "sleep", "state", "static", "stock", "switch", "tagof", "while",
3.10 "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput",
3.11 "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",