rewrite SSM and clonefunction

This commit is contained in:
Cloud Wu
2019-04-16 21:16:13 +08:00
committed by 云风
parent 2d6d2c75a4
commit 2ceb642b5d
32 changed files with 934 additions and 645 deletions

View File

@@ -65,7 +65,7 @@ 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->sp->code[fs->pc-1];
previous = &fs->f->code[fs->pc-1];
if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
int pfrom = GETARG_A(*previous); /* get previous range */
int pl = pfrom + GETARG_B(*previous);
@@ -88,7 +88,7 @@ void luaK_nil (FuncState *fs, int from, int n) {
** a list of jumps.
*/
static int getjump (FuncState *fs, int pc) {
int offset = GETARG_sBx(fs->f->sp->code[pc]);
int offset = GETARG_sBx(fs->f->code[pc]);
if (offset == NO_JUMP) /* point to itself represents end of list */
return NO_JUMP; /* end of list */
else
@@ -101,7 +101,7 @@ static int getjump (FuncState *fs, int pc) {
** (Jump addresses are relative in Lua)
*/
static void fixjump (FuncState *fs, int pc, int dest) {
Instruction *jmp = &fs->f->sp->code[pc];
Instruction *jmp = &fs->f->code[pc];
int offset = dest - (pc + 1);
lua_assert(dest != NO_JUMP);
if (abs(offset) > MAXARG_sBx)
@@ -177,7 +177,7 @@ int luaK_getlabel (FuncState *fs) {
** unconditional.
*/
static Instruction *getjumpcontrol (FuncState *fs, int pc) {
Instruction *pi = &fs->f->sp->code[pc];
Instruction *pi = &fs->f->code[pc];
if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
return pi-1;
else
@@ -278,10 +278,10 @@ void luaK_patchlist (FuncState *fs, int list, int target) {
void luaK_patchclose (FuncState *fs, int list, int level) {
level++; /* argument is +1 to reserve 0 as non-op */
for (; list != NO_JUMP; list = getjump(fs, list)) {
lua_assert(GET_OPCODE(fs->f->sp->code[list]) == OP_JMP &&
(GETARG_A(fs->f->sp->code[list]) == 0 ||
GETARG_A(fs->f->sp->code[list]) >= level));
SETARG_A(fs->f->sp->code[list], level);
lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
(GETARG_A(fs->f->code[list]) == 0 ||
GETARG_A(fs->f->code[list]) >= level));
SETARG_A(fs->f->code[list], level);
}
}
@@ -294,13 +294,13 @@ static int luaK_code (FuncState *fs, Instruction i) {
Proto *f = fs->f;
dischargejpc(fs); /* 'pc' will change */
/* put new instruction in code array */
luaM_growvector(fs->ls->L, f->sp->code, fs->pc, f->sp->sizecode, Instruction,
luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
MAX_INT, "opcodes");
f->sp->code[fs->pc] = i;
f->code[fs->pc] = i;
/* save corresponding line information */
luaM_growvector(fs->ls->L, f->sp->lineinfo, fs->pc, f->sp->sizelineinfo, int,
luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
MAX_INT, "opcodes");
f->sp->lineinfo[fs->pc] = fs->ls->lastline;
f->lineinfo[fs->pc] = fs->ls->lastline;
return fs->pc++;
}
@@ -360,11 +360,11 @@ int luaK_codek (FuncState *fs, int reg, int k) {
*/
void luaK_checkstack (FuncState *fs, int n) {
int newstack = fs->freereg + n;
if (newstack > fs->f->sp->maxstacksize) {
if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXREGS)
luaX_syntaxerror(fs->ls,
"function or expression needs too many registers");
fs->f->sp->maxstacksize = cast_byte(newstack);
fs->f->maxstacksize = cast_byte(newstack);
}
}
@@ -438,13 +438,13 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
return k; /* reuse index */
}
/* constant not found; create a new entry */
oldsize = f->sp->sizek;
oldsize = f->sizek;
k = fs->nk;
/* numerical value does not need GC barrier;
table has no metatable, so it does not need to invalidate cache */
setivalue(idx, k);
luaM_growvector(L, f->k, k, f->sp->sizek, TValue, MAXARG_Ax, "constants");
while (oldsize < f->sp->sizek) setnilvalue(&f->k[oldsize++]);
luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
setobj(L, &f->k[k], v);
fs->nk++;
luaC_barrier(L, f, v);
@@ -1175,7 +1175,7 @@ void luaK_posfix (FuncState *fs, BinOpr op,
** Change line information associated with current position.
*/
void luaK_fixline (FuncState *fs, int line) {
fs->f->sp->lineinfo[fs->pc - 1] = line;
fs->f->lineinfo[fs->pc - 1] = line;
}