Browse Source

better control of integer types and their limits

Roberto Ierusalimschy 31 năm trước cách đây
mục cha
commit
8cb8594a3b
14 tập tin đã thay đổi với 148 bổ sung143 xóa
  1. 5 5
      fallback.c
  2. 32 30
      hash.c
  3. 6 6
      hash.h
  4. 11 11
      inout.c
  5. 6 5
      inout.h
  6. 2 2
      lex.c
  7. 12 8
      lua.stx
  8. 3 3
      luamem.c
  9. 25 24
      opcode.c
  10. 20 25
      opcode.h
  11. 16 15
      table.c
  12. 4 4
      table.h
  13. 3 3
      tree.c
  14. 3 2
      tree.h

+ 5 - 5
fallback.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
  
-char *rcs_fallback="$Id: fallback.c,v 1.8 1994/11/21 13:30:15 roberto Exp roberto $";
+char *rcs_fallback="$Id: fallback.c,v 1.9 1994/11/21 18:22:58 roberto Stab roberto $";
 
 #include <stdio.h>
  
@@ -116,12 +116,12 @@ static void funcFB (void)
 */
 
 static Object *lockArray = NULL;
-static int lockSize = 0;
+static Word lockSize = 0;
 
 int luaI_lock (Object *object)
 {
-  int i;
-  int oldSize;
+  Word i;
+  Word oldSize;
   if (tag(object) == LUA_T_NIL)
     return -1;
   for (i=0; i<lockSize; i++)
@@ -163,7 +163,7 @@ Object *luaI_getlocked (int ref)
 
 void luaI_travlock (void (*fn)(Object *))
 {
-  int i;
+  Word i;
   for (i=0; i<lockSize; i++)
     fn(&lockArray[i]);
 }

+ 32 - 30
hash.c

@@ -3,7 +3,7 @@
 ** hash manager for lua
 */
 
-char *rcs_hash="$Id: hash.c,v 2.20 1994/11/28 15:10:51 roberto Exp roberto $";
+char *rcs_hash="$Id: hash.c,v 2.21 1994/12/16 15:55:04 roberto Exp roberto $";
 
 #include "mem.h"
 #include "opcode.h"
@@ -31,21 +31,23 @@ static Hash *listhead = NULL;
 
 
 /* hash dimensions values */
-static int dimensions[] = 
+static Word dimensions[] = 
  {3, 5, 7, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421,
-  12853, 25717, 51437, 0};
-static int redimension (int nhash)
+  12853, 25717, 51437, 65521, 0};  /* 65521 == last prime < MAX_WORD */
+
+static Word redimension (Word nhash)
 {
- int i;
+ Word i;
  for (i=0; dimensions[i]!=0; i++)
  {
   if (dimensions[i] > nhash)
    return dimensions[i];
  }
- return nhash*2+1;
+ lua_error("table overflow");
+ return 0;  /* to avoid warnings */
 }
 
-static int hashindex (Hash *t, Object *ref)		/* hash function */
+static Word hashindex (Hash *t, Object *ref)		/* hash function */
 {
  switch (tag(ref))
  {
@@ -53,7 +55,7 @@ static int hashindex (Hash *t, Object *ref)		/* hash function */
    lua_reportbug ("unexpected type to index table");
    return -1;  /* UNREACHEABLE */
   case LUA_T_NUMBER:
-   return (((int)nvalue(ref))%nhash(t));
+   return (((Word)nvalue(ref))%nhash(t));
   case LUA_T_STRING:
   {
    unsigned long h = tsvalue(ref)->hash;
@@ -64,20 +66,20 @@ static int hashindex (Hash *t, Object *ref)		/* hash function */
        h = ((h<<5)-h)^(unsigned char)*(name++);
      tsvalue(ref)->hash = h;
    }
-   return h%nhash(t);	/* make it a valid index */
+   return (Word)h%nhash(t);  /* make it a valid index */
   }
   case LUA_T_FUNCTION:
-   return (((int)bvalue(ref))%nhash(t));
+   return (((IntPoint)bvalue(ref))%nhash(t));
   case LUA_T_CFUNCTION:
-   return (((int)fvalue(ref))%nhash(t));
+   return (((IntPoint)fvalue(ref))%nhash(t));
   case LUA_T_ARRAY:
-   return (((int)avalue(ref))%nhash(t));
+   return (((IntPoint)avalue(ref))%nhash(t));
   default:  /* user data */
-   return (((int)uvalue(ref))%nhash(t));
+   return (((IntPoint)uvalue(ref))%nhash(t));
  }
 }
 
