aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c12
-rw-r--r--lopcodes.h36
-rw-r--r--ltests.c4
3 files changed, 28 insertions, 24 deletions
diff --git a/lcode.c b/lcode.c
index 1eae475a..ae024da8 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.147 2017/12/22 14:16:46 roberto Exp roberto $ 2** $Id: lcode.c,v 2.149 2018/01/09 11:21:41 roberto Exp $
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*/
@@ -262,16 +262,16 @@ void luaK_patchtohere (FuncState *fs, int list) {
262/* 262/*
263** Correct a jump list to jump to 'target'. If 'hasclose' is true, 263** Correct a jump list to jump to 'target'. If 'hasclose' is true,
264** 'target' contains an OP_CLOSE instruction (see first assert). 264** 'target' contains an OP_CLOSE instruction (see first assert).
265** Only jumps with the 'k' arg true need that close; other jumps 265** Only the jumps with ('m' == true) need that close; other jumps
266** avoid it jumping to the next instruction. 266** avoid it jumping to the next instruction.
267*/ 267*/
268void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) { 268void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) {
269 lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE); 269 lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE);
270 while (list != NO_JUMP) { 270 while (list != NO_JUMP) {
271 int next = getjump(fs, list); 271 int next = getjump(fs, list);
272 lua_assert(!GETARG_k(fs->f->code[list]) || hasclose); 272 lua_assert(!GETARG_m(fs->f->code[list]) || hasclose);
273 patchtestreg(fs, list, NO_REG); /* do not generate values */ 273 patchtestreg(fs, list, NO_REG); /* do not generate values */
274 if (!hasclose || GETARG_k(fs->f->code[list])) 274 if (!hasclose || GETARG_m(fs->f->code[list]))
275 fixjump(fs, list, target); 275 fixjump(fs, list, target);
276 else /* there is a CLOSE instruction but jump does not need it */ 276 else /* there is a CLOSE instruction but jump does not need it */
277 fixjump(fs, list, target + 1); /* avoid CLOSE instruction */ 277 fixjump(fs, list, target + 1); /* avoid CLOSE instruction */
@@ -281,14 +281,14 @@ void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) {
281 281
282 282
283/* 283/*
284** Mark (using the 'k' arg) all jumps in 'list' to close upvalues. Mark 284** Mark (using the 'm' arg) all jumps in 'list' to close upvalues. Mark
285** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE 285** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE
286** instructions. 286** instructions.
287*/ 287*/
288void luaK_patchclose (FuncState *fs, int list) { 288void luaK_patchclose (FuncState *fs, int list) {
289 for (; list != NO_JUMP; list = getjump(fs, list)) { 289 for (; list != NO_JUMP; list = getjump(fs, list)) {
290 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP); 290 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP);
291 SETARG_k(fs->f->code[list], 1); 291 SETARG_m(fs->f->code[list], 1);
292 } 292 }
293} 293}
294 294
diff --git a/lopcodes.h b/lopcodes.h
index eae0dfaf..22de7a71 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.180 2017/12/18 17:49:31 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.182 2018/01/09 11:21:41 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,11 +17,11 @@
17 17
18 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 18 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
19 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 19 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
20iABC |k| C(8) | | B(8) | | A(8) | | Op(7) | 20iABC C(8) | B(8) |k| A(8) | Op(7) |
21iABx | Bx(17) | | A(8) | | Op(7) | 21iABx Bx(17) | A(8) | Op(7) |
22iAsBx | sBx (signed)(17) | | A(8) | | Op(7) | 22iAsB sBx (signed)(17) | A(8) | Op(7) |
23iAx | Ax(25) | | Op(7) | 23iAx Ax(25) | Op(7) |
24iksJ |k| sJ(24) | | Op(7) | 24isJ sJ(24) |m| Op(7) |
25 25
26 A signed argument is represented in excess K: the represented value is 26 A signed argument is represented in excess K: the represented value is
27 the written unsigned value minus K, where K is half the maximum for the 27 the written unsigned value minus K, where K is half the maximum for the
@@ -36,25 +36,27 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
36** size and position of opcode arguments. 36** size and position of opcode arguments.
37*/ 37*/
38#define SIZE_C 8 38#define SIZE_C 8
39#define SIZE_Cx (SIZE_C + 1)
40#define SIZE_B 8 39#define SIZE_B 8
41#define SIZE_Bx (SIZE_Cx + SIZE_B) 40#define SIZE_Bx (SIZE_C + SIZE_B + 1)
42#define SIZE_A 8 41#define SIZE_A 8
43#define SIZE_Ax (SIZE_Cx + SIZE_B + SIZE_A) 42#define SIZE_Ax (SIZE_Bx + SIZE_A)
44#define SIZE_sJ (SIZE_C + SIZE_B + SIZE_A) 43#define SIZE_sJ (SIZE_Bx + SIZE_A - 1)
45
46 44
47#define SIZE_OP 7 45#define SIZE_OP 7
48 46
49#define POS_OP 0 47#define POS_OP 0
48
50#define POS_A (POS_OP + SIZE_OP) 49#define POS_A (POS_OP + SIZE_OP)
51#define POS_B (POS_A + SIZE_A) 50#define POS_k (POS_A + SIZE_A)
51#define POS_B (POS_k + 1)
52#define POS_C (POS_B + SIZE_B) 52#define POS_C (POS_B + SIZE_B)
53#define POS_k (POS_C + SIZE_C) 53
54#define POS_Bx POS_B 54#define POS_Bx POS_k
55
55#define POS_Ax POS_A 56#define POS_Ax POS_A
56#define POS_sJ POS_A
57 57
58#define POS_m POS_A
59#define POS_sJ (POS_A + 1)
58 60
59/* 61/*
60** limits for opcode arguments. 62** limits for opcode arguments.
@@ -125,7 +127,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
125#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 127#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
126 128
127#define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k)))) 129#define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k))))
128#define GETARG_k(i) getarg(i, POS_k, 1) 130#define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1))
129#define SETARG_k(i,v) setarg(i, v, POS_k, 1) 131#define SETARG_k(i,v) setarg(i, v, POS_k, 1)
130 132
131#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) 133#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
@@ -142,6 +144,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
142 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ) 144 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
143#define SETARG_sJ(i,j) \ 145#define SETARG_sJ(i,j) \
144 setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ) 146 setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
147#define GETARG_m(i) check_exp(checkopm(i, isJ), getarg(i, POS_m, 1))
148#define SETARG_m(i,m) setarg(i, m, POS_m, 1)
145 149
146 150
147#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \ 151#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
diff --git a/ltests.c b/ltests.c
index 513c846b..569c1896 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.237 2017/12/15 18:53:48 roberto Exp roberto $ 2** $Id: ltests.c,v 2.239 2018/01/09 11:21:41 roberto Exp $
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*/
@@ -557,7 +557,7 @@ static char *buildop (Proto *p, int pc, char *buff) {
557 break; 557 break;
558 case isJ: 558 case isJ:
559 sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i), 559 sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i),
560 !!GETARG_k(i)); 560 !!GETARG_m(i));
561 break; 561 break;
562 } 562 }
563 return buff; 563 return buff;