Bläddra i källkod

limits now are in `llims.n'

Roberto Ierusalimschy 25 år sedan
förälder
incheckning
213e9febc8
9 ändrade filer med 27 tillägg och 165 borttagningar
  1. 1 5
      lbuiltin.c
  2. 1 5
      lcode.c
  3. 1 5
      ldo.h
  4. 1 5
      llex.c
  5. 1 5
      llex.h
  6. 2 44
      lobject.h
  7. 18 52
      lopcodes.h
  8. 1 12
      lparser.c
  9. 1 32
      lparser.h

+ 1 - 5
lbuiltin.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbuiltin.c,v 1.95 2000/03/09 00:19:22 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.96 2000/03/10 18:37:44 roberto Exp roberto $
 ** Built-in functions
 ** Built-in functions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -130,10 +130,6 @@ void luaB__ERRORMESSAGE (lua_State *L) {
 ** model but changing `fputs' to put the strings at a proper place
 ** model but changing `fputs' to put the strings at a proper place
 ** (a console window or a log file, for instance).
 ** (a console window or a log file, for instance).
 */
 */
-#ifndef MAXPRINT
-#define MAXPRINT	40  /* arbitrary limit */
-#endif
-
 void luaB_print (lua_State *L) {
 void luaB_print (lua_State *L) {
   lua_Object args[MAXPRINT];
   lua_Object args[MAXPRINT];
   lua_Object obj;
   lua_Object obj;

+ 1 - 5
lcode.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lcode.c,v 1.16 2000/03/20 19:15:37 roberto Exp roberto $
+** $Id: lcode.c,v 1.17 2000/03/24 12:18:30 roberto Exp roberto $
 ** Code generator for Lua
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -212,10 +212,6 @@ void luaK_kstr (LexState *ls, int c) {
 }
 }
 
 
 
 
-#ifndef LOOKBACKNUMS
-#define LOOKBACKNUMS	20	/* arbitrary limit */
-#endif
-
 static int real_constant (FuncState *fs, Number r) {
 static int real_constant (FuncState *fs, Number r) {
   /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
   /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
   Proto *f = fs->f;
   Proto *f = fs->f;

+ 1 - 5
ldo.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldo.h,v 1.16 1999/12/30 18:28:40 roberto Exp roberto $
+** $Id: ldo.h,v 1.17 2000/01/19 12:00:45 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -12,10 +12,6 @@
 #include "lstate.h"
 #include "lstate.h"
 
 
 
 
-#define MULT_RET        255
-
-
-
 /*
 /*
 ** macro to increment stack top.
 ** macro to increment stack top.
 ** There must be always an empty slot at the L->stack.top
 ** There must be always an empty slot at the L->stack.top

+ 1 - 5
llex.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llex.c,v 1.52 2000/03/03 14:58:26 roberto Exp roberto $
+** $Id: llex.c,v 1.53 2000/03/10 18:37:44 roberto Exp roberto $
 ** Lexical Analyzer
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -114,10 +114,6 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) {
 ** =======================================================
 ** =======================================================
 */
 */
 
 
-#ifndef PRAGMASIZE
-#define PRAGMASIZE	80  /* arbitrary limit */
-#endif
-
 static void skipspace (LexState *LS) {
 static void skipspace (LexState *LS) {
   while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r')
   while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r')
     next(LS);
     next(LS);

+ 1 - 5
llex.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llex.h,v 1.19 2000/03/03 14:58:26 roberto Exp roberto $
+** $Id: llex.h,v 1.20 2000/03/10 18:37:44 roberto Exp roberto $
 ** Lexical Analyzer
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -35,10 +35,6 @@ enum RESERVED {
 #define NUM_RESERVED	((int)(TK_WHILE-FIRST_RESERVED+1))
 #define NUM_RESERVED	((int)(TK_WHILE-FIRST_RESERVED+1))
 
 
 
 
-#ifndef MAX_IFS
-#define MAX_IFS 5  /* arbitrary limit */
-#endif
-
 /* `ifState' keeps the state of each nested $if the lexical is dealing with. */
 /* `ifState' keeps the state of each nested $if the lexical is dealing with. */
 
 
 struct ifState {
 struct ifState {

+ 2 - 44
lobject.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lobject.h,v 1.52 2000/03/16 21:06:16 roberto Exp roberto $
+** $Id: lobject.h,v 1.53 2000/03/20 19:14:54 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
 */
 */
@@ -8,8 +8,7 @@
 #define lobject_h
 #define lobject_h
 
 
 
 
-#include <limits.h>
-
+#include "llims.h"
 #include "lua.h"
 #include "lua.h"
 
 
 
 
@@ -26,39 +25,6 @@
 
 
 #define UNUSED(x)	(void)x		/* to avoid warnings */
 #define UNUSED(x)	(void)x		/* to avoid warnings */
 
 
-/*
-** Define the type `number' of Lua
-** GREP LUA_NUMBER to change that
-*/
-#ifndef LUA_NUM_TYPE
-#define LUA_NUM_TYPE double
-#endif
-
-typedef LUA_NUM_TYPE Number;
-
-
-/*
-** type for virtual-machine instructions
-** must be an unsigned with 4 bytes (see details in lopcodes.h)
-*/
-typedef unsigned long Instruction;
-
-
-#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */
-
-
-/* conversion of pointer to int (for hashing only) */
-/* (the shift removes bits that are usually 0 because of alignment) */
-#define IntPoint(L, p)	(((unsigned long)(p)) >> 3)
-
-
-/*
-** number of `blocks' for garbage collection: each reference to other
-** objects count 1, and each 32 bytes of `raw' memory count 1; we add
-** 2 to the total as a minimum (and also to count the overhead of malloc)
-*/
-#define numblocks(L, o,b)	((o)+((b)>>5)+2)
-
 
 
 /*
 /*
 ** Lua TYPES
 ** Lua TYPES
@@ -112,7 +78,6 @@ typedef struct TObject {
 } TObject;
 } TObject;
 
 
 
 
-
 typedef struct GlobalVar {
 typedef struct GlobalVar {
   TObject value;
   TObject value;
   struct GlobalVar *next;
   struct GlobalVar *next;
@@ -142,8 +107,6 @@ typedef struct TString {
 } TString;
 } TString;
 
 
 
 
-
-
 /*
 /*
 ** Function Prototypes
 ** Function Prototypes
 */
 */
@@ -173,8 +136,6 @@ typedef struct LocVar {
 
 
 
 
 
 
-
-
 /* Macros to access structure members */
 /* Macros to access structure members */
 #define ttype(o)        ((o)->ttype)
 #define ttype(o)        ((o)->ttype)
 #define nvalue(o)       ((o)->value.n)
 #define nvalue(o)       ((o)->value.n)
@@ -199,7 +160,6 @@ typedef struct Closure {
 } Closure;
 } Closure;
 
 
 
 
-
 typedef struct Node {
 typedef struct Node {
   TObject key;
   TObject key;
   TObject val;
   TObject val;
@@ -221,8 +181,6 @@ extern const TObject luaO_nilobject;
 
 
 #define luaO_typename(o)        luaO_typenames[ttype(o)]
 #define luaO_typename(o)        luaO_typenames[ttype(o)]
 
 
-#define MINPOWER2	4	/* minimum size for "growing" vectors */
-
 unsigned long luaO_power2 (unsigned long n);
 unsigned long luaO_power2 (unsigned long n);
 
 
 #define luaO_equalObj(t1,t2)  (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))
 #define luaO_equalObj(t1,t2)  (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))

+ 18 - 52
lopcodes.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lopcodes.h,v 1.49 2000/03/13 20:37:16 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.50 2000/03/16 18:03:09 roberto Exp roberto $
 ** Opcodes for Lua virtual machine
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -7,36 +7,32 @@
 #ifndef lopcodes_h
 #ifndef lopcodes_h
 #define lopcodes_h
 #define lopcodes_h
 
 
+#include "llims.h"
 
 
 
 
 /*===========================================================================
 /*===========================================================================
-  We assume that instructions are unsigned numbers with 4 bytes.
-  All instructions have an opcode in the 8 bits. Moreover,
+  We assume that instructions are unsigned numbers.
+  All instructions have an opcode in the first 6 bits. Moreover,
   an instruction can have 0, 1, or 2 arguments. There are 4 types of
   an instruction can have 0, 1, or 2 arguments. There are 4 types of
   Instructions:
   Instructions:
   type 0: no arguments
   type 0: no arguments
-  type 1: 1 unsigned argument in the higher 24 bits (called `U')
-  type 2: 1 signed argument in the higher 24 bits          (`S')
-  type 3: 1st unsigned argument in the higher 16 bits      (`A')
-          2nd unsigned argument in the middle 8 bits       (`B')
-
-  The signed argument is represented in excess 2^23; that is, the number
-  value is the usigned value minus 2^23.
+  type 1: 1 unsigned argument in the higher bits (called `U')
+  type 2: 1 signed argument in the higher bits          (`S')
+  type 3: 1st unsigned argument in the higher bits      (`A')
+          2nd unsigned argument in the middle bits      (`B')
+
+  The signed argument is represented in excess 2^K; that is, the number
+  value is the usigned value minus 2^K.
+
+  The size of each argument is defined in `llims.h'. The usual is an
+  instruction with 32 bits, U and S arguments with 26 bits (32-6), B
+  argument with 9 bits, and A argument with 17 bits (32-6-9). For small
+  instalations, the instruction size can be 16, so U and S have 10 bits,
+  and A and B have 5 bits each.
 ===========================================================================*/
 ===========================================================================*/
 
 
-#define SIZE_INSTRUCTION	32
-
-#define SIZE_OP		8
-#define SIZE_U		(SIZE_INSTRUCTION-SIZE_OP)
-#define POS_U		SIZE_OP
-#define SIZE_S		(SIZE_INSTRUCTION-SIZE_OP)
-#define POS_S		SIZE_OP
-#define SIZE_B		8
-#define POS_B		SIZE_OP
-#define SIZE_A		(SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
-#define POS_A		(SIZE_OP+SIZE_B)
 
 
-#define EXCESS_S	(1<<(SIZE_S-1))		/* == 2^23 */
+#define EXCESS_S	(1<<(SIZE_S-1))		/* == 2^K */
 
 
 
 
 /* creates a mask with `n' 1 bits at position `p' */
 /* creates a mask with `n' 1 bits at position `p' */
@@ -49,11 +45,6 @@
 ** the following macros help to manipulate instructions
 ** the following macros help to manipulate instructions
 */
 */
 
 
-#define MAXARG_U	((1<<SIZE_U)-1)
-#define MAXARG_S	((1<<(SIZE_S-1))-1)  /* `S' is signed */
-#define MAXARG_A	((1<<SIZE_A)-1)
-#define MAXARG_B	((1<<SIZE_B)-1)
-
 #define GET_OPCODE(i)	((OpCode)((i)&MASK1(SIZE_OP,0)))
 #define GET_OPCODE(i)	((OpCode)((i)&MASK1(SIZE_OP,0)))
 #define GETARG_U(i)	((int)((i)>>POS_U))
 #define GETARG_U(i)	((int)((i)>>POS_U))
 #define GETARG_S(i)	((int)((i)>>POS_S)-EXCESS_S)
 #define GETARG_S(i)	((int)((i)>>POS_S)-EXCESS_S)
@@ -157,29 +148,4 @@ OP_SETLINE/*	U	-		-		LINE=u		*/
 #define ISJUMP(o)	(OP_IFNEQJMP <= (o) && (o) <= OP_JMP)
 #define ISJUMP(o)	(OP_IFNEQJMP <= (o) && (o) <= OP_JMP)
 
 
 
 
-#define RFIELDS_PER_FLUSH 32	/* records (SETMAP) */
-#define LFIELDS_PER_FLUSH 64	/* FPF - lists (SETLIST) (<=MAXARG_B) */
-
-
-/* 
-** we use int to manipulte most arguments, so they must fit
-*/
-#if MAXARG_U > MAX_INT
-#undef MAXARG_U
-#define MAXARG_U	MAX_INT
-#endif
-#if MAXARG_S > MAX_INT
-#undef MAXARG_S
-#define MAXARG_S	MAX_INT
-#endif
-#if MAXARG_A > MAX_INT
-#undef MAXARG_A
-#define MAXARG_A	MAX_INT
-#endif
-#if MAXARG_B > MAX_INT
-#undef MAXARG_B
-#define MAXARG_B	MAX_INT
-#endif
-
-
 #endif
 #endif

+ 1 - 12
lparser.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lparser.c,v 1.71 2000/03/20 19:15:37 roberto Exp roberto $
+** $Id: lparser.c,v 1.72 2000/03/24 12:17:53 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -22,17 +22,6 @@
 #include "lstring.h"
 #include "lstring.h"
 
 
 
 
-/*
-** check whether arbitrary limits fit into respective opcode types
-*/
-#if MAXLOCALS > MAXARG_U || MAXUPVALUES > MAXARG_B || MAXVARSLH > MAXARG_B || \
-    MAXPARAMS > MAXLOCALS || MAXSTACK > MAXARG_A || \
-    LFIELDS_PER_FLUSH > MAXARG_B || MULT_RET > MAXARG_B
-#error invalid limits
-#endif
-
-
-
 /*
 /*
 ** Constructors descriptor:
 ** Constructors descriptor:
 ** `n' indicates number of elements, and `k' signals whether
 ** `n' indicates number of elements, and `k' signals whether

+ 1 - 32
lparser.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lparser.h,v 1.12 2000/03/10 18:37:44 roberto Exp roberto $
+** $Id: lparser.h,v 1.13 2000/03/13 20:37:16 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -11,37 +11,6 @@
 #include "lzio.h"
 #include "lzio.h"
 
 
 
 
-/* maximum number of local variables */
-#ifndef MAXLOCALS
-#define MAXLOCALS 200		/* arbitrary limit (<=MAXARG_B) */
-#endif
-
-
-/* maximum number of upvalues */
-#ifndef MAXUPVALUES
-#define MAXUPVALUES 32		/* arbitrary limit (<=MAXARG_B) */
-#endif
-
-
-/* maximum number of variables in the left side of an assignment */
-#ifndef MAXVARSLH
-#define MAXVARSLH 100		/* arbitrary limit (<=MAXARG_B) */
-#endif
-
-
-/* maximum number of parameters in a function */
-#ifndef MAXPARAMS
-#define MAXPARAMS 100		/* arbitrary limit (<=MAXLOCALS) */
-#endif
-
-
-/* maximum stack size in a function */
-#ifndef MAXSTACK
-#define MAXSTACK 256		/* arbitrary limit (<=MAXARG_A) */
-#endif
-
-
-
 /*
 /*
 ** Expression descriptor
 ** Expression descriptor
 */
 */