From 4fc7ef863ab16292138ea6df30cbea7aacf6914f Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Thu, 26 Oct 2017 02:06:52 +0700 Subject: [PATCH 01/43] emit/__emit: Use 'tFIRST' instead of hardcoded '256' --- source/compiler/sc1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index e77b64c..a6d1f2f 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5842,7 +5842,7 @@ static void emit_invalid_token(int need_token, int current_token) char s[sNAMEMAX+ 2]; extern char *sc_tokens[]; - if (current_token<256) { + if (current_token Date: Thu, 26 Oct 2017 02:29:27 +0700 Subject: [PATCH 02/43] emit/__emit: Set the sign bit properly on non-32-bit cells --- 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 a6d1f2f..b384297 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5893,7 +5893,7 @@ static void emit_param_num(char *name, ucell *p, int size) p[curp]=-val; break; } else if (tok==tRATIONAL) { - p[curp]=val|0x80000000; + p[curp]=val|((cell)1 << (PAWN_CELL_SIZE-1)); break; } else { strcpy(ival+1,str); From 06feab9224f3d3273e328f025ffc928e18ae07e1 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Thu, 26 Oct 2017 23:29:29 +0700 Subject: [PATCH 03/43] emit/__emit: Code cleanup --- source/compiler/sc.h | 2 +- source/compiler/sc1.c | 207 ++++++++++++++++++------------------------ source/compiler/sc3.c | 4 +- 3 files changed, 91 insertions(+), 122 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 6adf043..69c2b27 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -699,7 +699,7 @@ SC_FUNC void dec(value *lval); SC_FUNC void jmp_ne0(int number); SC_FUNC void jmp_eq0(int number); SC_FUNC void outval(cell val,int newline); -SC_FUNC void outinstr(const char *name, int nargs, ucell *args); +SC_FUNC void outinstr(const char *name,int nargs,ucell *args); /* function prototypes in SC5.C */ SC_FUNC int error(int number,...); diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index b384297..a88bc99 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5833,24 +5833,23 @@ static void check_empty(const unsigned char *lptr) /* verifies that the string contains only whitespace */ while (*lptr<=' ' && *lptr!='\0') lptr++; - if (*lptr!='\0'&&*lptr!='}') + if (*lptr!='\0' && *lptr!='}') error(38); /* extra characters on line */ } -static void emit_invalid_token(int need_token, int current_token) +static void emit_invalid_token(int need_token,int current_token) { - char s[sNAMEMAX+ 2]; + char s[sNAMEMAX+2]; extern char *sc_tokens[]; - if (current_tokenident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) { + if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) error(17,str); /* undefined symbol */ + if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { + if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) + sym->addr=ntv_funcid++; + p[curp]=sym->addr; + markusage(sym,uREAD); } else { - if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { - if ((sym->usage & uNATIVE)!=0) { - if ((sym->usage & uREAD)==0 && sym->addr>=0) - sym->addr=ntv_funcid++; - } - p[curp]=sym->addr; - markusage(sym,uREAD); - } else { - p[curp]=sym->addr; - markusage(sym,uREAD|uWRITTEN); - } /* if */ + p[curp]=sym->addr; + markusage(sym,uREAD|uWRITTEN); } /* if */ break; default: @@ -5901,17 +5896,16 @@ static void emit_param_num(char *name, ucell *p, int size) break; } /* if */ } /* if */ - if (tokvclass!=sSTATIC) sym=findglb(str,sGLOBAL); - if (sym==NULL) { - error(17,str); - } else { - if (sym->ident!=iVARIABLE) { - error(17,str); /* undefined symbol */ - } /* if */ - markusage(sym,uREAD|uWRITTEN); - p[curp]=sym->addr; - } /* if */ - } while (++curp < size); + if (sym==NULL) + error(17,str); /* undefined symbol */ + if (sym->ident!=iVARIABLE) + error(17,str); /* undefined symbol */ + markusage(sym,uREAD|uWRITTEN); + p[curp]=sym->addr; + } while (++curpusage|=uREAD; outinstr(name,1,&sym->addr); @@ -5986,16 +5975,16 @@ static void OPHANDLER_CALL emit_parm2_num(char *name) { ucell p[2]; - emit_param_num(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_num(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm2_gvar(char *name) { ucell p[2]; - emit_param_data(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_data(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm2_gvar_num(char *name) @@ -6009,75 +5998,68 @@ static void OPHANDLER_CALL emit_parm2_gvar_num(char *name) extern char *sc_tokens[]; tok=lex(&val,&str); - if (tok!=tSYMBOL) { - emit_invalid_token(tSYMBOL, tok); - } /* if */ + if (tok!=tSYMBOL) + emit_invalid_token(tSYMBOL,tok); sym=findloc(str); if (sym==NULL || sym->vclass!=sSTATIC) sym=findglb(str,sGLOBAL); - if (sym==NULL) { - error(17,str); - } else { - if (sym->ident!=iVARIABLE) { - error(17,str); /* undefined symbol */ - } /* if */ - markusage(sym,uREAD); - p[0]=sym->addr; - tok=lex(&val,&str); - if (tok!=tNUMBER) { - emit_invalid_token(tNUMBER, tok); - } /* if */ - p[1]=val; - outinstr(name,arraysize(p),p); - } /* if */ + if (sym==NULL || sym->ident!=iVARIABLE) + error(17,str); /* undefined symbol */ + markusage(sym,uREAD); + p[0]=sym->addr; + tok=lex(&val,&str); + if (tok!=tNUMBER) + emit_invalid_token(tNUMBER,tok); + p[1]=val; + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm3_num(char *name) { ucell p[3]; - emit_param_num(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_num(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm3_gvar(char *name) { ucell p[3]; - emit_param_data(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_data(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm4_num(char *name) { ucell p[4]; - emit_param_num(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_num(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm4_gvar(char *name) { ucell p[4]; - emit_param_data(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_data(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm5_num(char *name) { ucell p[5]; - emit_param_num(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_num(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm5_gvar(char *name) { ucell p[5]; - emit_param_data(name, p, arraysize(p)); - outinstr(name,arraysize(p),p); + emit_param_data(name,p,(sizeof p / sizeof p[0])); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_do_case(char *name) @@ -6094,18 +6076,15 @@ static void OPHANDLER_CALL emit_do_case(char *name) stgwrite(" "); tok=lex(&val,&str); - if (tok!=tNUMBER) { - emit_invalid_token(tSYMBOL, tok); - } /* if */ + if (tok!=tNUMBER) + emit_invalid_token(tSYMBOL,tok); outval(val,FALSE); tok=lex(&val,&str); - if (tok!=tSYMBOL) { - emit_invalid_token(tSYMBOL, tok); - } /* if */ + if (tok!=tSYMBOL) + emit_invalid_token(tSYMBOL,tok); sym=fetchlab(str); - if (sym==NULL) { + if (sym==NULL) error(17,str); /* undefined symbol */ - } /* if */ outval(sym->addr,FALSE); stgwrite("\n"); code_idx+=opargs(2)+opcodes(0); @@ -6119,12 +6098,10 @@ static void OPHANDLER_CALL emit_do_lodb_strb(char *name) extern char *sc_tokens[]; tok=lex(&val,&str); - if (tok!=tNUMBER) { - emit_invalid_token(tNUMBER, tok); - } /* if */ - if (val!=1 && val!=2 && val!=4) { + if (tok!=tNUMBER) + emit_invalid_token(tNUMBER,tok); + if (val!=1 && val!=2 && val!=4) error(50); /* invalid range */ - } /* if */ outinstr(name,1,&val); } @@ -6137,22 +6114,18 @@ static void OPHANDLER_CALL emit_do_call(char *name) extern char *sc_tokens[]; tok=lex(&val,&str); - if (tok!=tSYMBOL) { - emit_invalid_token(tSYMBOL, tok); - } /* if */ + if (tok!=tSYMBOL) + emit_invalid_token(tSYMBOL,tok); sym=findglb(str,sGLOBAL); - if (sym==NULL) { + if (sym==NULL) error(12); /* invalid function call */ - } else { - stgwrite("\t"); - stgwrite(name); - stgwrite(" "); - stgwrite("."); - stgwrite(str); - stgwrite("\n"); - code_idx+=opcodes(1)+opargs(1); - markusage(sym,uREAD); - } + stgwrite("\t"); + stgwrite(name); + stgwrite(" ."); + stgwrite(str); + stgwrite("\n"); + code_idx+=opcodes(1)+opargs(1); + markusage(sym,uREAD); } static EMIT_OPCODE emit_opcodelist[] = { @@ -6354,36 +6327,32 @@ SC_FUNC void emit_parse_line(void) int tok,len,i; symbol *sym; char name[MAX_INSTR_LEN]; + extern char *sc_tokens[]; tok=tokeninfo(&val,&st); - if (tok==tSYMBOL || (tok > tMIDDLE && tok <= tLAST)) { + if (tok==tSYMBOL || (tok>tMIDDLE && tok<=tLAST)) { /* get the token length */ - if (tok > tMIDDLE && tok <= tLAST) { - extern char *sc_tokens[]; + if (tok>tMIDDLE && tok<=tLAST) len=strlen(sc_tokens[tok-tFIRST]); - } else { + else len=strlen(st); - } /* if */ lptr-=len; - for(i=0; iaddr); sym->usage|=uDEFINE; } /* if */ - if ((emit_block_parsing && matchtoken('}')) || !emit_block_parsing) { + if (!emit_block_parsing || matchtoken('}')) { matchtoken(';'); emit_block_parsing=FALSE; } /* if */ diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 2665ae8..de9e89f 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1453,12 +1453,12 @@ static int hier2(value *lval) cell val; char* st; if (!matchtoken('{')) - error(38); + error(38); /* extra characters on line */ lex(&val,&st); lval->ident=iEXPRESSION; emit_parse_line(); if (!matchtoken('}')) - error(38); + error(38); /* extra characters on line */ return FALSE; } /* case */ default: From d15c11f42054aa7bff6f2879c1ce22d9ae1dbbaf Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 29 Oct 2017 21:25:42 +0700 Subject: [PATCH 04/43] Fix OPHANDLER_CALL-related warnings issued by clang on non-x86 targets --- source/compiler/sc.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 69c2b27..664ca3c 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -47,19 +47,14 @@ #if defined _MSC_VER #define OPHANDLER_CALL __fastcall -#elif defined __GNUC__ - #if defined __clang__ +#elif defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __amd64__) + #if !defined __x86_64__ && !defined __amd64__ && (__GNUC__>=4 || __GNUC__==3 && __GNUC_MINOR__>=4) #define OPHANDLER_CALL __attribute__((fastcall)) - #elif (defined __i386__ || defined __x86_64__ || defined __amd64__) - #if !defined __x86_64__ && !defined __amd64__ && (__GNUC__>=4 || __GNUC__==3 && __GNUC_MINOR__>=4) - #define OPHANDLER_CALL __attribute__((fastcall)) - #else - #define OPHANDLER_CALL __attribute__((regparam(3))) - #endif #else - #define OPHANDLER_CALL + #define OPHANDLER_CALL __attribute__((regparam(3))) #endif -#else +#endif +#if !defined OPHANDLER_CALL #define OPHANDLER_CALL #endif From af31143ec3afe9ef2c0037ea785d8028025637d1 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Mon, 30 Oct 2017 18:59:21 +0700 Subject: [PATCH 05/43] emit/__emit: Avoid excess instruction name copying in emit_findopcode() --- source/compiler/sc1.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index a88bc99..3e19e67 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6290,14 +6290,10 @@ static EMIT_OPCODE emit_opcodelist[] = { { 92, "zero.s", emit_parm1_num }, }; -static int emit_findopcode(char *instr,int maxlen) +static int emit_findopcode(const char *instr,int maxlen) { int low,high,mid,cmp; - char str[MAX_INSTR_LEN]; - if (maxlen>=MAX_INSTR_LEN) - return 0; - strlcpy(str,instr,maxlen+1); /* look up the instruction with a binary search * the assembler is case insensitive to instructions (but case sensitive * to symbols) @@ -6307,7 +6303,7 @@ static int emit_findopcode(char *instr,int maxlen) while (low0) low=mid+1; else @@ -6315,7 +6311,7 @@ static int emit_findopcode(char *instr,int maxlen) } /* while */ assert(low==high); - if (stricmp(str,emit_opcodelist[low].name)==0) + if (stricmp(instr,emit_opcodelist[low].name)==0) return low; /* found */ return 0; /* not found, return special index */ } From eb5ee448e54fafad4d358fb16c438cb24506774a Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Mon, 30 Oct 2017 19:09:19 +0700 Subject: [PATCH 06/43] emit/__emit: Use case-sensitive search in emit_findopcode() The instruction name is copied in lower case anyway (see emit_parse_line()). --- source/compiler/sc1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 3e19e67..dfbe8b9 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6303,7 +6303,7 @@ static int emit_findopcode(const char *instr,int maxlen) while (low0) low=mid+1; else @@ -6311,7 +6311,7 @@ static int emit_findopcode(const char *instr,int maxlen) } /* while */ assert(low==high); - if (stricmp(instr,emit_opcodelist[low].name)==0) + if (strcmp(instr,emit_opcodelist[low].name)==0) return low; /* found */ return 0; /* not found, return special index */ } From 7440670150890ff757112197205b6c6dafaf5848 Mon Sep 17 00:00:00 2001 From: VVWVV Date: Fri, 27 Oct 2017 17:33:56 +0300 Subject: [PATCH 07/43] fix params for data seg. Conflicts: source/compiler/sc1.c --- source/compiler/sc1.c | 54 ++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index dfbe8b9..64e642d 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5901,6 +5901,7 @@ static void emit_param_num(char *name,ucell *p,int size) else strcpy(ival,sc_tokens[tok-tFIRST]); error(1,sc_tokens[tSYMBOL-tFIRST],ival); + break; } /* switch */ } while (++curpvclass!=sSTATIC) + error(17,str); + if (sym==NULL) + error(17,str); + markusage(sym,uREAD|uWRITTEN); + p[curp]=sym->addr; + break; + default: emit_invalid_token(tSYMBOL,tok); - sym=findloc(str); - if (sym==NULL || sym->vclass!=sSTATIC) - sym=findglb(str,sGLOBAL); - if (sym==NULL) - error(17,str); /* undefined symbol */ - if (sym->ident!=iVARIABLE) - error(17,str); /* undefined symbol */ - markusage(sym,uREAD|uWRITTEN); - p[curp]=sym->addr; + } /* switch */ } while (++curpvclass!=sSTATIC) + error(17,str); + if (sym==NULL) + error(17,str); + markusage(sym,uREAD|uWRITTEN); + p[0]=sym->addr; + break; + default: emit_invalid_token(tSYMBOL,tok); - sym=findloc(str); - if (sym==NULL || sym->vclass!=sSTATIC) - sym=findglb(str,sGLOBAL); - if (sym==NULL || sym->ident!=iVARIABLE) - error(17,str); /* undefined symbol */ - markusage(sym,uREAD); - p[0]=sym->addr; + } /* switch */ + tok=lex(&val,&str); if (tok!=tNUMBER) emit_invalid_token(tNUMBER,tok); From 28c69cd8c8a6242244cb4b4e507dd3cd901bce7a Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 16:59:28 +0700 Subject: [PATCH 08/43] #emit: Set the sign bit properly on non-32-bit cells --- source/compiler/sc2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 04f746b..38e5f6f 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1356,7 +1356,7 @@ static int command(void) break; } else if (current_token==tRATIONAL) { /* change the first bit to make float negative value */ - outval(val | 0x80000000,FALSE); + outval(val|((cell)1 << (PAWN_CELL_SIZE-1)),FALSE); code_idx+=opargs(1); break; } else { From f921451c8a34006cb8f9d747b1f3e1c7f984ee11 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 18:25:38 +0700 Subject: [PATCH 09/43] emit/__emit: Fix multiple occurences of NULL pointer dereference --- source/compiler/sc1.c | 55 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 64e642d..8628dc1 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5869,9 +5869,9 @@ static void emit_param_num(char *name,ucell *p,int size) sym=findloc(str); if (sym==NULL) sym=findglb(str,sSTATEVAR); - if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) + if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) { error(17,str); /* undefined symbol */ - if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { + } else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) sym->addr=ntv_funcid++; p[curp]=sym->addr; @@ -5892,16 +5892,14 @@ static void emit_param_num(char *name,ucell *p,int size) break; } else { strcpy(ival+1,str); - error(1,sc_tokens[tSYMBOL-tFIRST],ival); - break; } /* if */ + } else { + if (tokvclass!=sSTATIC) { + error(17,str); /* undefined symbol */ + continue; + } + } else { sym=findglb(str,sSTATIC); - else if (sym->vclass!=sSTATIC) - error(17,str); - if (sym==NULL) - error(17,str); + if (sym==NULL) { + error(17,str); /* undefined symbol */ + continue; + } + } markusage(sym,uREAD|uWRITTEN); p[curp]=sym->addr; break; @@ -6103,8 +6107,9 @@ static void OPHANDLER_CALL emit_do_case(char *name) sym=fetchlab(str); if (sym==NULL) error(17,str); /* undefined symbol */ - outval(sym->addr,FALSE); - stgwrite("\n"); + else + val=sym->addr; + outval(val,TRUE); code_idx+=opargs(2)+opcodes(0); } @@ -6135,15 +6140,17 @@ static void OPHANDLER_CALL emit_do_call(char *name) if (tok!=tSYMBOL) emit_invalid_token(tSYMBOL,tok); sym=findglb(str,sGLOBAL); - if (sym==NULL) + if (sym==NULL) { error(12); /* invalid function call */ - stgwrite("\t"); - stgwrite(name); - stgwrite(" ."); - stgwrite(str); - stgwrite("\n"); - code_idx+=opcodes(1)+opargs(1); - markusage(sym,uREAD); + } else { + stgwrite("\t"); + stgwrite(name); + stgwrite(" ."); + stgwrite(str); + stgwrite("\n"); + code_idx+=opcodes(1)+opargs(1); + markusage(sym,uREAD); + } } static EMIT_OPCODE emit_opcodelist[] = { From d4af23b5debea6ea64117d23e34e5e8f844faec2 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 19:28:59 +0700 Subject: [PATCH 10/43] emit/__emit: Allow local constants to be used as data addresses in emit_param_data() --- 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 8628dc1..4351ab7 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5922,7 +5922,7 @@ static void emit_param_data(char *name,ucell *p,int size) case tSYMBOL: sym=findloc(str); if (sym!=NULL) { - if (sym->vclass!=sSTATIC) { + if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) { error(17,str); /* undefined symbol */ continue; } From 35fb9e8393975eb0fd144986842f659920d0ab01 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 20:15:30 +0700 Subject: [PATCH 11/43] emit/__emit: Remove excess instruction name passing to emit_param_num() & emit_param_data() --- source/compiler/sc1.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 4351ab7..bf3e28b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5849,7 +5849,7 @@ static void emit_invalid_token(int need_token,int current_token) error(1,sc_tokens[tSYMBOL-tFIRST],s); } -static void emit_param_num(char *name,ucell *p,int size) +static void emit_param_num(ucell *p,int size) { char *str; cell val; @@ -5904,7 +5904,7 @@ static void emit_param_num(char *name,ucell *p,int size) } while (++curp Date: Sun, 12 Nov 2017 20:38:32 +0700 Subject: [PATCH 12/43] emit/__emit: Simplify the code in emit_parm2_gvar_num() --- source/compiler/sc1.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index bf3e28b..6196446 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6001,38 +6001,10 @@ static void OPHANDLER_CALL emit_parm2_gvar(char *name) static void OPHANDLER_CALL emit_parm2_gvar_num(char *name) { - cell val; - char *str; ucell p[2]; - symbol *sym; - int curp=0; - int tok; - extern char *sc_tokens[]; - tok=lex(&val,&str); - switch (tok) { - case tNUMBER: - p[0]=val; - break; - case tSYMBOL: - sym=findloc(str); - if (sym==NULL) - sym=findglb(str,sSTATIC); - else if (sym->vclass!=sSTATIC) - error(17,str); - if (sym==NULL) - error(17,str); - markusage(sym,uREAD|uWRITTEN); - p[0]=sym->addr; - break; - default: - emit_invalid_token(tSYMBOL,tok); - } /* switch */ - - tok=lex(&val,&str); - if (tok!=tNUMBER) - emit_invalid_token(tNUMBER,tok); - p[1]=val; + emit_param_data(&p[0],1); + emit_param_num(&p[1],1); outinstr(name,(sizeof p / sizeof p[0]),p); } From f5cbeb010bcd3ec45d35e7c63adaa5304deb6b62 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 21:19:57 +0700 Subject: [PATCH 13/43] emit/__emit: Remove excess sc_tokens declarations, fix cell*/ucell* argument type mismatch --- source/compiler/sc1.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 6196446..fef6b09 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5911,7 +5911,6 @@ static void emit_param_data(ucell *p,int size) symbol *sym; int curp=0; int tok; - extern char *sc_tokens[]; do { tok=lex(&val,&str); @@ -5980,7 +5979,7 @@ static void OPHANDLER_CALL emit_parm1_lbl(char *name) emit_invalid_token(tSYMBOL,tok); sym=fetchlab(str); sym->usage|=uREAD; - outinstr(name,1,&sym->addr); + outinstr(name,1,(ucell *)&sym->addr); } static void OPHANDLER_CALL emit_parm2_num(char *name) @@ -6063,7 +6062,6 @@ static void OPHANDLER_CALL emit_do_case(char *name) char *str; symbol* sym; int tok; - extern char *sc_tokens[]; stgwrite("\t"); stgwrite(name); @@ -6087,17 +6085,16 @@ static void OPHANDLER_CALL emit_do_case(char *name) static void OPHANDLER_CALL emit_do_lodb_strb(char *name) { - ucell val; + cell val; char *str; int tok; - extern char *sc_tokens[]; tok=lex(&val,&str); if (tok!=tNUMBER) emit_invalid_token(tNUMBER,tok); if (val!=1 && val!=2 && val!=4) error(50); /* invalid range */ - outinstr(name,1,&val); + outinstr(name,1,(ucell *)&val); } static void OPHANDLER_CALL emit_do_call(char *name) @@ -6106,7 +6103,6 @@ static void OPHANDLER_CALL emit_do_call(char *name) char *str; symbol *sym; int tok; - extern char *sc_tokens[]; tok=lex(&val,&str); if (tok!=tSYMBOL) From b726f44a0221af53169b7890da0fda8e4ce73c52 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 12 Nov 2017 22:49:09 +0700 Subject: [PATCH 14/43] emit/__emit: Simplify the code in emit_parm1_lbl() and emit_do_case() --- source/compiler/sc1.c | 54 ++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index fef6b09..d6b9d86 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5941,6 +5941,21 @@ static void emit_param_data(ucell *p,int size) } while (++curpusage|=uREAD; + *p=*(ucell *)&sym->addr; +} + static void OPHANDLER_CALL emit_noop(char *name) { (void)name; @@ -5969,17 +5984,10 @@ static void OPHANDLER_CALL emit_parm1_gvar(char *name) static void OPHANDLER_CALL emit_parm1_lbl(char *name) { - char *str; - cell val; - symbol *sym; - int tok; + ucell p[1]; - tok=lex(&val,&str); - if (tok!=tSYMBOL) - emit_invalid_token(tSYMBOL,tok); - sym=fetchlab(str); - sym->usage|=uREAD; - outinstr(name,1,(ucell *)&sym->addr); + emit_param_label(&p[0]); + outinstr(name,(sizeof p / sizeof p[0]),p); } static void OPHANDLER_CALL emit_parm2_num(char *name) @@ -6057,29 +6065,11 @@ static void OPHANDLER_CALL emit_parm5_gvar(char *name) static void OPHANDLER_CALL emit_do_case(char *name) { - /* case