aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-02 14:38:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-02 14:38:54 -0300
commita4d3080fe3d07af9d2d3124b8f49eadda7c21b44 (patch)
treee90941e2268f10ac4f7234f13efdbf85f5277e99
parent5627d51e0576887c4133f5b77b1dfb67334b3115 (diff)
downloadlua-a4d3080fe3d07af9d2d3124b8f49eadda7c21b44.tar.gz
lua-a4d3080fe3d07af9d2d3124b8f49eadda7c21b44.tar.bz2
lua-a4d3080fe3d07af9d2d3124b8f49eadda7c21b44.zip
SETLIST extra argument now is an "instruction" (OP_EXTRAARG)
-rw-r--r--lcode.c14
-rw-r--r--ldebug.c18
-rw-r--r--lopcodes.c4
-rw-r--r--lopcodes.h52
-rw-r--r--ltests.c5
-rw-r--r--lvm.c11
6 files changed, 68 insertions, 36 deletions
diff --git a/lcode.c b/lcode.c
index 853cffe2..96ef6b96 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.33 2007/03/27 14:11:38 roberto Exp roberto $ 2** $Id: lcode.c,v 2.34 2007/05/04 18:41:49 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -824,16 +824,24 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
824} 824}
825 825
826 826
827static int luaK_codeAx (FuncState *fs, OpCode o, int a) {
828 lua_assert(getOpMode(o) == iAx);
829 return luaK_code(fs, CREATE_Ax(o, a));
830}
831
832
827void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { 833void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
828 int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; 834 int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
829 int b = (tostore == LUA_MULTRET) ? 0 : tostore; 835 int b = (tostore == LUA_MULTRET) ? 0 : tostore;
830 lua_assert(tostore != 0); 836 lua_assert(tostore != 0);
831 if (c <= MAXARG_C) 837 if (c <= MAXARG_C)
832 luaK_codeABC(fs, OP_SETLIST, base, b, c); 838 luaK_codeABC(fs, OP_SETLIST, base, b, c);
833 else { 839 else if (c <= MAXARG_Ax) {
834 luaK_codeABC(fs, OP_SETLIST, base, b, 0); 840 luaK_codeABC(fs, OP_SETLIST, base, b, 0);
835 luaK_code(fs, cast(Instruction, c)); 841 luaK_codeAx(fs, OP_EXTRAARG, c);
836 } 842 }
843 else
844 luaX_syntaxerror(fs->ls, "constructor too long");
837 fs->freereg = base + 1; /* free registers with list values */ 845 fs->freereg = base + 1; /* free registers with list values */
838} 846}
839 847
diff --git a/ldebug.c b/ldebug.c
index e76da28c..eb11ce17 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.36 2007/05/09 15:49:36 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.37 2007/05/29 18:59:59 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -331,9 +331,9 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
331 int b = 0; 331 int b = 0;
332 int c = 0; 332 int c = 0;
333 check(op < NUM_OPCODES); 333 check(op < NUM_OPCODES);
334 checkreg(pt, a);
335 switch (getOpMode(op)) { 334 switch (getOpMode(op)) {
336 case iABC: { 335 case iABC: {
336 checkreg(pt, a);
337 b = GETARG_B(i); 337 b = GETARG_B(i);
338 c = GETARG_C(i); 338 c = GETARG_C(i);
339 check(checkArgMode(pt, b, getBMode(op))); 339 check(checkArgMode(pt, b, getBMode(op)));
@@ -341,31 +341,27 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
341 break; 341 break;
342 } 342 }
343 case iABx: { 343 case iABx: {
344 checkreg(pt, a);
344 b = GETARG_Bx(i); 345 b = GETARG_Bx(i);
345 if (getBMode(op) == OpArgK) check(b < pt->sizek); 346 if (getBMode(op) == OpArgK) check(b < pt->sizek);
346 break; 347 break;
347 } 348 }
348 case iAsBx: { 349 case iAsBx: {
350 checkreg(pt, a);
349 b = GETARG_sBx(i); 351 b = GETARG_sBx(i);
350 if (getBMode(op) == OpArgR) { 352 if (getBMode(op) == OpArgR) {
351 int dest = pc+1+b; 353 int dest = pc+1+b;
352 check(0 <= dest && dest < pt->sizecode); 354 check(0 <= dest && dest < pt->sizecode);
353 if (dest > 0) {
354 /* cannot jump to a setlist count */
355 Instruction d = pt->code[dest-1];
356 check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
357 }
358 } 355 }
359 break; 356 break;
360 } 357 }
358 case iAx: break;
361 } 359 }
362 if (testAMode(op)) { 360 if (testAMode(op)) {
363 if (a == reg) last = pc; /* change register `a' */ 361 if (a == reg) last = pc; /* change register `a' */
364 } 362 }
365 if (testTMode(op)) { 363 if (testTMode(op))
366 check(pc+2 < pt->sizecode); /* check skip */
367 check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); 364 check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);
368 }
369 switch (op) { 365 switch (op) {
370 case OP_LOADBOOL: { 366 case OP_LOADBOOL: {
371 check(c == 0 || pc+2 < pt->sizecode); /* check its jump */ 367 check(c == 0 || pc+2 < pt->sizecode); /* check its jump */
@@ -433,7 +429,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
433 } 429 }
434 case OP_SETLIST: { 430 case OP_SETLIST: {
435 if (b > 0) checkreg(pt, a + b); 431 if (b > 0) checkreg(pt, a + b);
436 if (c == 0) pc++; 432 if (c == 0) check(GET_OPCODE(pt->code[pc + 1]) == OP_EXTRAARG);
437 break; 433 break;
438 } 434 }
439 case OP_CLOSURE: { 435 case OP_CLOSURE: {
diff --git a/lopcodes.c b/lopcodes.c
index b298b410..133860fc 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp roberto $ 2** $Id: lopcodes.c,v 1.38 2006/09/11 14:07:24 roberto Exp roberto $
3** See Copyright Notice in lua.h 3** See Copyright Notice in lua.h
4*/ 4*/
5 5
@@ -52,6 +52,7 @@ const char *const luaP_opnames[NUM_OPCODES+1] = {
52 "CLOSE", 52 "CLOSE",
53 "CLOSURE", 53 "CLOSURE",
54 "VARARG", 54 "VARARG",
55 "EXTRAARG",
55 NULL 56 NULL
56}; 57};
57 58
@@ -98,5 +99,6 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = {
98 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ 99 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
99 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 100 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
100 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 101 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
102 ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
101}; 103};
102 104
diff --git a/lopcodes.h b/lopcodes.h
index 634a13f3..d52afc1d 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.126 2006/09/11 14:07:24 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*/
@@ -28,7 +28,7 @@
28===========================================================================*/ 28===========================================================================*/
29 29
30 30
31enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ 31enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
32 32
33 33
34/* 34/*
@@ -38,6 +38,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
38#define SIZE_B 9 38#define SIZE_B 9
39#define SIZE_Bx (SIZE_C + SIZE_B) 39#define SIZE_Bx (SIZE_C + SIZE_B)
40#define SIZE_A 8 40#define SIZE_A 8
41#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
41 42
42#define SIZE_OP 6 43#define SIZE_OP 6
43 44
@@ -46,6 +47,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
46#define POS_C (POS_A + SIZE_A) 47#define POS_C (POS_A + SIZE_A)
47#define POS_B (POS_C + SIZE_C) 48#define POS_B (POS_C + SIZE_C)
48#define POS_Bx POS_C 49#define POS_Bx POS_C
50#define POS_Ax POS_A
49 51
50 52
51/* 53/*
@@ -61,6 +63,12 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
61#define MAXARG_sBx MAX_INT 63#define MAXARG_sBx MAX_INT
62#endif 64#endif
63 65
66#if SIZE_Ax < LUAI_BITSINT-1
67#define MAXARG_Ax ((1<<SIZE_Ax)-1)
68#else
69#define MAXARG_Ax MAX_INT
70#endif
71
64 72
65#define MAXARG_A ((1<<SIZE_A)-1) 73#define MAXARG_A ((1<<SIZE_A)-1)
66#define MAXARG_B ((1<<SIZE_B)-1) 74#define MAXARG_B ((1<<SIZE_B)-1)
@@ -68,7 +76,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
68 76
69 77
70/* creates a mask with `n' 1 bits at position `p' */ 78/* creates a mask with `n' 1 bits at position `p' */
71#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p) 79#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
72 80
73/* creates a mask with `n' 0 bits at position `p' */ 81/* creates a mask with `n' 0 bits at position `p' */
74#define MASK0(n,p) (~MASK1(n,p)) 82#define MASK0(n,p) (~MASK1(n,p))
@@ -81,21 +89,24 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
81#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ 89#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
82 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) 90 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
83 91
84#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0))) 92#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)) | \ 93#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
86 ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A)))) 94 ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
95
96#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
97#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
87 98
88#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0))) 99#define GETARG_B(i) getarg(i, POS_B, SIZE_B)
89#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ 100#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
90 ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
91 101
92#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0))) 102#define GETARG_C(i) getarg(i, POS_C, SIZE_C)
93#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ 103#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
94 ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
95 104
96#define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0))) 105#define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx)
97#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ 106#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
98 ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx)))) 107
108#define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax)
109#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
99 110
100#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) 111#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
101#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 112#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
@@ -110,6 +121,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
110 | (cast(Instruction, a)<<POS_A) \ 121 | (cast(Instruction, a)<<POS_A) \
111 | (cast(Instruction, bc)<<POS_Bx)) 122 | (cast(Instruction, bc)<<POS_Bx))
112 123
124#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
125 | (cast(Instruction, a)<<POS_A))
126
113 127
114/* 128/*
115** Macros to operate RK indices 129** Macros to operate RK indices
@@ -204,11 +218,13 @@ OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
204OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ 218OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
205OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ 219OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */
206 220
207OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ 221OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
222
223OP_EXTRAARG/* Ax extra argument for previous opcode */
208} OpCode; 224} OpCode;
209 225
210 226
211#define NUM_OPCODES (cast(int, OP_VARARG) + 1) 227#define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
212 228
213 229
214 230
@@ -224,7 +240,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
224 (*) In OP_RETURN, if (B == 0) then return up to `top' 240 (*) In OP_RETURN, if (B == 0) then return up to `top'
225 241
226 (*) In OP_SETLIST, if (B == 0) then B = `top'; 242 (*) In OP_SETLIST, if (B == 0) then B = `top';
227 if (C == 0) then next `instruction' is real C 243 if (C == 0) then next `instruction' is EXTRAARG(real C)
228 244
229 (*) For comparisons, A specifies what condition the test should accept 245 (*) For comparisons, A specifies what condition the test should accept
230 (true or false). 246 (true or false).
diff --git a/ltests.c b/ltests.c
index ffed7d1d..37d26927 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.46 2008/02/11 19:04:16 roberto Exp roberto $ 2** $Id: ltests.c,v 2.47 2008/02/19 18:55:09 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -410,6 +410,9 @@ static char *buildop (Proto *p, int pc, char *buff) {
410 case iAsBx: 410 case iAsBx:
411 sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i)); 411 sprintf(buff+strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
412 break; 412 break;
413 case iAx:
414 sprintf(buff+strlen(buff), "%-12s%4d", name, GETARG_Ax(i));
415 break;
413 } 416 }
414 return buff; 417 return buff;
415} 418}
diff --git a/lvm.c b/lvm.c
index 6e227053..b295d5eb 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.72 2007/06/19 19:48:15 roberto Exp roberto $ 2** $Id: lvm.c,v 2.73 2007/09/10 17:59:32 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -704,7 +704,10 @@ void luaV_execute (lua_State *L, int nexeccalls) {
704 int last; 704 int last;
705 Table *h; 705 Table *h;
706 if (n == 0) n = cast_int(L->top - ra) - 1; 706 if (n == 0) n = cast_int(L->top - ra) - 1;
707 if (c == 0) c = cast_int(*L->savedpc++); 707 if (c == 0) {
708 lua_assert(GET_OPCODE(*L->savedpc) == OP_EXTRAARG);
709 c = GETARG_Ax(*L->savedpc++);
710 }
708 runtime_check(L, ttistable(ra)); 711 runtime_check(L, ttistable(ra));
709 h = hvalue(ra); 712 h = hvalue(ra);
710 last = ((c-1)*LFIELDS_PER_FLUSH) + n; 713 last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@@ -764,6 +767,10 @@ void luaV_execute (lua_State *L, int nexeccalls) {
764 } 767 }
765 continue; 768 continue;
766 } 769 }
770 case OP_EXTRAARG: {
771 luaG_runerror(L, "bad opcode");
772 return;
773 }
767 } 774 }
768 } 775 }
769} 776}