Add binary compares, some unary ops, fix binary arithmetic, add plain for loop.
This commit is contained in:
@@ -45,4 +45,35 @@ public class LDouble extends LNumber {
|
|||||||
return (int) m_value;
|
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) {
|
public LValue luaBinOpDouble(int opcode, double rhs) {
|
||||||
return LDouble.luaBinOpDoubleDouble(opcode, (double) m_value, 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() {
|
public String luaAsString() {
|
||||||
return m_string;
|
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() {
|
public String luaAsString() {
|
||||||
return m_hash.toString();
|
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();
|
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
|
/** set a value in a table
|
||||||
*/
|
*/
|
||||||
public void luaSetTable(LValue key, LValue value) {
|
public void luaSetTable(LValue key, LValue value) {
|
||||||
@@ -62,4 +80,16 @@ public class LValue {
|
|||||||
return 0;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
LUA_HOME=/cygdrive/c/programs/lua5.1
|
LUA_HOME=/cygdrive/c/programs/lua5.1
|
||||||
for x in test1 test2 test3 test4
|
TESTS="test1 test2 test3 test4 test5"
|
||||||
|
#TESTS="test5"
|
||||||
|
for x in $TESTS
|
||||||
do
|
do
|
||||||
echo compiling $x
|
echo compiling $x
|
||||||
${LUA_HOME}/luac5.1.exe -l -o ${x}.luac ${x}.lua
|
${LUA_HOME}/luac5.1.exe -l -o ${x}.luac ${x}.lua
|
||||||
|
${LUA_HOME}/lua5.1.exe ${x}.luac
|
||||||
done
|
done
|
||||||
|
|||||||
17
src/test/res/test5.lua
Normal file
17
src/test/res/test5.lua
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
i = 777
|
||||||
|
while i<780 do
|
||||||
|
print(i)
|
||||||
|
i = i+1
|
||||||
|
end
|
||||||
|
|
||||||
|
a,b = 0,1
|
||||||
|
while true do -- infinite loop
|
||||||
|
print( b )
|
||||||
|
a,b = b,a+b
|
||||||
|
if a>10 then break end -- exit the loop if the condition is true
|
||||||
|
end
|
||||||
|
|
||||||
|
for count = 336,330,-2 do print(count) end -- numerical iteration
|
||||||
|
|
||||||
|
-- for key,value in pairs({a=10, 3.14159265358, c="banana"}) do print(key, value) end
|
||||||
BIN
src/test/res/test5.luac
Normal file
BIN
src/test/res/test5.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user