diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
commit | bfd0179042b0b02fb88748d54e56e7e208bb117f (patch) | |
tree | 42d5fd51574054caaf673420fca1ec962d62d2f2 /apps/plugins/lua/lopcodes.h | |
parent | 36378988ad4059982742f05f5eb50580b456840a (diff) | |
download | rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.gz rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.zip |
Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and
application builds. I checked only a few random native builds
unfortunately. Sorry for inconvenience.
Diffstat (limited to 'apps/plugins/lua/lopcodes.h')
-rw-r--r-- | apps/plugins/lua/lopcodes.h | 106 |
1 files changed, 43 insertions, 63 deletions
diff --git a/apps/plugins/lua/lopcodes.h b/apps/plugins/lua/lopcodes.h index 51f5791545..e1aed0f637 100644 --- a/apps/plugins/lua/lopcodes.h +++ b/apps/plugins/lua/lopcodes.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.142.1.1 2013/04/12 18:48:47 roberto Exp $ | 2 | ** $Id$ |
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,7 +17,6 @@ | |||
17 | `A' : 8 bits | 17 | `A' : 8 bits |
18 | `B' : 9 bits | 18 | `B' : 9 bits |
19 | `C' : 9 bits | 19 | `C' : 9 bits |
20 | 'Ax' : 26 bits ('A', 'B', and 'C' together) | ||
21 | `Bx' : 18 bits (`B' and `C' together) | 20 | `Bx' : 18 bits (`B' and `C' together) |
22 | `sBx' : signed Bx | 21 | `sBx' : signed Bx |
23 | 22 | ||
@@ -29,7 +28,7 @@ | |||
29 | ===========================================================================*/ | 28 | ===========================================================================*/ |
30 | 29 | ||
31 | 30 | ||
32 | enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | 31 | enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ |
33 | 32 | ||
34 | 33 | ||
35 | /* | 34 | /* |
@@ -39,7 +38,6 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
39 | #define SIZE_B 9 | 38 | #define SIZE_B 9 |
40 | #define SIZE_Bx (SIZE_C + SIZE_B) | 39 | #define SIZE_Bx (SIZE_C + SIZE_B) |
41 | #define SIZE_A 8 | 40 | #define SIZE_A 8 |
42 | #define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A) | ||
43 | 41 | ||
44 | #define SIZE_OP 6 | 42 | #define SIZE_OP 6 |
45 | 43 | ||
@@ -48,7 +46,6 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
48 | #define POS_C (POS_A + SIZE_A) | 46 | #define POS_C (POS_A + SIZE_A) |
49 | #define POS_B (POS_C + SIZE_C) | 47 | #define POS_B (POS_C + SIZE_C) |
50 | #define POS_Bx POS_C | 48 | #define POS_Bx POS_C |
51 | #define POS_Ax POS_A | ||
52 | 49 | ||
53 | 50 | ||
54 | /* | 51 | /* |
@@ -64,12 +61,6 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
64 | #define MAXARG_sBx MAX_INT | 61 | #define MAXARG_sBx MAX_INT |
65 | #endif | 62 | #endif |
66 | 63 | ||
67 | #if SIZE_Ax < LUAI_BITSINT-1 | ||
68 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) | ||
69 | #else | ||
70 | #define MAXARG_Ax MAX_INT | ||
71 | #endif | ||
72 | |||
73 | 64 | ||
74 | #define MAXARG_A ((1<<SIZE_A)-1) | 65 | #define MAXARG_A ((1<<SIZE_A)-1) |
75 | #define MAXARG_B ((1<<SIZE_B)-1) | 66 | #define MAXARG_B ((1<<SIZE_B)-1) |
@@ -77,7 +68,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
77 | 68 | ||
78 | 69 | ||
79 | /* creates a mask with `n' 1 bits at position `p' */ | 70 | /* creates a mask with `n' 1 bits at position `p' */ |
80 | #define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p)) | 71 | #define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p) |
81 | 72 | ||
82 | /* creates a mask with `n' 0 bits at position `p' */ | 73 | /* creates a mask with `n' 0 bits at position `p' */ |
83 | #define MASK0(n,p) (~MASK1(n,p)) | 74 | #define MASK0(n,p) (~MASK1(n,p)) |
@@ -90,24 +81,21 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
90 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ | 81 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ |
91 | ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) | 82 | ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) |
92 | 83 | ||
93 | #define getarg(i,pos,size) (cast(int, ((i)>>pos) & MASK1(size,0))) | 84 | #define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0))) |
94 | #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ | 85 | #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ |
95 | ((cast(Instruction, v)<<pos)&MASK1(size,pos)))) | 86 | ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A)))) |
96 | 87 | ||
97 | #define GETARG_A(i) getarg(i, POS_A, SIZE_A) | 88 | #define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0))) |
98 | #define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) | 89 | #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ |
90 | ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B)))) | ||
99 | 91 | ||
100 | #define GETARG_B(i) getarg(i, POS_B, SIZE_B) | 92 | #define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0))) |
101 | #define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) | 93 | #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ |
94 | ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C)))) | ||
102 | 95 | ||
103 | #define GETARG_C(i) getarg(i, POS_C, SIZE_C) | 96 | #define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0))) |
104 | #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) | 97 | #define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ |
105 | 98 | ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx)))) | |
106 | #define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx) | ||
107 | #define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) | ||
108 | |||
109 | #define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax) | ||
110 | #define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) | ||
111 | 99 | ||
112 | #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) | 100 | #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) |
113 | #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) | 101 | #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) |
@@ -122,9 +110,6 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ | |||
122 | | (cast(Instruction, a)<<POS_A) \ | 110 | | (cast(Instruction, a)<<POS_A) \ |
123 | | (cast(Instruction, bc)<<POS_Bx)) | 111 | | (cast(Instruction, bc)<<POS_Bx)) |
124 | 112 | ||
125 | #define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \ | ||
126 | | (cast(Instruction, a)<<POS_Ax)) | ||
127 | |||
128 | 113 | ||
129 | /* | 114 | /* |
130 | ** Macros to operate RK indices | 115 | ** Macros to operate RK indices |
@@ -168,15 +153,14 @@ name args description | |||
168 | ------------------------------------------------------------------------*/ | 153 | ------------------------------------------------------------------------*/ |
169 | OP_MOVE,/* A B R(A) := R(B) */ | 154 | OP_MOVE,/* A B R(A) := R(B) */ |
170 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ | 155 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ |
171 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ | ||
172 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | 156 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ |
173 | OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ | 157 | OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ |
174 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ | 158 | OP_GETUPVAL,/* A B R(A) := UpValue[B] */ |
175 | 159 | ||
176 | OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ | 160 | OP_GETGLOBAL,/* A Bx R(A) := Gbl[Kst(Bx)] */ |
177 | OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ | 161 | OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ |
178 | 162 | ||
179 | OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */ | 163 | OP_SETGLOBAL,/* A Bx Gbl[Kst(Bx)] := R(A) */ |
180 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ | 164 | OP_SETUPVAL,/* A B UpValue[B] := R(A) */ |
181 | OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ | 165 | OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ |
182 | 166 | ||
@@ -196,13 +180,14 @@ OP_LEN,/* A B R(A) := length of R(B) */ | |||
196 | 180 | ||
197 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ | 181 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ |
198 | 182 | ||
199 | OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */ | 183 | OP_JMP,/* sBx pc+=sBx */ |
184 | |||
200 | OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ | 185 | OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ |
201 | OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ | 186 | OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ |
202 | OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ | 187 | OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ |
203 | 188 | ||
204 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ | 189 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ |
205 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ | 190 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ |
206 | 191 | ||
207 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ | 192 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ |
208 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ | 193 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ |
@@ -212,44 +197,39 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2); | |||
212 | if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ | 197 | if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ |
213 | OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ | 198 | OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ |
214 | 199 | ||
215 | OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */ | 200 | OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); |
216 | OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/ | 201 | if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ |
217 | |||
218 | OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ | 202 | OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ |
219 | 203 | ||
220 | OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */ | 204 | OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ |
221 | 205 | OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ | |
222 | OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */ | ||
223 | 206 | ||
224 | OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | 207 | OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ |
225 | } OpCode; | 208 | } OpCode; |
226 | 209 | ||
227 | 210 | ||
228 | #define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1) | 211 | #define NUM_OPCODES (cast(int, OP_VARARG) + 1) |
229 | 212 | ||
230 | 213 | ||
231 | 214 | ||
232 | /*=========================================================================== | 215 | /*=========================================================================== |
233 | Notes: | 216 | Notes: |
234 | (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then `top' is | 217 | (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, |
235 | set to last_result+1, so next open instruction (OP_CALL, OP_RETURN, | 218 | and can be 0: OP_CALL then sets `top' to last_result+1, so |
236 | OP_SETLIST) may use `top'. | 219 | next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. |
237 | 220 | ||
238 | (*) In OP_VARARG, if (B == 0) then use actual number of varargs and | 221 | (*) In OP_VARARG, if (B == 0) then use actual number of varargs and |
239 | set top (like in OP_CALL with C == 0). | 222 | set top (like in OP_CALL with C == 0). |
240 | 223 | ||
241 | (*) In OP_RETURN, if (B == 0) then return up to `top'. | 224 | (*) In OP_RETURN, if (B == 0) then return up to `top' |
242 | 225 | ||
243 | (*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next | 226 | (*) In OP_SETLIST, if (B == 0) then B = `top'; |
244 | 'instruction' is EXTRAARG(real C). | 227 | if (C == 0) then next `instruction' is real C |
245 | |||
246 | (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG. | ||
247 | 228 | ||
248 | (*) For comparisons, A specifies what condition the test should accept | 229 | (*) For comparisons, A specifies what condition the test should accept |
249 | (true or false). | 230 | (true or false). |
250 | |||
251 | (*) All `skips' (pc++) assume that next instruction is a jump. | ||
252 | 231 | ||
232 | (*) All `skips' (pc++) assume that next instruction is a jump | ||
253 | ===========================================================================*/ | 233 | ===========================================================================*/ |
254 | 234 | ||
255 | 235 | ||
@@ -259,8 +239,8 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
259 | ** bits 2-3: C arg mode | 239 | ** bits 2-3: C arg mode |
260 | ** bits 4-5: B arg mode | 240 | ** bits 4-5: B arg mode |
261 | ** bit 6: instruction set register A | 241 | ** bit 6: instruction set register A |
262 | ** bit 7: operator is a test (next instruction must be a jump) | 242 | ** bit 7: operator is a test |
263 | */ | 243 | */ |
264 | 244 | ||
265 | enum OpArgMask { | 245 | enum OpArgMask { |
266 | OpArgN, /* argument is not used */ | 246 | OpArgN, /* argument is not used */ |
@@ -269,7 +249,7 @@ enum OpArgMask { | |||
269 | OpArgK /* argument is a constant or register/constant */ | 249 | OpArgK /* argument is a constant or register/constant */ |
270 | }; | 250 | }; |
271 | 251 | ||
272 | LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; | 252 | LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; |
273 | 253 | ||
274 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) | 254 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) |
275 | #define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) | 255 | #define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) |
@@ -278,7 +258,7 @@ LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; | |||
278 | #define testTMode(m) (luaP_opmodes[m] & (1 << 7)) | 258 | #define testTMode(m) (luaP_opmodes[m] & (1 << 7)) |
279 | 259 | ||
280 | 260 | ||
281 | LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ | 261 | LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ |
282 | 262 | ||
283 | 263 | ||
284 | /* number of list items to accumulate before a SETLIST instruction */ | 264 | /* number of list items to accumulate before a SETLIST instruction */ |