Ver código fonte

better (?) treatment for 16-bit machines

Roberto Ierusalimschy 25 anos atrás
pai
commit
906434011f
1 arquivos alterados com 43 adições e 19 exclusões
  1. 43 19
      llimits.h

+ 43 - 19
llimits.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llimits.h,v 1.9 2000/06/06 16:27:11 roberto Exp roberto $
+** $Id: llimits.h,v 1.10 2000/06/16 17:16:34 roberto Exp roberto $
 ** Limits, basic types, and some other "instalation-dependent" definitions
 ** See Copyright Notice in lua.h
 */
@@ -12,6 +12,25 @@
 #include <stddef.h>
 
 
+
+/*
+** try to find number of bits in an integer
+*/
+#ifndef BITS_INT
+/* avoid overflows in comparison */
+#if INT_MAX-20 < 32760
+#define	BITS_INT	16
+#else
+#if INT_MAX > 2147483640L
+/* machine has at least 32 bits */
+#define BITS_INT	32
+#else
+#error "you must define BITS_INT with number of bits in an integer"
+#endif
+#endif
+#endif
+
+
 /*
 ** Define the type `number' of Lua
 ** GREP LUA_NUMBER to change that
@@ -66,51 +85,56 @@ typedef unsigned long Instruction;
 
 
 /*
-** limits for opcode arguments.
+** size and position of opcode arguments.
 ** For an instruction with 2 bytes, size is 16, and size_b can be 5
+** (accordingly, size_u will be 10, and size_a will be 5)
 */
 #define SIZE_INSTRUCTION        32
-#define SIZE_OP         6
 #define SIZE_B          9
 
+#define SIZE_OP         6
 #define SIZE_U          (SIZE_INSTRUCTION-SIZE_OP)
 #define POS_U           SIZE_OP
 #define POS_B           SIZE_OP
 #define SIZE_A          (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
 #define POS_A           (SIZE_OP+SIZE_B)
 
-#define MAXARG_U        ((1<<SIZE_U)-1)
-#define MAXARG_S        (MAXARG_U>>1)		/* `S' is signed */
-#define MAXARG_A        ((1<<SIZE_A)-1)
-#define MAXARG_B        ((1<<SIZE_B)-1)
-
 
 /*
-** we use int to manipulate most arguments, so they must fit
+** limits for opcode arguments.
+** we use (signed) int to manipulate most arguments,
+** so they must fit in BITS_INT-1 bits (-1 for signal)
 */
-#if MAXARG_U > MAX_INT
-#undef MAXARG_U
+#if SIZE_U < BITS_INT-1
+#define MAXARG_U        ((1<<SIZE_U)-1)
+#define MAXARG_S        (MAXARG_U>>1)		/* `S' is signed */
+#else
 #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
+#if SIZE_A < BITS_INT-1
+#define MAXARG_A        ((1<<SIZE_A)-1)
+#else
 #define MAXARG_A        MAX_INT
 #endif
 
-#if MAXARG_B > MAX_INT
-#undef MAXARG_B
+#if SIZE_B < BITS_INT-1
+#define MAXARG_B        ((1<<SIZE_B)-1)
+#else
 #define MAXARG_B        MAX_INT
 #endif
 
 
 /* maximum stack size in a function */
+#ifndef MAXSTACK
+#define MAXSTACK	250
+#endif
+
+#if MAXSTACK > MAXARG_B
+#undef MAXSTACK
 #define MAXSTACK	MAXARG_B
+#endif
 
 
 /* maximum number of local variables */