diff options
Diffstat (limited to 'liblll')
-rw-r--r-- | liblll/CMakeLists.txt | 10 | ||||
-rw-r--r-- | liblll/CodeFragment.cpp | 39 | ||||
-rw-r--r-- | liblll/Compiler.h | 2 |
3 files changed, 47 insertions, 4 deletions
diff --git a/liblll/CMakeLists.txt b/liblll/CMakeLists.txt index 4cdc073a..9566c62f 100644 --- a/liblll/CMakeLists.txt +++ b/liblll/CMakeLists.txt @@ -1,5 +1,9 @@ -file(GLOB sources "*.cpp") -file(GLOB headers "*.h") +set(sources + CodeFragment.cpp + Compiler.cpp + CompilerState.cpp + Parser.cpp +) -add_library(lll ${sources} ${headers}) +add_library(lll ${sources}) target_link_libraries(lll PUBLIC evmasm devcore) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index f37cb8b9..b32f14e9 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -259,6 +259,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) } else if (us == "SET") { + // TODO: move this to be a stack variable (and not a memory variable) if (_t.size() != 3) error<IncorrectParameterCount>(us); int c = 0; @@ -268,6 +269,15 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) m_asm.append((u256)varAddress(firstAsString(), true)); m_asm.append(Instruction::MSTORE); } + else if (us == "UNSET") + { + // TODO: this doesn't actually free up anything, since it is a memory variable (see "SET") + if (_t.size() != 2) + error<IncorrectParameterCount>(); + auto it = _s.vars.find(firstAsString()); + if (it != _s.vars.end()) + _s.vars.erase(it); + } else if (us == "GET") { if (_t.size() != 2) @@ -275,6 +285,35 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) m_asm.append((u256)varAddress(firstAsString())); m_asm.append(Instruction::MLOAD); } + else if (us == "WITH") + { + if (_t.size() != 4) + error<IncorrectParameterCount>(); + string key = firstAsString(); + if (_s.vars.find(key) != _s.vars.end()) + error<InvalidName>(string("Symbol already used: ") + key); + + // Create variable + // TODO: move this to be a stack variable (and not a memory variable) + size_t c = 0; + for (auto const& i: _t) + if (c++ == 2) + m_asm.append(CodeFragment(i, _s, m_readFile, false).m_asm); + m_asm.append((u256)varAddress(key, true)); + m_asm.append(Instruction::MSTORE); + + // Insert sub with variable access, but new state + CompilerState ns = _s; + c = 0; + for (auto const& i: _t) + if (c++ == 3) + m_asm.append(CodeFragment(i, _s, m_readFile, false).m_asm); + + // Remove variable + auto it = _s.vars.find(key); + if (it != _s.vars.end()) + _s.vars.erase(it); + } else if (us == "REF") m_asm.append((u256)varAddress(firstAsString())); else if (us == "DEF") diff --git a/liblll/Compiler.h b/liblll/Compiler.h index 1ff7d5f8..93235cdd 100644 --- a/liblll/Compiler.h +++ b/liblll/Compiler.h @@ -23,7 +23,7 @@ #include <libdevcore/Common.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <string> #include <vector> |