llimits.h 4.5 KB

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