From c93336cf5a0f5ee74e141083a8350e3a618420c6 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 27 Feb 2021 22:42:58 +0700 Subject: [PATCH 1/8] Do not erase code for fetching the value from variable arguments of `load.u.*` and `push.u` pseudo-opcodes (fixes #568) As a side effect, this also makes `push.u` generate two instructions (`load(.s).pri \ push.pri`) instead of just one (`push(.s)`) for variable arguments (`iVARIABLE`); there seems to be no easy way around it. --- source/compiler/sc1.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 85dafe7..f5d3c78 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6671,7 +6671,8 @@ static int SC_FASTCALL emit_getrval(int *identptr,emit_outval *p,int *islocal) case iVARIABLE: case iREFERENCE: *islocal=((sym->vclass & sLOCAL)!=0); - /* fallthrough */ + p->value.ucell=(ucell)sym->addr; + break; case iCONSTEXPR: /* If the expression result is a constant value or a variable - erase the code * for this expression so the caller would be able to generate more optimal @@ -6679,7 +6680,7 @@ static int SC_FASTCALL emit_getrval(int *identptr,emit_outval *p,int *islocal) */ if (staging) stgdel(index,cidx); - p->value.ucell=*(ucell *)((*identptr==iCONSTEXPR) ? &val : &sym->addr); + p->value.ucell=(ucell)val; break; case iARRAY: case iREFARRAY: @@ -7442,15 +7443,6 @@ static void SC_FASTCALL emit_do_load_u_pri_alt(char *name) else outinstr((reg==sPRI) ? "const.pri" : "const.alt",p,1); break; - case iVARIABLE: - if (islocal) - outinstr((reg==sPRI) ? "load.s.pri" : "load.s.alt",p,1); - else - outinstr((reg==sPRI) ? "load.pri" : "load.alt",p,1); - break; - case iREFERENCE: - outinstr((reg==sPRI) ? "lref.s.pri" : "lref.s.alt",p,1); - break; default: if (reg==sALT) outinstr("move.alt",NULL,0); @@ -7535,12 +7527,6 @@ static void SC_FASTCALL emit_do_push_u(char *name) case iCONSTEXPR: outinstr("push.c",&p[0],1); break; - case iVARIABLE: - outinstr(islocal ? "push.s" : "push",p,1); - break; - case iREFERENCE: - outinstr("lref.s.pri",&p[0],1); - /* fallthrough */ default: outinstr("push.pri",NULL,0); break; From f545d8f5fe0070a6b8f71ef997e8a828750837dd Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 28 Feb 2021 14:18:28 +0700 Subject: [PATCH 2/8] Update P-code tests --- source/compiler/tests/__emit_pcode_check.meta | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/compiler/tests/__emit_pcode_check.meta b/source/compiler/tests/__emit_pcode_check.meta index 3c1fd70..268a73e 100644 --- a/source/compiler/tests/__emit_pcode_check.meta +++ b/source/compiler/tests/__emit_pcode_check.meta @@ -409,12 +409,15 @@ [0-9a-f]+ strb.i 00000001 [0-9a-f]+ push.r 00000028 [0-9a-f]+ push.c 00001234 -[0-9a-f]+ push 00000000 +[0-9a-f]+ load.pri 00000000 +[0-9a-f]+ push.pri [0-9a-f]+ lref.s.pri 0000000c [0-9a-f]+ push.pri [0-9a-f]+ push.c 00005678 -[0-9a-f]+ push.s fffffffc -[0-9a-f]+ push 0000000c +[0-9a-f]+ load.s.pri fffffffc +[0-9a-f]+ push.pri +[0-9a-f]+ load.pri 0000000c +[0-9a-f]+ push.pri [0-9a-f]+ push.c 00009abc [0-9a-f]+ push.r 00000029 [0-9a-f]+ push.c 000068ac From 3901a61421ad35b4be4714a67a43830e6986b990 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 28 Feb 2021 15:53:16 +0700 Subject: [PATCH 3/8] Simplify the code even more --- source/compiler/sc1.c | 51 +++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index f5d3c78..941bf93 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6645,16 +6645,14 @@ invalid_lvalue: * * Looks for an rvalue and generates code to handle expressions. */ -static int SC_FASTCALL emit_getrval(int *identptr,emit_outval *p,int *islocal) +static int SC_FASTCALL emit_getrval(int *identptr,cell *val) { int index,result=TRUE; cell cidx; - cell val; symbol *sym; assert(identptr!=NULL); - assert(p!=NULL); - assert(islocal!=NULL); + assert(val!=NULL); if (staging) { assert((emit_flags & efEXPR)!=0); @@ -6665,13 +6663,11 @@ static int SC_FASTCALL emit_getrval(int *identptr,emit_outval *p,int *islocal) } /* if */ errorset(sEXPRMARK,0); - *identptr=expression(&val,NULL,&sym,TRUE); - p->type=eotNUMBER; + *identptr=expression(val,NULL,&sym,TRUE); switch (*identptr) { case iVARIABLE: case iREFERENCE: - *islocal=((sym->vclass & sLOCAL)!=0); - p->value.ucell=(ucell)sym->addr; + *val=sym->addr; break; case iCONSTEXPR: /* If the expression result is a constant value or a variable - erase the code @@ -6680,7 +6676,6 @@ static int SC_FASTCALL emit_getrval(int *identptr,emit_outval *p,int *islocal) */ if (staging) stgdel(index,cidx); - p->value.ucell=(ucell)val; break; case iARRAY: case iREFARRAY: @@ -7429,25 +7424,17 @@ static void SC_FASTCALL emit_do_pushn_s_adr(char *name) static void SC_FASTCALL emit_do_load_u_pri_alt(char *name) { - emit_outval p[1]; + cell val; regid reg; - int ident,islocal; + int ident; - if (!emit_getrval(&ident,&p[0],&islocal)) + if (!emit_getrval(&ident,&val)) return; reg=emit_findreg(name); - switch (ident) { - case iCONSTEXPR: - if (p[0].value.ucell==(ucell)0) - outinstr((reg==sPRI) ? "zero.pri" : "zero.alt",NULL,0); - else - outinstr((reg==sPRI) ? "const.pri" : "const.alt",p,1); - break; - default: - if (reg==sALT) - outinstr("move.alt",NULL,0); - break; - } /* switch */ + if (ident==iCONSTEXPR) + ldconst(val,reg); + else if (reg==sALT) + outinstr("move.alt",NULL,0); } static void SC_FASTCALL emit_do_stor_u_pri_alt(char *name) @@ -7518,19 +7505,15 @@ static void SC_FASTCALL emit_do_addr_u_pri_alt(char *name) static void SC_FASTCALL emit_do_push_u(char *name) { - emit_outval p[1]; - int ident,islocal; + cell val; + int ident; - if (!emit_getrval(&ident,&p[0],&islocal)) + if (!emit_getrval(&ident,&val)) return; - switch (ident) { - case iCONSTEXPR: - outinstr("push.c",&p[0],1); - break; - default: + if (ident==iCONSTEXPR) + pushval(val); + else outinstr("push.pri",NULL,0); - break; - } /* switch */ } static void SC_FASTCALL emit_do_push_u_adr(char *name) From 583836feee1d4b7b7f2e6b86f4e2bf71bebcefa1 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 28 Feb 2021 16:24:53 +0700 Subject: [PATCH 4/8] Remove `SC_FASTCALL` from the headers for `emit_*` functions Those functions aren't called frequently, so `SC_FASTCALL` is rather excessive there. It might still be needed for opcode handlers in sc6.c though. --- source/compiler/sc1.c | 100 +++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 941bf93..054c313 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -146,7 +146,7 @@ static int *readwhile(void); static void dopragma(void); static void pragma_apply(symbol *sym); -typedef void (SC_FASTCALL *OPCODE_PROC)(char *name); +typedef void (*OPCODE_PROC)(char *name); typedef struct { char *name; OPCODE_PROC func; @@ -6427,7 +6427,7 @@ static symbol *fetchlab(char *name) return sym; } -static void SC_FASTCALL emit_invalid_token(int expected_token,int found_token) +static void emit_invalid_token(int expected_token,int found_token) { extern char *sc_tokens[]; char s[2]; @@ -6441,7 +6441,7 @@ static void SC_FASTCALL emit_invalid_token(int expected_token,int found_token) } /* if */ } -static regid SC_FASTCALL emit_findreg(char *opname) +static regid emit_findreg(char *opname) { const char *regname=strrchr(opname,'.'); assert(regname!=NULL); @@ -6455,9 +6455,9 @@ static regid SC_FASTCALL emit_findreg(char *opname) * Looks for an lvalue and generates code to get cell address in PRI * if the lvalue is an array element (iARRAYCELL or iARRAYCHAR). */ -static int SC_FASTCALL emit_getlval(int *identptr,emit_outval *p,int *islocal, - regid reg,int allow_char,int allow_const, - int store_pri,int store_alt,int *ispushed) +static int emit_getlval(int *identptr,emit_outval *p,int *islocal, + regid reg,int allow_char,int allow_const, + int store_pri,int store_alt,int *ispushed) { int tok,index,ident,close; cell cidx,val,length; @@ -6645,7 +6645,7 @@ invalid_lvalue: * * Looks for an rvalue and generates code to handle expressions. */ -static int SC_FASTCALL emit_getrval(int *identptr,cell *val) +static int emit_getrval(int *identptr,cell *val) { int index,result=TRUE; cell cidx; @@ -6688,8 +6688,8 @@ static int SC_FASTCALL emit_getrval(int *identptr,cell *val) return result; } -static int SC_FASTCALL emit_param_any_internal(emit_outval *p,int expected_tok, - int allow_nonint,int allow_expr) +static int emit_param_any_internal(emit_outval *p,int expected_tok, + int allow_nonint,int allow_expr) { char *str; cell val,cidx; @@ -6811,18 +6811,18 @@ fetchtok: return TRUE; } -static void SC_FASTCALL emit_param_any(emit_outval *p) +static void emit_param_any(emit_outval *p) { emit_param_any_internal(p,teANY,TRUE,TRUE); } -static void SC_FASTCALL emit_param_integer(emit_outval *p) +static void emit_param_integer(emit_outval *p) { emit_param_any_internal(p,tNUMBER,FALSE,TRUE); } -static void SC_FASTCALL emit_param_index(emit_outval *p,int isrange, - const cell *valid_values,int numvalues) +static void emit_param_index(emit_outval *p,int isrange, + const cell *valid_values,int numvalues) { int i; cell val; @@ -6842,7 +6842,7 @@ static void SC_FASTCALL emit_param_index(emit_outval *p,int isrange, error(241); /* negative or too big shift count */ } -static void SC_FASTCALL emit_param_nonneg(emit_outval *p) +static void emit_param_nonneg(emit_outval *p) { if (!emit_param_any_internal(p,teNONNEG,FALSE,TRUE)) return; @@ -6862,14 +6862,14 @@ static void SC_FASTCALL emit_param_nonneg(emit_outval *p) } /* if */ } -static void SC_FASTCALL emit_param_shift(emit_outval *p) +static void emit_param_shift(emit_outval *p) { if (emit_param_any_internal(p,tNUMBER,FALSE,TRUE)) if (p->value.ucell>=(sizeof(cell)*8)) error(50); /* invalid range */ } -static void SC_FASTCALL emit_param_data(emit_outval *p) +static void emit_param_data(emit_outval *p) { cell val; char *str; @@ -6923,7 +6923,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p) error(11); /* must be a multiple of cell size */ } -static void SC_FASTCALL emit_param_local(emit_outval *p,int allow_ref) +static void emit_param_local(emit_outval *p,int allow_ref) { cell val; char *str; @@ -7003,7 +7003,7 @@ fetchtok: p->value.ucell=(ucell)(negate ? -val : val); } -static void SC_FASTCALL emit_param_label(emit_outval *p) +static void emit_param_label(emit_outval *p) { cell val; char *str; @@ -7050,7 +7050,7 @@ static void SC_FASTCALL emit_param_label(emit_outval *p) } } -static void SC_FASTCALL emit_param_function(emit_outval *p,int isnative) +static void emit_param_function(emit_outval *p,int isnative) { cell val; char *str; @@ -7104,17 +7104,17 @@ static void SC_FASTCALL emit_param_function(emit_outval *p,int isnative) } /* if */ } -static void SC_FASTCALL emit_noop(char *name) +static void emit_noop(char *name) { (void)name; } -static void SC_FASTCALL emit_parm0(char *name) +static void emit_parm0(char *name) { outinstr(name,NULL,0); } -static void SC_FASTCALL emit_parm1_any(char *name) +static void emit_parm1_any(char *name) { emit_outval p[1]; @@ -7122,7 +7122,7 @@ static void SC_FASTCALL emit_parm1_any(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_integer(char *name) +static void emit_parm1_integer(char *name) { emit_outval p[1]; @@ -7130,7 +7130,7 @@ static void SC_FASTCALL emit_parm1_integer(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_nonneg(char *name) +static void emit_parm1_nonneg(char *name) { emit_outval p[1]; @@ -7138,7 +7138,7 @@ static void SC_FASTCALL emit_parm1_nonneg(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_shift(char *name) +static void emit_parm1_shift(char *name) { emit_outval p[1]; @@ -7146,7 +7146,7 @@ static void SC_FASTCALL emit_parm1_shift(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_data(char *name) +static void emit_parm1_data(char *name) { emit_outval p[1]; @@ -7154,7 +7154,7 @@ static void SC_FASTCALL emit_parm1_data(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_local(char *name) +static void emit_parm1_local(char *name) { emit_outval p[1]; @@ -7162,7 +7162,7 @@ static void SC_FASTCALL emit_parm1_local(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_local_noref(char *name) +static void emit_parm1_local_noref(char *name) { emit_outval p[1]; @@ -7170,7 +7170,7 @@ static void SC_FASTCALL emit_parm1_local_noref(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_parm1_label(char *name) +static void emit_parm1_label(char *name) { emit_outval p[1]; @@ -7178,7 +7178,7 @@ static void SC_FASTCALL emit_parm1_label(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_do_casetbl(char *name) +static void emit_do_casetbl(char *name) { emit_outval p[2]; @@ -7189,7 +7189,7 @@ static void SC_FASTCALL emit_do_casetbl(char *name) outinstr("case",p,arraysize(p)); } -static void SC_FASTCALL emit_do_case(char *name) +static void emit_do_case(char *name) { emit_outval p[2]; @@ -7199,7 +7199,7 @@ static void SC_FASTCALL emit_do_case(char *name) code_idx-=opcodes(1); } -static void SC_FASTCALL emit_do_lodb_strb(char *name) +static void emit_do_lodb_strb(char *name) { static const cell valid_values[] = { 1,2,4 }; emit_outval p[1]; @@ -7208,7 +7208,7 @@ static void SC_FASTCALL emit_do_lodb_strb(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_do_align(char *name) +static void emit_do_align(char *name) { static const cell valid_values[] = { 0,sizeof(cell)-1 }; emit_outval p[1]; @@ -7217,7 +7217,7 @@ static void SC_FASTCALL emit_do_align(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_do_call(char *name) +static void emit_do_call(char *name) { emit_outval p[1]; @@ -7225,7 +7225,7 @@ static void SC_FASTCALL emit_do_call(char *name) outinstr(name,p,arraysize(p)); } -static void SC_FASTCALL emit_do_sysreq_c(char *name) +static void emit_do_sysreq_c(char *name) { emit_outval p[1]; @@ -7244,7 +7244,7 @@ static void SC_FASTCALL emit_do_sysreq_c(char *name) } /* if */ } -static void SC_FASTCALL emit_do_sysreq_n(char *name) +static void emit_do_sysreq_n(char *name) { emit_outval p[2]; @@ -7267,7 +7267,7 @@ static void SC_FASTCALL emit_do_sysreq_n(char *name) } /* if */ } -static void SC_FASTCALL emit_do_const(char *name) +static void emit_do_const(char *name) { emit_outval p[2]; @@ -7291,7 +7291,7 @@ static void SC_FASTCALL emit_do_const(char *name) } /* if */ } -static void SC_FASTCALL emit_do_const_s(char *name) +static void emit_do_const_s(char *name) { emit_outval p[2]; @@ -7315,7 +7315,7 @@ static void SC_FASTCALL emit_do_const_s(char *name) } /* if */ } -static void SC_FASTCALL emit_do_load_both(char *name) +static void emit_do_load_both(char *name) { emit_outval p[2]; @@ -7335,7 +7335,7 @@ static void SC_FASTCALL emit_do_load_both(char *name) } /* if */ } -static void SC_FASTCALL emit_do_load_s_both(char *name) +static void emit_do_load_s_both(char *name) { emit_outval p[2]; @@ -7355,7 +7355,7 @@ static void SC_FASTCALL emit_do_load_s_both(char *name) } /* if */ } -static void SC_FASTCALL emit_do_pushn_c(char *name) +static void emit_do_pushn_c(char *name) { emit_outval p[5]; int i,numargs; @@ -7377,7 +7377,7 @@ static void SC_FASTCALL emit_do_pushn_c(char *name) } /* if */ } -static void SC_FASTCALL emit_do_pushn(char *name) +static void emit_do_pushn(char *name) { emit_outval p[5]; int i,numargs; @@ -7399,7 +7399,7 @@ static void SC_FASTCALL emit_do_pushn(char *name) } /* if */ } -static void SC_FASTCALL emit_do_pushn_s_adr(char *name) +static void emit_do_pushn_s_adr(char *name) { emit_outval p[5]; int i,numargs; @@ -7422,7 +7422,7 @@ static void SC_FASTCALL emit_do_pushn_s_adr(char *name) } /* if */ } -static void SC_FASTCALL emit_do_load_u_pri_alt(char *name) +static void emit_do_load_u_pri_alt(char *name) { cell val; regid reg; @@ -7437,7 +7437,7 @@ static void SC_FASTCALL emit_do_load_u_pri_alt(char *name) outinstr("move.alt",NULL,0); } -static void SC_FASTCALL emit_do_stor_u_pri_alt(char *name) +static void emit_do_stor_u_pri_alt(char *name) { emit_outval p[1]; regid reg; @@ -7473,7 +7473,7 @@ static void SC_FASTCALL emit_do_stor_u_pri_alt(char *name) } /* switch */ } -static void SC_FASTCALL emit_do_addr_u_pri_alt(char *name) +static void emit_do_addr_u_pri_alt(char *name) { emit_outval p[1]; regid reg; @@ -7503,7 +7503,7 @@ static void SC_FASTCALL emit_do_addr_u_pri_alt(char *name) } /* switch */ } -static void SC_FASTCALL emit_do_push_u(char *name) +static void emit_do_push_u(char *name) { cell val; int ident; @@ -7516,7 +7516,7 @@ static void SC_FASTCALL emit_do_push_u(char *name) outinstr("push.pri",NULL,0); } -static void SC_FASTCALL emit_do_push_u_adr(char *name) +static void emit_do_push_u_adr(char *name) { emit_outval p[1]; int ident,islocal; @@ -7540,7 +7540,7 @@ static void SC_FASTCALL emit_do_push_u_adr(char *name) } /* switch */ } -static void SC_FASTCALL emit_do_zero_u(char *name) +static void emit_do_zero_u(char *name) { emit_outval p[1]; int ident,islocal; @@ -7570,7 +7570,7 @@ static void SC_FASTCALL emit_do_zero_u(char *name) } /* switch */ } -static void SC_FASTCALL emit_do_inc_dec_u(char *name) +static void emit_do_inc_dec_u(char *name) { emit_outval p[1]; int ident,islocal; From e8346c047885a9dee6b26f567b234f6f1f33acee Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 28 Feb 2021 17:11:16 +0700 Subject: [PATCH 5/8] Add forward declarations for `emit_*` functions at the beginning of sc1.c --- source/compiler/sc1.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 054c313..8017276 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -134,6 +134,56 @@ static int doswitch(void); static void docase(int isdefault); static int dogoto(void); static void dolabel(void); +static void emit_invalid_token(int expected_token,int found_token); +static regid emit_findreg(char *opname); +static int emit_getlval(int *identptr,emit_outval *p,int *islocal, + regid reg,int allow_char,int allow_const, + int store_pri,int store_alt,int *ispushed); +static int emit_getrval(int *identptr,cell *val); +static int emit_param_any_internal(emit_outval *p,int expected_tok, + int allow_nonint,int allow_expr); +static void emit_param_any(emit_outval *p); +static void emit_param_integer(emit_outval *p); +static void emit_param_index(emit_outval *p,int isrange, + const cell *valid_values,int numvalues); +static void emit_param_nonneg(emit_outval *p); +static void emit_param_shift(emit_outval *p); +static void emit_param_data(emit_outval *p); +static void emit_param_local(emit_outval *p,int allow_ref); +static void emit_param_label(emit_outval *p); +static void emit_param_function(emit_outval *p,int isnative); +static void emit_noop(char *name); +static void emit_parm0(char *name); +static void emit_parm1_any(char *name); +static void emit_parm1_integer(char *name); +static void emit_parm1_nonneg(char *name); +static void emit_parm1_shift(char *name); +static void emit_parm1_data(char *name); +static void emit_parm1_local(char *name); +static void emit_parm1_local_noref(char *name); +static void emit_parm1_label(char *name); +static void emit_do_casetbl(char *name); +static void emit_do_case(char *name); +static void emit_do_lodb_strb(char *name); +static void emit_do_align(char *name); +static void emit_do_call(char *name); +static void emit_do_sysreq_c(char *name); +static void emit_do_sysreq_n(char *name); +static void emit_do_const(char *name); +static void emit_do_const_s(char *name); +static void emit_do_load_both(char *name); +static void emit_do_load_s_both(char *name); +static void emit_do_pushn_c(char *name); +static void emit_do_pushn(char *name); +static void emit_do_pushn_s_adr(char *name); +static void emit_do_load_u_pri_alt(char *name); +static void emit_do_stor_u_pri_alt(char *name); +static void emit_do_addr_u_pri_alt(char *name); +static void emit_do_push_u(char *name); +static void emit_do_push_u_adr(char *name); +static void emit_do_zero_u(char *name); +static void emit_do_inc_dec_u(char *name); +static int emit_findopcode(const char *instr); static int isterminal(int tok); static void doreturn(void); static void dobreak(void); From b849d614874e0da829a899b2f42848bc17eb59ee Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 4 Mar 2021 20:21:45 +0700 Subject: [PATCH 6/8] Do not use `errorset()` in `emit_*` functions --- source/compiler/sc1.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 8017276..dc702f6 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6567,9 +6567,7 @@ invalid_lvalue: pushreg(store_pri ? sPRI : sALT); *ispushed=TRUE; } /* if */ - errorset(sEXPRMARK,0); ident=expression(&val,NULL,NULL,TRUE); - errorset(sEXPRRELEASE,0); needtoken(close); /* check if the index isn't out of bounds */ @@ -6712,7 +6710,6 @@ static int emit_getrval(int *identptr,cell *val) result=FALSE; } /* if */ - errorset(sEXPRMARK,0); *identptr=expression(val,NULL,&sym,TRUE); switch (*identptr) { case iVARIABLE: @@ -6733,7 +6730,6 @@ static int emit_getrval(int *identptr,cell *val) result=FALSE; break; } /* switch */ - errorset(sEXPRRELEASE,0); return result; } @@ -6812,9 +6808,7 @@ fetchtok: if ((emit_flags & efEXPR)==0) stgset(TRUE); stgget(&index,&cidx); - errorset(sEXPRMARK,0); ident=expression(&val,NULL,NULL,FALSE); - errorset(sEXPRRELEASE,0); stgdel(index,cidx); if ((emit_flags & efEXPR)==0) stgset(FALSE); From 3706859c39e7f4d3adae8bc20c2f06eb481fd71d Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sat, 3 Aug 2019 17:53:21 +0700 Subject: [PATCH 7/8] __emit: Use proper search criterion for global 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 dc702f6..cc70a26 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6939,7 +6939,7 @@ static void emit_param_data(emit_outval *p) goto invalid_token; } /* if */ } else { - sym=findglb(str,sSTATIC); + sym=findglb(str,sSTATEVAR); if (sym==NULL) { error(17,str); /* undefined symbol */ return; From 647cd3471766425f52b88db8875a55a31aeced1d Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Tue, 6 Aug 2019 23:31:16 +0700 Subject: [PATCH 8/8] __emit: Switch to the code segment when used outside functions --- source/compiler/sc1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index cc70a26..ca5fa5c 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -1784,6 +1784,7 @@ static void parse(void) /* ignore zero's */ break; case t__EMIT: + begcseg(); emit_flags |= efGLOBAL; lex(&val,&str); emit_parse_line();