Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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