diff options
Diffstat (limited to 'liblll')
-rw-r--r-- | liblll/All.h | 6 | ||||
-rw-r--r-- | liblll/CodeFragment.cpp | 18 |
2 files changed, 15 insertions, 9 deletions
diff --git a/liblll/All.h b/liblll/All.h deleted file mode 100644 index 7c4192f6..00000000 --- a/liblll/All.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "CodeFragment.h" -#include "Compiler.h" -#include "CompilerState.h" -#include "Parser.h" diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 1329ec9b..7496fe83 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -171,11 +171,23 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) return string(); }; - auto varAddress = [&](string const& n) + auto varAddress = [&](string const& n, bool createMissing = false) { + if (n.empty()) + error<InvalidName>("Empty variable name not allowed"); auto it = _s.vars.find(n); if (it == _s.vars.end()) - error<InvalidName>(std::string("Symbol not found: ") + s); + { + if (createMissing) + { + // Create new variable + bool ok; + tie(it, ok) = _s.vars.insert(make_pair(n, make_pair(_s.stackSize, 32))); + _s.stackSize += 32; + } + else + error<InvalidName>(std::string("Symbol not found: ") + n); + } return it->second.first; }; @@ -208,7 +220,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) for (auto const& i: _t) if (c++ == 2) m_asm.append(CodeFragment(i, _s, false).m_asm); - m_asm.append((u256)varAddress(firstAsString())); + m_asm.append((u256)varAddress(firstAsString(), true)); m_asm.append(Instruction::MSTORE); } else if (us == "GET") |