mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
LLL: implement WITH keyword
This commit is contained in:
@@ -285,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")
|
||||
|
||||
Reference in New Issue
Block a user