aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c55
1 files changed, 3 insertions, 52 deletions
diff --git a/lcode.c b/lcode.c
index 661c7916..ab91561c 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.159 2018/03/07 15:55:38 roberto Exp roberto $ 2** $Id: lcode.c,v 2.160 2018/03/16 14:22:09 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -678,10 +678,6 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
678 e->k = VNONRELOC; /* becomes a non-relocatable value */ 678 e->k = VNONRELOC; /* becomes a non-relocatable value */
679 break; 679 break;
680 } 680 }
681 case VUNDEF: { /* not a real expression */
682 luaK_semerror(fs->ls, "'undef' is not a value!!");
683 break;
684 }
685 case VUPVAL: { /* move value to some (pending) register */ 681 case VUPVAL: { /* move value to some (pending) register */
686 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); 682 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
687 e->k = VRELOC; 683 e->k = VRELOC;
@@ -1410,48 +1406,6 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1410} 1406}
1411 1407
1412 1408
1413static void normalizeindexed (FuncState *fs, expdesc *v) {
1414 if (v->k != VINDEXED) { /* not in proper form? */
1415 int key = fs->freereg; /* register with key value */
1416 luaK_reserveregs(fs, 1);
1417 switch (v->k) {
1418 case VINDEXI:
1419 luaK_int(fs, key, v->u.ind.idx);
1420 break;
1421 case VINDEXSTR:
1422 luaK_codek(fs, key, v->u.ind.idx);
1423 break;
1424 case VINDEXUP:
1425 luaK_codek(fs, key, v->u.ind.idx);
1426 luaK_codeABC(fs, OP_GETUPVAL, fs->freereg, v->u.ind.t, 0);
1427 v->u.ind.t = fs->freereg;
1428 luaK_reserveregs(fs, 1); /* one more register for the upvalue */
1429 break;
1430 default:
1431 luaK_semerror(fs->ls, "'undef' is not a value!!");
1432 break;
1433 }
1434 v->u.ind.idx = key;
1435 v->k = VINDEXED;
1436 }
1437 freeregs(fs, v->u.ind.t, v->u.ind.idx);
1438}
1439
1440
1441static void codeisdef (FuncState *fs, int eq, expdesc *v) {
1442 normalizeindexed(fs, v);
1443 v->u.info = luaK_codeABCk(fs, OP_ISDEF, 0, v->u.ind.t, v->u.ind.idx, eq);
1444 v->k = VRELOC;
1445}
1446
1447
1448void luaK_codeundef (FuncState *fs, expdesc *v) {
1449 normalizeindexed(fs, v);
1450 v->u.info = luaK_codeABC(fs, OP_UNDEF, v->u.ind.t, v->u.ind.idx, 0);
1451 v->k = VRELOC;
1452}
1453
1454
1455/* 1409/*
1456** Apply prefix operation 'op' to expression 'e'. 1410** Apply prefix operation 'op' to expression 'e'.
1457*/ 1411*/
@@ -1500,7 +1454,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
1500 break; 1454 break;
1501 } 1455 }
1502 case OPR_EQ: case OPR_NE: { 1456 case OPR_EQ: case OPR_NE: {
1503 if (!tonumeral(v, NULL) && fs->ls->t.token != TK_UNDEF) 1457 if (!tonumeral(v, NULL))
1504 luaK_exp2RK(fs, v); 1458 luaK_exp2RK(fs, v);
1505 /* else keep numeral, which may be an immediate operand */ 1459 /* else keep numeral, which may be an immediate operand */
1506 break; 1460 break;
@@ -1597,10 +1551,7 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
1597 break; 1551 break;
1598 } 1552 }
1599 case OPR_EQ: case OPR_NE: { 1553 case OPR_EQ: case OPR_NE: {
1600 if (e2->k == VUNDEF) 1554 codeeq(fs, opr, e1, e2);
1601 codeisdef(fs, opr == OPR_NE, e1);
1602 else
1603 codeeq(fs, opr, e1, e2);
1604 break; 1555 break;
1605 } 1556 }
1606 case OPR_LT: case OPR_LE: { 1557 case OPR_LT: case OPR_LE: {