diff options
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 54 |
1 files changed, 27 insertions, 27 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.93 2002/03/25 17:47:14 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.94 2002/04/09 19:47:44 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 | */ |
@@ -17,8 +17,8 @@ | |||
17 | `A' : 8 bits (25-32) | 17 | `A' : 8 bits (25-32) |
18 | `B' : 8 bits (17-24) | 18 | `B' : 8 bits (17-24) |
19 | `C' : 10 bits (7-16) | 19 | `C' : 10 bits (7-16) |
20 | `Bc' : 18 bits (`B' and `C' together) | 20 | `Bx' : 18 bits (`B' and `C' together) |
21 | `sBc' : signed Bc | 21 | `sBx' : signed Bx |
22 | 22 | ||
23 | A signed argument is represented in excess K; that is, the number | 23 | A signed argument is represented in excess K; that is, the number |
24 | value is the unsigned value minus K. K is exactly the maximum value | 24 | value is the unsigned value minus K. K is exactly the maximum value |
@@ -28,7 +28,7 @@ | |||
28 | ===========================================================================*/ | 28 | ===========================================================================*/ |
29 | 29 | ||
30 | 30 | ||
31 | enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | 31 | enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ |
32 | 32 | ||
33 | 33 | ||
34 | /* | 34 | /* |
@@ -36,14 +36,14 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | |||
36 | */ | 36 | */ |
37 | #define SIZE_C 10 | 37 | #define SIZE_C 10 |
38 | #define SIZE_B 8 | 38 | #define SIZE_B 8 |
39 | #define SIZE_Bc (SIZE_C + SIZE_B) | 39 | #define SIZE_Bx (SIZE_C + SIZE_B) |
40 | #define SIZE_A 8 | 40 | #define SIZE_A 8 |
41 | 41 | ||
42 | #define SIZE_OP 6 | 42 | #define SIZE_OP 6 |
43 | 43 | ||
44 | #define POS_C SIZE_OP | 44 | #define POS_C SIZE_OP |
45 | #define POS_B (POS_C + SIZE_C) | 45 | #define POS_B (POS_C + SIZE_C) |
46 | #define POS_Bc POS_C | 46 | #define POS_Bx POS_C |
47 | #define POS_A (POS_B + SIZE_B) | 47 | #define POS_A (POS_B + SIZE_B) |
48 | 48 | ||
49 | 49 | ||
@@ -52,12 +52,12 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | |||
52 | ** we use (signed) int to manipulate most arguments, | 52 | ** we use (signed) int to manipulate most arguments, |
53 | ** so they must fit in BITS_INT-1 bits (-1 for sign) | 53 | ** so they must fit in BITS_INT-1 bits (-1 for sign) |
54 | */ | 54 | */ |
55 | #if SIZE_Bc < BITS_INT-1 | 55 | #if SIZE_Bx < BITS_INT-1 |
56 | #define MAXARG_Bc ((1<<SIZE_Bc)-1) | 56 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) |
57 | #define MAXARG_sBc (MAXARG_Bc>>1) /* `sBc' is signed */ | 57 | #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ |
58 | #else | 58 | #else |
59 | #define MAXARG_Bc MAX_INT | 59 | #define MAXARG_Bx MAX_INT |
60 | #define MAXARG_sBc MAX_INT | 60 | #define MAXARG_sBx MAX_INT |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | 63 | ||
@@ -91,12 +91,12 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | |||
91 | #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ | 91 | #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ |
92 | (cast(Instruction, b)<<POS_C))) | 92 | (cast(Instruction, b)<<POS_C))) |
93 | 93 | ||
94 | #define GETARG_Bc(i) (cast(int, ((i)>>POS_Bc) & MASK1(SIZE_Bc,0))) | 94 | #define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0))) |
95 | #define SETARG_Bc(i,b) ((i) = (((i)&MASK0(SIZE_Bc,POS_Bc)) | \ | 95 | #define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ |
96 | (cast(Instruction, b)<<POS_Bc))) | 96 | (cast(Instruction, b)<<POS_Bx))) |
97 | 97 | ||
98 | #define GETARG_sBc(i) (GETARG_Bc(i)-MAXARG_sBc) | 98 | #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) |
99 | #define SETARG_sBc(i,b) SETARG_Bc((i),cast(unsigned int, (b)+MAXARG_sBc)) | 99 | #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) |
100 | 100 | ||
101 | 101 | ||
102 | #define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \ | 102 | #define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \ |
@@ -104,9 +104,9 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | |||
104 | | (cast(Instruction, b)<<POS_B) \ | 104 | | (cast(Instruction, b)<<POS_B) \ |
105 | | (cast(Instruction, c)<<POS_C)) | 105 | | (cast(Instruction, c)<<POS_C)) |
106 | 106 | ||
107 | #define CREATE_ABc(o,a,bc) (cast(Instruction, o) \ | 107 | #define CREATE_ABx(o,a,bc) (cast(Instruction, o) \ |
108 | | (cast(Instruction, a)<<POS_A) \ | 108 | | (cast(Instruction, a)<<POS_A) \ |
109 | | (cast(Instruction, bc)<<POS_Bc)) | 109 | | (cast(Instruction, bc)<<POS_Bx)) |
110 | 110 | ||
111 | 111 | ||
112 | 112 | ||
@@ -129,15 +129,15 @@ typedef enum { | |||
129 | name args description | 129 | name args description |
130 | ------------------------------------------------------------------------*/ | 130 | ------------------------------------------------------------------------*/ |
131 | OP_MOVE,/* A B R(A) := R(B) */ | 131 | OP_MOVE,/* A B R(A) := R(B) */ |
132 | OP_LOADK,/* A Bc R(A) := Kst(Bc) */ | 132 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ |
133 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) PC++ */ | 133 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) PC++ */ |
134 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ | 134 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ |
135 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ | 135 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ |
136 | 136 | ||
137 | OP_GETGLOBAL,/* A Bc R(A) := Gbl[Kst(Bc)] */ | 137 | OP_GETGLOBAL,/* A Bx R(A) := Gbl[Kst(Bx)] */ |
138 | OP_GETTABLE,/* A B C R(A) := R(B)[R/K(C)] */ | 138 | OP_GETTABLE,/* A B C R(A) := R(B)[R/K(C)] */ |
139 | 139 | ||
140 | OP_SETGLOBAL,/* A Bc Gbl[Kst(Bc)] := R(A) */ | 140 | OP_SETGLOBAL,/* A Bx Gbl[Kst(Bx)] := R(A) */ |
141 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ | 141 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ |
142 | OP_SETTABLE,/* A B C R(B)[R/K(C)] := R(A) */ | 142 | OP_SETTABLE,/* A B C R(B)[R/K(C)] := R(A) */ |
143 | 143 | ||
@@ -155,7 +155,7 @@ OP_NOT,/* A B R(A) := not R(B) */ | |||
155 | 155 | ||
156 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ | 156 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ |
157 | 157 | ||
158 | OP_JMP,/* sBc PC += sBc */ | 158 | OP_JMP,/* sBx PC += sBx */ |
159 | 159 | ||
160 | OP_TESTEQ,/* A C if not (R(A) == R/K(C)) then pc++ */ | 160 | OP_TESTEQ,/* A C if not (R(A) == R/K(C)) then pc++ */ |
161 | OP_TESTNE,/* A C if not (R(A) ~= R/K(C)) then pc++ */ | 161 | OP_TESTNE,/* A C if not (R(A) ~= R/K(C)) then pc++ */ |
@@ -171,17 +171,17 @@ OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ | |||
171 | OP_TAILCALL,/* A B return R(A)(R(A+1), ... ,R(A+B-1)) */ | 171 | OP_TAILCALL,/* A B return R(A)(R(A+1), ... ,R(A+B-1)) */ |
172 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see (3)) */ | 172 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see (3)) */ |
173 | 173 | ||
174 | OP_FORLOOP,/* A sBc R(A)+=R(A+2); if R(A) <?= R(A+1) then PC+= sBc */ | 174 | OP_FORLOOP,/* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then PC+= sBx */ |
175 | 175 | ||
176 | OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); | 176 | OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); |
177 | if R(A+2) ~= nil then pc++ */ | 177 | if R(A+2) ~= nil then pc++ */ |
178 | OP_TFORPREP,/* A if type(R(A)) == table then R(A+1):=R(A), R(A):=next */ | 178 | OP_TFORPREP,/* A if type(R(A)) == table then R(A+1):=R(A), R(A):=next */ |
179 | 179 | ||
180 | OP_SETLIST,/* A Bc R(A)[Bc-Bc%FPF+i] := R(A+i), 1 <= i <= Bc%FPF+1 */ | 180 | OP_SETLIST,/* A Bx R(A)[Bx-Bx%FPF+i] := R(A+i), 1 <= i <= Bx%FPF+1 */ |
181 | OP_SETLISTO,/* A Bc */ | 181 | OP_SETLISTO,/* A Bx */ |
182 | 182 | ||
183 | OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ | 183 | OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ |
184 | OP_CLOSURE/* A Bc R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n)) */ | 184 | OP_CLOSURE/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ |
185 | } OpCode; | 185 | } OpCode; |
186 | 186 | ||
187 | 187 | ||
@@ -207,7 +207,7 @@ enum OpModeMask { | |||
207 | OpModeBreg = 2, /* B is a register */ | 207 | OpModeBreg = 2, /* B is a register */ |
208 | OpModeCreg, /* C is a register/constant */ | 208 | OpModeCreg, /* C is a register/constant */ |
209 | OpModesetA, /* instruction set register A */ | 209 | OpModesetA, /* instruction set register A */ |
210 | OpModeK, /* Bc is a constant */ | 210 | OpModeK, /* Bx is a constant */ |
211 | OpModeT /* operator is a test */ | 211 | OpModeT /* operator is a test */ |
212 | }; | 212 | }; |
213 | 213 | ||