llimits.h 4.4 KB

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