Add binary compares, some unary ops, fix binary arithmetic, add plain for loop.
This commit is contained in:
@@ -44,5 +44,36 @@ public class LDouble extends LNumber {
|
||||
public int luaAsInt() {
|
||||
return (int) m_value;
|
||||
}
|
||||
|
||||
// binary compares on integers, first dispatch
|
||||
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
|
||||
return lhs.luaBinCmpDouble( opcode, this.m_value );
|
||||
}
|
||||
|
||||
// binary compares on mixtures of doubles and integers
|
||||
public boolean luaBinCmpInteger(int opcode, int rhs) {
|
||||
return luaBinCmpDoubleDouble( opcode, m_value, (double) rhs );
|
||||
}
|
||||
|
||||
// binary compares on doubles
|
||||
public boolean luaBinCmpDouble(int opcode, double rhs) {
|
||||
return luaBinCmpDoubleDouble( opcode, m_value, rhs );
|
||||
}
|
||||
|
||||
// compare two doubles
|
||||
public static boolean luaBinCmpDoubleDouble( int opcode, double lhs, double rhs ) {
|
||||
switch ( opcode ) {
|
||||
case Lua.OP_EQ: return lhs == rhs;
|
||||
case Lua.OP_LT: return lhs < rhs;
|
||||
case Lua.OP_LE: return lhs <= rhs;
|
||||
}
|
||||
luaUnsupportedOperation();
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Arithmetic negative */
|
||||
public LValue luaUnaryMinus() {
|
||||
return new LDouble( -m_value );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,4 +40,32 @@ public class LInteger extends LNumber {
|
||||
public LValue luaBinOpDouble(int opcode, double rhs) {
|
||||
return LDouble.luaBinOpDoubleDouble(opcode, (double) m_value, rhs );
|
||||
}
|
||||
|
||||
// binary compare for integers, first dispatch
|
||||
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
|
||||
return lhs.luaBinCmpInteger( opcode, this.m_value );
|
||||
}
|
||||
|
||||
// unsupported except for numbers
|
||||
public boolean luaBinCmpInteger(int opcode, int rhs) {
|
||||
switch ( opcode ) {
|
||||
case Lua.OP_EQ: return m_value == rhs;
|
||||
case Lua.OP_LT: return m_value < rhs;
|
||||
case Lua.OP_LE: return m_value <= rhs;
|
||||
}
|
||||
luaUnsupportedOperation();
|
||||
return false;
|
||||
}
|
||||
|
||||
// unsupported except for numbers
|
||||
public boolean luaBinCmpDouble(int opcode, double rhs) {
|
||||
return LDouble.luaBinCmpDoubleDouble(opcode, (double) m_value, rhs );
|
||||
}
|
||||
|
||||
/** Arithmetic negative */
|
||||
public LValue luaUnaryMinus() {
|
||||
return new LInteger( -m_value );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,4 +18,10 @@ public class LString extends LValue {
|
||||
public String luaAsString() {
|
||||
return m_string;
|
||||
}
|
||||
|
||||
/** Built-in opcode LEN, for Strings and Tables */
|
||||
public LValue luaLength() {
|
||||
return new LInteger( m_string.length() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ public class LTable extends LValue {
|
||||
public String luaAsString() {
|
||||
return m_hash.toString();
|
||||
}
|
||||
|
||||
/** Built-in opcode LEN, for Strings and Tables */
|
||||
public LValue luaLength() {
|
||||
return new LInteger( m_array.size() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,24 @@ public class LValue {
|
||||
return luaUnsupportedOperation();
|
||||
}
|
||||
|
||||
// unsupported except for numbers
|
||||
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
|
||||
luaUnsupportedOperation();
|
||||
return false;
|
||||
}
|
||||
|
||||
// unsupported except for numbers
|
||||
public boolean luaBinCmpInteger(int opcode, int rhs) {
|
||||
luaUnsupportedOperation();
|
||||
return false;
|
||||
}
|
||||
|
||||
// unsupported except for numbers
|
||||
public boolean luaBinCmpDouble(int opcode, double rhs) {
|
||||
luaUnsupportedOperation();
|
||||
return false;
|
||||
}
|
||||
|
||||
/** set a value in a table
|
||||
*/
|
||||
public void luaSetTable(LValue key, LValue value) {
|
||||
@@ -61,5 +79,17 @@ public class LValue {
|
||||
luaUnsupportedOperation();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Arithmetic negative */
|
||||
public LValue luaUnaryMinus() {
|
||||
return luaUnsupportedOperation();
|
||||
}
|
||||
|
||||
/** Built-in opcode LEN, for Strings and Tables */
|
||||
public LValue luaLength() {
|
||||
// TODO: call meta-method TM_LEN here
|
||||
return luaUnsupportedOperation();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user