llimits.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. ** $Id: llimits.h,v 1.27 2001/02/23 20:28:56 roberto Exp roberto $
  3. ** Limits, basic types, and some other `installation-dependent' definitions
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef llimits_h
  7. #define llimits_h
  8. #include <limits.h>
  9. #include <stddef.h>
  10. #include "lua.h"
  11. /*
  12. ** try to find number of bits in an integer
  13. */
  14. #ifndef BITS_INT
  15. /* avoid overflows in comparison */
  16. #if INT_MAX-20 < 32760
  17. #define BITS_INT 16
  18. #else
  19. #if INT_MAX > 2147483640L
  20. /* machine has at least 32 bits */
  21. #define BITS_INT 32
  22. #else
  23. #error "you must define BITS_INT with number of bits in an integer"
  24. #endif
  25. #endif
  26. #endif
  27. /*
  28. ** the following types define integer types for values that may not
  29. ** fit in a `small int' (16 bits), but may waste space in a
  30. ** `large long' (64 bits). The current definitions should work in
  31. ** any machine, but may not be optimal.
  32. */
  33. /* an unsigned integer to hold hash values */
  34. typedef unsigned int lu_hash;
  35. /* its signed equivalent */
  36. typedef int ls_hash;
  37. /* an unsigned integer big enough to count the total memory used by Lua */
  38. typedef unsigned long lu_mem;
  39. /* an integer big enough to count the number of strings in use */
  40. typedef long ls_nstr;
  41. /* chars used as small naturals (so that `char' is reserved for characteres) */
  42. typedef unsigned char lu_byte;
  43. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  44. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  45. /*
  46. ** conversion of pointer to integer
  47. ** this is for hashing only; there is no problem if the integer
  48. ** cannot hold the whole pointer value
  49. ** (the shift removes bits that are usually 0 because of alignment)
  50. */
  51. #define IntPoint(p) ((((lu_hash)(p)) >> 4) ^ (lu_hash)(p))
  52. #define MINPOWER2 4 /* minimum size for `growing' vectors */
  53. #ifndef DEFAULT_STACK_SIZE
  54. #define DEFAULT_STACK_SIZE 1024
  55. #endif
  56. /* type to ensure maximum alignment */
  57. union L_Umaxalign { double d; void *s; long l; };
  58. /*
  59. ** type for virtual-machine instructions
  60. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  61. ** For a very small machine, you may change that to 2 bytes (and adjust
  62. ** the following limits accordingly)
  63. */
  64. typedef unsigned long Instruction;
  65. /*
  66. ** size and position of opcode arguments.
  67. ** For an instruction with 2 bytes, size is 16, and size_b can be 5
  68. ** (accordingly, size_u will be 10, and size_a will be 5)
  69. */
  70. #define SIZE_INSTRUCTION 32
  71. #define SIZE_B 8
  72. #define SIZE_OP 6
  73. #define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
  74. #define POS_U SIZE_OP
  75. #define POS_B SIZE_OP
  76. #define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
  77. #define POS_A (SIZE_OP+SIZE_B)
  78. /*
  79. ** limits for opcode arguments.
  80. ** we use (signed) int to manipulate most arguments,
  81. ** so they must fit in BITS_INT-1 bits (-1 for sign)
  82. */
  83. #if SIZE_U < BITS_INT-1
  84. #define MAXARG_U ((1<<SIZE_U)-1)
  85. #define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
  86. #else
  87. #define MAXARG_U MAX_INT
  88. #define MAXARG_S MAX_INT
  89. #endif
  90. #if SIZE_A < BITS_INT-1
  91. #define MAXARG_A ((1<<SIZE_A)-1)
  92. #else
  93. #define MAXARG_A MAX_INT
  94. #endif
  95. #if SIZE_B < BITS_INT-1
  96. #define MAXARG_B ((1<<SIZE_B)-1)
  97. #else
  98. #define MAXARG_B MAX_INT
  99. #endif
  100. /* maximum stack size in a function */
  101. #ifndef MAXSTACK
  102. #define MAXSTACK 250
  103. #endif
  104. #if MAXSTACK > MAXARG_B
  105. #undef MAXSTACK
  106. #define MAXSTACK MAXARG_B
  107. #endif
  108. /* maximum number of local variables */
  109. #ifndef MAXLOCALS
  110. #define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
  111. #endif
  112. #if MAXLOCALS>=MAXSTACK
  113. #undef MAXLOCALS
  114. #define MAXLOCALS (MAXSTACK-1)
  115. #endif
  116. /* maximum number of upvalues */
  117. #ifndef MAXUPVALUES
  118. #define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
  119. #endif
  120. #if MAXUPVALUES>MAXARG_B
  121. #undef MAXUPVALUES
  122. #define MAXUPVALUES MAXARG_B
  123. #endif
  124. /* maximum number of variables in the left side of an assignment */
  125. #ifndef MAXVARSLH
  126. #define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
  127. #endif
  128. #if MAXVARSLH>=MULT_RET
  129. #undef MAXVARSLH
  130. #define MAXVARSLH (MULT_RET-1)
  131. #endif
  132. /* maximum number of parameters in a function */
  133. #ifndef MAXPARAMS
  134. #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
  135. #endif
  136. #if MAXPARAMS>=MAXLOCALS
  137. #undef MAXPARAMS
  138. #define MAXPARAMS (MAXLOCALS-1)
  139. #endif
  140. /* number of list items to accumulate before a SETLIST instruction */
  141. #define LFIELDS_PER_FLUSH 64
  142. #if LFIELDS_PER_FLUSH>(MAXSTACK/4)
  143. #undef LFIELDS_PER_FLUSH
  144. #define LFIELDS_PER_FLUSH (MAXSTACK/4)
  145. #endif
  146. /* number of record items to accumulate before a SETMAP instruction */
  147. /* (each item counts 2 elements on the stack: an index and a value) */
  148. #define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2)
  149. /* maximum lookback to find a real constant (for code generation) */
  150. #ifndef LOOKBACKNUMS
  151. #define LOOKBACKNUMS 20 /* arbitrary constant */
  152. #endif
  153. #endif