3535#define MAXREGS 255
3636
3737
38+ /* (note that expressions VJMP also have jumps.) */
3839#define hasjumps (e ) ((e)->t != (e)->f)
3940
4041
@@ -415,7 +416,7 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
415416/*
416417** Format and emit an 'iAsBx' instruction.
417418*/
418- int luaK_codeAsBx (FuncState * fs , OpCode o , int a , int bc ) {
419+ static int codeAsBx (FuncState * fs , OpCode o , int a , int bc ) {
419420 unsigned int b = bc + OFFSET_sBx ;
420421 lua_assert (getOpMode (o ) == iAsBx );
421422 lua_assert (a <= MAXARG_A && b <= MAXARG_Bx );
@@ -671,7 +672,7 @@ static int fitsBx (lua_Integer i) {
671672
672673void luaK_int (FuncState * fs , int reg , lua_Integer i ) {
673674 if (fitsBx (i ))
674- luaK_codeAsBx (fs , OP_LOADI , reg , cast_int (i ));
675+ codeAsBx (fs , OP_LOADI , reg , cast_int (i ));
675676 else
676677 luaK_codek (fs , reg , luaK_intK (fs , i ));
677678}
@@ -680,7 +681,7 @@ void luaK_int (FuncState *fs, int reg, lua_Integer i) {
680681static void luaK_float (FuncState * fs , int reg , lua_Number f ) {
681682 lua_Integer fi ;
682683 if (luaV_flttointeger (f , & fi , F2Ieq ) && fitsBx (fi ))
683- luaK_codeAsBx (fs , OP_LOADF , reg , cast_int (fi ));
684+ codeAsBx (fs , OP_LOADF , reg , cast_int (fi ));
684685 else
685686 luaK_codek (fs , reg , luaK_numberK (fs , f ));
686687}
@@ -776,7 +777,8 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
776777 break ;
777778 }
778779 case VLOCAL : { /* already in a register */
779- e -> u .info = e -> u .var .ridx ;
780+ int temp = e -> u .var .ridx ;
781+ e -> u .info = temp ; /* (can't do a direct assignment; values overlap) */
780782 e -> k = VNONRELOC ; /* becomes a non-relocatable value */
781783 break ;
782784 }
@@ -984,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
984986** or it is a constant.
985987*/
986988void luaK_exp2val (FuncState * fs , expdesc * e ) {
987- if (hasjumps (e ))
989+ if (e -> k == VJMP || hasjumps (e ))
988990 luaK_exp2anyreg (fs , e );
989991 else
990992 luaK_dischargevars (fs , e );
@@ -1025,7 +1027,7 @@ static int luaK_exp2K (FuncState *fs, expdesc *e) {
10251027** in the range of R/K indices).
10261028** Returns 1 iff expression is K.
10271029*/
1028- int luaK_exp2RK (FuncState * fs , expdesc * e ) {
1030+ static int exp2RK (FuncState * fs , expdesc * e ) {
10291031 if (luaK_exp2K (fs , e ))
10301032 return 1 ;
10311033 else { /* not a constant in the right range: put it in a register */
@@ -1037,7 +1039,7 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
10371039
10381040static void codeABRK (FuncState * fs , OpCode o , int a , int b ,
10391041 expdesc * ec ) {
1040- int k = luaK_exp2RK (fs , ec );
1042+ int k = exp2RK (fs , ec );
10411043 luaK_codeABCk (fs , o , a , b , ec -> u .info , k );
10421044}
10431045
@@ -1215,7 +1217,7 @@ static void codenot (FuncState *fs, expdesc *e) {
12151217
12161218
12171219/*
1218- ** Check whether expression 'e' is a small literal string
1220+ ** Check whether expression 'e' is a short literal string
12191221*/
12201222static int isKstr (FuncState * fs , expdesc * e ) {
12211223 return (e -> k == VK && !hasjumps (e ) && e -> u .info <= MAXARG_B &&
@@ -1225,7 +1227,7 @@ static int isKstr (FuncState *fs, expdesc *e) {
12251227/*
12261228** Check whether expression 'e' is a literal integer.
12271229*/
1228- int luaK_isKint (expdesc * e ) {
1230+ static int isKint (expdesc * e ) {
12291231 return (e -> k == VKINT && !hasjumps (e ));
12301232}
12311233
@@ -1235,7 +1237,7 @@ int luaK_isKint (expdesc *e) {
12351237** proper range to fit in register C
12361238*/
12371239static int isCint (expdesc * e ) {
1238- return luaK_isKint (e ) && (l_castS2U (e -> u .ival ) <= l_castS2U (MAXARG_C ));
1240+ return isKint (e ) && (l_castS2U (e -> u .ival ) <= l_castS2U (MAXARG_C ));
12391241}
12401242
12411243
@@ -1244,7 +1246,7 @@ static int isCint (expdesc *e) {
12441246** proper range to fit in register sC
12451247*/
12461248static int isSCint (expdesc * e ) {
1247- return luaK_isKint (e ) && fitsC (e -> u .ival );
1249+ return isKint (e ) && fitsC (e -> u .ival );
12481250}
12491251
12501252
@@ -1283,15 +1285,17 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
12831285 if (t -> k == VUPVAL && !isKstr (fs , k )) /* upvalue indexed by non 'Kstr'? */
12841286 luaK_exp2anyreg (fs , t ); /* put it in a register */
12851287 if (t -> k == VUPVAL ) {
1286- t -> u .ind .t = t -> u .info ; /* upvalue index */
1287- t -> u .ind .idx = k -> u .info ; /* literal string */
1288+ int temp = t -> u .info ; /* upvalue index */
1289+ lua_assert (isKstr (fs , k ));
1290+ t -> u .ind .t = temp ; /* (can't do a direct assignment; values overlap) */
1291+ t -> u .ind .idx = k -> u .info ; /* literal short string */
12881292 t -> k = VINDEXUP ;
12891293 }
12901294 else {
12911295 /* register index of the table */
12921296 t -> u .ind .t = (t -> k == VLOCAL ) ? t -> u .var .ridx : t -> u .info ;
12931297 if (isKstr (fs , k )) {
1294- t -> u .ind .idx = k -> u .info ; /* literal string */
1298+ t -> u .ind .idx = k -> u .info ; /* literal short string */
12951299 t -> k = VINDEXSTR ;
12961300 }
12971301 else if (isCint (k )) {
@@ -1459,7 +1463,7 @@ static void codebinK (FuncState *fs, BinOpr opr,
14591463*/
14601464static int finishbinexpneg (FuncState * fs , expdesc * e1 , expdesc * e2 ,
14611465 OpCode op , int line , TMS event ) {
1462- if (!luaK_isKint (e2 ))
1466+ if (!isKint (e2 ))
14631467 return 0 ; /* not an integer constant */
14641468 else {
14651469 lua_Integer i2 = e2 -> u .ival ;
@@ -1592,7 +1596,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
15921596 op = OP_EQI ;
15931597 r2 = im ; /* immediate operand */
15941598 }
1595- else if (luaK_exp2RK (fs , e2 )) { /* 2nd expression is constant? */
1599+ else if (exp2RK (fs , e2 )) { /* 2nd expression is constant? */
15961600 op = OP_EQK ;
15971601 r2 = e2 -> u .info ; /* constant index */
15981602 }
@@ -1658,7 +1662,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
16581662 }
16591663 case OPR_EQ : case OPR_NE : {
16601664 if (!tonumeral (v , NULL ))
1661- luaK_exp2RK (fs , v );
1665+ exp2RK (fs , v );
16621666 /* else keep numeral, which may be an immediate operand */
16631667 break ;
16641668 }
0 commit comments