From 3234a29eb192a5e06ad39d9b6cf96501cbc37746 Mon Sep 17 00:00:00 2001 From: Yashas Date: Mon, 26 Dec 2016 17:40:36 +0530 Subject: [PATCH 1/6] allow negative numbers in #emit --- source/compiler/sc2.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index db9f420..270de9c 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1343,8 +1343,20 @@ static int command(void) } /* if */ break; default: { - char s2[20]; extern char *sc_tokens[];/* forward declaration */ + if ((char)tok == '-') { + if (lex(&val, &str) == tNUMBER) { + outval(-val, FALSE); + code_idx += opargs(1); + break; + } else { + char s2[33] = "-"; + strcpy((s2 + 1), str); + error(1, sc_tokens[tSYMBOL - tFIRST], s2); + break; + }/* if */ + }/* if */ + char s2[20]; if (tok<256) sprintf(s2,"%c",(char)tok); else From 111785e767300bc42529f0ee50440794af503a22 Mon Sep 17 00:00:00 2001 From: Yashas Date: Mon, 26 Dec 2016 21:27:40 +0530 Subject: [PATCH 2/6] public variables behaviour 1. 'stock' public (or public const) variables will be written to the file IF AND ONLY IF it has been used (read or write) 2. 'non-stock' public (or public const) variables will always be written to the file (whether or not it has been used) 3. public variables (or public const) NEVER ever trigger unused symbol warnings --- source/compiler/sc6.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc6.c b/source/compiler/sc6.c index 1e235ae..e0886a7 100644 --- a/source/compiler/sc6.c +++ b/source/compiler/sc6.c @@ -747,8 +747,13 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) mainaddr=sym->addr; } /* if */ } else if (sym->ident==iVARIABLE) { - if ((sym->usage & uPUBLIC)!=0) - match=++numpubvars; + if ((sym->usage & uPUBLIC) != 0) { + if ((sym->usage & uSTOCK) != 0) { + if ((sym->usage & (uREAD | uWRITTEN)) != 0) + match = ++numpubvars; + } + else match = ++numpubvars; + } /* if */ } /* if */ if (match) { char alias[sNAMEMAX+1]; @@ -925,6 +930,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) count=0; for (sym=glbtab.next; sym!=NULL; sym=sym->next) { if (sym->ident==iVARIABLE && (sym->usage & uPUBLIC)!=0) { + if (((sym->usage & uSTOCK) != 0) && ((sym->usage & (uREAD | uWRITTEN)) == 0)) continue; assert((sym->usage & uDEFINE)!=0); assert(sym->vclass==sGLOBAL); func.address=sym->addr; From 602178a0b56febf61033337ef528f1e4eb11a7b7 Mon Sep 17 00:00:00 2001 From: Yashas Date: Mon, 26 Dec 2016 21:30:32 +0530 Subject: [PATCH 3/6] public variables behaviour stops unused warnings from being triggered for public variables --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 6b76991..2795320 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4690,7 +4690,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) /* a variable */ if (sym->parent!=NULL) break; /* hierarchical data type */ - if ((sym->usage & (uWRITTEN | uREAD | uSTOCK))==0) { + if ((sym->usage & (uWRITTEN | uREAD | uSTOCK | uPUBLIC))==0) { if (testconst) errorset(sSETPOS,sym->lnumber); error(203,sym->name,sym->lnumber); /* symbol isn't used (and not stock) */ From fa86f8f6cb8f0569e5850dae7995a9340d9a08e4 Mon Sep 17 00:00:00 2001 From: Yashas Date: Sat, 14 Jan 2017 19:34:22 +0530 Subject: [PATCH 4/6] fixed indentation --- source/compiler/sc6.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/compiler/sc6.c b/source/compiler/sc6.c index e0886a7..ff37d75 100644 --- a/source/compiler/sc6.c +++ b/source/compiler/sc6.c @@ -747,12 +747,12 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) mainaddr=sym->addr; } /* if */ } else if (sym->ident==iVARIABLE) { - if ((sym->usage & uPUBLIC) != 0) { - if ((sym->usage & uSTOCK) != 0) { - if ((sym->usage & (uREAD | uWRITTEN)) != 0) - match = ++numpubvars; - } - else match = ++numpubvars; + if ((sym->usage & uPUBLIC) != 0) { + if ((sym->usage & uSTOCK) != 0) { + if ((sym->usage & (uREAD | uWRITTEN)) != 0) + match = ++numpubvars; + } /* if */ + else match = ++numpubvars; } /* if */ } /* if */ if (match) { From b13928c584c2552c64d7d13d52ce4ad0752676b0 Mon Sep 17 00:00:00 2001 From: Yashas Date: Sat, 14 Jan 2017 20:10:56 +0530 Subject: [PATCH 5/6] moved a declaration to the start of block Abiding by the C89 declaration rules so that AppVeyor build can succeed. --- source/compiler/sc2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 270de9c..ec54173 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1344,19 +1344,18 @@ static int command(void) break; default: { extern char *sc_tokens[];/* forward declaration */ + char s2[33] = "-"; if ((char)tok == '-') { if (lex(&val, &str) == tNUMBER) { outval(-val, FALSE); code_idx += opargs(1); break; - } else { - char s2[33] = "-"; + } else { strcpy((s2 + 1), str); error(1, sc_tokens[tSYMBOL - tFIRST], s2); break; }/* if */ - }/* if */ - char s2[20]; + }/* if */ if (tok<256) sprintf(s2,"%c",(char)tok); else From 9d8c1c55c55cc03edcac0f3f414fd712056c071d Mon Sep 17 00:00:00 2001 From: Zeex Date: Tue, 17 Jan 2017 23:32:18 +0600 Subject: [PATCH 6/6] Minor style fixes --- source/compiler/sc2.c | 18 +++++++++--------- source/compiler/sc6.c | 43 ++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index ec54173..55da378 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1344,18 +1344,18 @@ static int command(void) break; default: { extern char *sc_tokens[];/* forward declaration */ - char s2[33] = "-"; - if ((char)tok == '-') { - if (lex(&val, &str) == tNUMBER) { - outval(-val, FALSE); - code_idx += opargs(1); + char s2[33]="-"; + if ((char)tok=='-') { + if (lex(&val,&str)==tNUMBER) { + outval(-val,FALSE); + code_idx+=opargs(1); break; } else { - strcpy((s2 + 1), str); - error(1, sc_tokens[tSYMBOL - tFIRST], s2); + strcpy(s2+1, str); + error(1,sc_tokens[tSYMBOL-tFIRST],s2); break; - }/* if */ - }/* if */ + } /* if */ + } /* if */ if (tok<256) sprintf(s2,"%c",(char)tok); else diff --git a/source/compiler/sc6.c b/source/compiler/sc6.c index ff37d75..8e9e2c6 100644 --- a/source/compiler/sc6.c +++ b/source/compiler/sc6.c @@ -160,26 +160,26 @@ static uint32_t *align32(uint32_t *v) #if PAWN_CELL_SIZE>=64 static uint64_t *align64(uint64_t *v) { - unsigned char *s = (unsigned char *)v; - unsigned char t; + unsigned char *s = (unsigned char *)v; + unsigned char t; - t=s[0]; - s[0]=s[7]; - s[7]=t; + t=s[0]; + s[0]=s[7]; + s[7]=t; - t=s[1]; - s[1]=s[6]; - s[6]=t; + t=s[1]; + s[1]=s[6]; + s[6]=t; - t=s[2]; - s[2]=s[5]; - s[5]=t; + t=s[2]; + s[2]=s[5]; + s[5]=t; - t=s[3]; - s[3]=s[4]; - s[4]=t; + t=s[3]; + s[3]=s[4]; + s[4]=t; - return v; + return v; } #endif @@ -747,13 +747,9 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) mainaddr=sym->addr; } /* if */ } else if (sym->ident==iVARIABLE) { - if ((sym->usage & uPUBLIC) != 0) { - if ((sym->usage & uSTOCK) != 0) { - if ((sym->usage & (uREAD | uWRITTEN)) != 0) - match = ++numpubvars; - } /* if */ - else match = ++numpubvars; - } /* if */ + if ((sym->usage & uPUBLIC)!=0 + && ((sym->usage & uSTOCK)==0 || (sym->usage & (uREAD | uWRITTEN))!=0)) + match=++numpubvars; } /* if */ if (match) { char alias[sNAMEMAX+1]; @@ -930,7 +926,8 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) count=0; for (sym=glbtab.next; sym!=NULL; sym=sym->next) { if (sym->ident==iVARIABLE && (sym->usage & uPUBLIC)!=0) { - if (((sym->usage & uSTOCK) != 0) && ((sym->usage & (uREAD | uWRITTEN)) == 0)) continue; + if ((sym->usage & uSTOCK)!=0 && (sym->usage & (uREAD | uWRITTEN))==0) + continue; assert((sym->usage & uDEFINE)!=0); assert(sym->vclass==sGLOBAL); func.address=sym->addr;