浏览代码

better control over extensions of char/short to int

Roberto Ierusalimschy 25 年之前
父节点
当前提交
01b00cc292
共有 6 个文件被更改,包括 22 次插入20 次删除
  1. 3 3
      lcode.c
  2. 5 3
      lcode.h
  3. 2 2
      ldebug.c
  4. 5 5
      lparser.c
  5. 4 4
      lparser.h
  6. 3 3
      ltm.c

+ 3 - 3
lcode.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.c,v 1.50 2000/08/31 14:08:27 roberto Exp roberto $
+** $Id: lcode.c,v 1.51 2000/09/29 12:42:13 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -445,7 +445,7 @@ int luaK_code1 (FuncState *fs, OpCode o, int arg1) {
 
 int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
   Instruction i = previous_instruction(fs);
-  int delta = luaK_opproperties[o].push - luaK_opproperties[o].pop;
+  int delta = (int)luaK_opproperties[o].push - (int)luaK_opproperties[o].pop;
   int optm = 0;  /* 1 when there is an optimization */
   switch (o) {
     case OP_CLOSURE: {
@@ -647,7 +647,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
 }
 
 
-const struct OpProperties luaK_opproperties[NUM_OPCODES] = {
+const OpProperties luaK_opproperties[NUM_OPCODES] = {
   {iO, 0, 0},	/* OP_END */
   {iU, 0, 0},	/* OP_RETURN */
   {iAB, 0, 0},	/* OP_CALL */

+ 5 - 3
lcode.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.h,v 1.15 2000/06/28 20:20:36 roberto Exp roberto $
+** $Id: lcode.h,v 1.16 2000/08/09 14:49:13 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -38,11 +38,13 @@ enum Mode {iO, iU, iS, iAB};  /* instruction format */
 
 #define VD	100	/* flag for variable delta */
 
-extern const struct OpProperties {
+typedef struct OpProperties {
   char mode;
   unsigned char push;
   unsigned char pop;
-} luaK_opproperties[];
+} OpProperties;
+
+extern const OpProperties luaK_opproperties[];
 
 
 void luaK_error (LexState *ls, const char *msg);

+ 2 - 2
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 1.49 2000/10/27 11:39:52 roberto Exp roberto $
+** $Id: ldebug.c,v 1.50 2000/10/30 12:38:50 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -371,7 +371,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) {
         OpCode op = GET_OPCODE(i);
         LUA_ASSERT(luaK_opproperties[op].push != VD,
                    "invalid opcode for default");
-        top -= luaK_opproperties[op].pop;
+        top -= (int)luaK_opproperties[op].pop;
         LUA_ASSERT(top >= 0, "wrong stack");
         top = pushpc(stack, pc, top, luaK_opproperties[op].push);
       }

+ 5 - 5
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.116 2000/10/27 11:39:52 roberto Exp roberto $
+** $Id: lparser.c,v 1.117 2000/11/29 11:57:42 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -690,8 +690,8 @@ static BinOpr getbinopr (int op) {
 
 
 static const struct {
-  char left;  /* left priority for each binary operator */
-  char right; /* right priority */
+  unsigned char left;  /* left priority for each binary operator */
+  unsigned char right; /* right priority */
 } priority[] = {  /* ORDER OPR */
    {5, 5}, {5, 5}, {6, 6}, {6, 6},  /* arithmetic */
    {9, 8}, {4, 3},                  /* power and concat (right associative) */
@@ -718,13 +718,13 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
   else simpleexp(ls, v);
   /* expand while operators have priorities higher than `limit' */
   op = getbinopr(ls->t.token);
-  while (op != OPR_NOBINOPR && priority[op].left > limit) {
+  while (op != OPR_NOBINOPR && (int)priority[op].left > limit) {
     expdesc v2;
     BinOpr nextop;
     next(ls);
     luaK_infix(ls, op, v);
     /* read sub-expression with higher priority */
-    nextop = subexpr(ls, &v2, priority[op].right);
+    nextop = subexpr(ls, &v2, (int)priority[op].right);
     luaK_posfix(ls, op, v, &v2);
     op = nextop;
   }

+ 4 - 4
lparser.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.h,v 1.25 2000/09/29 12:42:13 roberto Exp roberto $
+** $Id: lparser.h,v 1.26 2000/10/09 13:47:46 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -44,9 +44,9 @@ typedef struct FuncState {
   int pc;  /* next position to code */
   int lasttarget;   /* `pc' of last `jump target' */
   int jlt;  /* list of jumps to `lasttarget' */
-  short stacklevel;  /* number of values on activation register */
-  short nactloc;  /* number of active local variables */
-  short nupvalues;  /* number of upvalues */
+  int stacklevel;  /* number of values on activation register */
+  int nactloc;  /* number of active local variables */
+  int nupvalues;  /* number of upvalues */
   int lastline;  /* line where last `lineinfo' was generated */
   struct Breaklabel *bl;  /* chain of breakable blocks */
   expdesc upvalues[MAXUPVALUES];  /* upvalues */

+ 3 - 3
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.55 2000/10/20 16:39:03 roberto Exp roberto $
+** $Id: ltm.c,v 1.56 2000/10/31 13:10:24 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -51,7 +51,7 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) {
 *  'placeholder' for "default" fallbacks
 */
 /* ORDER LUA_T, ORDER TM */
-static const char luaT_validevents[NUM_TAGS][TM_N] = {
+static const unsigned char luaT_validevents[NUM_TAGS][TM_N] = {
   {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},  /* LUA_TUSERDATA */
   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},  /* LUA_TNIL */
   {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},  /* LUA_TNUMBER */
@@ -61,7 +61,7 @@ static const char luaT_validevents[NUM_TAGS][TM_N] = {
 };
 
 int luaT_validevent (int t, int e) {  /* ORDER LUA_T */
-  return (t >= NUM_TAGS) ?  1 : luaT_validevents[t][e];
+  return (t >= NUM_TAGS) ?  1 : (int)luaT_validevents[t][e];
 }