aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c16
-rw-r--r--lcode.h5
-rw-r--r--lopcodes.c4
-rw-r--r--lopcodes.h3
-rw-r--r--lparser.c4
-rw-r--r--lvm.c7
6 files changed, 27 insertions, 12 deletions
diff --git a/lcode.c b/lcode.c
index aca0256d..f48221cf 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.111 2016/07/19 17:12:07 roberto Exp roberto $ 2** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 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*/
@@ -343,7 +343,7 @@ static int codeextraarg (FuncState *fs, int a) {
343** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX' 343** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'
344** instruction with "extra argument". 344** instruction with "extra argument".
345*/ 345*/
346int luaK_codek (FuncState *fs, int reg, int k) { 346static int luaK_codek (FuncState *fs, int reg, int k) {
347 if (k <= MAXARG_Bx) 347 if (k <= MAXARG_Bx)
348 return luaK_codeABx(fs, OP_LOADK, reg, k); 348 return luaK_codeABx(fs, OP_LOADK, reg, k);
349 else { 349 else {
@@ -468,7 +468,7 @@ int luaK_stringK (FuncState *fs, TString *s) {
468** same value; conversion to 'void*' is used only for hashing, so there 468** same value; conversion to 'void*' is used only for hashing, so there
469** are no "precision" problems. 469** are no "precision" problems.
470*/ 470*/
471int luaK_intK (FuncState *fs, lua_Integer n) { 471static int luaK_intK (FuncState *fs, lua_Integer n) {
472 TValue k, o; 472 TValue k, o;
473 setpvalue(&k, cast(void*, cast(size_t, n))); 473 setpvalue(&k, cast(void*, cast(size_t, n)));
474 setivalue(&o, n); 474 setivalue(&o, n);
@@ -507,6 +507,14 @@ static int nilK (FuncState *fs) {
507} 507}
508 508
509 509
510void luaK_int (FuncState *fs, int reg, lua_Integer i) {
511 if (-MAXARG_sBx <= i && i <= MAXARG_sBx)
512 luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i));
513 else
514 luaK_codek(fs, reg, luaK_intK(fs, i));
515}
516
517
510/* 518/*
511** Fix an expression to return the number of results 'nresults'. 519** Fix an expression to return the number of results 'nresults'.
512** Either 'e' is a multi-ret expression (function call or vararg) 520** Either 'e' is a multi-ret expression (function call or vararg)
@@ -612,7 +620,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
612 break; 620 break;
613 } 621 }
614 case VKINT: { 622 case VKINT: {
615 luaK_codek(fs, reg, luaK_intK(fs, e->u.ival)); 623 luaK_int(fs, reg, e->u.ival);
616 break; 624 break;
617 } 625 }
618 case VRELOCABLE: { 626 case VRELOCABLE: {
diff --git a/lcode.h b/lcode.h
index d2b5100e..e7ff3522 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.63 2013/12/30 20:47:58 roberto Exp roberto $ 2** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 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*/
@@ -51,13 +51,12 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
51 51
52LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 52LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
53LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 53LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
54LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);
55LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 54LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
56LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 55LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
57LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 56LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
58LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 57LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
59LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 58LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
60LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 59LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
61LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 60LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
62LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 61LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
63LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 62LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
diff --git a/lopcodes.c b/lopcodes.c
index 10d4bbce..18199764 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.c,v 1.54 2014/11/02 19:19:04 roberto Exp roberto $ 2** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,6 +20,7 @@
20LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 20LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
21 "MOVE", 21 "MOVE",
22 "LOADK", 22 "LOADK",
23 "LOADI",
23 "LOADKX", 24 "LOADKX",
24 "LOADBOOL", 25 "LOADBOOL",
25 "LOADNIL", 26 "LOADNIL",
@@ -75,6 +76,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
75/* T A B C mode opcode */ 76/* T A B C mode opcode */
76 opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
77 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
79 ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADI */
78 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 80 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
79 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 81 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
80 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 82 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
diff --git a/lopcodes.h b/lopcodes.h
index dd2a7571..afb9205a 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.148 2014/10/25 11:50:46 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -170,6 +170,7 @@ name args description
170------------------------------------------------------------------------*/ 170------------------------------------------------------------------------*/
171OP_MOVE,/* A B R(A) := R(B) */ 171OP_MOVE,/* A B R(A) := R(B) */
172OP_LOADK,/* A Bx R(A) := Kst(Bx) */ 172OP_LOADK,/* A Bx R(A) := Kst(Bx) */
173OP_LOADI,/* A sBx R(A) := sBx */
173OP_LOADKX,/* A R(A) := Kst(extra arg) */ 174OP_LOADKX,/* A R(A) := Kst(extra arg) */
174OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ 175OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
175OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ 176OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
diff --git a/lparser.c b/lparser.c
index 5894d8ff..25134f11 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.154 2016/06/22 15:48:25 roberto Exp roberto $ 2** $Id: lparser.c,v 2.155 2016/08/01 19:51:24 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*/
@@ -1329,7 +1329,7 @@ static void fornum (LexState *ls, TString *varname, int line) {
1329 if (testnext(ls, ',')) 1329 if (testnext(ls, ','))
1330 exp1(ls); /* optional step */ 1330 exp1(ls); /* optional step */
1331 else { /* default step = 1 */ 1331 else { /* default step = 1 */
1332 luaK_codek(fs, fs->freereg, luaK_intK(fs, 1)); 1332 luaK_int(fs, fs->freereg, 1);
1333 luaK_reserveregs(fs, 1); 1333 luaK_reserveregs(fs, 1);
1334 } 1334 }
1335 forbody(ls, base, line, 1, 1); 1335 forbody(ls, base, line, 1, 1);
diff --git a/lvm.c b/lvm.c
index 32958665..a15ebe56 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.269 2017/04/06 13:08:56 roberto Exp roberto $ 2** $Id: lvm.c,v 2.270 2017/04/11 18:41:09 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -808,6 +808,11 @@ void luaV_execute (lua_State *L) {
808 setobj2s(L, ra, rb); 808 setobj2s(L, ra, rb);
809 vmbreak; 809 vmbreak;
810 } 810 }
811 vmcase(OP_LOADI) {
812 lua_Integer b = GETARG_sBx(i);
813 setivalue(ra, b);
814 vmbreak;
815 }
811 vmcase(OP_LOADKX) { 816 vmcase(OP_LOADKX) {
812 TValue *rb; 817 TValue *rb;
813 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG); 818 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);