-int lua_equalObj (Object *t1, Object *t2)
+Bool lua_equalObj (Object *t1, Object *t2)
 {
   if (tag(t1) != tag(t2)) return 0;
   switch (tag(t1))
@@ -92,9 +94,9 @@ int lua_equalObj (Object *t1, Object *t2)
   }
 }
 
-static int present (Hash *t, Object *ref)
+static Word present (Hash *t, Object *ref)
 { 
- int h = hashindex(t, ref);
+ Word h = hashindex(t, ref);
  while (tag(ref(node(t, h))) != LUA_T_NIL)
  {
   if (lua_equalObj(ref, ref(node(t, h))))
@@ -108,9 +110,9 @@ static int present (Hash *t, Object *ref)
 /*
 ** Alloc a vector node 
 */
-static Node *hashnodecreate (int nhash)
+static Node *hashnodecreate (Word nhash)
 {
- int i;
+ Word i;
  Node *v = newvector (nhash, Node);
  for (i=0; i<nhash; i++)
    tag(ref(&v[i])) = LUA_T_NIL;
@@ -120,10 +122,10 @@ static Node *hashnodecreate (int nhash)
 /*
 ** Create a new hash. Return the hash pointer or NULL on error.
 */
-static Hash *hashcreate (int nhash)
+static Hash *hashcreate (Word nhash)
 {
  Hash *t = new(Hash);
- nhash = redimension((int)((float)nhash/REHASH_LIMIT));
+ nhash = redimension((Word)((float)nhash/REHASH_LIMIT));
  nodevector(t) = hashnodecreate(nhash);
  nhash(t) = nhash;
  nuse(t) = 0;
@@ -148,7 +150,7 @@ void lua_hashmark (Hash *h)
 {
  if (markarray(h) == 0)
  {
-  int i;
+  Word i;
   markarray(h) = 1;
   for (i=0; i<nhash(h); i++)
   {
@@ -183,10 +185,10 @@ static void call_fallbacks (void)
 ** Garbage collection to arrays
 ** Delete all unmarked arrays.
 */
-int lua_hashcollector (void)
+Word lua_hashcollector (void)
 {
  Hash *curr_array = listhead, *prev = NULL;
- int counter = 0;
+ Word counter = 0;
  call_fallbacks();
  while (curr_array != NULL)
  {
@@ -215,7 +217,7 @@ int lua_hashcollector (void)
 ** executes garbage collection if the number of arrays created
 ** exceed a pre-defined range.
 */
-Hash *lua_createarray (int nhash)
+Hash *lua_createarray (Word nhash)
 {
  Hash *array;
  lua_pack();
@@ -231,8 +233,8 @@ Hash *lua_createarray (int nhash)
 */
 static void rehash (Hash *t)
 {
- int i;
- int   nold = nhash(t);
+ Word i;
+ Word   nold = nhash(t);
  Node *vold = nodevector(t);
  nhash(t) = redimension(nhash(t));
  nodevector(t) = hashnodecreate(nhash(t));
@@ -251,7 +253,7 @@ static void rehash (Hash *t)
 */
 Object *lua_hashget (Hash *t, Object *ref)
 {
- int h = present(t, ref);
+ Word h = present(t, ref);
  if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
  else return NULL;
 }
@@ -263,7 +265,7 @@ Object *lua_hashget (Hash *t, Object *ref)
 */
 Object *lua_hashdefine (Hash *t, Object *ref)
 {
- int   h;
+ Word   h;
  Node *n;
  h = present(t, ref);
  n = node(t, h);
@@ -289,7 +291,7 @@ Object *lua_hashdefine (Hash *t, Object *ref)
 ** in the hash.
 ** This function pushs the element value and its reference to the stack.
 */
-static void hashnext (Hash *t, int i)
+static void hashnext (Hash *t, Word i)
 {
  if (i >= nhash(t))
  {
@@ -326,7 +328,7 @@ void lua_next (void)
  }
  else
  {
-  int h = present (t, luaI_Address(r));
+  Word h = present (t, luaI_Address(r));
   hashnext(t, h+1);
  }
 }

+ 6 - 6
hash.h

@@ -2,7 +2,7 @@
 ** hash.h
 ** hash manager for lua
 ** Luiz Henrique de Figueiredo - 17 Aug 90
-** $Id: hash.h,v 2.5 1994/11/14 18:41:15 roberto Exp roberto $
+** $Id: hash.h,v 2.6 1994/11/17 13:58:57 roberto Stab roberto $
 */
 
 #ifndef hash_h
@@ -18,16 +18,16 @@ typedef struct Hash
 {
  struct Hash   *next;
  char           mark;
- unsigned int   nhash;
- unsigned int   nuse;
+ Word          nhash;
+ Word           nuse;
  Node          *node;
 } Hash;
 
 
-int      lua_equalObj (Object *t1, Object *t2);
-Hash    *lua_createarray (int nhash);
+Bool     lua_equalObj (Object *t1, Object *t2);
+Hash    *lua_createarray (Word nhash);
 void     lua_hashmark (Hash *h);
-int      lua_hashcollector (void);
+Word     lua_hashcollector (void);
 Object  *lua_hashget (Hash *t, Object *ref);
 Object 	*lua_hashdefine (Hash *t, Object *ref);
 void     lua_next (void);

+ 11 - 11
inout.c

@@ -5,7 +5,7 @@
 ** Also provides some predefined lua functions.
 */
 
-char *rcs_inout="$Id: inout.c,v 2.14 1994/12/13 15:54:21 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.15 1994/12/16 15:55:04 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,9 +20,9 @@ char *rcs_inout="$Id: inout.c,v 2.14 1994/12/13 15:54:21 roberto Exp roberto $";
 #include "lua.h"
 
 /* Exported variables */
-int lua_linenumber;
-int lua_debug;
-int lua_debugline = 0;
+Word lua_linenumber;
+Bool lua_debug;
+Word lua_debugline = 0;
 
 
 /* Internal variables */
@@ -34,12 +34,12 @@ int lua_debugline = 0;
 typedef struct FuncStackNode {
   struct FuncStackNode *next;
   char *file;
-  int function;
-  int line;
+  Word function;
+  Word line;
 } FuncStackNode;
  
 static FuncStackNode *funcStack = NULL;
-static int nfuncstack=0;
+static Word nfuncstack=0;
 
 static FILE *fp;
 static char *st;
@@ -119,7 +119,7 @@ void lua_closestring (void)
 ** Called to execute  SETFUNCTION opcode, this function pushs a function into
 ** function stack.
 */
-void lua_pushfunction (char *file, int function)
+void lua_pushfunction (char *file, Word function)
 {
  FuncStackNode *newNode;
  if (nfuncstack++ >= MAXFUNCSTACK)
@@ -165,8 +165,8 @@ void lua_reportbug (char *s)
    do
    {
      sprintf (strchr(msg,0),
-       "\t-> function \"%s\" at file \"%s\":%d\n", 
-                     lua_constant[func->function]->str, func->file, line);
+       "\t-> function \"%s\" at file \"%s\":%u\n", 
+              lua_constant[func->function]->str, func->file, line);
      line = func->line;
      func = func->next;
      lua_popfunction();
@@ -175,7 +175,7 @@ void lua_reportbug (char *s)
   else
   {
    sprintf (strchr(msg,0),
-         "\n\tin statement begining at line %d of file \"%s\"", 
+         "\n\tin statement begining at line %u of file \"%s\"", 
          lua_debugline, lua_filename());
   }
  }

+ 6 - 5
inout.h

@@ -1,21 +1,22 @@
 /*
-** $Id: inout.h,v 1.5 1994/11/08 20:06:15 roberto Exp roberto $
+** $Id: inout.h,v 1.6 1994/11/21 21:41:09 roberto Stab roberto $
 */
 
 
 #ifndef inout_h
 #define inout_h
 
+#include "types.h"
 
-extern int lua_linenumber;
-extern int lua_debug;
-extern int lua_debugline;
+extern Word lua_linenumber;
+extern Bool lua_debug;
+extern Word lua_debugline;
 
 char *lua_openfile     (char *fn);
 void lua_closefile    (void);
 char *lua_openstring   (char *s);
 void lua_closestring  (void);
-void lua_pushfunction (char *file, int function);
+void lua_pushfunction (char *file, Word function);
 void lua_popfunction  (void);
 void lua_reportbug    (char *s);
 

+ 2 - 2
lex.c

@@ -1,4 +1,4 @@
-char *rcs_lex = "$Id: lex.c,v 2.11 1994/11/14 21:40:14 roberto Exp $";
+char *rcs_lex = "$Id: lex.c,v 2.12 1994/11/22 16:13:45 roberto Stab $";
  
 
 #include <ctype.h>
@@ -195,7 +195,7 @@ int yylex (void)
       case 'Z':
       case '_':
       {
-        int res;
+        Word res;
         do { save_and_next(); } while (isalnum(current) || current == '_');
         *yytextLast = 0;
         res = findReserved(yytext);

+ 12 - 8
lua.stx

@@ -1,6 +1,6 @@
 %{
 
-char *rcs_luastx = "$Id: lua.stx,v 3.12 1994/11/25 19:24:57 roberto Exp $";
+char *rcs_luastx = "$Id: lua.stx,v 3.13 1994/12/06 14:27:18 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,17 +29,17 @@ int yyparse (void);
 #ifndef CODE_BLOCK
 #define CODE_BLOCK 256
 #endif
-static Long   maxcode;
-static Long   maxmain;
-static Long   maxcurr ;
+static Word   maxcode;
+static Word   maxmain;
+static Long   maxcurr;  /* to allow maxcurr *= 2 without overflow */
 static Byte  *funcCode = NULL;
 static Byte **initcode;
 static Byte  *basepc;
-static Long   maincode;
-static Long   pc;
+static Word   maincode;
+static Word   pc;
 
 #define MAXVAR 32
-static long    varbuffer[MAXVAR];    /* variables in an assignment list;
+static Long    varbuffer[MAXVAR];    /* variables in an assignment list;
 				it's long to store negative Word values */
 static int     nvarbuffer=0;	     /* number of variables at a list */
 
@@ -57,7 +57,11 @@ static void code_byte (Byte c)
 {
  if (pc>maxcurr-2)  /* 1 byte free to code HALT of main code */
  {
+  if (maxcurr >= MAX_WORD)
+    lua_error("code size overflow");
   maxcurr *= 2;
+  if (maxcurr >= MAX_WORD)
+    maxcurr = MAX_WORD;
   basepc = growvector(basepc, maxcurr, Byte);
  }
  basepc[pc++] = c;
@@ -567,7 +571,7 @@ static int lua_localname (Word n)
 ** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
 ** Otherwise, if zero, push indexed variable (record).
 */
-static void lua_pushvar (long number)
+static void lua_pushvar (Long number)
 { 
  if (number > 0)	/* global var */
  {

+ 3 - 3
luamem.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_mem = "$Id: mem.c,v 1.1 1994/11/16 17:38:08 roberto Exp $";
+char *rcs_mem = "$Id: mem.c,v 1.2 1994/11/16 18:09:11 roberto Stab $";
 
 #include <stdlib.h>
 
@@ -19,7 +19,7 @@ void luaI_free (void *block)
 
 void *luaI_malloc (unsigned long size)
 {
-  void *block = malloc(size);
+  void *block = malloc((size_t)size);
   if (block == NULL)
     lua_error("not enough memory");
   return block;
@@ -28,7 +28,7 @@ void *luaI_malloc (unsigned long size)
 
 void *luaI_realloc (void *oldblock, unsigned long size)
 {
-  void *block = realloc(oldblock, size);
+  void *block = realloc(oldblock, (size_t)size);
   if (block == NULL)
     lua_error("not enough memory");
   return block;

+ 25 - 24
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.26 1994/12/16 15:56:45 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 3.27 1994/12/16 16:08:34 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
@@ -24,6 +24,8 @@ char *rcs_opcode="$Id: opcode.c,v 3.26 1994/12/16 15:56:45 roberto Exp roberto $
 
 #define STACK_BUFFER (STACKGAP+128)
 
+typedef unsigned int StkId;  /* index to stack elements */
+
 static Long    maxstack = 0L;
 static Object *stack = NULL;
 static Object *top = NULL;
@@ -35,16 +37,16 @@ static Object *top = NULL;
 #define Ref(st)         ((st)-stack+1)
  
 
-static int CBase = 0;   /* when Lua calls C or C calls Lua, points to the */
-                        /* first slot after the last parameter. */
+static StkId CBase = 0;  /* when Lua calls C or C calls Lua, points to */
+                          /* the first slot after the last parameter. */
 static int CnResults = 0; /* when Lua calls C, has the number of parameters; */
                          /* when C calls Lua, has the number of results. */
 
 static  jmp_buf *errorJmp = NULL; /* current error recover point */
 
 
-static int lua_execute (Byte *pc, int base);
-static void do_call (Object *func, int base, int nResults, int whereRes);
+static StkId lua_execute (Byte *pc, StkId base);
+static void do_call (Object *func, StkId base, int nResults, StkId whereRes);
 
 
 
@@ -94,11 +96,11 @@ static void lua_initstack (void)
 /*
 ** Check stack overflow and, if necessary, realloc vector
 */
-static void lua_checkstack (Word n)
+static void lua_checkstack (StkId n)
 {
  if ((Long)n > maxstack)
  {
-  int t;
+  StkId t;
   if (stack == NULL)
     lua_initstack();
   t = top-stack;
@@ -176,7 +178,7 @@ static int lua_tostring (Object *obj)
 /*
 ** Adjust stack. Set top to the given value, pushing NILs if needed.
 */
-static void adjust_top (int newtop)
+static void adjust_top (StkId newtop)
 {
   Object *nt = stack+newtop;
   while (top < nt) tag(top++) = LUA_T_NIL;
@@ -195,11 +197,11 @@ static void adjustC (int nParams)
 ** and CnResults is the number of parameters. Returns an index
 ** to the first result from C.
 */
-static int callC (lua_CFunction func, int base)
+static StkId callC (lua_CFunction func, StkId base)
 {
-  int oldBase = CBase;
+  StkId oldBase = CBase;
   int oldCnResults = CnResults;
-  int firstResult;
+  StkId firstResult;
   CnResults = (top-stack) - base;
   /* incorporate parameters on the stack */
   CBase = base+CnResults;
@@ -213,9 +215,9 @@ static int callC (lua_CFunction func, int base)
 /*
 ** Call the fallback for invalid functions (see do_call)
 */
-static void call_funcFB (Object *func, int base, int nResults, int whereRes)
+static void call_funcFB (Object *func, StkId base, int nResults, StkId whereRes)
 {
-  int i;
+  StkId i;
   /* open space for first parameter (func) */
   for (i=top-stack; i>base; i--)
     stack[i] = stack[i-1];
@@ -231,9 +233,9 @@ static void call_funcFB (Object *func, int base, int nResults, int whereRes)
 ** between [stack+whereRes,top). The number of results is nResults, unless
 ** nResults=MULT_RET.
 */
-static void do_call (Object *func, int base, int nResults, int whereRes)
+static void do_call (Object *func, StkId base, int nResults, StkId whereRes)
 {
-  int firstResult;
+  StkId firstResult;
   if (tag(func) == LUA_T_CFUNCTION)
     firstResult = callC(fvalue(func), base);
   else if (tag(func) == LUA_T_FUNCTION)
@@ -315,7 +317,7 @@ static int do_protectedrun (Object *function, int nResults)
 {
   jmp_buf myErrorJmp;
   int status;
-  int oldCBase = CBase;
+  StkId oldCBase = CBase;
   jmp_buf *oldErr = errorJmp;
   errorJmp = &myErrorJmp;
   if (setjmp(myErrorJmp) == 0)
@@ -340,7 +342,7 @@ static int do_protectedmain (void)
 {
   Byte *code = NULL;
   int status;
-  int oldCBase = CBase;
+  StkId oldCBase = CBase;
   jmp_buf myErrorJmp;
   jmp_buf *oldErr = errorJmp;
   errorJmp = &myErrorJmp;
@@ -377,7 +379,7 @@ int lua_callfunction (lua_Object function)
 
 int lua_call (char *funcname)
 {
- int n = luaI_findsymbolbyname(funcname);
+ Word n = luaI_findsymbolbyname(funcname);
  return do_protectedrun(&s_object(n), MULT_RET);
 }
 
@@ -455,7 +457,7 @@ lua_Object lua_getsubscript (void)
 #define MAX_C_BLOCKS 10
 
 static int numCblocks = 0;
-static int Cblocks[MAX_C_BLOCKS];
+static StkId Cblocks[MAX_C_BLOCKS];
 
 /*
 ** API: starts a new block
@@ -580,7 +582,7 @@ int lua_lock (void)
 */
 lua_Object lua_getglobal (char *name)
 {
- int n = luaI_findsymbolbyname(name);
+ Word n = luaI_findsymbolbyname(name);
  adjustC(0);
  *top = s_object(n);
  top++;
@@ -594,8 +596,7 @@ lua_Object lua_getglobal (char *name)
 */
 int lua_storeglobal (char *name)
 {
- int n = luaI_findsymbolbyname(name);
- if (n < 0) return 1;
+ Word n = luaI_findsymbolbyname(name);
  adjustC(1);
  s_object(n) = *(--top);
  return 0;
@@ -736,7 +737,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal,
 ** [stack+base,top). Returns n such that the the results are between
 ** [stack+n,top).
 */
-static int lua_execute (Byte *pc, int base)
+static StkId lua_execute (Byte *pc, StkId base)
 {
  lua_checkstack(STACKGAP+MAX_TEMPS+base);
  while (1)
@@ -1080,7 +1081,7 @@ static int lua_execute (Byte *pc, int base)
      int nParams = *(pc++);
      int nResults = *(pc++);
      Object *func = top-1-nParams; /* function is below parameters */
-     int newBase = (top-stack)-nParams;
+     StkId newBase = (top-stack)-nParams;
      do_call(func, newBase, nResults, newBase-1);
    }
    break;

+ 20 - 25
opcode.h

@@ -1,12 +1,13 @@
 /*
 ** TeCGraf - PUC-Rio
-** $Id: opcode.h,v 3.8 1994/11/10 17:36:54 roberto Exp roberto $
+** $Id: opcode.h,v 3.9 1994/11/23 14:31:11 roberto Stab $
 */
 
 #ifndef opcode_h
 #define opcode_h
 
 #include "lua.h"
+#include "types.h"
 #include "tree.h"
 
 #ifndef STACKGAP
@@ -21,29 +22,6 @@
 
 #define MAX_TEMPS	20
 
-typedef unsigned char  Byte;
-
-typedef unsigned short Word;
-
-typedef signed long  Long;
-
-typedef union
-{
- struct {char c1; char c2;} m;
- Word w;
-} CodeWord;
-
-typedef union
-{
- struct {char c1; char c2; char c3; char c4;} m;
- float f;
-} CodeFloat;
-
-typedef union
-{
- struct {char c1; char c2; char c3; char c4;} m;
- Byte *b;
-} CodeCode;
 
 typedef enum 
 { 
@@ -147,12 +125,29 @@ typedef struct
 #define s_fvalue(i)	(fvalue(&s_object(i)))
 #define s_uvalue(i)	(uvalue(&s_object(i)))
 
+typedef union
+{
+ struct {char c1; char c2;} m;
+ Word w;
+} CodeWord;
 #define get_word(code,pc)    {code.m.c1 = *pc++; code.m.c2 = *pc++;}
+
+typedef union
+{
+ struct {char c1; char c2; char c3; char c4;} m;
+ float f;
+} CodeFloat;
 #define get_float(code,pc)   {code.m.c1 = *pc++; code.m.c2 = *pc++;\
                               code.m.c3 = *pc++; code.m.c4 = *pc++;}
+
+typedef union
+{
+ struct {char c1; char c2; char c3; char c4;} m;
+ Byte *b;
+} CodeCode;
 #define get_code(code,pc)    {code.m.c1 = *pc++; code.m.c2 = *pc++;\
                               code.m.c3 = *pc++; code.m.c4 = *pc++;}
- 
+
 
 /* Exported functions */
 char   *lua_strdup (char *l);

+ 16 - 15
table.c

@@ -3,7 +3,7 @@
 ** Module to control static tables
 */
 
-char *rcs_table="$Id: table.c,v 2.23 1994/11/23 14:31:11 roberto Stab roberto $";
+char *rcs_table="$Id: table.c,v 2.24 1994/12/16 15:55:04 roberto Exp roberto $";
 
 #include <string.h>
 
@@ -17,8 +17,6 @@ char *rcs_table="$Id: table.c,v 2.23 1994/11/23 14:31:11 roberto Stab roberto $"
 #include "fallback.h"
 
 
-#define MAX_WORD  0xFFFD
-
 #define BUFFER_BLOCK 256
 
 Symbol *lua_table;
@@ -47,7 +45,7 @@ static void getglobal (void);
 */
 static void lua_initsymbol (void)
 {
- int n;
+ Word n;
  lua_maxsymbol = BUFFER_BLOCK;
  lua_table = newvector(lua_maxsymbol, Symbol);
  n = luaI_findsymbolbyname("next");
@@ -88,9 +86,8 @@ void lua_initconstant (void)
 /*
 ** Given a name, search it at symbol table and return its index. If not
 ** found, allocate it.
-** On error, return -1.
 */
-int luaI_findsymbol (TreeNode *t)
+Word luaI_findsymbol (TreeNode *t)
 {
  if (lua_table == NULL)
   lua_initsymbol(); 
@@ -98,9 +95,11 @@ int luaI_findsymbol (TreeNode *t)
  {
   if (lua_ntable == lua_maxsymbol)
   {
-   lua_maxsymbol *= 2;
-   if (lua_maxsymbol > MAX_WORD)
+   if (lua_maxsymbol >= MAX_WORD)
      lua_error("symbol table overflow");
+   lua_maxsymbol *= 2;
+   if (lua_maxsymbol >= MAX_WORD)
+     lua_maxsymbol = MAX_WORD; 
    lua_table = growvector(lua_table, lua_maxsymbol, Symbol);
   }
   t->varindex = lua_ntable;
@@ -111,7 +110,7 @@ int luaI_findsymbol (TreeNode *t)
 }
 
 
-int luaI_findsymbolbyname (char *name)
+Word luaI_findsymbolbyname (char *name)
 {
   return luaI_findsymbol(lua_constcreate(name));
 }
@@ -122,7 +121,7 @@ int luaI_findsymbolbyname (char *name)
 ** found, allocate it.
 ** On error, return -1.
 */
-int luaI_findconstant (TreeNode *t)
+Word luaI_findconstant (TreeNode *t)
 {
  if (lua_constant == NULL)
   lua_initconstant();
@@ -130,9 +129,11 @@ int luaI_findconstant (TreeNode *t)
  {
   if (lua_nconstant == lua_maxconstant)
   {
-   lua_maxconstant *= 2;
-   if (lua_maxconstant > MAX_WORD)
+   if (lua_maxconstant >= MAX_WORD)
      lua_error("constant table overflow");
+   lua_maxconstant *= 2;
+   if (lua_maxconstant >= MAX_WORD)
+     lua_maxconstant = MAX_WORD;
    lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *);
   }
   t->constindex = lua_nconstant;
@@ -172,9 +173,9 @@ void lua_markobject (Object *o)
 */
 void lua_pack (void)
 {
-  static int block = GARBAGE_BLOCK; /* when garbage collector will be called */
-  static int nentity = 0;   /* counter of new entities (strings and arrays) */
-  int recovered = 0;
+  static Word block = GARBAGE_BLOCK; /* when garbage collector will be called */
+  static Word nentity = 0;  /* counter of new entities (strings and arrays) */
+  Word recovered = 0;
   if (nentity++ < block) return;
   lua_travstack(lua_markobject); /* mark stack objects */
   lua_travsymbol(lua_markobject); /* mark symbol table objects */

+ 4 - 4
table.h

@@ -1,7 +1,7 @@
 /*
 ** Module to control static tables
 ** TeCGraf - PUC-Rio
-** $Id: table.h,v 2.8 1994/11/18 19:27:38 roberto Exp roberto $
+** $Id: table.h,v 2.9 1994/11/23 14:31:11 roberto Stab roberto $
 */
 
 #ifndef table_h
@@ -18,9 +18,9 @@ extern int     lua_nfile;
 
 
 void  lua_initconstant (void);
-int   luaI_findsymbolbyname (char *name);
-int   luaI_findsymbol      (TreeNode *t);
-int   luaI_findconstant    (TreeNode *t);
+Word  luaI_findsymbolbyname (char *name);
+Word  luaI_findsymbol      (TreeNode *t);
+Word  luaI_findconstant    (TreeNode *t);
 void  lua_travsymbol      (void (*fn)(Object *));
 void  lua_markobject      (Object *o);
 void  lua_pack            (void);

+ 3 - 3
tree.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
  
-char *rcs_tree="$Id: tree.c,v 1.10 1994/11/23 14:31:11 roberto Stab roberto $";
+char *rcs_tree="$Id: tree.c,v 1.11 1994/11/25 19:27:03 roberto Exp roberto $";
 
 
 #include <string.h>
@@ -78,10 +78,10 @@ TreeNode *lua_constcreate (char *str)
 ** Garbage collection function.
 ** This function traverse the string list freeing unindexed strings
 */
-int lua_strcollector (void)
+Word lua_strcollector (void)
 {
   StringNode *curr = string_root, *prev = NULL;
-  int counter = 0;
+  Word counter = 0;
   while (curr)
   {
     StringNode *next = curr->next;

+ 3 - 2
tree.h

@@ -1,12 +1,13 @@
 /*
 ** tree.h
 ** TecCGraf - PUC-Rio
-** $Id: tree.h,v 1.6 1994/11/23 14:31:11 roberto Stab roberto $
+** $Id: tree.h,v 1.7 1994/11/25 19:27:03 roberto Exp roberto $
 */
 
 #ifndef tree_h
 #define tree_h
 
+#include "types.h"
 
 #define NOT_USED  0xFFFE
 
@@ -30,7 +31,7 @@ typedef struct TreeNode
 
 TaggedString *lua_createstring (char *str);
 TreeNode *lua_constcreate  (char *str);
-int  lua_strcollector (void);
+Word lua_strcollector (void);
 TreeNode *lua_varnext      (char *n);
 
 #endif