From 5ee186223f1c59f41e8f486145f457401bc12658 Mon Sep 17 00:00:00 2001 From: VVWVV Date: Fri, 27 Jan 2017 18:30:01 +0300 Subject: [PATCH 1/5] Fix the compiler crash with #emit Signed-off-by: VVWVV --- source/compiler/sc2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 7eecd3e..8b48cd2 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1318,6 +1318,8 @@ static int command(void) error(17,str); /* undefined symbol */ } else { if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { + int count; + if ((sym->usage & uNATIVE)!=0) { /* reserve a SYSREQ id if called for the first time */ if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) @@ -1333,7 +1335,11 @@ static int command(void) /* mark function as "used" */ /* do NOT mark it as written as that has a different meaning for * functions (marks them as "should return a value") */ - markusage(sym,uREAD); + + for (count=0; countnumrefers && curfunc->refer[count]; count++) + /* nothing */; + if (count!=0 || (curfunc->usage & uPUBLIC)!=0) + markusage(sym,uREAD); } else { outval(sym->addr,FALSE); /* mark symbol as "used", unknown whether for read or write */ From 6124e5e66268ae3e09627d451f5a0af02aa12277 Mon Sep 17 00:00:00 2001 From: VVWVV Date: Fri, 10 Mar 2017 03:33:24 +0300 Subject: [PATCH 2/5] Add comments Signed-off-by: VVWVV --- source/compiler/sc2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 8b48cd2..3e89e9f 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1318,7 +1318,7 @@ static int command(void) error(17,str); /* undefined symbol */ } else { if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { - int count; + int count; /* number of references on the function */ if ((sym->usage & uNATIVE)!=0) { /* reserve a SYSREQ id if called for the first time */ @@ -1336,8 +1336,10 @@ static int command(void) /* do NOT mark it as written as that has a different meaning for * functions (marks them as "should return a value") */ + /* compute the number of references on the function */ for (count=0; countnumrefers && curfunc->refer[count]; count++) /* nothing */; + /* if there's references on the function or/and this function was declared as public */ if (count!=0 || (curfunc->usage & uPUBLIC)!=0) markusage(sym,uREAD); } else { From ba64ad437e619a8e34af38598011683876ea325f Mon Sep 17 00:00:00 2001 From: VVWVV Date: Sun, 12 Mar 2017 10:28:28 +0300 Subject: [PATCH 3/5] Update the fix --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 2 ++ source/compiler/sc2.c | 7 +------ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 3313ce3..20b4c71 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -145,6 +145,7 @@ typedef struct s_symbol { struct s_symbol **refer; /* referrer list, functions that "use" this symbol */ int numrefers; /* number of entries in the referrer list */ char *documentation; /* optional documentation string */ + int func_skipped; } symbol; diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index af736bd..345577a 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3569,9 +3569,11 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc /* so it is not a prototype, proceed */ /* if this is a function that is not referred to (this can only be detected * in the second stage), shut code generation off */ + sym->func_skipped=FALSE; if (sc_status==statWRITE && (sym->usage & uREAD)==0 && !fpublic) { sc_status=statSKIP; cidx=code_idx; + sym->func_skipped=TRUE; glbdecl=glb_declared; } /* if */ if ((sym->flags & flgDEPRECATED)!=0) { diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 3e89e9f..a509ac8 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1335,12 +1335,7 @@ static int command(void) /* mark function as "used" */ /* do NOT mark it as written as that has a different meaning for * functions (marks them as "should return a value") */ - - /* compute the number of references on the function */ - for (count=0; countnumrefers && curfunc->refer[count]; count++) - /* nothing */; - /* if there's references on the function or/and this function was declared as public */ - if (count!=0 || (curfunc->usage & uPUBLIC)!=0) + if (!curfunc->func_skipped) markusage(sym,uREAD); } else { outval(sym->addr,FALSE); From 284bbc1a124d81a59f7caa6d41d08f6cbc3fadf5 Mon Sep 17 00:00:00 2001 From: VVWVV Date: Sun, 12 Mar 2017 10:33:59 +0300 Subject: [PATCH 4/5] Remove a variable for reference counting in emit Signed-off-by: VVWVV --- source/compiler/sc2.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index a509ac8..1bd27dd 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1318,8 +1318,6 @@ static int command(void) error(17,str); /* undefined symbol */ } else { if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { - int count; /* number of references on the function */ - if ((sym->usage & uNATIVE)!=0) { /* reserve a SYSREQ id if called for the first time */ if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) From e0d5c1dc6a778fc2b8558574ed4a2e53590fd141 Mon Sep 17 00:00:00 2001 From: VVWVV Date: Sat, 29 Jul 2017 22:12:58 +0300 Subject: [PATCH 5/5] Update fix Signed-off-by: VVWVV --- source/compiler/sc.h | 1 - source/compiler/sc1.c | 2 -- source/compiler/sc2.c | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 20b4c71..3313ce3 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -145,7 +145,6 @@ typedef struct s_symbol { struct s_symbol **refer; /* referrer list, functions that "use" this symbol */ int numrefers; /* number of entries in the referrer list */ char *documentation; /* optional documentation string */ - int func_skipped; } symbol; diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 345577a..af736bd 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3569,11 +3569,9 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc /* so it is not a prototype, proceed */ /* if this is a function that is not referred to (this can only be detected * in the second stage), shut code generation off */ - sym->func_skipped=FALSE; if (sc_status==statWRITE && (sym->usage & uREAD)==0 && !fpublic) { sc_status=statSKIP; cidx=code_idx; - sym->func_skipped=TRUE; glbdecl=glb_declared; } /* if */ if ((sym->flags & flgDEPRECATED)!=0) { diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 1bd27dd..54ea437 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1333,7 +1333,7 @@ static int command(void) /* mark function as "used" */ /* do NOT mark it as written as that has a different meaning for * functions (marks them as "should return a value") */ - if (!curfunc->func_skipped) + if (sc_status!=statSKIP) markusage(sym,uREAD); } else { outval(sym->addr,FALSE);