Fix for loop processing, add vmerror()
This commit is contained in:
@@ -364,7 +364,7 @@ public class BaseLib extends LFunction {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException( "bad id: "+id );
|
LuaState.vmerror( "bad base id" );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class MathLib extends LFunction {
|
|||||||
setResult( vm, LInteger.valueOf( (int) Math.floor( vm.tonumber(2) ) ) );
|
setResult( vm, LInteger.valueOf( (int) Math.floor( vm.tonumber(2) ) ) );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException( "bad id: "+id );
|
LuaState.vmerror( "bad math id" );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ public class TableLib extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException( "bad id" );
|
LuaState.vmerror( "bad table id" );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ public class LDouble extends LNumber {
|
|||||||
case Lua.OP_MOD: return new LDouble( lhs - Math.floor(lhs/rhs) * rhs );
|
case Lua.OP_MOD: return new LDouble( lhs - Math.floor(lhs/rhs) * rhs );
|
||||||
case Lua.OP_POW: throw new LuaErrorException("math.pow() not implemented for doubles");
|
case Lua.OP_POW: throw new LuaErrorException("math.pow() not implemented for doubles");
|
||||||
}
|
}
|
||||||
throw new RuntimeException("bad opcode");
|
LuaState.vmerror( "bad bin opcode" );
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* warning: NOT TESTED
|
/* warning: NOT TESTED
|
||||||
@@ -134,7 +135,8 @@ public class LDouble extends LNumber {
|
|||||||
case Lua.OP_LT: return lhs < rhs;
|
case Lua.OP_LT: return lhs < rhs;
|
||||||
case Lua.OP_LE: return lhs <= rhs;
|
case Lua.OP_LE: return lhs <= rhs;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("bad opcode");
|
LuaState.vmerror( "bad cmp opcode" );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Arithmetic negative */
|
/** Arithmetic negative */
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ public class LInteger extends LNumber {
|
|||||||
case Lua.OP_MOD: return LInteger.valueOf( m_value - ((int) Math.floor(m_value/(double)rhs)) * rhs );
|
case Lua.OP_MOD: return LInteger.valueOf( m_value - ((int) Math.floor(m_value/(double)rhs)) * rhs );
|
||||||
case Lua.OP_POW: return LInteger.valueOf( ipow(m_value, rhs) );
|
case Lua.OP_POW: return LInteger.valueOf( ipow(m_value, rhs) );
|
||||||
}
|
}
|
||||||
throw new RuntimeException("bad opcode");
|
LuaState.vmerror( "bad bin opcode" );
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ipow(int v, int rhs) {
|
private static int ipow(int v, int rhs) {
|
||||||
@@ -113,7 +114,8 @@ public class LInteger extends LNumber {
|
|||||||
case Lua.OP_LT: return m_value < rhs;
|
case Lua.OP_LT: return m_value < rhs;
|
||||||
case Lua.OP_LE: return m_value <= rhs;
|
case Lua.OP_LE: return m_value <= rhs;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("bad opcode");
|
LuaState.vmerror( "bad cmp opcode" );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsupported except for numbers
|
// unsupported except for numbers
|
||||||
|
|||||||
@@ -315,7 +315,8 @@ public class LString extends LValue {
|
|||||||
case Lua.OP_LT: return compareTo(rhs) < 0;
|
case Lua.OP_LT: return compareTo(rhs) < 0;
|
||||||
case Lua.OP_LE: return compareTo(rhs) <= 0;
|
case Lua.OP_LE: return compareTo(rhs) <= 0;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("bad opcode");
|
LuaState.vmerror( "bad cmp opcode" );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LValue luaBinOpDouble( int opcode, double m_value ) {
|
public LValue luaBinOpDouble( int opcode, double m_value ) {
|
||||||
|
|||||||
@@ -822,34 +822,30 @@ public class LuaState extends Lua {
|
|||||||
case LuaState.OP_FORPREP: {
|
case LuaState.OP_FORPREP: {
|
||||||
init = this.stack[base + a];
|
init = this.stack[base + a];
|
||||||
step = this.stack[base + a + 2];
|
step = this.stack[base + a + 2];
|
||||||
this.stack[base + a] = step.luaBinOpUnknown(Lua.OP_SUB,
|
this.stack[base + a] = step.luaBinOpUnknown(Lua.OP_SUB, init);
|
||||||
init);
|
|
||||||
b = LuaState.GETARG_sBx(i);
|
b = LuaState.GETARG_sBx(i);
|
||||||
ci.pc += b;
|
ci.pc += b;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case LuaState.OP_TFORLOOP: {
|
case LuaState.OP_TFORLOOP: {
|
||||||
cb = a + 3; /* call base */
|
cb = base + a + 3; /* call base */
|
||||||
System.arraycopy(this.stack, base + a, this.stack,
|
base = cb;
|
||||||
base + cb, 3);
|
adjustTop( cb + 3 );
|
||||||
base += cb;
|
System.arraycopy(this.stack, cb-3, this.stack, cb, 3);
|
||||||
try {
|
|
||||||
top = base + 3; /* func. + 2 args (state and index) */
|
// call the iterator
|
||||||
|
c = LuaState.GETARG_C(i);
|
||||||
// call the iterator
|
this.nresults = c;
|
||||||
c = LuaState.GETARG_C(i);
|
if (this.stack[cb].luaStackCall(this))
|
||||||
if (this.stack[base].luaStackCall(this))
|
execute();
|
||||||
execute();
|
base = ci.base;
|
||||||
adjustTop( base + c - 1 );
|
adjustTop( cb + c );
|
||||||
|
|
||||||
// test for continuation
|
// test for continuation
|
||||||
if (this.stack[base] != LNil.NIL) { // continue?
|
if (this.stack[cb] != LNil.NIL ) { // continue?
|
||||||
this.stack[base - 1] = this.stack[base]; // save control variable
|
this.stack[cb-1] = this.stack[cb]; // save control variable
|
||||||
} else {
|
} else {
|
||||||
ci.pc++; // skip over jump
|
ci.pc++; // skip over jump
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
base -= cb;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2568,22 +2564,14 @@ public class LuaState extends Lua {
|
|||||||
public Long toboxedlong(int index) {
|
public Long toboxedlong(int index) {
|
||||||
return topointer(index).toJavaBoxedLong();
|
return topointer(index).toJavaBoxedLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current environment.
|
* Method to indicate a vm internal error has occurred.
|
||||||
*
|
* Generally, this is not recoverable, so we convert to
|
||||||
* @return LTable the current environment
|
* a lua error during production so that the code may recover.
|
||||||
*/
|
*/
|
||||||
// public LTable curr_env() {
|
public static void vmerror(String description) {
|
||||||
// LuaState vm = (LThread.running!=null?
|
throw new LuaErrorException( "internal error: "+description );
|
||||||
// LThread.running.threadVm:
|
}
|
||||||
// this);
|
|
||||||
// for ( int i=vm.cc; i>=0; i-- ) {
|
|
||||||
// LClosure c = vm.calls[cc].closure;
|
|
||||||
// if ( c != null )
|
|
||||||
// return c.env;
|
|
||||||
// }
|
|
||||||
// return _G;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class LuaRunner {
|
|||||||
public static void main( String[] args ) throws IOException {
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
// new lua state
|
// new lua state
|
||||||
LuaState state = new LuaState();
|
LuaState state = LuaState.newState();
|
||||||
|
|
||||||
// get script name
|
// get script name
|
||||||
String script = (args.length>0? args[0]: "/test2.luac");
|
String script = (args.length>0? args[0]: "/test2.luac");
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user