Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4680 right-hear 1
/*
2
** $Id: llimits.h,v 1.84 2010/11/08 16:33:20 roberto Exp $
3
** Limits, basic types, and some other `installation-dependent' definitions
4
** See Copyright Notice in lua.h
5
*/
6
 
7
#ifndef llimits_h
8
#define llimits_h
9
 
10
 
11
#include 
12
#include 
13
 
14
 
15
#include "lua.h"
16
 
17
 
18
typedef unsigned LUA_INT32 lu_int32;
19
 
20
typedef LUAI_UMEM lu_mem;
21
 
22
typedef LUAI_MEM l_mem;
23
 
24
 
25
 
26
/* chars used as small naturals (so that `char' is reserved for characters) */
27
typedef unsigned char lu_byte;
28
 
29
 
30
#define MAX_SIZET	((size_t)(~(size_t)0)-2)
31
 
32
#define MAX_LUMEM	((lu_mem)(~(lu_mem)0)-2)
33
#define MIN_LMEM	((l_mem)~((~(lu_mem)0)>>1))
34
 
35
 
36
#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */
37
 
38
/*
39
** conversion of pointer to integer
40
** this is for hashing only; there is no problem if the integer
41
** cannot hold the whole pointer value
42
*/
43
#define IntPoint(p)  ((unsigned int)(lu_mem)(p))
44
 
45
 
46
 
47
/* type to ensure maximum alignment */
48
#if !defined(LUAI_USER_ALIGNMENT_T)
49
#define LUAI_USER_ALIGNMENT_T	union { double u; void *s; long l; }
50
#endif
51
 
52
typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
53
 
54
 
55
/* result of a `usual argument conversion' over lua_Number */
56
typedef LUAI_UACNUMBER l_uacNumber;
57
 
58
 
59
/* internal assertions for in-house debugging */
60
#if defined(lua_assert)
61
#define check_exp(c,e)		(lua_assert(c), (e))
62
#else
63
#define lua_assert(c)		/* empty */
64
#define check_exp(c,e)		(e)
65
#endif
66
 
67
/*
68
** assertion for checking API calls
69
*/
70
#if defined(LUA_USE_APICHECK)
71
#include 
72
#define luai_apicheck(L,e)	{ (void)L; assert(e); }
73
#elif !defined(luai_apicheck)
74
#define luai_apicheck(L,e)	lua_assert(e)
75
#endif
76
 
77
#define api_check(l,e,msg)	luai_apicheck(l,(e) && msg)
78
 
79
 
80
#if !defined(UNUSED)
81
#define UNUSED(x)	((void)(x))	/* to avoid warnings */
82
#endif
83
 
84
 
85
#define cast(t, exp)	((t)(exp))
86
 
87
#define cast_byte(i)	cast(lu_byte, (i))
88
#define cast_num(i)	cast(lua_Number, (i))
89
#define cast_int(i)	cast(int, (i))
90
 
91
 
92
/*
93
** maximum depth for nested C calls and syntactical nested non-terminals
94
** in a program. (Value must fit in an unsigned short int.)
95
*/
96
#if !defined(LUAI_MAXCCALLS)
97
#define LUAI_MAXCCALLS		200
98
#endif
99
 
100
/*
101
** maximum number of upvalues in a closure (both C and Lua). (Value
102
** must fit in an unsigned char.)
103
*/
104
#define MAXUPVAL	UCHAR_MAX
105
 
106
 
107
/*
108
** type for virtual-machine instructions
109
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
110
*/
111
typedef lu_int32 Instruction;
112
 
113
 
114
 
115
/* maximum stack for a Lua function */
116
#define MAXSTACK	250
117
 
118
 
119
 
120
/* minimum size for the string table (must be power of 2) */
121
#if !defined(MINSTRTABSIZE)
122
#define MINSTRTABSIZE	32
123
#endif
124
 
125
 
126
/* minimum size for string buffer */
127
#if !defined(LUA_MINBUFFER)
128
#define LUA_MINBUFFER	32
129
#endif
130
 
131
 
132
#if !defined(lua_lock)
133
#define lua_lock(L)     ((void) 0)
134
#define lua_unlock(L)   ((void) 0)
135
#endif
136
 
137
#if !defined(luai_threadyield)
138
#define luai_threadyield(L)     {lua_unlock(L); lua_lock(L);}
139
#endif
140
 
141
 
142
/*
143
** these macros allow user-specific actions on threads when you defined
144
** LUAI_EXTRASPACE and need to do something extra when a thread is
145
** created/deleted/resumed/yielded.
146
*/
147
#if !defined(luai_userstateopen)
148
#define luai_userstateopen(L)		((void)L)
149
#endif
150
 
