Lua 5.2 compatibility fixes.
This commit is contained in:
@@ -862,10 +862,15 @@ public class FuncState extends LuaC {
|
||||
this.removevalues(e.t.i);
|
||||
}
|
||||
|
||||
static boolean vkisinreg(int k) {
|
||||
return ((k) == LexState.VNONRELOC || (k) == LexState.VLOCAL);
|
||||
}
|
||||
|
||||
void indexed(expdesc t, expdesc k) {
|
||||
t.u.ind_t = (short) t.u.info;
|
||||
t.u.ind_idx = (short) this.exp2RK(k);
|
||||
t.u.ind_vt = (short) ((t.k == LexState.VUPVAL) ? LexState.VUPVAL : LexState.VLOCAL);
|
||||
LuaC._assert(t.k == LexState.VUPVAL || vkisinreg(t.k));
|
||||
t.u.ind_vt = (short) ((t.k == LexState.VUPVAL) ? LexState.VUPVAL : LexState.VLOCAL);
|
||||
t.k = LexState.VINDEXED;
|
||||
}
|
||||
|
||||
@@ -912,7 +917,7 @@ public class FuncState extends LuaC {
|
||||
return true;
|
||||
}
|
||||
|
||||
void codearith(int op, expdesc e1, expdesc e2) {
|
||||
void codearith(int op, expdesc e1, expdesc e2, int line) {
|
||||
if (constfolding(op, e1, e2))
|
||||
return;
|
||||
else {
|
||||
@@ -928,6 +933,7 @@ public class FuncState extends LuaC {
|
||||
}
|
||||
e1.u.info = this.codeABC(op, 0, o1, o2);
|
||||
e1.k = LexState.VRELOCABLE;
|
||||
fixline(line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,14 +953,14 @@ public class FuncState extends LuaC {
|
||||
e1.k = LexState.VJMP;
|
||||
}
|
||||
|
||||
void prefix(int /* UnOpr */op, expdesc e) {
|
||||
void prefix(int /* UnOpr */op, expdesc e, int line) {
|
||||
expdesc e2 = new expdesc();
|
||||
e2.init(LexState.VKNUM, 0);
|
||||
switch (op) {
|
||||
case LexState.OPR_MINUS: {
|
||||
if (e.k == LexState.VK)
|
||||
this.exp2anyreg(e); /* cannot operate on non-numeric constants */
|
||||
this.codearith(OP_UNM, e, e2);
|
||||
this.codearith(OP_UNM, e, e2, line);
|
||||
break;
|
||||
}
|
||||
case LexState.OPR_NOT:
|
||||
@@ -962,7 +968,7 @@ public class FuncState extends LuaC {
|
||||
break;
|
||||
case LexState.OPR_LEN: {
|
||||
this.exp2anyreg(e); /* cannot operate on constants */
|
||||
this.codearith(OP_LEN, e, e2);
|
||||
this.codearith(OP_LEN, e, e2, line);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -1002,7 +1008,7 @@ public class FuncState extends LuaC {
|
||||
}
|
||||
|
||||
|
||||
void posfix(int op, expdesc e1, expdesc e2) {
|
||||
void posfix(int op, expdesc e1, expdesc e2, int line) {
|
||||
switch (op) {
|
||||
case LexState.OPR_AND: {
|
||||
_assert (e1.t.i == LexState.NO_JUMP); /* list must be closed */
|
||||
@@ -1031,27 +1037,27 @@ public class FuncState extends LuaC {
|
||||
e1.u.info = e2.u.info;
|
||||
} else {
|
||||
this.exp2nextreg(e2); /* operand must be on the 'stack' */
|
||||
this.codearith(OP_CONCAT, e1, e2);
|
||||
this.codearith(OP_CONCAT, e1, e2, line);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LexState.OPR_ADD:
|
||||
this.codearith(OP_ADD, e1, e2);
|
||||
this.codearith(OP_ADD, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_SUB:
|
||||
this.codearith(OP_SUB, e1, e2);
|
||||
this.codearith(OP_SUB, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_MUL:
|
||||
this.codearith(OP_MUL, e1, e2);
|
||||
this.codearith(OP_MUL, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_DIV:
|
||||
this.codearith(OP_DIV, e1, e2);
|
||||
this.codearith(OP_DIV, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_MOD:
|
||||
this.codearith(OP_MOD, e1, e2);
|
||||
this.codearith(OP_MOD, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_POW:
|
||||
this.codearith(OP_POW, e1, e2);
|
||||
this.codearith(OP_POW, e1, e2, line);
|
||||
break;
|
||||
case LexState.OPR_EQ:
|
||||
this.codecomp(OP_EQ, 1, e1, e2);
|
||||
|
||||
@@ -103,12 +103,12 @@ public class LexState {
|
||||
VFALSE = 3,
|
||||
VK = 4, /* info = index of constant in `k' */
|
||||
VKNUM = 5, /* nval = numerical value */
|
||||
VLOCAL = 6, /* info = local register */
|
||||
VUPVAL = 7, /* info = index of upvalue in `upvalues' */
|
||||
VINDEXED = 8, /* info = table register, aux = index register (or `k') */
|
||||
VJMP = 9, /* info = instruction pc */
|
||||
VRELOCABLE = 10, /* info = instruction pc */
|
||||
VNONRELOC = 11, /* info = result register */
|
||||
VNONRELOC = 6, /* info = result register */
|
||||
VLOCAL = 7, /* info = local register */
|
||||
VUPVAL = 8, /* info = index of upvalue in `upvalues' */
|
||||
VINDEXED = 9, /* info = table register, aux = index register (or `k') */
|
||||
VJMP = 10, /* info = instruction pc */
|
||||
VRELOCABLE = 11, /* info = instruction pc */
|
||||
VCALL = 12, /* info = instruction pc */
|
||||
VVARARG = 13; /* info = instruction pc */
|
||||
|
||||
@@ -699,6 +699,7 @@ public class LexState {
|
||||
lookahead.token = TK_EOS; /* and discharge it */
|
||||
} else
|
||||
t.token = llex(t.seminfo); /* read next token */
|
||||
// System.out.println("---- next t.token " + t.token + " (" + txtToken(t.token) + ") " + linenumber );
|
||||
}
|
||||
|
||||
void lookahead() {
|
||||
@@ -1546,21 +1547,22 @@ public class LexState {
|
||||
this.enterlevel();
|
||||
uop = getunopr(this.t.token);
|
||||
if (uop != OPR_NOUNOPR) {
|
||||
int line = linenumber;
|
||||
this.next();
|
||||
this.subexpr(v, UNARY_PRIORITY);
|
||||
fs.prefix(uop, v);
|
||||
fs.prefix(uop, v, line);
|
||||
} else
|
||||
this.simpleexp(v);
|
||||
/* expand while operators have priorities higher than `limit' */
|
||||
op = getbinopr(this.t.token);
|
||||
while (op != OPR_NOBINOPR && priority[op].left > limit) {
|
||||
expdesc v2 = new expdesc();
|
||||
int nextop;
|
||||
int line = linenumber;
|
||||
this.next();
|
||||
fs.infix(op, v);
|
||||
/* read sub-expression with higher priority */
|
||||
nextop = this.subexpr(v2, priority[op].right);
|
||||
fs.posfix(op, v, v2);
|
||||
int nextop = this.subexpr(v2, priority[op].right);
|
||||
fs.posfix(op, v, v2, line);
|
||||
op = nextop;
|
||||
}
|
||||
this.leavelevel();
|
||||
@@ -1640,8 +1642,10 @@ public class LexState {
|
||||
}
|
||||
}
|
||||
if (conflict) {
|
||||
fs.codeABC(Lua.OP_MOVE, fs.freereg, v.u.info, 0); /* make copy */
|
||||
fs.reserveregs(1);
|
||||
/* copy upvalue/local value to a temporary (in position 'extra') */
|
||||
int op = (v.k == VLOCAL) ? Lua.OP_MOVE : Lua.OP_GETUPVAL;
|
||||
fs.codeABC(op, extra, v.u.info, 0);
|
||||
fs.reserveregs(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1919,15 +1923,11 @@ public class LexState {
|
||||
}
|
||||
|
||||
void localfunc() {
|
||||
expdesc v = new expdesc();
|
||||
expdesc b = new expdesc();
|
||||
FuncState fs = this.fs;
|
||||
this.new_localvar(this.str_checkname());
|
||||
v.init(VLOCAL, fs.freereg);
|
||||
fs.reserveregs(1);
|
||||
this.adjustlocalvars(1);
|
||||
this.body(b, false, this.linenumber);
|
||||
fs.storevar(v, b);
|
||||
/* debug information will only see the variable after this point! */
|
||||
fs.getlocvar(fs.nactvar - 1).startpc = fs.pc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user