35
35
#define MAXREGS 255
36
36
37
37
38
+ /* (note that expressions VJMP also have jumps.) */
38
39
#define hasjumps (e ) ((e)->t != (e)->f)
39
40
40
41
@@ -415,7 +416,7 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
415
416
/*
416
417
** Format and emit an 'iAsBx' instruction.
417
418
*/
418
- int luaK_codeAsBx (FuncState * fs , OpCode o , int a , int bc ) {
419
+ static int codeAsBx (FuncState * fs , OpCode o , int a , int bc ) {
419
420
unsigned int b = bc + OFFSET_sBx ;
420
421
lua_assert (getOpMode (o ) == iAsBx );
421
422
lua_assert (a <= MAXARG_A && b <= MAXARG_Bx );
@@ -671,7 +672,7 @@ static int fitsBx (lua_Integer i) {
671
672
672
673
void luaK_int (FuncState * fs , int reg , lua_Integer i ) {
673
674
if (fitsBx (i ))
674
- luaK_codeAsBx (fs , OP_LOADI , reg , cast_int (i ));
675
+ codeAsBx (fs , OP_LOADI , reg , cast_int (i ));
675
676
else
676
677
luaK_codek (fs , reg , luaK_intK (fs , i ));
677
678
}
@@ -680,7 +681,7 @@ void luaK_int (FuncState *fs, int reg, lua_Integer i) {
680
681
static void luaK_float (FuncState * fs , int reg , lua_Number f ) {
681
682
lua_Integer fi ;
682
683
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 ));
684
685
else
685
686
luaK_codek (fs , reg , luaK_numberK (fs , f ));
686
687
}
@@ -776,7 +777,8 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
776
777
break ;
777
778
}
778
779
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) */
780
782
e -> k = VNONRELOC ; /* becomes a non-relocatable value */
781
783
break ;
782
784
}
@@ -984,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
984
986
** or it is a constant.
985
987
*/
986
988
void luaK_exp2val (FuncState * fs , expdesc * e ) {
987
- if (hasjumps (e ))
989
+ if (e -> k == VJMP || hasjumps (e ))
988
990
luaK_exp2anyreg (fs , e );
989
991
else
990
992
luaK_dischargevars (fs , e );
@@ -1025,7 +1027,7 @@ static int luaK_exp2K (FuncState *fs, expdesc *e) {
1025
1027
** in the range of R/K indices).
1026
1028
** Returns 1 iff expression is K.
1027
1029
*/
1028
- int luaK_exp2RK (FuncState * fs , expdesc * e ) {
1030
+ static int exp2RK (FuncState * fs , expdesc * e ) {
1029
1031
if (luaK_exp2K (fs , e ))
1030
1032
return 1 ;
1031
1033
else { /* not a constant in the right range: put it in a register */
@@ -1037,7 +1039,7 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
1037
1039
1038
1040
static void codeABRK (FuncState * fs , OpCode o , int a , int b ,
1039
1041
expdesc * ec ) {
1040
- int k = luaK_exp2RK (fs , ec );
1042
+ int k = exp2RK (fs , ec );
1041
1043
luaK_codeABCk (fs , o , a , b , ec -> u .info , k );
1042
1044
}
1043
1045
@@ -1215,7 +1217,7 @@ static void codenot (FuncState *fs, expdesc *e) {
1215
1217
1216
1218
1217
1219
/*
1218
- ** Check whether expression 'e' is a small literal string
1220
+ ** Check whether expression 'e' is a short literal string
1219
1221
*/
1220
1222
static int isKstr (FuncState * fs , expdesc * e ) {
1221
1223
return (e -> k == VK && !hasjumps (e ) && e -> u .info <= MAXARG_B &&
@@ -1225,7 +1227,7 @@ static int isKstr (FuncState *fs, expdesc *e) {
1225
1227
/*
1226
1228
** Check whether expression 'e' is a literal integer.
1227
1229
*/
1228
- int luaK_isKint (expdesc * e ) {
1230
+ static int isKint (expdesc * e ) {
1229
1231
return (e -> k == VKINT && !hasjumps (e ));
1230
1232
}
1231
1233
@@ -1235,7 +1237,7 @@ int luaK_isKint (expdesc *e) {
1235
1237
** proper range to fit in register C
1236
1238
*/
1237
1239
static 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 ));
1239
1241
}
1240
1242
1241
1243
@@ -1244,7 +1246,7 @@ static int isCint (expdesc *e) {
1244
1246
** proper range to fit in register sC
1245
1247
*/
1246
1248
static int isSCint (expdesc * e ) {
1247
- return luaK_isKint (e ) && fitsC (e -> u .ival );
1249
+ return isKint (e ) && fitsC (e -> u .ival );
1248
1250
}
1249
1251
1250
1252
@@ -1283,15 +1285,17 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
1283
1285
if (t -> k == VUPVAL && !isKstr (fs , k )) /* upvalue indexed by non 'Kstr'? */
1284
1286
luaK_exp2anyreg (fs , t ); /* put it in a register */
1285
1287
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 */
1288
1292
t -> k = VINDEXUP ;
1289
1293
}
1290
1294
else {
1291
1295
/* register index of the table */
1292
1296
t -> u .ind .t = (t -> k == VLOCAL ) ? t -> u .var .ridx : t -> u .info ;
1293
1297
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 */
1295
1299
t -> k = VINDEXSTR ;
1296
1300
}
1297
1301
else if (isCint (k )) {
@@ -1459,7 +1463,7 @@ static void codebinK (FuncState *fs, BinOpr opr,
1459
1463
*/
1460
1464
static int finishbinexpneg (FuncState * fs , expdesc * e1 , expdesc * e2 ,
1461
1465
OpCode op , int line , TMS event ) {
1462
- if (!luaK_isKint (e2 ))
1466
+ if (!isKint (e2 ))
1463
1467
return 0 ; /* not an integer constant */
1464
1468
else {
1465
1469
lua_Integer i2 = e2 -> u .ival ;
@@ -1592,7 +1596,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1592
1596
op = OP_EQI ;
1593
1597
r2 = im ; /* immediate operand */
1594
1598
}
1595
- else if (luaK_exp2RK (fs , e2 )) { /* 2nd expression is constant? */
1599
+ else if (exp2RK (fs , e2 )) { /* 2nd expression is constant? */
1596
1600
op = OP_EQK ;
1597
1601
r2 = e2 -> u .info ; /* constant index */
1598
1602
}
@@ -1658,7 +1662,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
1658
1662
}
1659
1663
case OPR_EQ : case OPR_NE : {
1660
1664
if (!tonumeral (v , NULL ))
1661
- luaK_exp2RK (fs , v );
1665
+ exp2RK (fs , v );
1662
1666
/* else keep numeral, which may be an immediate operand */
1663
1667
break ;
1664
1668
}
0 commit comments