151
#if !defined(luai_userstateclose)
152
#define luai_userstateclose(L)		((void)L)
153
#endif
154
 
155
#if !defined(luai_userstatethread)
156
#define luai_userstatethread(L,L1)	((void)L)
157
#endif
158
 
159
#if !defined(luai_userstatefree)
160
#define luai_userstatefree(L,L1)	((void)L)
161
#endif
162
 
163
#if !defined(luai_userstateresume)
164
#define luai_userstateresume(L,n)       ((void)L)
165
#endif
166
 
167
#if !defined(luai_userstateyield)
168
#define luai_userstateyield(L,n)        ((void)L)
169
#endif
170
 
171
/*
172
** lua_number2int is a macro to convert lua_Number to int.
173
** lua_number2integer is a macro to convert lua_Number to lua_Integer.
174
** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
175
** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
176
*/
177
 
178
#if defined(MS_ASMTRICK)	/* { */
179
/* trick with Microsoft assembler for X86 */
180
 
181
#define lua_number2int(i,n)  __asm {__asm fld n   __asm fistp i}
182
#define lua_number2integer(i,n)		lua_number2int(i, n)
183
#define lua_number2unsigned(i,n)  \
184
  {__int64 l; __asm {__asm fld n   __asm fistp l} i = (unsigned int)l;}
185
 
186
 
187
#elif defined(LUA_IEEE754TRICK)		/* }{ */
188
/* the next trick should work on any machine using IEEE754 with
189
   a 32-bit integer type */
190
 
191
union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
192
 
193
#if !defined(LUA_IEEEENDIAN)	/* { */
194
#define LUAI_EXTRAIEEE	\
195
  static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
196
#define LUA_IEEEENDIAN		(ieeeendian.l_p[1] == 33)
197
#else
198
#define LUAI_EXTRAIEEE		/* empty */
199
#endif				/* } */
200
 
201
#define lua_number2int32(i,n,t) \
202
  { LUAI_EXTRAIEEE \
203
    volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
204
    (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
205
 
206
#define lua_number2int(i,n)		lua_number2int32(i, n, int)
207
#define lua_number2integer(i,n)		lua_number2int32(i, n, lua_Integer)
208
#define lua_number2unsigned(i,n)	lua_number2int32(i, n, lua_Unsigned)
209
 
210
#endif				/* } */
211
 
212
 
213
/* the following definitions always work, but may be slow */
214
 
215
#if !defined(lua_number2int)
216
#define lua_number2int(i,n)	((i)=(int)(n))
217
#endif
218
 
219
#if !defined(lua_number2integer)
220
#define lua_number2integer(i,n)	((i)=(lua_Integer)(n))
221
#endif
222
 
223
#if !defined(lua_number2unsigned)	/* { */
224
/* the following definition assures proper modulo behavior */
225
#if defined(LUA_NUMBER_DOUBLE)
226
#include 
227
#define SUPUNSIGNED	((lua_Number)(~(lua_Unsigned)0) + 1)
228
#define lua_number2unsigned(i,n)  \
229
	((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
230
#else
231
#define lua_number2unsigned(i,n)	((i)=(lua_Unsigned)(n))
232
#endif
233
#endif				/* } */
234
 
235
 
236
#if !defined(lua_unsigned2number)
237
/* on several machines, coercion from unsigned to double is slow,
238
   so it may be worth to avoid */
239
#define lua_unsigned2number(u)  \
240
    (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
241
#endif
242
 
243
 
244
/*
245
** luai_hashnum is a macro do hash a lua_Number value into an integer.
246
** The hash must be deterministic and give reasonable values for
247
** both small and large values (outside the range of integers).
248
** It is used only in ltable.c.
249
*/
250
 
251
#if !defined(luai_hashnum)	/* { */
252
 
253
#include 
254
#include 
255
 
256
#define luai_hashnum(i,n) { int e;  \
257
  n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP);  \
258
  lua_number2int(i, n); i += e; }
259
 
260
#endif						/* } */
261
 
262
 
263
 
264
/*
265
** macro to control inclusion of some hard tests on stack reallocation
266
*/
267
#if !defined(HARDSTACKTESTS)
268
#define condmovestack(L)	((void)0)
269
#else
270
/* realloc stack keeping its size */
271
#define condmovestack(L)	luaD_reallocstack((L), (L)->stacksize)
272
#endif
273
 
274
#if !defined(HARDMEMTESTS)
275
#define condchangemem(L)	condmovestack(L)
276
#else
277
#define condchangemem(L)  \
278
	((void)(gcstopped(G(L)) || (luaC_fullgc(L, 0), 1)))
279
#endif
280
 
281
#endif