mirror of
https://github.com/lua/lua
synced 2025-01-06 01:22:06 +03:00
change in opcode OP_LOADNIL: B is used as a counter instead of a
register. (Avoids an assignment to R(B), not present in any other instruction.)
This commit is contained in:
parent
a4e644add2
commit
4758113043
18
lcode.c
18
lcode.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $
|
||||
** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) {
|
||||
|
||||
void luaK_nil (FuncState *fs, int from, int n) {
|
||||
Instruction *previous;
|
||||
int l = from + n - 1; /* last register to set nil */
|
||||
if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
|
||||
previous = &fs->f->code[fs->pc-1];
|
||||
if (GET_OPCODE(*previous) == OP_LOADNIL) {
|
||||
int pfrom = GETARG_A(*previous);
|
||||
int pto = GETARG_B(*previous);
|
||||
if (pfrom <= from && from <= pto+1) { /* can connect both? */
|
||||
if (from+n-1 > pto)
|
||||
SETARG_B(*previous, from+n-1);
|
||||
int pl = pfrom + GETARG_B(*previous);
|
||||
if ((pfrom <= from && from <= pl + 1) ||
|
||||
(from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
|
||||
if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
|
||||
if (pl > l) l = pl; /* l = max(l, pl) */
|
||||
SETARG_A(*previous, from);
|
||||
SETARG_B(*previous, l - from);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} /* else go through */
|
||||
}
|
||||
luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
|
||||
luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
|
||||
}
|
||||
|
||||
|
||||
|
6
ldebug.c
6
ldebug.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldebug.c,v 2.78 2011/04/18 15:02:37 roberto Exp roberto $
|
||||
** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $
|
||||
** Debug Interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -355,8 +355,8 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
|
||||
break;
|
||||
}
|
||||
case OP_LOADNIL: {
|
||||
int b = GETARG_B(i); /* move from 'b' to 'a' */
|
||||
if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */
|
||||
int b = GETARG_B(i);
|
||||
if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
|
||||
what = NULL;
|
||||
break;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.c,v 1.46 2011/04/07 18:14:12 roberto Exp roberto $
|
||||
** $Id: lopcodes.c,v 1.47 2011/04/12 17:27:35 roberto Exp roberto $
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
@ -66,7 +66,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
|
||||
,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
|
||||
,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
|
||||
,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
|
||||
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */
|
||||
,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
|
||||
,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
|
||||
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */
|
||||
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.h,v 1.139 2011/02/07 12:24:42 roberto Exp roberto $
|
||||
** $Id: lopcodes.h,v 1.140 2011/04/07 18:14:12 roberto Exp roberto $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -170,7 +170,7 @@ OP_MOVE,/* A B R(A) := R(B) */
|
||||
OP_LOADK,/* A Bx R(A) := Kst(Bx) */
|
||||
OP_LOADKX,/* A R(A) := Kst(extra arg) */
|
||||
OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
|
||||
OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */
|
||||
OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
|
||||
OP_GETUPVAL,/* A B R(A) := UpValue[B] */
|
||||
|
||||
OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */
|
||||
|
8
lvm.c
8
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.134 2011/04/07 18:14:12 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 2.135 2011/04/18 19:48:53 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -541,10 +541,10 @@ void luaV_execute (lua_State *L) {
|
||||
if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
|
||||
)
|
||||
vmcase(OP_LOADNIL,
|
||||
TValue *rb = RB(i);
|
||||
int b = GETARG_B(i);
|
||||
do {
|
||||
setnilvalue(rb--);
|
||||
} while (rb >= ra);
|
||||
setnilvalue(ra++);
|
||||
} while (b--);
|
||||
)
|
||||
vmcase(OP_GETUPVAL,
|
||||
int b = GETARG_B(i);
|
||||
|
Loading…
Reference in New Issue
Block a user