From 2598138eced28b6ff8d4db9550a4e70c26cd4baa Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 10 Jun 2009 13:52:03 -0300 Subject: new function 'luaK_codek' (detail) --- lcode.c | 14 +++++++++++--- lcode.h | 3 ++- lparser.c | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lcode.c b/lcode.c index 12a69362..2b932b94 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.35 2008/04/02 16:16:06 roberto Exp roberto $ +** $Id: lcode.c,v 2.36 2008/04/07 18:41:47 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -349,11 +349,11 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { break; } case VK: { - luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + luaK_codek(fs, reg, e->u.s.info); break; } case VKNUM: { - luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); break; } case VRELOCABLE: { @@ -813,6 +813,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { lua_assert(getOpMode(o) == iABC); lua_assert(getBMode(o) != OpArgN || b == 0); lua_assert(getCMode(o) != OpArgN || c == 0); + lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C); return luaK_code(fs, CREATE_ABC(o, a, b, c)); } @@ -820,16 +821,23 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); lua_assert(getCMode(o) == OpArgN); + lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx); return luaK_code(fs, CREATE_ABx(o, a, bc)); } static int luaK_codeAx (FuncState *fs, OpCode o, int a) { lua_assert(getOpMode(o) == iAx); + lua_assert(a <= MAXARG_Ax); return luaK_code(fs, CREATE_Ax(o, a)); } +void luaK_codek (FuncState *fs, int reg, int k) { + luaK_codeABx(fs, OP_LOADK, reg, k); +} + + void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; int b = (tostore == LUA_MULTRET) ? 0 : tostore; diff --git a/lcode.h b/lcode.h index 27f12a3d..77f1450a 100644 --- a/lcode.h +++ b/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp roberto $ +** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -44,6 +44,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) +LUAI_FUNC void luaK_codek (FuncState *fs, int reg, int k); LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); LUAI_FUNC void luaK_fixline (FuncState *fs, int line); diff --git a/lparser.c b/lparser.c index 45506b9c..753dbce2 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.61 2009/03/26 12:56:38 roberto Exp roberto $ +** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -1085,7 +1085,7 @@ static void fornum (LexState *ls, TString *varname, int line) { if (testnext(ls, ',')) exp1(ls); /* optional step */ else { /* default step = 1 */ - luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1)); luaK_reserveregs(fs, 1); } forbody(ls, base, line, 1, 1); -- cgit v1.2.3-55-g6feb