llimits.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. ** $Id: llimits.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $
  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. #include "lua.h"
  11. /*
  12. ** try to find number of bits in an integer
  13. */
  14. #ifndef BITS_INT
  15. /* avoid overflows in comparison */
  16. #if INT_MAX-20 < 32760
  17. #define BITS_INT 16
  18. #else
  19. #if INT_MAX > 2147483640L
  20. /* machine has at least 32 bits */
  21. #define BITS_INT 32
  22. #else
  23. #error "you must define BITS_INT with number of bits in an integer"
  24. #endif
  25. #endif
  26. #endif
  27. /*
  28. ** the following types define integer types for values that may not
  29. ** fit in a `small int' (16 bits), but may waste space in a
  30. ** `large long' (64 bits). The current definitions should work in
  31. ** any machine, but may not be optimal.
  32. */
  33. /* an unsigned integer to hold hash values */
  34. typedef unsigned int lu_hash;
  35. /* its signed equivalent */
  36. typedef int ls_hash;
  37. /* an unsigned integer big enough to count the total memory used by Lua; */
  38. /* it should be at least as large as size_t */
  39. typedef unsigned long lu_mem;
  40. /* an integer big enough to count the number of strings in use */
  41. typedef long ls_nstr;
  42. /* chars used as small naturals (so that `char' is reserved for characteres) */
  43. typedef unsigned char lu_byte;
  44. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  45. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  46. /*
  47. ** conversion of pointer to integer
  48. ** this is for hashing only; there is no problem if the integer
  49. ** cannot hold the whole pointer value
  50. ** (the shift removes bits that are usually 0 because of alignment)
  51. */
  52. #define IntPoint(p) ((((lu_hash)(p)) >> 4) ^ (lu_hash)(p))
  53. /* type to ensure maximum alignment */
  54. #ifndef LUSER_ALIGNMENT_T
  55. #define LUSER_ALIGNMENT_T double
  56. #endif
  57. union L_Umaxalign { LUSER_ALIGNMENT_T u; void *s; long l; };
  58. /*
  59. ** type for virtual-machine instructions
  60. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  61. */
  62. typedef unsigned long Instruction;
  63. /* maximum stack for a Lua function */
  64. #define MAXSTACK 250
  65. /* maximum number of local variables */
  66. #ifndef MAXLOCALS
  67. #define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */
  68. #endif
  69. /* maximum number of upvalues per function */
  70. #ifndef MAXUPVALUES
  71. #define MAXUPVALUES 32
  72. #endif
  73. /* maximum number of parameters in a function */
  74. #ifndef MAXPARAMS
  75. #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
  76. #endif
  77. /* number of list items to accumulate before a SETLIST instruction */
  78. /* (must be a power of 2) */
  79. #define LFIELDS_PER_FLUSH 64
  80. #endif