Merge pull request #14 from Enyby/patch-6
Fix for proper print OP_SETLIST additional opcode Closes #7
This commit was merged in pull request #14.
This commit is contained in:
@@ -128,6 +128,10 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void printValue( PrintStream ps, LuaValue v ) {
|
static void printValue( PrintStream ps, LuaValue v ) {
|
||||||
|
if (v == null) {
|
||||||
|
ps.print("null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch ( v.type() ) {
|
switch ( v.type() ) {
|
||||||
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
|
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
|
||||||
default: ps.print( v.tojstring() );
|
default: ps.print( v.tojstring() );
|
||||||
@@ -136,7 +140,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void printConstant(PrintStream ps, Prototype f, int i) {
|
static void printConstant(PrintStream ps, Prototype f, int i) {
|
||||||
printValue( ps, f.k[i] );
|
printValue( ps, i < f.k.length ? f.k[i] : LuaValue.valueOf("UNKNOWN_CONST_" + i) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printUpvalue(PrintStream ps, Upvaldesc u) {
|
static void printUpvalue(PrintStream ps, Upvaldesc u) {
|
||||||
@@ -152,7 +156,7 @@ public class Print extends Lua {
|
|||||||
int[] code = f.code;
|
int[] code = f.code;
|
||||||
int pc, n = code.length;
|
int pc, n = code.length;
|
||||||
for (pc = 0; pc < n; pc++) {
|
for (pc = 0; pc < n; pc++) {
|
||||||
printOpCode(f, pc);
|
pc = printOpCode(f, pc);
|
||||||
ps.println();
|
ps.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,9 +165,10 @@ public class Print extends Lua {
|
|||||||
* Print an opcode in a prototype
|
* Print an opcode in a prototype
|
||||||
* @param f the {@link Prototype}
|
* @param f the {@link Prototype}
|
||||||
* @param pc the program counter to look up and print
|
* @param pc the program counter to look up and print
|
||||||
|
* @return pc same as above or changed
|
||||||
*/
|
*/
|
||||||
public static void printOpCode(Prototype f, int pc) {
|
public static int printOpCode(Prototype f, int pc) {
|
||||||
printOpCode(ps,f,pc);
|
return printOpCode(ps,f,pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,8 +176,9 @@ public class Print extends Lua {
|
|||||||
* @param ps the {@link PrintStream} to print to
|
* @param ps the {@link PrintStream} to print to
|
||||||
* @param f the {@link Prototype}
|
* @param f the {@link Prototype}
|
||||||
* @param pc the program counter to look up and print
|
* @param pc the program counter to look up and print
|
||||||
|
* @return pc same as above or changed
|
||||||
*/
|
*/
|
||||||
public static void printOpCode(PrintStream ps, Prototype f, int pc) {
|
public static int printOpCode(PrintStream ps, Prototype f, int pc) {
|
||||||
int[] code = f.code;
|
int[] code = f.code;
|
||||||
int i = code[pc];
|
int i = code[pc];
|
||||||
int o = GET_OPCODE(i);
|
int o = GET_OPCODE(i);
|
||||||
@@ -187,80 +193,67 @@ public class Print extends Lua {
|
|||||||
ps.print("[" + line + "] ");
|
ps.print("[" + line + "] ");
|
||||||
else
|
else
|
||||||
ps.print("[-] ");
|
ps.print("[-] ");
|
||||||
ps.print(OPNAMES[o] + " ");
|
if (o >= OPNAMES.length - 1) {
|
||||||
switch (getOpMode(o)) {
|
ps.print("UNKNOWN_OP_" + o + " ");
|
||||||
case iABC:
|
} else {
|
||||||
ps.print( a );
|
ps.print(OPNAMES[o] + " ");
|
||||||
if (getBMode(o) != OpArgN)
|
switch (getOpMode(o)) {
|
||||||
ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
|
case iABC:
|
||||||
if (getCMode(o) != OpArgN)
|
ps.print( a );
|
||||||
ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
|
if (getBMode(o) != OpArgN)
|
||||||
break;
|
ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
|
||||||
case iABx:
|
if (getCMode(o) != OpArgN)
|
||||||
if (getBMode(o) == OpArgK) {
|
ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
|
||||||
ps.print(a + " " + (-1 - bx));
|
break;
|
||||||
} else {
|
case iABx:
|
||||||
ps.print(a + " " + (bx));
|
if (getBMode(o) == OpArgK) {
|
||||||
|
ps.print(a + " " + (-1 - bx));
|
||||||
|
} else {
|
||||||
|
ps.print(a + " " + (bx));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case iAsBx:
|
||||||
|
if (o == OP_JMP)
|
||||||
|
ps.print( sbx );
|
||||||
|
else
|
||||||
|
ps.print(a + " " + sbx);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
switch (o) {
|
||||||
case iAsBx:
|
case OP_LOADK:
|
||||||
if (o == OP_JMP)
|
|
||||||
ps.print( sbx );
|
|
||||||
else
|
|
||||||
ps.print(a + " " + sbx);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (o) {
|
|
||||||
case OP_LOADK:
|
|
||||||
ps.print(" ; ");
|
|
||||||
printConstant(ps, f, bx);
|
|
||||||
break;
|
|
||||||
case OP_GETUPVAL:
|
|
||||||
case OP_SETUPVAL:
|
|
||||||
ps.print(" ; ");
|
|
||||||
printUpvalue(ps, f.upvalues[b]);
|
|
||||||
break;
|
|
||||||
case OP_GETTABUP:
|
|
||||||
ps.print(" ; ");
|
|
||||||
printUpvalue(ps, f.upvalues[b]);
|
|
||||||
ps.print(" ");
|
|
||||||
if (ISK(c))
|
|
||||||
printConstant(ps, f, INDEXK(c));
|
|
||||||
else
|
|
||||||
ps.print("-");
|
|
||||||
break;
|
|
||||||
case OP_SETTABUP:
|
|
||||||
ps.print(" ; ");
|
|
||||||
printUpvalue(ps, f.upvalues[a]);
|
|
||||||
ps.print(" ");
|
|
||||||
if (ISK(b))
|
|
||||||
printConstant(ps, f, INDEXK(b));
|
|
||||||
else
|
|
||||||
ps.print("-");
|
|
||||||
ps.print(" ");
|
|
||||||
if (ISK(c))
|
|
||||||
printConstant(ps, f, INDEXK(c));
|
|
||||||
else
|
|
||||||
ps.print("-");
|
|
||||||
break;
|
|
||||||
case OP_GETTABLE:
|
|
||||||
case OP_SELF:
|
|
||||||
if (ISK(c)) {
|
|
||||||
ps.print(" ; ");
|
ps.print(" ; ");
|
||||||
printConstant(ps, f, INDEXK(c));
|
printConstant(ps, f, bx);
|
||||||
}
|
break;
|
||||||
break;
|
case OP_GETUPVAL:
|
||||||
case OP_SETTABLE:
|
case OP_SETUPVAL:
|
||||||
case OP_ADD:
|
|
||||||
case OP_SUB:
|
|
||||||
case OP_MUL:
|
|
||||||
case OP_DIV:
|
|
||||||
case OP_POW:
|
|
||||||
case OP_EQ:
|
|
||||||
case OP_LT:
|
|
||||||
case OP_LE:
|
|
||||||
if (ISK(b) || ISK(c)) {
|
|
||||||
ps.print(" ; ");
|
ps.print(" ; ");
|
||||||
|
if (b < f.upvalues.length) {
|
||||||
|
printUpvalue(ps, f.upvalues[b]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_GETTABUP:
|
||||||
|
ps.print(" ; ");
|
||||||
|
if (b < f.upvalues.length) {
|
||||||
|
printUpvalue(ps, f.upvalues[b]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + b);
|
||||||
|
}
|
||||||
|
ps.print(" ");
|
||||||
|
if (ISK(c))
|
||||||
|
printConstant(ps, f, INDEXK(c));
|
||||||
|
else
|
||||||
|
ps.print("-");
|
||||||
|
break;
|
||||||
|
case OP_SETTABUP:
|
||||||
|
ps.print(" ; ");
|
||||||
|
if (a < f.upvalues.length) {
|
||||||
|
printUpvalue(ps, f.upvalues[a]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + a);
|
||||||
|
}
|
||||||
|
ps.print(" ");
|
||||||
if (ISK(b))
|
if (ISK(b))
|
||||||
printConstant(ps, f, INDEXK(b));
|
printConstant(ps, f, INDEXK(b));
|
||||||
else
|
else
|
||||||
@@ -270,28 +263,62 @@ public class Print extends Lua {
|
|||||||
printConstant(ps, f, INDEXK(c));
|
printConstant(ps, f, INDEXK(c));
|
||||||
else
|
else
|
||||||
ps.print("-");
|
ps.print("-");
|
||||||
|
break;
|
||||||
|
case OP_GETTABLE:
|
||||||
|
case OP_SELF:
|
||||||
|
if (ISK(c)) {
|
||||||
|
ps.print(" ; ");
|
||||||
|
printConstant(ps, f, INDEXK(c));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_SETTABLE:
|
||||||
|
case OP_ADD:
|
||||||
|
case OP_SUB:
|
||||||
|
case OP_MUL:
|
||||||
|
case OP_DIV:
|
||||||
|
case OP_POW:
|
||||||
|
case OP_EQ:
|
||||||
|
case OP_LT:
|
||||||
|
case OP_LE:
|
||||||
|
if (ISK(b) || ISK(c)) {
|
||||||
|
ps.print(" ; ");
|
||||||
|
if (ISK(b))
|
||||||
|
printConstant(ps, f, INDEXK(b));
|
||||||
|
else
|
||||||
|
ps.print("-");
|
||||||
|
ps.print(" ");
|
||||||
|
if (ISK(c))
|
||||||
|
printConstant(ps, f, INDEXK(c));
|
||||||
|
else
|
||||||
|
ps.print("-");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_JMP:
|
||||||
|
case OP_FORLOOP:
|
||||||
|
case OP_FORPREP:
|
||||||
|
ps.print(" ; to " + (sbx + pc + 2));
|
||||||
|
break;
|
||||||
|
case OP_CLOSURE:
|
||||||
|
if (bx < f.p.length) {
|
||||||
|
ps.print(" ; " + f.p[bx].getClass().getName());
|
||||||
|
} else {
|
||||||
|
ps.print(" ; UNKNOWN_PROTYPE_" + bx);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_SETLIST:
|
||||||
|
if (c == 0)
|
||||||
|
ps.print(" ; " + ((int) code[++pc]) + " (stored in the next OP)");
|
||||||
|
else
|
||||||
|
ps.print(" ; " + ((int) c));
|
||||||
|
break;
|
||||||
|
case OP_VARARG:
|
||||||
|
ps.print( " ; is_vararg="+ f.is_vararg );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case OP_JMP:
|
|
||||||
case OP_FORLOOP:
|
|
||||||
case OP_FORPREP:
|
|
||||||
ps.print(" ; to " + (sbx + pc + 2));
|
|
||||||
break;
|
|
||||||
case OP_CLOSURE:
|
|
||||||
ps.print(" ; " + f.p[bx].getClass().getName());
|
|
||||||
break;
|
|
||||||
case OP_SETLIST:
|
|
||||||
if (c == 0)
|
|
||||||
ps.print(" ; " + ((int) code[++pc]));
|
|
||||||
else
|
|
||||||
ps.print(" ; " + ((int) c));
|
|
||||||
break;
|
|
||||||
case OP_VARARG:
|
|
||||||
ps.print( " ; is_vararg="+ f.is_vararg );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getline(Prototype f, int pc) {
|
private static int getline(Prototype f, int pc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user