diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-10 13:52:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-06-10 13:52:03 -0300 |
commit | 2598138eced28b6ff8d4db9550a4e70c26cd4baa (patch) | |
tree | 3af8e254e508a5dc5ce29c16d8197c542582d43d | |
parent | 4a67e48611c1ffaa6d474e443c3c89849c8b6e5f (diff) | |
download | lua-2598138eced28b6ff8d4db9550a4e70c26cd4baa.tar.gz lua-2598138eced28b6ff8d4db9550a4e70c26cd4baa.tar.bz2 lua-2598138eced28b6ff8d4db9550a4e70c26cd4baa.zip |
new function 'luaK_codek' (detail)
-rw-r--r-- | lcode.c | 14 | ||||
-rw-r--r-- | lcode.h | 3 | ||||
-rw-r--r-- | lparser.c | 4 |
3 files changed, 15 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.35 2008/04/02 16:16:06 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.36 2008/04/07 18:41:47 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 | */ |
@@ -349,11 +349,11 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { | |||
349 | break; | 349 | break; |
350 | } | 350 | } |
351 | case VK: { | 351 | case VK: { |
352 | luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); | 352 | luaK_codek(fs, reg, e->u.s.info); |
353 | break; | 353 | break; |
354 | } | 354 | } |
355 | case VKNUM: { | 355 | case VKNUM: { |
356 | luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); | 356 | luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); |
357 | break; | 357 | break; |
358 | } | 358 | } |
359 | case VRELOCABLE: { | 359 | case VRELOCABLE: { |
@@ -813,6 +813,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | |||
813 | lua_assert(getOpMode(o) == iABC); | 813 | lua_assert(getOpMode(o) == iABC); |
814 | lua_assert(getBMode(o) != OpArgN || b == 0); | 814 | lua_assert(getBMode(o) != OpArgN || b == 0); |
815 | lua_assert(getCMode(o) != OpArgN || c == 0); | 815 | lua_assert(getCMode(o) != OpArgN || c == 0); |
816 | lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); | ||
816 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); | 817 | return luaK_code(fs, CREATE_ABC(o, a, b, c)); |
817 | } | 818 | } |
818 | 819 | ||
@@ -820,16 +821,23 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { | |||
820 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { | 821 | int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { |
821 | lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); | 822 | lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); |
822 | lua_assert(getCMode(o) == OpArgN); | 823 | lua_assert(getCMode(o) == OpArgN); |
824 | lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); | ||
823 | return luaK_code(fs, CREATE_ABx(o, a, bc)); | 825 | return luaK_code(fs, CREATE_ABx(o, a, bc)); |
824 | } | 826 | } |
825 | 827 | ||
826 | 828 | ||
827 | static int luaK_codeAx (FuncState *fs, OpCode o, int a) { | 829 | static int luaK_codeAx (FuncState *fs, OpCode o, int a) { |
828 | lua_assert(getOpMode(o) == iAx); | 830 | lua_assert(getOpMode(o) == iAx); |
831 | lua_assert(a <= MAXARG_Ax); | ||
829 | return luaK_code(fs, CREATE_Ax(o, a)); | 832 | return luaK_code(fs, CREATE_Ax(o, a)); |
830 | } | 833 | } |
831 | 834 | ||
832 | 835 | ||
836 | void luaK_codek (FuncState *fs, int reg, int k) { | ||
837 | luaK_codeABx(fs, OP_LOADK, reg, k); | ||
838 | } | ||
839 | |||
840 | |||
833 | void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | 841 | void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { |
834 | int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; | 842 | int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; |
835 | int b = (tostore == LUA_MULTRET) ? 0 : tostore; | 843 | int b = (tostore == LUA_MULTRET) ? 0 : tostore; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 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 | */ |
@@ -44,6 +44,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; | |||
44 | 44 | ||
45 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) | 45 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) |
46 | 46 | ||
47 | LUAI_FUNC void luaK_codek (FuncState *fs, int reg, int k); | ||
47 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | 48 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); |
48 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 49 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
49 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); | 50 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.61 2009/03/26 12:56:38 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 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 | */ |
@@ -1085,7 +1085,7 @@ static void fornum (LexState *ls, TString *varname, int line) { | |||
1085 | if (testnext(ls, ',')) | 1085 | if (testnext(ls, ',')) |
1086 | exp1(ls); /* optional step */ | 1086 | exp1(ls); /* optional step */ |
1087 | else { /* default step = 1 */ | 1087 | else { /* default step = 1 */ |
1088 | luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); | 1088 | luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1)); |
1089 | luaK_reserveregs(fs, 1); | 1089 | luaK_reserveregs(fs, 1); |
1090 | } | 1090 | } |
1091 | forbody(ls, base, line, 1, 1); | 1091 | forbody(ls, base, line, 1, 1); |