Bläddra i källkod

new function 'luaK_codek' (detail)

Roberto Ierusalimschy 16 år sedan
förälder
incheckning
2598138ece
3 ändrade filer med 15 tillägg och 6 borttagningar
  1. 11 3
      lcode.c
  2. 2 1
      lcode.h
  3. 2 2
      lparser.c

+ 11 - 3
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;

+ 2 - 1
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);

+ 2 - 2
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);