aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-01-05 14:22:37 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-01-05 14:22:37 -0200
commit1f259be52a6ac8f7cfdee3787ffbf7dd0966748e (patch)
treebf26e713d78c5d95c7c18b438f582accd9b0ac44
parent1a44e822009752513ce895b9eabc51a4ee4a195a (diff)
downloadlua-1f259be52a6ac8f7cfdee3787ffbf7dd0966748e.tar.gz
lua-1f259be52a6ac8f7cfdee3787ffbf7dd0966748e.tar.bz2
lua-1f259be52a6ac8f7cfdee3787ffbf7dd0966748e.zip
'getcode' -> 'getinstruction'
-rw-r--r--lcode.c27
-rw-r--r--lcode.h5
-rw-r--r--lparser.c8
3 files changed, 22 insertions, 18 deletions
diff --git a/lcode.c b/lcode.c
index a274e974..06646e76 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.106 2015/12/18 13:53:36 roberto Exp roberto $ 2** $Id: lcode.c,v 2.107 2016/01/04 13:40:57 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*/
@@ -514,11 +514,12 @@ static int nilK (FuncState *fs) {
514*/ 514*/
515void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { 515void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
516 if (e->k == VCALL) { /* expression is an open function call? */ 516 if (e->k == VCALL) { /* expression is an open function call? */
517 SETARG_C(getcode(fs, e), nresults+1); 517 SETARG_C(getinstruction(fs, e), nresults + 1);
518 } 518 }
519 else if (e->k == VVARARG) { 519 else if (e->k == VVARARG) {
520 SETARG_B(getcode(fs, e), nresults+1); 520 Instruction *pc = &getinstruction(fs, e);
521 SETARG_A(getcode(fs, e), fs->freereg); 521 SETARG_B(*pc, nresults + 1);
522 SETARG_A(*pc, fs->freereg);
522 luaK_reserveregs(fs, 1); 523 luaK_reserveregs(fs, 1);
523 } 524 }
524 else lua_assert(nresults == LUA_MULTRET); 525 else lua_assert(nresults == LUA_MULTRET);
@@ -537,12 +538,13 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
537*/ 538*/
538void luaK_setoneret (FuncState *fs, expdesc *e) { 539void luaK_setoneret (FuncState *fs, expdesc *e) {
539 if (e->k == VCALL) { /* expression is an open function call? */ 540 if (e->k == VCALL) { /* expression is an open function call? */
540 lua_assert(GETARG_C(getcode(fs, e)) == 2); /* already returns 1 value */ 541 /* already returns 1 value */
542 lua_assert(GETARG_C(getinstruction(fs, e)) == 2);
541 e->k = VNONRELOC; /* result has fixed position */ 543 e->k = VNONRELOC; /* result has fixed position */
542 e->u.info = GETARG_A(getcode(fs, e)); 544 e->u.info = GETARG_A(getinstruction(fs, e));
543 } 545 }
544 else if (e->k == VVARARG) { 546 else if (e->k == VVARARG) {
545 SETARG_B(getcode(fs, e), 2); 547 SETARG_B(getinstruction(fs, e), 2);
546 e->k = VRELOCABLE; /* can relocate its simple result */ 548 e->k = VRELOCABLE; /* can relocate its simple result */
547 } 549 }
548} 550}
@@ -614,7 +616,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
614 break; 616 break;
615 } 617 }
616 case VRELOCABLE: { 618 case VRELOCABLE: {
617 Instruction *pc = &getcode(fs, e); 619 Instruction *pc = &getinstruction(fs, e);
618 SETARG_A(*pc, reg); /* instruction will put result in 'reg' */ 620 SETARG_A(*pc, reg); /* instruction will put result in 'reg' */
619 break; 621 break;
620 } 622 }
@@ -836,7 +838,7 @@ static void negatecondition (FuncState *fs, expdesc *e) {
836*/ 838*/
837static int jumponcond (FuncState *fs, expdesc *e, int cond) { 839static int jumponcond (FuncState *fs, expdesc *e, int cond) {
838 if (e->k == VRELOCABLE) { 840 if (e->k == VRELOCABLE) {
839 Instruction ie = getcode(fs, e); 841 Instruction ie = getinstruction(fs, e);
840 if (GET_OPCODE(ie) == OP_NOT) { 842 if (GET_OPCODE(ie) == OP_NOT) {
841 fs->pc--; /* remove previous OP_NOT */ 843 fs->pc--; /* remove previous OP_NOT */
842 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); 844 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
@@ -1134,10 +1136,11 @@ void luaK_posfix (FuncState *fs, BinOpr op,
1134 } 1136 }
1135 case OPR_CONCAT: { 1137 case OPR_CONCAT: {
1136 luaK_exp2val(fs, e2); 1138 luaK_exp2val(fs, e2);
1137 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { 1139 if (e2->k == VRELOCABLE &&
1138 lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1); 1140 GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {
1141 lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);
1139 freeexp(fs, e1); 1142 freeexp(fs, e1);
1140 SETARG_B(getcode(fs, e2), e1->u.info); 1143 SETARG_B(getinstruction(fs, e2), e1->u.info);
1141 e1->k = VRELOCABLE; e1->u.info = e2->u.info; 1144 e1->k = VRELOCABLE; e1->u.info = e2->u.info;
1142 } 1145 }
1143 else { 1146 else {
diff --git a/lcode.h b/lcode.h
index a3fdf520..d2b5100e 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.62 2013/12/18 14:12:03 roberto Exp roberto $ 2** $Id: lcode.h,v 1.63 2013/12/30 20:47:58 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*/
@@ -40,7 +40,8 @@ typedef enum BinOpr {
40typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 40typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
41 41
42 42
43#define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 43/* get (pointer to) instruction of given 'expdesc' */
44#define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
44 45
45#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 46#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
46 47
diff --git a/lparser.c b/lparser.c
index e687051e..757d6546 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.149 2015/11/02 16:09:30 roberto Exp roberto $ 2** $Id: lparser.c,v 2.150 2015/12/09 15:21:28 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1498,7 +1498,7 @@ static void exprstat (LexState *ls) {
1498 } 1498 }
1499 else { /* stat -> func */ 1499 else { /* stat -> func */
1500 check_condition(ls, v.v.k == VCALL, "syntax error"); 1500 check_condition(ls, v.v.k == VCALL, "syntax error");
1501 SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ 1501 SETARG_C(getinstruction(fs, &v.v), 1); /* call statement uses no results */
1502 } 1502 }
1503} 1503}
1504 1504
@@ -1515,8 +1515,8 @@ static void retstat (LexState *ls) {
1515 if (hasmultret(e.k)) { 1515 if (hasmultret(e.k)) {
1516 luaK_setmultret(fs, &e); 1516 luaK_setmultret(fs, &e);
1517 if (e.k == VCALL && nret == 1) { /* tail call? */ 1517 if (e.k == VCALL && nret == 1) { /* tail call? */
1518 SET_OPCODE(getcode(fs,&e), OP_TAILCALL); 1518 SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);
1519 lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); 1519 lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);
1520 } 1520 }
1521 first = fs->nactvar; 1521 first = fs->nactvar;
1522 nret = LUA_MULTRET; /* return all values */ 1522 nret = LUA_MULTRET; /* return all values */