llimits.h 4.3 KB

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