2000-03-24 20:26:08 +03:00
|
|
|
/*
|
2001-02-22 20:15:18 +03:00
|
|
|
** $Id: llimits.h,v 1.23 2001/02/20 18:15:33 roberto Exp roberto $
|
2000-08-15 22:28:48 +04:00
|
|
|
** Limits, basic types, and some other "installation-dependent" definitions
|
2000-03-24 20:26:08 +03:00
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
2000-03-24 22:49:23 +03:00
|
|
|
#ifndef llimits_h
|
|
|
|
#define llimits_h
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <limits.h>
|
2000-05-24 17:54:49 +04:00
|
|
|
#include <stddef.h>
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
|
2000-06-28 21:03:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** 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
|
|
|
|
|
|
|
|
|
2000-12-04 21:33:40 +03:00
|
|
|
/* function to convert a lua_Number to a string */
|
2001-02-22 20:15:18 +03:00
|
|
|
#ifndef NUMBER_FMT
|
2000-10-06 23:28:47 +04:00
|
|
|
#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
|
2001-02-22 20:15:18 +03:00
|
|
|
#endif
|
|
|
|
#ifndef lua_number2str
|
2000-10-06 23:28:47 +04:00
|
|
|
#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
|
2001-02-22 20:15:18 +03:00
|
|
|
#endif
|
2000-10-03 18:03:21 +04:00
|
|
|
|
2000-12-04 21:33:40 +03:00
|
|
|
/* function to convert a string to a lua_Number */
|
2001-02-22 20:15:18 +03:00
|
|
|
#ifndef lua_str2number
|
2000-10-03 18:03:21 +04:00
|
|
|
#define lua_str2number(s,p) strtod((s), (p))
|
2001-02-22 20:15:18 +03:00
|
|
|
#endif
|
2000-10-03 18:03:21 +04:00
|
|
|
|
|
|
|
|
2000-03-24 20:26:08 +03:00
|
|
|
|
2001-02-20 21:15:33 +03:00
|
|
|
/*
|
|
|
|
** the following types define integer types for values that may not
|
|
|
|
** fit in a "small int" (16 bits), but may waste space in a
|
|
|
|
** "large long" (64 bits). The current definitions should work in
|
|
|
|
** any machine, but may not be optimal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* an unsigned integer to hold hash values */
|
|
|
|
typedef unsigned int lu_hash;
|
|
|
|
/* its signed equivalent */
|
|
|
|
typedef int ls_hash;
|
2000-11-24 20:39:56 +03:00
|
|
|
|
|
|
|
/* an unsigned integer big enough to count the total memory used by Lua */
|
2001-02-20 21:15:33 +03:00
|
|
|
typedef unsigned long lu_mem;
|
|
|
|
|
|
|
|
/* an integer big enough to count the number of strings in use */
|
|
|
|
typedef long ls_nstr;
|
|
|
|
|
|
|
|
|
|
|
|
/* chars used as small naturals (so that `char' is reserved for characteres) */
|
|
|
|
typedef unsigned char lu_byte;
|
2000-05-24 17:54:49 +04:00
|
|
|
|
|
|
|
|
2001-02-22 20:15:18 +03:00
|
|
|
/* macro to `unsign' a character */
|
|
|
|
#define uchar(c) ((unsigned char)(c))
|
|
|
|
|
|
|
|
|
2000-06-06 20:27:11 +04:00
|
|
|
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
|
2000-05-24 17:54:49 +04:00
|
|
|
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
|
|
|
|
|
|
|
/*
|
2001-02-20 21:15:33 +03:00
|
|
|
** conversion of pointer to integer
|
|
|
|
** this is for hashing only; there is no problem if the integer
|
|
|
|
** cannot hold the whole pointer value
|
2000-03-24 20:26:08 +03:00
|
|
|
** (the shift removes bits that are usually 0 because of alignment)
|
|
|
|
*/
|
2001-02-20 21:15:33 +03:00
|
|
|
#define IntPoint(p) ((((lu_hash)(p)) >> 4) ^ (lu_hash)(p))
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MINPOWER2 4 /* minimum size for "growing" vectors */
|
|
|
|
|
|
|
|
|
2000-03-31 20:28:45 +04:00
|
|
|
|
|
|
|
#ifndef DEFAULT_STACK_SIZE
|
|
|
|
#define DEFAULT_STACK_SIZE 1024
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-10-26 16:47:05 +04:00
|
|
|
/* type to ensure maximum alignment */
|
2001-02-20 21:15:33 +03:00
|
|
|
union L_Umaxalign { double d; void *s; long l; };
|
2000-10-26 16:47:05 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-24 20:26:08 +03:00
|
|
|
/*
|
|
|
|
** type for virtual-machine instructions
|
2000-09-29 16:42:13 +04:00
|
|
|
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
2000-03-24 20:26:08 +03:00
|
|
|
** For a very small machine, you may change that to 2 bytes (and adjust
|
|
|
|
** the following limits accordingly)
|
|
|
|
*/
|
2001-02-20 21:15:33 +03:00
|
|
|
typedef unsigned long Instruction;
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-06-28 21:03:32 +04:00
|
|
|
** size and position of opcode arguments.
|
2000-03-24 20:26:08 +03:00
|
|
|
** For an instruction with 2 bytes, size is 16, and size_b can be 5
|
2000-06-28 21:03:32 +04:00
|
|
|
** (accordingly, size_u will be 10, and size_a will be 5)
|
2000-03-24 20:26:08 +03:00
|
|
|
*/
|
|
|
|
#define SIZE_INSTRUCTION 32
|
2001-02-09 23:29:33 +03:00
|
|
|
#define SIZE_B 8
|
2000-03-24 20:26:08 +03:00
|
|
|
|
2000-06-28 21:03:32 +04:00
|
|
|
#define SIZE_OP 6
|
2000-03-24 20:26:08 +03:00
|
|
|
#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)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-06-28 21:03:32 +04:00
|
|
|
** limits for opcode arguments.
|
|
|
|
** we use (signed) int to manipulate most arguments,
|
2000-10-09 17:47:32 +04:00
|
|
|
** so they must fit in BITS_INT-1 bits (-1 for sign)
|
2000-03-24 20:26:08 +03:00
|
|
|
*/
|
2000-06-28 21:03:32 +04:00
|
|
|
#if SIZE_U < BITS_INT-1
|
|
|
|
#define MAXARG_U ((1<<SIZE_U)-1)
|
|
|
|
#define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
|
|
|
|
#else
|
2000-03-24 20:26:08 +03:00
|
|
|
#define MAXARG_U MAX_INT
|
|
|
|
#define MAXARG_S MAX_INT
|
|
|
|
#endif
|
|
|
|
|
2000-06-28 21:03:32 +04:00
|
|
|
#if SIZE_A < BITS_INT-1
|
|
|
|
#define MAXARG_A ((1<<SIZE_A)-1)
|
|
|
|
#else
|
2000-03-24 20:26:08 +03:00
|
|
|
#define MAXARG_A MAX_INT
|
|
|
|
#endif
|
|
|
|
|
2000-06-28 21:03:32 +04:00
|
|
|
#if SIZE_B < BITS_INT-1
|
|
|
|
#define MAXARG_B ((1<<SIZE_B)-1)
|
|
|
|
#else
|
2000-03-24 20:26:08 +03:00
|
|
|
#define MAXARG_B MAX_INT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* maximum stack size in a function */
|
2000-06-28 21:03:32 +04:00
|
|
|
#ifndef MAXSTACK
|
|
|
|
#define MAXSTACK 250
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MAXSTACK > MAXARG_B
|
|
|
|
#undef MAXSTACK
|
2000-03-24 20:26:08 +03:00
|
|
|
#define MAXSTACK MAXARG_B
|
2000-06-28 21:03:32 +04:00
|
|
|
#endif
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* maximum number of local variables */
|
|
|
|
#ifndef MAXLOCALS
|
|
|
|
#define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
|
|
|
|
#endif
|
|
|
|
#if MAXLOCALS>=MAXSTACK
|
|
|
|
#undef MAXLOCALS
|
|
|
|
#define MAXLOCALS (MAXSTACK-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* maximum number of upvalues */
|
|
|
|
#ifndef MAXUPVALUES
|
|
|
|
#define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
|
|
|
|
#endif
|
|
|
|
#if MAXUPVALUES>MAXARG_B
|
|
|
|
#undef MAXUPVALUES
|
|
|
|
#define MAXUPVALUES MAXARG_B
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* maximum number of variables in the left side of an assignment */
|
|
|
|
#ifndef MAXVARSLH
|
|
|
|
#define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
|
|
|
|
#endif
|
|
|
|
#if MAXVARSLH>=MULT_RET
|
|
|
|
#undef MAXVARSLH
|
|
|
|
#define MAXVARSLH (MULT_RET-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* maximum number of parameters in a function */
|
|
|
|
#ifndef MAXPARAMS
|
|
|
|
#define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
|
|
|
|
#endif
|
|
|
|
#if MAXPARAMS>=MAXLOCALS
|
|
|
|
#undef MAXPARAMS
|
|
|
|
#define MAXPARAMS (MAXLOCALS-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* number of list items to accumulate before a SETLIST instruction */
|
2000-03-31 20:28:45 +04:00
|
|
|
#define LFIELDS_PER_FLUSH 64
|
|
|
|
#if LFIELDS_PER_FLUSH>(MAXSTACK/4)
|
|
|
|
#undef LFIELDS_PER_FLUSH
|
2000-03-24 20:26:08 +03:00
|
|
|
#define LFIELDS_PER_FLUSH (MAXSTACK/4)
|
2000-03-31 20:28:45 +04:00
|
|
|
#endif
|
2000-03-24 20:26:08 +03:00
|
|
|
|
|
|
|
/* number of record items to accumulate before a SETMAP instruction */
|
|
|
|
/* (each item counts 2 elements on the stack: an index and a value) */
|
|
|
|
#define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2)
|
|
|
|
|
|
|
|
|
|
|
|
/* maximum lookback to find a real constant (for code generation) */
|
|
|
|
#ifndef LOOKBACKNUMS
|
2000-03-28 00:08:33 +04:00
|
|
|
#define LOOKBACKNUMS 20 /* arbitrary constant */
|
2000-03-24 20:26:08 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|