PoC-7: Instruction set reform

This commit is contained in:
Gav Wood 2014-10-31 14:32:32 +01:00
parent f6e24989ec
commit 64786387c1
2 changed files with 8 additions and 8 deletions

View File

@ -251,7 +251,7 @@ Assembly& Assembly::optimise(bool _enable)
{ { PushSub, Instruction::POP }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } },
{ { PushSubSize, Instruction::POP }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } },
{ { Push, PushTag, Instruction::JUMPI }, [](AssemblyItemsConstRef m) -> AssemblyItems { if (m[0].data()) return { m[1], Instruction::JUMP }; else return {}; } },
{ { Instruction::NOT, Instruction::NOT }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } },
{ { Instruction::ISZERO, Instruction::ISZERO }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } },
};
for (auto const& i: c_simple)

View File

@ -328,7 +328,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
std::map<std::string, Instruction> const c_arith = { { "+", Instruction::ADD }, { "-", Instruction::SUB }, { "*", Instruction::MUL }, { "/", Instruction::DIV }, { "%", Instruction::MOD }, { "&", Instruction::AND }, { "|", Instruction::OR }, { "^", Instruction::XOR } };
std::map<std::string, pair<Instruction, bool>> 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<std::string, Instruction> const c_unary = { { "!", Instruction::NOT } };
std::map<std::string, Instruction> const c_unary = { { "!", Instruction::ISZERO } };
vector<CodeFragment> code;
CompilerState ns = _s;
@ -403,7 +403,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
m_asm.append(code[0].m_asm, 1);
m_asm.append(it->second.first);
if (it->second.second)
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
}
else if (c_unary.count(us))
{
@ -437,7 +437,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
m_asm.append(code[0].m_asm);
if (us == "WHEN")
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
auto end = m_asm.appendJumpI();
m_asm.onePath();
m_asm.otherPath();
@ -452,7 +452,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
auto begin = m_asm.append();
m_asm.append(code[0].m_asm);
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
auto end = m_asm.appendJumpI();
m_asm.append(code[1].m_asm, 0);
m_asm.appendJump(begin);
@ -466,7 +466,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
m_asm.append(code[0].m_asm, 0);
auto begin = m_asm.append();
m_asm.append(code[1].m_asm);
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
auto end = m_asm.appendJumpI();
m_asm.append(code[3].m_asm, 0);
m_asm.append(code[2].m_asm, 0);
@ -502,7 +502,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
requireDeposit(2, 1);
m_asm.append(code[2].m_asm, 1);
m_asm.append(Instruction::LT);
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
m_asm.append(Instruction::MUL);
m_asm.append(Instruction::DUP1);
}
@ -525,7 +525,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
// Check if true - predicate
m_asm.append(code[i - 1].m_asm, 1);
if (us == "&&")
m_asm.append(Instruction::NOT);
m_asm.append(Instruction::ISZERO);
m_asm.appendJumpI(end);
}
m_asm.append(Instruction::POP);