diff options
-rw-r--r-- | lcode.c | 16 | ||||
-rw-r--r-- | lcode.h | 5 | ||||
-rw-r--r-- | lopcodes.c | 4 | ||||
-rw-r--r-- | lopcodes.h | 3 | ||||
-rw-r--r-- | lparser.c | 4 | ||||
-rw-r--r-- | lvm.c | 7 |
6 files changed, 27 insertions, 12 deletions
@@ -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 | */ |
346 | int luaK_codek (FuncState *fs, int reg, int k) { | 346 | static 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 | */ |
471 | int luaK_intK (FuncState *fs, lua_Integer n) { | 471 | static 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 | ||
510 | void 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: { |
@@ -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 | ||
52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); |
53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
54 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); | ||
55 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); | 54 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); |
56 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); | 55 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); |
57 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); | 56 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); |
58 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); | 57 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); |
59 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); | 58 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); |
60 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); | 59 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n); |
61 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); | 60 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); |
62 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); | 61 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); |
63 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); | 62 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); |
@@ -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 @@ | |||
20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | 20 | LUAI_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 */ |
@@ -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 | ------------------------------------------------------------------------*/ |
171 | OP_MOVE,/* A B R(A) := R(B) */ | 171 | OP_MOVE,/* A B R(A) := R(B) */ |
172 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ | 172 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ |
173 | OP_LOADI,/* A sBx R(A) := sBx */ | ||
173 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ | 174 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ |
174 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | 175 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ |
175 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ | 176 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ |
@@ -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); |
@@ -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); |