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