llimits.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. ** $Id: llimits.h,v 1.13 2000/08/28 17:57:04 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. /*
  11. ** try to find number of bits in an integer
  12. */
  13. #ifndef BITS_INT
  14. /* avoid overflows in comparison */
  15. #if INT_MAX-20 < 32760
  16. #define BITS_INT 16
  17. #else
  18. #if INT_MAX > 2147483640L
  19. /* machine has at least 32 bits */
  20. #define BITS_INT 32
  21. #else
  22. #error "you must define BITS_INT with number of bits in an integer"
  23. #endif
  24. #endif
  25. #endif
  26. /*
  27. ** Define the type `number' of Lua
  28. ** GREP LUA_NUMBER to change that
  29. */
  30. #ifndef LUA_NUM_TYPE
  31. #define LUA_NUM_TYPE double
  32. #endif
  33. typedef LUA_NUM_TYPE Number;
  34. typedef unsigned long lint32; /* unsigned int with at least 32 bits */
  35. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  36. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  37. /*
  38. ** conversion of pointer to int (for hashing only)
  39. ** (the shift removes bits that are usually 0 because of alignment)
  40. */
  41. #define IntPoint(p) (((unsigned long)(p)) >> 3)
  42. /*
  43. ** number of `blocks' for garbage collection: each reference to other
  44. ** objects count 1, and each 32 bytes of `raw' memory count 1; we add
  45. ** 2 to the total as a minimum (and also to count the overhead of malloc)
  46. */
  47. #define numblocks(L, o,b) ((o)+((b)>>5)+2)
  48. #define MINPOWER2 4 /* minimum size for "growing" vectors */
  49. #ifndef DEFAULT_STACK_SIZE
  50. #define DEFAULT_STACK_SIZE 1024
  51. #endif
  52. /*
  53. ** type for virtual-machine instructions
  54. ** must be an unsigned with 4 bytes (see details in lopcodes.h)
  55. ** For a very small machine, you may change that to 2 bytes (and adjust
  56. ** the following limits accordingly)
  57. */
  58. typedef unsigned long Instruction;
  59. /*
  60. ** size and position of opcode arguments.
  61. ** For an instruction with 2 bytes, size is 16, and size_b can be 5
  62. ** (accordingly, size_u will be 10, and size_a will be 5)
  63. */
  64. #define SIZE_INSTRUCTION 32
  65. #define SIZE_B 9
  66. #define SIZE_OP 6
  67. #define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
  68. #define POS_U SIZE_OP
  69. #define POS_B SIZE_OP
  70. #define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
  71. #define POS_A (SIZE_OP+SIZE_B)
  72. /*
  73. ** limits for opcode arguments.
  74. ** we use (signed) int to manipulate most arguments,
  75. ** so they must fit in BITS_INT-1 bits (-1 for signal)
  76. */
  77. #if SIZE_U < BITS_INT-1
  78. #define MAXARG_U ((1<<SIZE_U)-1)
  79. #define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
  80. #else
  81. #define MAXARG_U MAX_INT
  82. #define MAXARG_S MAX_INT
  83. #endif
  84. #if SIZE_A < BITS_INT-1
  85. #define MAXARG_A ((1<<SIZE_A)-1)
  86. #else
  87. #define MAXARG_A MAX_INT
  88. #endif
  89. #if SIZE_B < BITS_INT-1
  90. #define MAXARG_B ((1<<SIZE_B)-1)
  91. #else
  92. #define MAXARG_B MAX_INT
  93. #endif
  94. /* maximum stack size in a function */
  95. #ifndef MAXSTACK
  96. #define MAXSTACK 250
  97. #endif
  98. #if MAXSTACK > MAXARG_B
  99. #undef MAXSTACK
  100. #define MAXSTACK MAXARG_B
  101. #endif
  102. /* maximum number of local variables */
  103. #ifndef MAXLOCALS
  104. #define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
  105. #endif
  106. #if MAXLOCALS>=MAXSTACK
  107. #undef MAXLOCALS
  108. #define MAXLOCALS (MAXSTACK-1)
  109. #endif
  110. /* maximum number of upvalues */
  111. #ifndef MAXUPVALUES
  112. #define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
  113. #endif
  114. #if MAXUPVALUES>MAXARG_B
  115. #undef MAXUPVALUES
  116. #define MAXUPVALUES MAXARG_B
  117. #endif
  118. /* maximum number of variables in the left side of an assignment */
  119. #ifndef MAXVARSLH
  120. #define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
  121. #endif
  122. #if MAXVARSLH>=MULT_RET
  123. #undef MAXVARSLH
  124. #define MAXVARSLH (MULT_RET-1)
  125. #endif
  126. /* maximum number of parameters in a function */
  127. #ifndef MAXPARAMS
  128. #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
  129. #endif
  130. #if MAXPARAMS>=MAXLOCALS
  131. #undef MAXPARAMS
  132. #define MAXPARAMS (MAXLOCALS-1)
  133. #endif
  134. /* number of list items to accumulate before a SETLIST instruction */
  135. #define LFIELDS_PER_FLUSH 64
  136. #if LFIELDS_PER_FLUSH>(MAXSTACK/4)
  137. #undef LFIELDS_PER_FLUSH
  138. #define LFIELDS_PER_FLUSH (MAXSTACK/4)
  139. #endif
  140. /* number of record items to accumulate before a SETMAP instruction */
  141. /* (each item counts 2 elements on the stack: an index and a value) */
  142. #define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2)
  143. /* maximum lookback to find a real constant (for code generation) */
  144. #ifndef LOOKBACKNUMS
  145. #define LOOKBACKNUMS 20 /* arbitrary constant */
  146. #endif
  147. /* maximum part of a file name kept for error messages */
  148. #ifndef MAXFILENAME
  149. #define MAXFILENAME 260
  150. #endif
  151. #endif