Browse Source

Style.

cl-refactor
chriseth 10 years ago
parent
commit
bab25a2bd7
  1. 36
      libsolidity/CompilerUtils.cpp
  2. 20
      libsolidity/ExpressionCompiler.cpp

36
libsolidity/CompilerUtils.cpp

@ -110,11 +110,11 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
if (type.location() == ReferenceType::Location::CallData) if (type.location() == ReferenceType::Location::CallData)
{ {
// stack: target source_offset source_len // stack: target source_offset source_len
m_context << eth::Instruction::DUP1 << eth::Instruction::DUP3 << eth::Instruction::DUP5 m_context << eth::Instruction::DUP1 << eth::Instruction::DUP3 << eth::Instruction::DUP5;
// stack: target source_offset source_len source_len source_offset target // stack: target source_offset source_len source_len source_offset target
<< eth::Instruction::CALLDATACOPY m_context << eth::Instruction::CALLDATACOPY;
<< eth::Instruction::DUP3 << eth::Instruction::ADD m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
<< eth::Instruction::SWAP2 << eth::Instruction::POP << eth::Instruction::POP; m_context << eth::Instruction::SWAP2 << eth::Instruction::POP << eth::Instruction::POP;
} }
else if (type.location() == ReferenceType::Location::Memory) else if (type.location() == ReferenceType::Location::Memory)
{ {
@ -200,16 +200,16 @@ void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBound
// stack here: memory_end_offset storage_data_offset memory_offset // stack here: memory_end_offset storage_data_offset memory_offset
eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopStart = m_context.newTag();
m_context << loopStart m_context << loopStart;
// load and store // load and store
<< eth::Instruction::DUP2 << eth::Instruction::SLOAD m_context << eth::Instruction::DUP2 << eth::Instruction::SLOAD;
<< eth::Instruction::DUP2 << eth::Instruction::MSTORE m_context << eth::Instruction::DUP2 << eth::Instruction::MSTORE;
// increment storage_data_offset by 1 // increment storage_data_offset by 1
<< eth::Instruction::SWAP1 << u256(1) << eth::Instruction::ADD m_context << eth::Instruction::SWAP1 << u256(1) << eth::Instruction::ADD;
// increment memory offset by 32 // increment memory offset by 32
<< eth::Instruction::SWAP1 << u256(32) << eth::Instruction::ADD m_context << eth::Instruction::SWAP1 << u256(32) << eth::Instruction::ADD;
// check for loop condition // check for loop condition
<< eth::Instruction::DUP1 << eth::Instruction::DUP4 << eth::Instruction::GT; m_context << eth::Instruction::DUP1 << eth::Instruction::DUP4 << eth::Instruction::GT;
m_context.appendConditionalJumpTo(loopStart); m_context.appendConditionalJumpTo(loopStart);
// stack here: memory_end_offset storage_data_offset memory_offset // stack here: memory_end_offset storage_data_offset memory_offset
if (_padToWordBoundaries) if (_padToWordBoundaries)
@ -368,9 +368,11 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
if (targetType.getNumBytes() == 0) if (targetType.getNumBytes() == 0)
m_context << eth::Instruction::DUP1 << eth::Instruction::XOR; m_context << eth::Instruction::DUP1 << eth::Instruction::XOR;
else else
m_context << (u256(1) << (256 - targetType.getNumBytes() * 8)) {
<< eth::Instruction::DUP1 << eth::Instruction::SWAP2 m_context << (u256(1) << (256 - targetType.getNumBytes() * 8));
<< eth::Instruction::DIV << eth::Instruction::MUL; m_context << eth::Instruction::DUP1 << eth::Instruction::SWAP2;
m_context << eth::Instruction::DIV << eth::Instruction::MUL;
}
} }
} }
} }

20
libsolidity/ExpressionCompiler.cpp

@ -436,8 +436,10 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
_functionCall.getExpression().accept(*this); _functionCall.getExpression().accept(*this);
m_context << u256(0); // do not send gas (there still is the stipend) m_context << u256(0); // do not send gas (there still is the stipend)
arguments.front()->accept(*this); arguments.front()->accept(*this);
utils().convertType(*arguments.front()->getType(), utils().convertType(
*function.getParameterTypes().front(), true); *arguments.front()->getType(),
*function.getParameterTypes().front(), true
);
appendExternalFunctionCall( appendExternalFunctionCall(
FunctionType( FunctionType(
TypePointers{}, TypePointers{},
@ -612,13 +614,19 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
case Type::Category::Integer: case Type::Category::Integer:
if (member == "balance") if (member == "balance")
{ {
utils().convertType(*_memberAccess.getExpression().getType(), utils().convertType(
IntegerType(0, IntegerType::Modifier::Address), true); *_memberAccess.getExpression().getType(),
IntegerType(0, IntegerType::Modifier::Address),
true
);
m_context << eth::Instruction::BALANCE; m_context << eth::Instruction::BALANCE;
} }
else if ((set<string>{"send", "call", "callcode"}).count(member)) else if ((set<string>{"send", "call", "callcode"}).count(member))
utils().convertType(*_memberAccess.getExpression().getType(), utils().convertType(
IntegerType(0, IntegerType::Modifier::Address), true); *_memberAccess.getExpression().getType(),
IntegerType(0, IntegerType::Modifier::Address),
true
);
else else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to integer.")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to integer."));
break; break;

Loading…
Cancel
Save