aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-05-27 02:09:15 +0800
committerGav Wood <i@gavwood.com>2014-05-27 02:09:15 +0800
commit8a0dcc26c45c29b86fc4c9ea5195b44c8fe4b493 (patch)
tree248a1aa38d2c901349577b6b0d34ee6ec70573f7
parent51e6c251641eef12ba93b725974faa35b514d636 (diff)
downloaddexon-solidity-8a0dcc26c45c29b86fc4c9ea5195b44c8fe4b493.tar.gz
dexon-solidity-8a0dcc26c45c29b86fc4c9ea5195b44c8fe4b493.tar.zst
dexon-solidity-8a0dcc26c45c29b86fc4c9ea5195b44c8fe4b493.zip
Convenience fixups.
-rw-r--r--Assembly.cpp4
-rw-r--r--Assembly.h1
-rw-r--r--CodeFragment.cpp9
-rw-r--r--CodeFragment.h4
4 files changed, 13 insertions, 5 deletions
diff --git a/Assembly.cpp b/Assembly.cpp
index 1f53cfb5..3614bfc4 100644
--- a/Assembly.cpp
+++ b/Assembly.cpp
@@ -142,6 +142,10 @@ AssemblyItem const& Assembly::append(AssemblyItem const& _i)
return back();
}
+void Assembly::optimise()
+{
+}
+
bytes Assembly::assemble() const
{
bytes ret;
diff --git a/Assembly.h b/Assembly.h
index 86b37622..26392d14 100644
--- a/Assembly.h
+++ b/Assembly.h
@@ -92,6 +92,7 @@ public:
std::string out() const { std::stringstream ret; streamOut(ret); return ret.str(); }
int deposit() const { return m_deposit; }
bytes assemble() const;
+ void optimise();
std::ostream& streamOut(std::ostream& _out) const;
private:
diff --git a/CodeFragment.cpp b/CodeFragment.cpp
index 59ff729e..299cda5f 100644
--- a/CodeFragment.cpp
+++ b/CodeFragment.cpp
@@ -102,7 +102,7 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowAS
void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
{
- if (_t.empty())
+ if (_t.tag() == 0 && _t.empty())
error<EmptyList>();
else if (_t.tag() == 0 && _t.front().which() != sp::utree_type::symbol_type)
error<DataNotExecutable>();
@@ -361,14 +361,17 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
{
requireSize(3);
requireDeposit(0, 1);
+ int minDep = min(code[1].m_asm.deposit(), code[2].m_asm.deposit());
m_asm.append(code[0].m_asm);
auto pos = m_asm.appendJumpI();
m_asm.onePath();
- m_asm << code[2].m_asm;
+ m_asm.append(code[2].m_asm, minDep);
auto end = m_asm.appendJump();
m_asm.otherPath();
- m_asm << pos.tag() << code[1].m_asm << end.tag();
+ m_asm << pos.tag();
+ m_asm.append(code[1].m_asm, minDep);
+ m_asm << end.tag();
m_asm.donePaths();
}
else if (us == "WHEN" || us == "UNLESS")
diff --git a/CodeFragment.h b/CodeFragment.h
index 64760484..6935a111 100644
--- a/CodeFragment.h
+++ b/CodeFragment.h
@@ -43,10 +43,10 @@ public:
static CodeFragment compile(std::string const& _src, CompilerState& _s);
/// Consolidates data and compiles code.
- bytes code() const { return m_asm.assemble(); }
+ bytes code() { m_asm.optimise(); return m_asm.assemble(); }
/// Consolidates data and compiles code.
- std::string assembly() const { return m_asm.out(); }
+ std::string assembly() { m_asm.optimise(); return m_asm.out(); }
private:
template <class T> void error() const { throw T(); }