diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-24 14:26:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-24 14:26:08 -0300 |
commit | 13578517c7a4434fe0ea3ec25febd88a09a73b90 (patch) | |
tree | b4e92be53a39484b2061d89eb998d5f144f2710d | |
parent | 213e9febc889d5aaae8ef0e8b777cdb4889e30c1 (diff) | |
download | lua-13578517c7a4434fe0ea3ec25febd88a09a73b90.tar.gz lua-13578517c7a4434fe0ea3ec25febd88a09a73b90.tar.bz2 lua-13578517c7a4434fe0ea3ec25febd88a09a73b90.zip |
new file to keep all limits and instalation-dependent definitions
-rw-r--r-- | llimits.h | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/llimits.h b/llimits.h new file mode 100644 index 00000000..e7984d17 --- /dev/null +++ b/llimits.h | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | ** $Id: $ | ||
3 | ** Limits, basic types, and some other "instalation-dependent" definitions | ||
4 | ** See Copyright Notice in lua.h | ||
5 | */ | ||
6 | |||
7 | #ifndef llims_h | ||
8 | #define llims_h | ||
9 | |||
10 | |||
11 | #include <limits.h> | ||
12 | |||
13 | |||
14 | /* | ||
15 | ** Define the type `number' of Lua | ||
16 | ** GREP LUA_NUMBER to change that | ||
17 | */ | ||
18 | #ifndef LUA_NUM_TYPE | ||
19 | #define LUA_NUM_TYPE double | ||
20 | #endif | ||
21 | |||
22 | typedef LUA_NUM_TYPE Number; | ||
23 | |||
24 | |||
25 | |||
26 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ | ||
27 | |||
28 | /* | ||
29 | ** conversion of pointer to int (for hashing only) | ||
30 | ** (the shift removes bits that are usually 0 because of alignment) | ||
31 | */ | ||
32 | #define IntPoint(L, p) (((unsigned long)(p)) >> 3) | ||
33 | |||
34 | |||
35 | /* | ||
36 | ** number of `blocks' for garbage collection: each reference to other | ||
37 | ** objects count 1, and each 32 bytes of `raw' memory count 1; we add | ||
38 | ** 2 to the total as a minimum (and also to count the overhead of malloc) | ||
39 | */ | ||
40 | #define numblocks(L, o,b) ((o)+((b)>>5)+2) | ||
41 | |||
42 | |||
43 | #define MINPOWER2 4 /* minimum size for "growing" vectors */ | ||
44 | |||
45 | |||
46 | /* | ||
47 | ** type for virtual-machine instructions | ||
48 | ** must be an unsigned with 4 bytes (see details in lopcodes.h) | ||
49 | ** For a very small machine, you may change that to 2 bytes (and adjust | ||
50 | ** the following limits accordingly) | ||
51 | */ | ||
52 | typedef unsigned long Instruction; | ||
53 | |||
54 | |||
55 | /* | ||
56 | ** limits for opcode arguments. | ||
57 | ** For an instruction with 2 bytes, size is 16, and size_b can be 5 | ||
58 | */ | ||
59 | #define SIZE_INSTRUCTION 32 | ||
60 | #define SIZE_OP 6 | ||
61 | #define SIZE_B 9 | ||
62 | |||
63 | #define SIZE_U (SIZE_INSTRUCTION-SIZE_OP) | ||
64 | #define POS_U SIZE_OP | ||
65 | #define SIZE_S (SIZE_INSTRUCTION-SIZE_OP) | ||
66 | #define POS_S SIZE_OP | ||
67 | #define POS_B SIZE_OP | ||
68 | #define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B)) | ||
69 | #define POS_A (SIZE_OP+SIZE_B) | ||
70 | |||
71 | #define MAXARG_U ((1<<SIZE_U)-1) | ||
72 | #define MAXARG_S ((1<<(SIZE_S-1))-1) /* `S' is signed */ | ||
73 | #define MAXARG_A ((1<<SIZE_A)-1) | ||
74 | #define MAXARG_B ((1<<SIZE_B)-1) | ||
75 | |||
76 | |||
77 | /* | ||
78 | ** we use int to manipulate most arguments, so they must fit | ||
79 | */ | ||
80 | #if MAXARG_U > MAX_INT | ||
81 | #undef MAXARG_U | ||
82 | #define MAXARG_U MAX_INT | ||
83 | #endif | ||
84 | |||
85 | #if MAXARG_S > MAX_INT | ||
86 | #undef MAXARG_S | ||
87 | #define MAXARG_S MAX_INT | ||
88 | #endif | ||
89 | |||
90 | #if MAXARG_A > MAX_INT | ||
91 | #undef MAXARG_A | ||
92 | #define MAXARG_A MAX_INT | ||
93 | #endif | ||
94 | |||
95 | #if MAXARG_B > MAX_INT | ||
96 | #undef MAXARG_B | ||
97 | #define MAXARG_B MAX_INT | ||
98 | #endif | ||
99 | |||
100 | |||
101 | /* maximum stack size in a function */ | ||
102 | #define MAXSTACK MAXARG_B | ||
103 | |||
104 | |||
105 | /* maximum number of local variables */ | ||
106 | #ifndef MAXLOCALS | ||
107 | #define MAXLOCALS 200 /* arbitrary limit (<MAXSTACK) */ | ||
108 | #endif | ||
109 | #if MAXLOCALS>=MAXSTACK | ||
110 | #undef MAXLOCALS | ||
111 | #define MAXLOCALS (MAXSTACK-1) | ||
112 | #endif | ||
113 | |||
114 | |||
115 | /* maximum number of upvalues */ | ||
116 | #ifndef MAXUPVALUES | ||
117 | #define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */ | ||
118 | #endif | ||
119 | #if MAXUPVALUES>MAXARG_B | ||
120 | #undef MAXUPVALUES | ||
121 | #define MAXUPVALUES MAXARG_B | ||
122 | #endif | ||
123 | |||
124 | |||
125 | /* special code for multiple returns */ | ||
126 | #define MULT_RET 255 /* (<=MAXARG_B) */ | ||
127 | #if MULT_RET>MAXARG_B | ||
128 | #undef MULT_RET | ||
129 | #define MULT_RET MAXARG_B | ||
130 | #endif | ||
131 | |||
132 | |||
133 | /* maximum number of variables in the left side of an assignment */ | ||
134 | #ifndef MAXVARSLH | ||
135 | #define MAXVARSLH 100 /* arbitrary limit (<MULT_RET) */ | ||
136 | #endif | ||
137 | #if MAXVARSLH>=MULT_RET | ||
138 | #undef MAXVARSLH | ||
139 | #define MAXVARSLH (MULT_RET-1) | ||
140 | #endif | ||
141 | |||
142 | |||
143 | /* maximum number of parameters in a function */ | ||
144 | #ifndef MAXPARAMS | ||
145 | #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */ | ||
146 | #endif | ||
147 | #if MAXPARAMS>=MAXLOCALS | ||
148 | #undef MAXPARAMS | ||
149 | #define MAXPARAMS (MAXLOCALS-1) | ||
150 | #endif | ||
151 | |||
152 | |||
153 | /* number of list items to accumulate before a SETLIST instruction */ | ||
154 | #define LFIELDS_PER_FLUSH (MAXSTACK/4) | ||
155 | |||
156 | /* number of record items to accumulate before a SETMAP instruction */ | ||
157 | /* (each item counts 2 elements on the stack: an index and a value) */ | ||
158 | #define RFIELDS_PER_FLUSH (LFIELDS_PER_FLUSH/2) | ||
159 | |||
160 | |||
161 | /* maximum number of values printed in one call to `print' */ | ||
162 | #ifndef MAXPRINT | ||
163 | #define MAXPRINT 40 /* arbitrary limit */ | ||
164 | #endif | ||
165 | |||
166 | |||
167 | /* maximum depth of nested $ifs */ | ||
168 | #ifndef MAX_IFS | ||
169 | #define MAX_IFS 5 /* arbitrary limit */ | ||
170 | #endif | ||
171 | |||
172 | |||
173 | /* maximum size of a pragma line */ | ||
174 | #ifndef PRAGMASIZE | ||
175 | #define PRAGMASIZE 80 /* arbitrary limit */ | ||
176 | #endif | ||
177 | |||
178 | |||
179 | /* maximum lookback to find a real constant (for code generation) */ | ||
180 | #ifndef LOOKBACKNUMS | ||
181 | #define LOOKBACKNUMS 20 /* arbitrary limit */ | ||
182 | #endif | ||
183 | |||
184 | |||
185 | #endif | ||