llimits.h 4.2 KB

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