summaryrefslogtreecommitdiff
path: root/src/trans/codegen_c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/trans/codegen_c.cpp')
-rw-r--r--src/trans/codegen_c.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index e1f4b0ad..cd103d19 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -134,6 +134,7 @@ namespace {
emit_ctype( monomorph(ty), inner );
}
};
+ m_of << "// struct " << p << "\n";
m_of << "struct s_" << Trans_Mangle(p) << " {\n";
TU_MATCHA( (item.m_data), (e),
(Unit,
@@ -197,6 +198,18 @@ namespace {
if( item.m_markings.has_drop_impl ) {
m_of << "\t" << Trans_Mangle( ::HIR::Path(struct_ty.clone(), m_resolve.m_lang_Drop, "drop") ) << "(rv);\n";
}
+ else if( const auto* ity = m_resolve.is_type_owned_box(struct_ty) )
+ {
+ // Obtain inner pointer
+ // TODO: This is very specific to the structure of the official liballoc's Box.
+ ::HIR::TypeRef inner_ptr = ::HIR::TypeRef::new_pointer( ::HIR::BorrowType::Unique, ity->clone() );
+ m_of << "\t"; emit_ctype(inner_ptr, FMT_CB(ss, ss << "tmp0"; )); m_of << " = rv->_0._0._0;\n";
+ // Call destructor of inner data
+ emit_destructor_call(::MIR::LValue::make_Temporary({0}), *ity, true);
+ // Emit a call to box_free for the type
+ ::HIR::GenericPath box_free { m_crate.get_lang_item_path(sp, "box_free"), { ity->clone() } };
+ m_of << "\t" << Trans_Mangle(box_free) << "(tmp0);\n";
+ }
auto self = ::MIR::LValue::make_Deref({ box$(::MIR::LValue::make_Return({})) });
auto fld_lv = ::MIR::LValue::make_Field({ box$(self), 0 });