llimits.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. ** $Id: llimits.h,v 1.18 2000/10/09 13:47:32 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. /* type to ensure maximum alignment */
  52. union L_Umaxalign { double d; char *s; long l; };
  53. /*
  54. ** type for virtual-machine instructions
  55. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  56. ** For a very small machine, you may change that to 2 bytes (and adjust
  57. ** the following limits accordingly)
  58. */
  59. typedef unsigned long Instruction;
  60. /*
  61. ** size and position of opcode arguments.
  62. ** For an instruction with 2 bytes, size is 16, and size_b can be 5
  63. ** (accordingly, size_u will be 10, and size_a will be 5)
  64. */
  65. #define SIZE_INSTRUCTION 32
  66. #define SIZE_B 9
  67. #define SIZE_OP 6
  68. #define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
  69. #define POS_U SIZE_OP
  70. #define POS_B SIZE_OP
  71. #define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
  72. #define POS_A (SIZE_OP+SIZE_B)
  73. /*
  74. ** limits for opcode arguments.
  75. ** we use (signed) int to manipulate most arguments,
  76. ** so they must fit in BITS_INT-1 bits (-1 for sign)
  77. */
  78. #if SIZE_U < BITS_INT-1
  79. #define MAXARG_U ((1<<SIZE_U)-1)
  80. #define MAXARG_S (MAXARG_U>>1) /* `S' is signed */
  81. #else
  82. #define MAXARG_U MAX_INT
  83. #define MAXARG_S MAX_INT
  84. #endif
  85. #if SIZE_A < BITS_INT-1
  86. #define MAXARG_A ((1<<SIZE_A)-1)
  87. #else
  88. #define MAXARG_A MAX_INT
  89. #endif
  90. #if SIZE_B < BITS_INT-1
  91. #define MAXARG_B ((1<<SIZE_B)-1)
  92. #else
  93. #define MAXARG_B MAX_INT
  94. #endif
  95. /* maximum stack size in a function */
  96. #ifndef MAXSTACK
  97. #define MAXSTACK 250
  98. #endif
  99. #if MAXSTACK > MAXARG_B
  100. #undef MAXSTACK
  101. #define MAXSTACK MAXARG_B
  102. #endif
  103. /* maximum number of local variables */
  104. #ifndef MAXLOCALS
  105. #define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
  106. #endif
  107. #if MAXLOCALS>=MAXSTACK
  108. #undef MAXLOCALS
  109. #define MAXLOCALS (MAXSTACK-1)
  110. #endif
  111. /* maximum number of upvalues */
  112. #ifndef MAXUPVALUES
  113. #define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
  114. #endif
  115. #if MAXUPVALUES>MAXARG_B
  116. #undef MAXUPVALUES
  117. #define MAXUPVALUES MAXARG_B
  118. #endif
  119. /* maximum number of variables in the left side of an assignment */
  120. #ifndef MAXVARSLH
  121. #define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */
  122. #endif
  123. #if MAXVARSLH>=MULT_RET
  124. #undef MAXVARSLH
  125. #define MAXVARSLH (MULT_RET-1)
  126. #endif
  127. /* maximum number of parameters in a function */
  128. #ifndef MAXPARAMS
  129. #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
  130. #endif
  131. #if MAXPARAMS>=MAXLOCALS
  132. #undef MAXPARAMS
  133. #define MAXPARAMS (MAXLOCALS-1)
  134. #endif
  135. /* number of list items to accumulate before a SETLIST instruction */
  136. #define LFIELDS_PER_FLUSH 64
  137. #if LFIELDS_PER_FLUSH>(MAXSTACK/4)
  138. #undef LFIELDS_PER_FLUSH
  139. #define LFIELDS_PER_FLUSH (MAXSTACK/4)
  140. #endif
  141. /* number of record items to accumulate before a SETMAP instruction */
  142. /* (each item counts 2 elements on the stack: an index and a value) */
  143. #define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2)
  144. /* maximum lookback to find a real constant (for code generation) */
  145. #ifndef LOOKBACKNUMS
  146. #define LOOKBACKNUMS 20 /* arbitrary constant */
  147. #endif
  148. #endif