diff options
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 70 |
1 files changed, 18 insertions, 52 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.49 2000/03/13 20:37:16 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.50 2000/03/16 18:03:09 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -7,36 +7,32 @@ | |||
7 | #ifndef lopcodes_h | 7 | #ifndef lopcodes_h |
8 | #define lopcodes_h | 8 | #define lopcodes_h |
9 | 9 | ||
10 | #include "llims.h" | ||
10 | 11 | ||
11 | 12 | ||
12 | /*=========================================================================== | 13 | /*=========================================================================== |
13 | We assume that instructions are unsigned numbers with 4 bytes. | 14 | We assume that instructions are unsigned numbers. |
14 | All instructions have an opcode in the 8 bits. Moreover, | 15 | All instructions have an opcode in the first 6 bits. Moreover, |
15 | an instruction can have 0, 1, or 2 arguments. There are 4 types of | 16 | an instruction can have 0, 1, or 2 arguments. There are 4 types of |
16 | Instructions: | 17 | Instructions: |
17 | type 0: no arguments | 18 | type 0: no arguments |
18 | type 1: 1 unsigned argument in the higher 24 bits (called `U') | 19 | type 1: 1 unsigned argument in the higher bits (called `U') |
19 | type 2: 1 signed argument in the higher 24 bits (`S') | 20 | type 2: 1 signed argument in the higher bits (`S') |
20 | type 3: 1st unsigned argument in the higher 16 bits (`A') | 21 | type 3: 1st unsigned argument in the higher bits (`A') |
21 | 2nd unsigned argument in the middle 8 bits (`B') | 22 | 2nd unsigned argument in the middle bits (`B') |
22 | 23 | ||
23 | The signed argument is represented in excess 2^23; that is, the number | 24 | The signed argument is represented in excess 2^K; that is, the number |
24 | value is the usigned value minus 2^23. | 25 | value is the usigned value minus 2^K. |
26 | |||
27 | The size of each argument is defined in `llims.h'. The usual is an | ||
28 | instruction with 32 bits, U and S arguments with 26 bits (32-6), B | ||
29 | argument with 9 bits, and A argument with 17 bits (32-6-9). For small | ||
30 | instalations, the instruction size can be 16, so U and S have 10 bits, | ||
31 | and A and B have 5 bits each. | ||
25 | ===========================================================================*/ | 32 | ===========================================================================*/ |
26 | 33 | ||
27 | #define SIZE_INSTRUCTION 32 | ||
28 | |||
29 | #define SIZE_OP 8 | ||
30 | #define SIZE_U (SIZE_INSTRUCTION-SIZE_OP) | ||
31 | #define POS_U SIZE_OP | ||
32 | #define SIZE_S (SIZE_INSTRUCTION-SIZE_OP) | ||
33 | #define POS_S SIZE_OP | ||
34 | #define SIZE_B 8 | ||
35 | #define POS_B SIZE_OP | ||
36 | #define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B)) | ||
37 | #define POS_A (SIZE_OP+SIZE_B) | ||
38 | 34 | ||
39 | #define EXCESS_S (1<<(SIZE_S-1)) /* == 2^23 */ | 35 | #define EXCESS_S (1<<(SIZE_S-1)) /* == 2^K */ |
40 | 36 | ||
41 | 37 | ||
42 | /* creates a mask with `n' 1 bits at position `p' */ | 38 | /* creates a mask with `n' 1 bits at position `p' */ |
@@ -49,11 +45,6 @@ | |||
49 | ** the following macros help to manipulate instructions | 45 | ** the following macros help to manipulate instructions |
50 | */ | 46 | */ |
51 | 47 | ||
52 | #define MAXARG_U ((1<<SIZE_U)-1) | ||
53 | #define MAXARG_S ((1<<(SIZE_S-1))-1) /* `S' is signed */ | ||
54 | #define MAXARG_A ((1<<SIZE_A)-1) | ||
55 | #define MAXARG_B ((1<<SIZE_B)-1) | ||
56 | |||
57 | #define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) | 48 | #define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) |
58 | #define GETARG_U(i) ((int)((i)>>POS_U)) | 49 | #define GETARG_U(i) ((int)((i)>>POS_U)) |
59 | #define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S) | 50 | #define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S) |
@@ -157,29 +148,4 @@ OP_SETLINE/* U - - LINE=u */ | |||
157 | #define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP) | 148 | #define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP) |
158 | 149 | ||
159 | 150 | ||
160 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ | ||
161 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */ | ||
162 | |||
163 | |||
164 | /* | ||
165 | ** we use int to manipulte most arguments, so they must fit | ||
166 | */ | ||
167 | #if MAXARG_U > MAX_INT | ||
168 | #undef MAXARG_U | ||
169 | #define MAXARG_U MAX_INT | ||
170 | #endif | ||
171 | #if MAXARG_S > MAX_INT | ||
172 | #undef MAXARG_S | ||
173 | #define MAXARG_S MAX_INT | ||
174 | #endif | ||
175 | #if MAXARG_A > MAX_INT | ||
176 | #undef MAXARG_A | ||
177 | #define MAXARG_A MAX_INT | ||
178 | #endif | ||
179 | #if MAXARG_B > MAX_INT | ||
180 | #undef MAXARG_B | ||
181 | #define MAXARG_B MAX_INT | ||
182 | #endif | ||
183 | |||
184 | |||
185 | #endif | 151 | #endif |