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