2
** $Id: llimits.h,v 1.1 2003/02/09 21:30:32 dheck Exp $
3
** Limits, basic types, and some other "installation-dependent" definitions
4
** See Copyright Notice in lua.h
17
** try to find number of bits in an integer
20
/* avoid overflows in comparison */
21
#if INT_MAX-20 < 32760
24
#if INT_MAX > 2147483640L
25
/* machine has at least 32 bits */
28
#error "you must define BITS_INT with number of bits in an integer"
35
** Define the type `number' of Lua
36
** GREP LUA_NUMBER to change that
39
#define LUA_NUM_TYPE double
42
typedef LUA_NUM_TYPE Number;
44
/* function to convert a Number to a string */
45
#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
46
#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
48
/* function to convert a string to a Number */
49
#define lua_str2number(s,p) strtod((s), (p))
53
typedef unsigned long lint32; /* unsigned int with at least 32 bits */
56
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
59
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
62
** conversion of pointer to int (for hashing only)
63
** (the shift removes bits that are usually 0 because of alignment)
65
#define IntPoint(p) (((unsigned long)(p)) >> 3)
69
#define MINPOWER2 4 /* minimum size for "growing" vectors */
73
#ifndef DEFAULT_STACK_SIZE
74
#define DEFAULT_STACK_SIZE 1024
79
/* type to ensure maximum alignment */
80
union L_Umaxalign { double d; char *s; long l; };
85
** type for virtual-machine instructions
86
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
87
** For a very small machine, you may change that to 2 bytes (and adjust
88
** the following limits accordingly)
90
typedef unsigned long Instruction;
94
** size and position of opcode arguments.
95
** For an instruction with 2 bytes, size is 16, and size_b can be 5
96
** (accordingly, size_u will be 10, and size_a will be 5)
98
#define SIZE_INSTRUCTION 32
102
#define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
103
#define POS_U SIZE_OP
104
#define POS_B SIZE_OP
105
#define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
106
#define POS_A (SIZE_OP+SIZE_B)
110
** limits for opcode arguments.
111
** we use (signed) int to manipulate most arguments,
112
** so they must fit in BITS_INT-1 bits (-1 for sign)
114
#if SIZE_U < BITS_INT-1
115
#define MAXARG_U ((1<<SIZE_U)-1)
116
#define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
118
#define MAXARG_U MAX_INT
119
#define MAXARG_S MAX_INT
122
#if SIZE_A < BITS_INT-1
123
#define MAXARG_A ((1<<SIZE_A)-1)
125
#define MAXARG_A MAX_INT
128
#if SIZE_B < BITS_INT-1
129
#define MAXARG_B ((1<<SIZE_B)-1)
131
#define MAXARG_B MAX_INT
135
/* maximum stack size in a function */
140
#if MAXSTACK > MAXARG_B
142
#define MAXSTACK MAXARG_B
146
/* maximum number of local variables */
148
#define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
150
#if MAXLOCALS>=MAXSTACK
152
#define MAXLOCALS (MAXSTACK-1)
156
/* maximum number of upvalues */
158
#define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
160
#if MAXUPVALUES>MAXARG_B
162
#define MAXUPVALUES MAXARG_B
166
/* maximum number of variables in the left side of an assignment */
168
#define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
170
#if MAXVARSLH>=MULT_RET
172
#define MAXVARSLH (MULT_RET-1)
176
/* maximum number of parameters in a function */
178
#define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
180
#if MAXPARAMS>=MAXLOCALS
182
#define MAXPARAMS (MAXLOCALS-1)
186
/* number of list items to accumulate before a SETLIST instruction */
187
#define LFIELDS_PER_FLUSH 64
188
#if LFIELDS_PER_FLUSH>(MAXSTACK/4)
189
#undef LFIELDS_PER_FLUSH
190
#define LFIELDS_PER_FLUSH (MAXSTACK/4)
193
/* number of record items to accumulate before a SETMAP instruction */
194
/* (each item counts 2 elements on the stack: an index and a value) */
195
#define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2)
198
/* maximum lookback to find a real constant (for code generation) */
200
#define LOOKBACKNUMS 20 /* arbitrary constant */