From 906434011f09a5afe60fbb644db6995a5ca21f0d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 28 Jun 2000 14:03:32 -0300 Subject: better (?) treatment for 16-bit machines --- llimits.h | 62 +++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/llimits.h b/llimits.h index 146ae73d..f1ac6acf 100644 --- a/llimits.h +++ b/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 + +/* +** 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<>1) /* `S' is signed */ -#define MAXARG_A ((1< MAX_INT -#undef MAXARG_U +#if SIZE_U < BITS_INT-1 +#define MAXARG_U ((1<>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< MAX_INT -#undef MAXARG_B +#if SIZE_B < BITS_INT-1 +#define MAXARG_B ((1< MAXARG_B +#undef MAXSTACK #define MAXSTACK MAXARG_B +#endif /* maximum number of local variables */ -- cgit v1.2.3-55-g6feb