diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 103cc0d..57940c6 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6091,8 +6091,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 store_pri,int store_alt,int *ispushed) +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) { int tok,index,ident,close; cell cidx,val,length; @@ -6123,6 +6124,8 @@ invalid_lvalue: return FALSE; } /* if */ markusage(sym,uREAD | uWRITTEN); + if (!allow_const && (sym->usage & uCONST)!=0) + goto invalid_lvalue; p->type=eotNUMBER; switch (sym->ident) @@ -6458,7 +6461,8 @@ static void SC_FASTCALL 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 SC_FASTCALL emit_param_index(emit_outval *p,int isrange, + const cell *valid_values,int numvalues) { int i; cell val; @@ -7097,7 +7101,7 @@ static void SC_FASTCALL emit_do_stor_u_pri_alt(char *name) int ident,islocal,ispushed; reg=emit_findreg(name); - if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,(reg==sPRI),(reg==sALT),&ispushed)) + if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,(reg==sPRI),(reg==sALT),&ispushed)) return; switch (ident) { case iVARIABLE: @@ -7133,7 +7137,7 @@ static void SC_FASTCALL emit_do_addr_u_pri_alt(char *name) int ident,islocal; reg=emit_findreg(name); - if (!emit_getlval(&ident,&p[0],&islocal,reg,TRUE,FALSE,FALSE,NULL)) + if (!emit_getlval(&ident,&p[0],&islocal,reg,TRUE,TRUE,FALSE,FALSE,NULL)) return; switch (ident) { case iVARIABLE: @@ -7184,7 +7188,7 @@ static void SC_FASTCALL emit_do_push_u_adr(char *name) emit_outval p[1]; int ident,islocal; - if (!emit_getlval(&ident,&p[0],&islocal,sPRI,FALSE,FALSE,FALSE,NULL)) + if (!emit_getlval(&ident,&p[0],&islocal,sPRI,FALSE,TRUE,FALSE,FALSE,NULL)) return; switch (ident) { case iVARIABLE: @@ -7208,7 +7212,7 @@ static void SC_FASTCALL emit_do_zero_u(char *name) emit_outval p[1]; int ident,islocal; - if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,FALSE,NULL)) + if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,FALSE,FALSE,NULL)) return; switch (ident) { case iVARIABLE: @@ -7240,7 +7244,7 @@ static void SC_FASTCALL emit_do_inc_dec_u(char *name) assert(strcmp(name,"inc.u")==0 || strcmp(name,"dec.u")==0); - if (!emit_getlval(&ident,&p[0],&islocal,sPRI,TRUE,FALSE,FALSE,NULL)) + if (!emit_getlval(&ident,&p[0],&islocal,sPRI,TRUE,FALSE,FALSE,FALSE,NULL)) return; switch (ident) { case iVARIABLE: @@ -7445,7 +7449,6 @@ static int emit_findopcode(const char *instr) high=(sizeof emit_opcodelist / sizeof emit_opcodelist[0])-1; while (low0) low=mid+1; diff --git a/source/compiler/tests/__emit.inc b/source/compiler/tests/__emit.inc index 834ec6d..3febc1e 100644 --- a/source/compiler/tests/__emit.inc +++ b/source/compiler/tests/__emit.inc @@ -3,5 +3,6 @@ const global_const = 0; new stock global_var = 0; new stock global_array[2]; +new stock const global_const_var = 0; forward global_func(); public global_func() { return 0; } native global_native(const string[]) = print; diff --git a/source/compiler/tests/__emit_p6.meta b/source/compiler/tests/__emit_p6.meta index d747d6d..81b62b3 100644 --- a/source/compiler/tests/__emit_p6.meta +++ b/source/compiler/tests/__emit_p6.meta @@ -9,17 +9,18 @@ __emit_p6.pwn(45) : error 022: must be lvalue (non-constant) __emit_p6.pwn(46) : error 022: must be lvalue (non-constant) __emit_p6.pwn(47) : error 022: must be lvalue (non-constant) __emit_p6.pwn(48) : error 022: must be lvalue (non-constant) -__emit_p6.pwn(49) : error 033: array must be indexed (variable "local_array") -__emit_p6.pwn(50) : error 033: array must be indexed (variable "local_refarray") -__emit_p6.pwn(69) : error 022: must be lvalue (non-constant) -__emit_p6.pwn(70) : error 022: must be lvalue (non-constant) +__emit_p6.pwn(49) : error 022: must be lvalue (non-constant) +__emit_p6.pwn(50) : error 033: array must be indexed (variable "local_array") +__emit_p6.pwn(51) : error 033: array must be indexed (variable "local_refarray") __emit_p6.pwn(71) : error 022: must be lvalue (non-constant) __emit_p6.pwn(72) : error 022: must be lvalue (non-constant) -__emit_p6.pwn(73) : error 033: array must be indexed (variable "local_array") -__emit_p6.pwn(74) : error 033: array must be indexed (variable "local_refarray") -__emit_p6.pwn(96) : error 076: syntax error in the expression, or invalid function call -__emit_p6.pwn(97) : error 076: syntax error in the expression, or invalid function call -__emit_p6.pwn(98) : error 033: array must be indexed (variable "local_array") -__emit_p6.pwn(99) : error 033: array must be indexed (variable "local_refarray") +__emit_p6.pwn(73) : error 022: must be lvalue (non-constant) +__emit_p6.pwn(74) : error 022: must be lvalue (non-constant) +__emit_p6.pwn(75) : error 033: array must be indexed (variable "local_array") +__emit_p6.pwn(76) : error 033: array must be indexed (variable "local_refarray") +__emit_p6.pwn(98) : error 076: syntax error in the expression, or invalid function call +__emit_p6.pwn(99) : error 076: syntax error in the expression, or invalid function call +__emit_p6.pwn(100) : error 033: array must be indexed (variable "local_array") +__emit_p6.pwn(101) : error 033: array must be indexed (variable "local_refarray") """ } diff --git a/source/compiler/tests/__emit_p6.pwn b/source/compiler/tests/__emit_p6.pwn index 0e9a543..ca09b7b 100644 --- a/source/compiler/tests/__emit_p6.pwn +++ b/source/compiler/tests/__emit_p6.pwn @@ -45,6 +45,7 @@ stock test__op_stor_u_pri_alt(&local_refvar, local_refarray[]) emit stor.u.pri global_const; emit stor.u.pri global_func; emit stor.u.pri global_native; + emit stor.u.pri global_const_var; emit stor.u.pri local_const; emit stor.u.pri local_array; emit stor.u.pri local_refarray; @@ -59,6 +60,7 @@ stock test__op_addr_u_pri_alt(&local_refvar, local_refarray[]) // ok emit addr.u.pri global_var; + emit addr.u.pri global_const_var; emit addr.u.pri local_var; emit addr.u.pri local_static_var; emit addr.u.pri local_refvar; @@ -104,7 +106,7 @@ main() { new t, a[2]; test__op_load_u_pri_alt(t, a); // 4 - test__op_stor_u_pri_alt(t, a); // 6 + test__op_stor_u_pri_alt(t, a); // 7 test__op_addr_u_pri_alt(t, a); // 6 test__push_u(t, a); // 4 } diff --git a/source/compiler/tests/__emit_p7.meta b/source/compiler/tests/__emit_p7.meta index e32da8a..a9c185f 100644 --- a/source/compiler/tests/__emit_p7.meta +++ b/source/compiler/tests/__emit_p7.meta @@ -1,25 +1,27 @@ { 'test_type': 'output_check', 'errors': """ -__emit_p7.pwn(20) : error 022: must be lvalue (non-constant) __emit_p7.pwn(21) : error 022: must be lvalue (non-constant) __emit_p7.pwn(22) : error 022: must be lvalue (non-constant) __emit_p7.pwn(23) : error 022: must be lvalue (non-constant) -__emit_p7.pwn(24) : error 033: array must be indexed (variable "local_array") -__emit_p7.pwn(25) : error 033: array must be indexed (variable "local_refarray") -__emit_p7.pwn(26) : error 035: argument type mismatch (argument 1) +__emit_p7.pwn(24) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(25) : error 033: array must be indexed (variable "local_array") +__emit_p7.pwn(26) : error 033: array must be indexed (variable "local_refarray") __emit_p7.pwn(27) : error 035: argument type mismatch (argument 1) -__emit_p7.pwn(46) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(28) : error 035: argument type mismatch (argument 1) __emit_p7.pwn(47) : error 022: must be lvalue (non-constant) __emit_p7.pwn(48) : error 022: must be lvalue (non-constant) __emit_p7.pwn(49) : error 022: must be lvalue (non-constant) -__emit_p7.pwn(50) : error 033: array must be indexed (variable "local_array") -__emit_p7.pwn(51) : error 033: array must be indexed (variable "local_refarray") -__emit_p7.pwn(70) : error 022: must be lvalue (non-constant) -__emit_p7.pwn(71) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(50) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(51) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(52) : error 033: array must be indexed (variable "local_array") +__emit_p7.pwn(53) : error 033: array must be indexed (variable "local_refarray") __emit_p7.pwn(72) : error 022: must be lvalue (non-constant) __emit_p7.pwn(73) : error 022: must be lvalue (non-constant) -__emit_p7.pwn(74) : error 033: array must be indexed (variable "local_array") -__emit_p7.pwn(75) : error 033: array must be indexed (variable "local_refarray") +__emit_p7.pwn(74) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(75) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(76) : error 022: must be lvalue (non-constant) +__emit_p7.pwn(77) : error 033: array must be indexed (variable "local_array") +__emit_p7.pwn(78) : error 033: array must be indexed (variable "local_refarray") """ } diff --git a/source/compiler/tests/__emit_p7.pwn b/source/compiler/tests/__emit_p7.pwn index 65e7773..0ee4e44 100644 --- a/source/compiler/tests/__emit_p7.pwn +++ b/source/compiler/tests/__emit_p7.pwn @@ -10,6 +10,7 @@ stock test__push_u_adr(&local_refvar, local_refarray[]) // ok emit push.u.adr global_var; + emit push.u.adr global_const_var; emit push.u.adr local_refvar; emit push.u.adr local_var; emit push.u.adr local_static_var; @@ -46,6 +47,7 @@ stock test__zero_u(&local_refvar, local_refarray[]) emit zero.u global_const; emit zero.u global_func; emit zero.u global_native; + emit zero.u global_const_var; emit zero.u local_const; emit zero.u local_array; emit zero.u local_refarray; @@ -70,6 +72,7 @@ stock test__inc_dec_u(&local_refvar, local_refarray[]) emit inc.u global_const; emit inc.u global_func; emit inc.u global_native; + emit inc.u global_const_var; emit inc.u local_const; emit inc.u local_array; emit inc.u local_refarray; @@ -80,6 +83,6 @@ main() { new t, a[2]; test__push_u_adr(t, a); // 8 - test__zero_u(t, a); // 6 - test__inc_dec_u(t, a); // 6 + test__zero_u(t, a); // 7 + test__inc_dec_u(t, a); // 7 }