summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lopcodes.h
diff options
context:
space:
mode:
authorRichard Quirk <richard.quirk@gmail.com>2014-03-19 19:31:31 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-04-02 20:31:54 +0200
commit36378988ad4059982742f05f5eb50580b456840a (patch)
treeee70be810d894566c5e351f21a1ebb79be742a85 /apps/plugins/lua/lopcodes.h
parent020f16a1c7d5bc9a302671cef03f56ac735e20c5 (diff)
downloadrockbox-36378988ad4059982742f05f5eb50580b456840a.tar.gz
rockbox-36378988ad4059982742f05f5eb50580b456840a.zip
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change reduces the number of modifications in the Lua source using some new defines and because the upstream source is now more flexible. Unless otherwise stated, l*.[ch] files are taken unmodified from the upstream lua-5.2.3. fscanf.c: file descriptors in rockbox are just ints, they are hidden behind a void* now so liolib requires less modifications. fscanf is updated to use void* too. getc.c: this is a new file required for getc implementation in lauxlib.c lauxlib.c: LoadF replaced FILE* with int, the rockbox file descriptor int are cast to FILE* (actually void* due to typedef). getc uses the PREFIX version. stdin is not used, as per 5.1.4. lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now rather than being commented out. lbitlib.c: use the built-in version from 5.2.3 rather than Reuben Thomas's external library. Backwards compatible and adds some new bit operations. ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have been removed from rockconf.h liolib.c: here the implementation has changed to use the LStream from the original source, and cast the FILE* pointers to int. This has reduced the number of modifications from the upstream version. llex.c: the only change from upstream is to remove the locale include. lmathlib.c: updated from the 5.2.3 version and re-applied the changes that were made vs 5.1.4 for random numbers and to remove unsupported float functions. loadlib.c: upstream version, with the 5.1.4 changes for missing functions. lobject.c: upstream version, with ctype.h added and sprintf changed to snprintf. loslib.c: upstream version with locale.h removed and 5.1.4 changes for unsupportable functions. lstrlib.c: sprintf changed to snprintf. ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp in luai_hashnum. luaconf.h: updated to 5.2.3 version, restored relevant parts from the original 5.1.4 configuration. The COMPAT defines that are no longer available are not included. lundump.c: VERSION macro conflicts with the core Rockbox equivalent. rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg equivalent. Moved checkboolean/optboolean functions to this file and out of core lua files. luaL_getn is no longer available, replaced by luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs replacements. rli_init has to be called before setting up the newlib to avoid overwriting the rb table. rocklib_aux.pl: use rli_checkboolean from rocklib.c. rocklua.c: new default bits library used, update the library loading code with idiomatic 5.2 code. strcspn.c: no longer needed, but strspn.c is required for strspn in lbaselib.c Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651 Reviewed-on: http://gerrit.rockbox.org/774 Tested: Richard Quirk <richard.quirk@gmail.com> Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'apps/plugins/lua/lopcodes.h')
-rw-r--r--apps/plugins/lua/lopcodes.h106
1 files changed, 63 insertions, 43 deletions
diff --git a/apps/plugins/lua/lopcodes.h b/apps/plugins/lua/lopcodes.h
index e1aed0f637..51f5791545 100644
--- a/apps/plugins/lua/lopcodes.h
+++ b/apps/plugins/lua/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id$ 2** $Id: lopcodes.h,v 1.142.1.1 2013/04/12 18:48:47 roberto Exp $
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,6 +17,7 @@
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)
20 `Bx' : 18 bits (`B' and `C' together) 21 `Bx' : 18 bits (`B' and `C' together)
21 `sBx' : signed Bx 22 `sBx' : signed Bx
22 23
@@ -28,7 +29,7 @@
28===========================================================================*/ 29===========================================================================*/
29 30
30 31
31enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ 32enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
32 33
33 34
34/* 35/*
@@ -38,6 +39,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
38#define SIZE_B 9 39#define SIZE_B 9
39#define SIZE_Bx (SIZE_C + SIZE_B) 40#define SIZE_Bx (SIZE_C + SIZE_B)
40#define SIZE_A 8 41#define SIZE_A 8
42#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
41 43
42#define SIZE_OP 6 44#define SIZE_OP 6
43 45
@@ -46,6 +48,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
46#define POS_C (POS_A + SIZE_A) 48#define POS_C (POS_A + SIZE_A)
47#define POS_B (POS_C + SIZE_C) 49#define POS_B (POS_C + SIZE_C)
48#define POS_Bx POS_C 50#define POS_Bx POS_C
51#define POS_Ax POS_A
49 52
50 53
51/* 54/*
@@ -61,6 +64,12 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
61#define MAXARG_sBx MAX_INT 64#define MAXARG_sBx MAX_INT
62#endif 65#endif
63 66
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
64 73
65#define MAXARG_A ((1<<SIZE_A)-1) 74#define MAXARG_A ((1<<SIZE_A)-1)
66#define MAXARG_B ((1<<SIZE_B)-1) 75#define MAXARG_B ((1<<SIZE_B)-1)
@@ -68,7 +77,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
68 77
69 78
70/* creates a mask with `n' 1 bits at position `p' */ 79/* creates a mask with `n' 1 bits at position `p' */
71#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p) 80#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
72 81
73/* creates a mask with `n' 0 bits at position `p' */ 82/* creates a mask with `n' 0 bits at position `p' */
74#define MASK0(n,p) (~MASK1(n,p)) 83#define MASK0(n,p) (~MASK1(n,p))
@@ -81,21 +90,24 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
81#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ 90#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
82 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) 91 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
83 92
84#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0))) 93#define getarg(i,pos,size) (cast(int, ((i)>>pos) & MASK1(size,0)))
85#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ 94#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
86 ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A)))) 95 ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
87 96
88#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0))) 97#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
89#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ 98#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
90 ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
91 99
92#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0))) 100#define GETARG_B(i) getarg(i, POS_B, SIZE_B)
93#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ 101#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
94 ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
95 102
96#define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0))) 103#define GETARG_C(i) getarg(i, POS_C, SIZE_C)
97#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ 104#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
98 ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx)))) 105
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)
99 111
100#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) 112#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
101#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 113#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
@@ -110,6 +122,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
110 | (cast(Instruction, a)<<POS_A) \ 122 | (cast(Instruction, a)<<POS_A) \
111 | (cast(Instruction, bc)<<POS_Bx)) 123 | (cast(Instruction, bc)<<POS_Bx))
112 124
125#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
126 | (cast(Instruction, a)<<POS_Ax))
127
113 128
114/* 129/*
115** Macros to operate RK indices 130** Macros to operate RK indices
@@ -153,14 +168,15 @@ name args description
153------------------------------------------------------------------------*/ 168------------------------------------------------------------------------*/
154OP_MOVE,/* A B R(A) := R(B) */ 169OP_MOVE,/* A B R(A) := R(B) */
155OP_LOADK,/* A Bx R(A) := Kst(Bx) */ 170OP_LOADK,/* A Bx R(A) := Kst(Bx) */
171OP_LOADKX,/* A R(A) := Kst(extra arg) */
156OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ 172OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
157OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ 173OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
158OP_GETUPVAL,/* A B R(A) := UpValue[B] */ 174OP_GETUPVAL,/* A B R(A) := UpValue[B] */
159 175
160OP_GETGLOBAL,/* A Bx R(A) := Gbl[Kst(Bx)] */ 176OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */
161OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ 177OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */
162 178
163OP_SETGLOBAL,/* A Bx Gbl[Kst(Bx)] := R(A) */ 179OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */
164OP_SETUPVAL,/* A B UpValue[B] := R(A) */ 180OP_SETUPVAL,/* A B UpValue[B] := R(A) */
165OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ 181OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */
166 182
@@ -180,14 +196,13 @@ OP_LEN,/* A B R(A) := length of R(B) */
180 196
181OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ 197OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
182 198
183OP_JMP,/* sBx pc+=sBx */ 199OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
184
185OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ 200OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
186OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ 201OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
187OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ 202OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
188 203
189OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ 204OP_TEST,/* A C if not (R(A) <=> C) then pc++ */
190OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ 205OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
191 206
192OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ 207OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
193OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ 208OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
@@ -197,39 +212,44 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2);
197 if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ 212 if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
198OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ 213OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
199 214
200OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); 215OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
201 if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ 216OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
217
202OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ 218OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
203 219
204OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ 220OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
205OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ 221
222OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
206 223
207OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ 224OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
208} OpCode; 225} OpCode;
209 226
210 227
211#define NUM_OPCODES (cast(int, OP_VARARG) + 1) 228#define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
212 229
213 230
214 231
215/*=========================================================================== 232/*===========================================================================
216 Notes: 233 Notes:
217 (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, 234 (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then `top' is
218 and can be 0: OP_CALL then sets `top' to last_result+1, so 235 set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,
219 next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. 236 OP_SETLIST) may use `top'.
220 237
221 (*) In OP_VARARG, if (B == 0) then use actual number of varargs and 238 (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
222 set top (like in OP_CALL with C == 0). 239 set top (like in OP_CALL with C == 0).
223 240
224 (*) In OP_RETURN, if (B == 0) then return up to `top' 241 (*) In OP_RETURN, if (B == 0) then return up to `top'.
225 242
226 (*) In OP_SETLIST, if (B == 0) then B = `top'; 243 (*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next
227 if (C == 0) then next `instruction' is real C 244 'instruction' is EXTRAARG(real C).
245
246 (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.
228 247
229 (*) For comparisons, A specifies what condition the test should accept 248 (*) For comparisons, A specifies what condition the test should accept
230 (true or false). 249 (true or false).
250
251 (*) All `skips' (pc++) assume that next instruction is a jump.
231 252
232 (*) All `skips' (pc++) assume that next instruction is a jump
233===========================================================================*/ 253===========================================================================*/
234 254
235 255
@@ -239,8 +259,8 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
239** bits 2-3: C arg mode 259** bits 2-3: C arg mode
240** bits 4-5: B arg mode 260** bits 4-5: B arg mode
241** bit 6: instruction set register A 261** bit 6: instruction set register A
242** bit 7: operator is a test 262** bit 7: operator is a test (next instruction must be a jump)
243*/ 263*/
244 264
245enum OpArgMask { 265enum OpArgMask {
246 OpArgN, /* argument is not used */ 266 OpArgN, /* argument is not used */
@@ -249,7 +269,7 @@ enum OpArgMask {
249 OpArgK /* argument is a constant or register/constant */ 269 OpArgK /* argument is a constant or register/constant */
250}; 270};
251 271
252LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; 272LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];
253 273
254#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) 274#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
255#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) 275#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
@@ -258,7 +278,7 @@ LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
258#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) 278#define testTMode(m) (luaP_opmodes[m] & (1 << 7))
259 279
260 280
261LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ 281LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
262 282
263 283
264/* number of list items to accumulate before a SETLIST instruction */ 284/* number of list items to accumulate before a SETLIST instruction */