From 58e75c7a48f8166cca41e9017dad351113952ab5 Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Mon, 14 Nov 2016 12:41:58 -0800 Subject: Unimplemented features moved to their own exception (#1361) Unimplemented features moved to their own exception InternalCompilerError is an exception that really should be reserved for actual internal errors of the compiler. Unimplemented features can now use either solUnimplemented( ) or, if it should be conditional, then solUnimplementedAssert( ). * Revert some unimplemented exceptions, add handlers The jsonCompiler and CommandLineInterface needed handlers for the new UnimplementedFeatureException, and some cases I had moved on to the new exception were better treated as real internal compiler errors. * Standardize on "Unimplemented feature" message --- libsolidity/codegen/LValue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index c1e05792..69a80b6a 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -120,7 +120,7 @@ void MemoryItem::storeValue(Type const& _sourceType, SourceLocation const&, bool } else { - solAssert(_sourceType == *m_dataType, "Conversion not implemented for assignment to memory."); + solUnimplementedAssert(_sourceType == *m_dataType, "Conversion not implemented for assignment to memory."); solAssert(m_dataType->sizeOnStack() == 1, ""); if (!_move) @@ -181,7 +181,7 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const << u256(0x100) << Instruction::EXP << Instruction::SWAP1 << Instruction::DIV; if (m_dataType->category() == Type::Category::FixedPoint) // implementation should be very similar to the integer case. - solAssert(false, "Not yet implemented - FixedPointType."); + solUnimplemented("Not yet implemented - FixedPointType."); if (m_dataType->category() == Type::Category::FixedBytes) m_context << (u256(0x1) << (256 - 8 * m_dataType->storageBytes())) << Instruction::MUL; else if ( -- cgit v1.2.3 From 95d7555e3c0e8fc4826114a336e0e717fe7a1a2d Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 14 Oct 2016 12:27:46 +0200 Subject: External functions in storage. --- libsolidity/codegen/LValue.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 69a80b6a..98ab6d41 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -153,7 +153,8 @@ StorageItem::StorageItem(CompilerContext& _compilerContext, Type const& _type): { if (m_dataType->isValueType()) { - solAssert(m_dataType->storageSize() == m_dataType->sizeOnStack(), ""); + if (m_dataType->category() != Type::Category::Function) + solAssert(m_dataType->storageSize() == m_dataType->sizeOnStack(), ""); solAssert(m_dataType->storageSize() == 1, "Invalid storage size."); } } @@ -189,8 +190,16 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const dynamic_cast(*m_dataType).isSigned() ) m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND; + else if ( + m_dataType->category() == Type::Category::Function && + dynamic_cast(*m_dataType).location() == FunctionType::Location::External + ) + CompilerUtils(m_context).splitExternalFunctionType(); else + { + solAssert(m_dataType->sizeOnStack() == 1, ""); m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND; + } } } @@ -204,6 +213,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc solAssert(m_dataType->storageBytes() > 0, "Invalid storage bytes size."); if (m_dataType->storageBytes() == 32) { + solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); // offset should be zero m_context << Instruction::POP; if (!_move) @@ -222,16 +232,23 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc m_context << Instruction::DUP2 << ((u256(1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::MUL; - m_context << Instruction::NOT << Instruction::AND; - // stack: value storage_ref multiplier cleared_value - m_context - << Instruction::SWAP1 << Instruction::DUP4; + m_context << Instruction::NOT << Instruction::AND << Instruction::SWAP1; + // stack: value storage_ref cleared_value multiplier + utils.copyToStackTop(4, m_dataType->sizeOnStack()); // stack: value storage_ref cleared_value multiplier value - if (m_dataType->category() == Type::Category::FixedBytes) + if ( + m_dataType->category() == Type::Category::Function && + dynamic_cast(*m_dataType).location() == FunctionType::Location::External + ) + // Combine the two-item function type into a single stack slot. + utils.combineExternalFunctionType(); + else if (m_dataType->category() == Type::Category::FixedBytes) m_context << (u256(0x1) << (256 - 8 * dynamic_cast(*m_dataType).numBytes())) << Instruction::SWAP1 << Instruction::DIV; else + { + solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type."); // remove the higher order bits m_context << (u256(1) << (8 * (32 - m_dataType->storageBytes()))) @@ -239,11 +256,12 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc << Instruction::DUP2 << Instruction::MUL << Instruction::DIV; + } m_context << Instruction::MUL << Instruction::OR; // stack: value storage_ref updated_value m_context << Instruction::SWAP1 << Instruction::SSTORE; if (_move) - m_context << Instruction::POP; + utils.popStackElement(*m_dataType); } } else -- cgit v1.2.3 From ff3553a34895c70c473a27c29464ebfc15375416 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 19 Oct 2016 18:43:31 +0200 Subject: Change alignment. --- libsolidity/codegen/LValue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 98ab6d41..cb7cbbe3 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -194,7 +194,7 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const m_dataType->category() == Type::Category::Function && dynamic_cast(*m_dataType).location() == FunctionType::Location::External ) - CompilerUtils(m_context).splitExternalFunctionType(); + CompilerUtils(m_context).splitExternalFunctionType(false); else { solAssert(m_dataType->sizeOnStack() == 1, ""); @@ -241,7 +241,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc dynamic_cast(*m_dataType).location() == FunctionType::Location::External ) // Combine the two-item function type into a single stack slot. - utils.combineExternalFunctionType(); + utils.combineExternalFunctionType(false); else if (m_dataType->category() == Type::Category::FixedBytes) m_context << (u256(0x1) << (256 - 8 * dynamic_cast(*m_dataType).numBytes())) -- cgit v1.2.3 From cc847df3c20982372d601016382b0a93266467a4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 28 Oct 2016 17:30:56 +0200 Subject: Bugfix in code generator. --- libsolidity/codegen/LValue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index cb7cbbe3..d2c75445 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -234,7 +234,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc << Instruction::MUL; m_context << Instruction::NOT << Instruction::AND << Instruction::SWAP1; // stack: value storage_ref cleared_value multiplier - utils.copyToStackTop(4, m_dataType->sizeOnStack()); + utils.copyToStackTop(3 + m_dataType->sizeOnStack(), m_dataType->sizeOnStack()); // stack: value storage_ref cleared_value multiplier value if ( m_dataType->category() == Type::Category::Function && -- cgit v1.2.3 From 47794c1da406a28f0e8a10e3e57cd935f5cc7f3d Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 7 Nov 2016 20:08:05 +0100 Subject: Implement uninitialized storage functions. --- libsolidity/codegen/LValue.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index d2c75445..66449fc4 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -190,11 +190,11 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const dynamic_cast(*m_dataType).isSigned() ) m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND; - else if ( - m_dataType->category() == Type::Category::Function && - dynamic_cast(*m_dataType).location() == FunctionType::Location::External - ) - CompilerUtils(m_context).splitExternalFunctionType(false); + else if (FunctionType const* fun = dynamic_cast(m_dataType)) + { + if (fun->location() == FunctionType::Location::External) + CompilerUtils(m_context).splitExternalFunctionType(false); + } else { solAssert(m_dataType->sizeOnStack() == 1, ""); @@ -236,12 +236,16 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc // stack: value storage_ref cleared_value multiplier utils.copyToStackTop(3 + m_dataType->sizeOnStack(), m_dataType->sizeOnStack()); // stack: value storage_ref cleared_value multiplier value - if ( - m_dataType->category() == Type::Category::Function && - dynamic_cast(*m_dataType).location() == FunctionType::Location::External - ) - // Combine the two-item function type into a single stack slot. - utils.combineExternalFunctionType(false); + if (FunctionType const* fun = dynamic_cast(m_dataType)) + { + if (fun->location() == FunctionType::Location::External) + // Combine the two-item function type into a single stack slot. + utils.combineExternalFunctionType(false); + else + m_context << + ((u256(1) << (8 * m_dataType->storageBytes())) - 1) << + Instruction::AND; + } else if (m_dataType->category() == Type::Category::FixedBytes) m_context << (u256(0x1) << (256 - 8 * dynamic_cast(*m_dataType).numBytes())) -- cgit v1.2.3 From e1df3bd77f78d5564fc173474015e5d84b192824 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 9 Nov 2016 13:34:51 +0100 Subject: Fix tests. --- libsolidity/codegen/LValue.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 66449fc4..2ec7f800 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -177,6 +177,7 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const m_context << Instruction::POP << Instruction::SLOAD; else { + bool cleaned = false; m_context << Instruction::SWAP1 << Instruction::SLOAD << Instruction::SWAP1 << u256(0x100) << Instruction::EXP << Instruction::SWAP1 << Instruction::DIV; @@ -184,18 +185,27 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const // implementation should be very similar to the integer case. solUnimplemented("Not yet implemented - FixedPointType."); if (m_dataType->category() == Type::Category::FixedBytes) + { m_context << (u256(0x1) << (256 - 8 * m_dataType->storageBytes())) << Instruction::MUL; + cleaned = true; + } else if ( m_dataType->category() == Type::Category::Integer && dynamic_cast(*m_dataType).isSigned() ) + { m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND; + cleaned = true; + } else if (FunctionType const* fun = dynamic_cast(m_dataType)) { if (fun->location() == FunctionType::Location::External) + { CompilerUtils(m_context).splitExternalFunctionType(false); + cleaned = true; + } } - else + if (!cleaned) { solAssert(m_dataType->sizeOnStack() == 1, ""); m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND; -- cgit v1.2.3