Add support for OP_LOADKX. #43
This commit is contained in:
@@ -80,7 +80,6 @@ public class Lua {
|
|||||||
public static final int POS_Bx = POS_C;
|
public static final int POS_Bx = POS_C;
|
||||||
public static final int POS_Ax = POS_A;
|
public static final int POS_Ax = POS_A;
|
||||||
|
|
||||||
|
|
||||||
public static final int MAX_OP = ((1<<SIZE_OP)-1);
|
public static final int MAX_OP = ((1<<SIZE_OP)-1);
|
||||||
public static final int MAXARG_A = ((1<<SIZE_A)-1);
|
public static final int MAXARG_A = ((1<<SIZE_A)-1);
|
||||||
public static final int MAXARG_B = ((1<<SIZE_B)-1);
|
public static final int MAXARG_B = ((1<<SIZE_B)-1);
|
||||||
@@ -94,6 +93,7 @@ public class Lua {
|
|||||||
public static final int MASK_B = ((1<<SIZE_B)-1)<<POS_B;
|
public static final int MASK_B = ((1<<SIZE_B)-1)<<POS_B;
|
||||||
public static final int MASK_C = ((1<<SIZE_C)-1)<<POS_C;
|
public static final int MASK_C = ((1<<SIZE_C)-1)<<POS_C;
|
||||||
public static final int MASK_Bx = ((1<<SIZE_Bx)-1)<<POS_Bx;
|
public static final int MASK_Bx = ((1<<SIZE_Bx)-1)<<POS_Bx;
|
||||||
|
public static final int MASK_Ax = ((1<<SIZE_Ax)-1)<<POS_Ax;
|
||||||
|
|
||||||
public static final int MASK_NOT_OP = ~MASK_OP;
|
public static final int MASK_NOT_OP = ~MASK_OP;
|
||||||
public static final int MASK_NOT_A = ~MASK_A;
|
public static final int MASK_NOT_A = ~MASK_A;
|
||||||
|
|||||||
@@ -214,6 +214,17 @@ public class LuaClosure extends LuaFunction {
|
|||||||
stack[a] = k[i>>>14];
|
stack[a] = k[i>>>14];
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
case Lua.OP_LOADKX:/* A R(A) := Kst(extra arg) */
|
||||||
|
++pc;
|
||||||
|
i = code[pc];
|
||||||
|
if ((i & 0x3f) != Lua.OP_EXTRAARG) {
|
||||||
|
int op = i & 0x3f;
|
||||||
|
throw new LuaError("OP_EXTRAARG expected after OP_LOADKX, got " +
|
||||||
|
(op < Print.OPNAMES.length - 1 ? Print.OPNAMES[op] : "UNKNOWN_OP_" + op));
|
||||||
|
}
|
||||||
|
stack[a] = k[i>>>6];
|
||||||
|
continue;
|
||||||
|
|
||||||
case Lua.OP_LOADBOOL:/* A B C R(A):= (Bool)B: if (C) pc++ */
|
case Lua.OP_LOADBOOL:/* A B C R(A):= (Bool)B: if (C) pc++ */
|
||||||
stack[a] = (i>>>23!=0)? LuaValue.TRUE: LuaValue.FALSE;
|
stack[a] = (i>>>23!=0)? LuaValue.TRUE: LuaValue.FALSE;
|
||||||
if ((i&(0x1ff<<14)) != 0)
|
if ((i&(0x1ff<<14)) != 0)
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ public class Constants extends Lua {
|
|||||||
((bc << POS_Bx) & MASK_Bx) ;
|
((bc << POS_Bx) & MASK_Bx) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int CREATE_Ax(int o, int a) {
|
||||||
|
return ((o << POS_OP) & MASK_OP) |
|
||||||
|
((a << POS_Ax) & MASK_Ax) ;
|
||||||
|
}
|
||||||
|
|
||||||
// vector reallocation
|
// vector reallocation
|
||||||
|
|
||||||
static LuaValue[] realloc(LuaValue[] v, int n) {
|
static LuaValue[] realloc(LuaValue[] v, int n) {
|
||||||
|
|||||||
@@ -580,11 +580,11 @@ public class FuncState extends Constants {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VK: {
|
case LexState.VK: {
|
||||||
this.codeABx(OP_LOADK, reg, e.u.info);
|
this.codeK(reg, e.u.info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VKNUM: {
|
case LexState.VKNUM: {
|
||||||
this.codeABx(OP_LOADK, reg, this.numberK(e.u.nval()));
|
this.codeK(reg, this.numberK(e.u.nval()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LexState.VRELOCABLE: {
|
case LexState.VRELOCABLE: {
|
||||||
@@ -1116,6 +1116,20 @@ public class FuncState extends Constants {
|
|||||||
return this.code(CREATE_ABx(o, a, bc), this.ls.lastline);
|
return this.code(CREATE_ABx(o, a, bc), this.ls.lastline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int codeextraarg(int a) {
|
||||||
|
_assert(a <= MAXARG_Ax);
|
||||||
|
return this.code(CREATE_Ax(OP_EXTRAARG, a), this.ls.lastline);
|
||||||
|
}
|
||||||
|
|
||||||
|
int codeK(int reg, int k) {
|
||||||
|
if (k <= MAXARG_Bx)
|
||||||
|
return codeABx(OP_LOADK, reg, k);
|
||||||
|
else {
|
||||||
|
int p = codeABx(OP_LOADKX, reg, 0);
|
||||||
|
codeextraarg(k);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setlist(int base, int nelems, int tostore) {
|
void setlist(int base, int nelems, int tostore) {
|
||||||
int c = (nelems - 1) / LFIELDS_PER_FLUSH + 1;
|
int c = (nelems - 1) / LFIELDS_PER_FLUSH + 1;
|
||||||
|
|||||||
@@ -1845,7 +1845,7 @@ public class LexState extends Constants {
|
|||||||
if (this.testnext(','))
|
if (this.testnext(','))
|
||||||
this.exp1(); /* optional step */
|
this.exp1(); /* optional step */
|
||||||
else { /* default step = 1 */
|
else { /* default step = 1 */
|
||||||
fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
|
fs.codeK(fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
|
||||||
fs.reserveregs(1);
|
fs.reserveregs(1);
|
||||||
}
|
}
|
||||||
this.forbody(base, line, 1, true);
|
this.forbody(base, line, 1, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user