llimits.h 4.4 KB

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