Initial draft of interpreter. Lua compiled "chunks" can be unmarshalled. Approximately half of bytecodes implemented in some form or another.

This commit is contained in:
James Roseborough
2007-06-08 05:11:37 +00:00
commit 70dfc20f57
31 changed files with 1368 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package lua.value;
import lua.Lua;
public class LDouble extends LNumber {
private final double m_value;
public LDouble(double value) {
this.m_value = value;
}
public String luaAsString() {
return String.valueOf(m_value);
}
// binary operations on integers, first dispatch
public LValue luaBinOpUnknown(int opcode, LValue lhs) {
return lhs.luaBinOpDouble( opcode, this.m_value );
}
// binary operations on mixtures of doubles and integers
public LValue luaBinOpInteger(int opcode, int rhs) {
return luaBinOpDoubleDouble( opcode, m_value, (double) rhs );
}
// binary operations on doubles
public LValue luaBinOpDouble(int opcode, double rhs) {
return luaBinOpDoubleDouble( opcode, m_value, rhs );
}
public static LValue luaBinOpDoubleDouble( int opcode, double lhs, double rhs ) {
switch ( opcode ) {
case Lua.OP_ADD: return new LDouble( lhs + rhs );
case Lua.OP_SUB: return new LDouble( lhs - rhs );
case Lua.OP_MUL: return new LDouble( lhs * rhs );
case Lua.OP_DIV: return new LDouble( lhs / rhs );
case Lua.OP_MOD: return new LDouble( lhs % rhs );
case Lua.OP_POW: return new LDouble( Math.pow(lhs, rhs) );
}
return luaUnsupportedOperation();
}
public int luaAsInt() {
return (int) m_value;
}
}