Browse Source

better identification of types which are tags

Roberto Ierusalimschy 28 years ago
parent
commit
52d5e8032c
3 changed files with 31 additions and 60 deletions
  1. 3 4
      lobject.c
  2. 13 12
      lobject.h
  3. 15 44
      ltm.c

+ 3 - 4
lobject.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lobject.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: lobject.c,v 1.2 1997/09/26 16:46:20 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -12,9 +12,8 @@
 
 
 
 
 char *luaO_typenames[] = { /* ORDER LUA_T */
 char *luaO_typenames[] = { /* ORDER LUA_T */
-  "userdata", "line", "cmark", "mark", "function", "function",
-  "prototype", "table", "string", "number", "nil",
-  NULL
+    "userdata", "number", "string", "table", "function", "function",
+    "nil", "prototype", "mark", "cmark", "line", NULL
 };
 };
 
 
 
 

+ 13 - 12
lobject.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lobject.h,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $
+** $Id: lobject.h,v 1.4 1997/10/16 10:59:34 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -35,20 +35,21 @@ typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hash
 ** grep "ORDER LUA_T"
 ** grep "ORDER LUA_T"
 */
 */
 typedef enum {
 typedef enum {
-  LUA_T_NIL      = -10,
-  LUA_T_NUMBER   = -9,
-  LUA_T_STRING   = -8,
-  LUA_T_ARRAY    = -7,  /* array==table */
-  LUA_T_PROTO    = -6,
-  LUA_T_FUNCTION = -5,
-  LUA_T_CFUNCTION= -4,
-  LUA_T_MARK     = -3,
-  LUA_T_CMARK    = -2,
-  LUA_T_LINE     = -1,
-  LUA_T_USERDATA = 0
+  LUA_T_USERDATA =  0,  /* tag default for userdata */
+  LUA_T_NUMBER   = -1,  /* fixed tag for numbers */
+  LUA_T_STRING   = -2,  /* fixed tag for strings */
+  LUA_T_ARRAY    = -3,  /* tag default for tables (or arrays) */
+  LUA_T_FUNCTION = -4,  /* fixed tag for functions */
+  LUA_T_CFUNCTION= -5,  /* fixed tag for Cfunctions */
+  LUA_T_NIL      = -6,  /* last "pre-defined" tag */
+  LUA_T_PROTO    = -7,
+  LUA_T_MARK     = -8,
+  LUA_T_CMARK    = -9,
+  LUA_T_LINE     = -10
 } lua_Type;
 } lua_Type;
 
 
 #define NUM_TYPES 11
 #define NUM_TYPES 11
+#define NUM_TAGS  7
 
 
 
 
 typedef union {
 typedef union {

+ 15 - 44
ltm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltm.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: ltm.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
 ** Tag methods
 ** Tag methods
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -14,31 +14,7 @@
 #include "lobject.h"
 #include "lobject.h"
 #include "ltm.h"
 #include "ltm.h"
 
 
-static struct IM init_IM[NUM_TYPES] = {
-{{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}},
-{{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}},
-{{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}},
-{{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
-  {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}},
+static struct IM init_IM[NUM_TAGS] = {
 {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
 {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
   {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
   {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
   {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
   {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}},
@@ -89,8 +65,7 @@ static struct IM init_IM[NUM_TYPES] = {
 char *luaT_eventname[] = {  /* ORDER IM */
 char *luaT_eventname[] = {  /* ORDER IM */
   "gettable", "settable", "index", "getglobal", "setglobal", "add",
   "gettable", "settable", "index", "getglobal", "setglobal", "add",
   "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
   "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
-  "concat", "gc", "function",
-  NULL
+  "concat", "gc", "function", NULL
 };
 };
 
 
 
 
@@ -105,26 +80,22 @@ static int luaI_checkevent (char *name, char *list[])
 
 
 struct IM *luaT_IMtable = init_IM;
 struct IM *luaT_IMtable = init_IM;
 
 
-static int IMtable_size = NUM_TYPES;
+static int IMtable_size = NUM_TAGS;
 
 
-static int last_tag = -(NUM_TYPES-1);
+static int last_tag = -(NUM_TAGS-1);
 
 
 
 
-/* events in LUA_T_LINE are all allowed, since this is used as a
+/* events in LUA_T_NIL are all allowed, since this is used as a
 *  'placeholder' for "default" fallbacks
 *  'placeholder' for "default" fallbacks
 */
 */
-static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */
+static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
 {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},  /* LUA_T_USERDATA */
 {1, 1, 0, 0, 0, 1, 1, 1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_FUNCTION */
+{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},  /* LUA_T_CFUNCTION */
+{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}   /* LUA_T_NIL */
 };
 };
 
 
 static int validevent (lua_Type t, int e)
 static int validevent (lua_Type t, int e)
@@ -159,7 +130,7 @@ int lua_newtag (void)
 
 
 
 
 static void checktag (int tag)
 static void checktag (int tag)
-{ /* ORDER LUA_T */
+{
   if (!(last_tag <= tag && tag <= 0))
   if (!(last_tag <= tag && tag <= 0))
     luaL_verror("%d is not a valid tag", tag);
     luaL_verror("%d is not a valid tag", tag);
 }
 }
@@ -289,7 +260,7 @@ void luaT_setfallback (void)
     }
     }
     case 3: {  /* old order fallback */
     case 3: {  /* old order fallback */
       int i;
       int i;
-      oldfunc = *luaT_getim(LUA_T_LINE, IM_LT);
+      oldfunc = *luaT_getim(LUA_T_NIL, IM_LT);
       for (i=IM_LT; i<=IM_GE; i++)  /* ORDER IM */
       for (i=IM_LT; i<=IM_GE; i++)  /* ORDER IM */
         fillvalids(i, luaA_Address(func));
         fillvalids(i, luaA_Address(func));
       replace = typeFB;
       replace = typeFB;
@@ -298,7 +269,7 @@ void luaT_setfallback (void)
     default: {
     default: {
       int e;
       int e;
       if ((e = luaO_findstring(name, luaT_eventname)) >= 0) {
       if ((e = luaO_findstring(name, luaT_eventname)) >= 0) {
-        oldfunc = *luaT_getim(LUA_T_LINE, e);
+        oldfunc = *luaT_getim(LUA_T_NIL, e);
         fillvalids(e, luaA_Address(func));
         fillvalids(e, luaA_Address(func));
         replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
         replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
       }
       }