diff --git a/libethereum/Instruction.cpp b/libethereum/Instruction.cpp index 130793f93..0ff68d0e0 100644 --- a/libethereum/Instruction.cpp +++ b/libethereum/Instruction.cpp @@ -42,6 +42,8 @@ const std::map eth::c_instructions = { "NEG", Instruction::NEG }, { "LT", Instruction::LT }, { "GT", Instruction::GT }, + { "SLT", Instruction::SLT }, + { "SGT", Instruction::SGT }, { "EQ", Instruction::EQ }, { "NOT", Instruction::NOT }, { "AND", Instruction::AND }, @@ -131,6 +133,8 @@ const std::map eth::c_instructionInfo = { Instruction::NEG, { "NEG", 0, 1, 1 } }, { Instruction::LT, { "LT", 0, 2, 1 } }, { Instruction::GT, { "GT", 0, 2, 1 } }, + { Instruction::SLT, { "SLT", 0, 2, 1 } }, + { Instruction::SGT, { "SGT", 0, 2, 1 } }, { Instruction::EQ, { "EQ", 0, 2, 1 } }, { Instruction::NOT, { "NOT", 0, 1, 1 } }, { Instruction::AND, { "AND", 0, 2, 1 } }, @@ -348,7 +352,7 @@ static void appendCode(bytes& o_code, vector& o_locs, bytes _code, vec static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes& o_code, vector& o_locs, map& _vars) { std::map const c_arith = { { "+", Instruction::ADD }, { "-", Instruction::SUB }, { "*", Instruction::MUL }, { "/", Instruction::DIV }, { "%", Instruction::MOD }, { "&", Instruction::AND }, { "|", Instruction::OR }, { "^", Instruction::XOR } }; - std::map> const c_binary = { { "<", { Instruction::LT, false } }, { "<=", { Instruction::GT, true } }, { ">", { Instruction::GT, false } }, { ">=", { Instruction::LT, true } }, { "=", { Instruction::EQ, false } }, { "!=", { Instruction::EQ, true } } }; + std::map> const c_binary = { { "<", { Instruction::LT, false } }, { "<=", { Instruction::GT, true } }, { ">", { Instruction::GT, false } }, { ">=", { Instruction::LT, true } }, { "S<", { Instruction::SLT, false } }, { "S<=", { Instruction::SGT, true } }, { "S>", { Instruction::SGT, false } }, { "S>=", { Instruction::SLT, true } }, { "=", { Instruction::EQ, false } }, { "!=", { Instruction::EQ, true } } }; std::map const c_unary = { { "!", Instruction::NOT } }; std::set const c_allowed = { '+', '-', '*', '/', '%', '<', '>', '=', '!', '&', '|', '~' }; diff --git a/libethereum/Instruction.h b/libethereum/Instruction.h index f49100a2e..c8d59a553 100644 --- a/libethereum/Instruction.h +++ b/libethereum/Instruction.h @@ -43,6 +43,8 @@ enum class Instruction: uint8_t NEG, LT, GT, + SLT, + SGT, EQ, NOT, diff --git a/libethereum/VM.h b/libethereum/VM.h index 97ef4bb86..cc1c8f974 100644 --- a/libethereum/VM.h +++ b/libethereum/VM.h @@ -253,6 +253,16 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps) m_stack[m_stack.size() - 2] = m_stack.back() > m_stack[m_stack.size() - 2] ? 1 : 0; m_stack.pop_back(); break; + case Instruction::SLT: + require(2); + m_stack[m_stack.size() - 2] = (s256&)m_stack.back() < (s256&)m_stack[m_stack.size() - 2] ? 1 : 0; + m_stack.pop_back(); + break; + case Instruction::SGT: + require(2); + m_stack[m_stack.size() - 2] = (s256&)m_stack.back() > (s256&)m_stack[m_stack.size() - 2] ? 1 : 0; + m_stack.pop_back(); + break; case Instruction::EQ: require(2); m_stack[m_stack.size() - 2] = m_stack.back() == m_stack[m_stack.size() - 2] ? 1 : 0;