diff options
-rw-r--r-- | src/trans/codegen_c.cpp | 13 | ||||
-rw-r--r-- | src/trans/enumerate.cpp | 11 | ||||
-rw-r--r-- | src/trans/mangling.cpp | 12 | ||||
-rw-r--r-- | src/trans/mangling.hpp | 2 |
4 files changed, 34 insertions, 4 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 }); diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp index dc886f50..24dfce3c 100644 --- a/src/trans/enumerate.cpp +++ b/src/trans/enumerate.cpp @@ -287,6 +287,7 @@ namespace { // Enumerate types required for the enumerated items void Trans_Enumerate_Types(TransList& out, const ::HIR::Crate& crate) { + static Span sp; TypeVisitor tv { crate, out.m_types }; unsigned int types_count = 0; @@ -349,11 +350,19 @@ void Trans_Enumerate_Types(TransList& out, const ::HIR::Crate& crate) if( markings_ptr->has_drop_impl ) { // Add the Drop impl to the codegen list - Trans_Enumerate_FillFrom_Path(out, crate, ::HIR::Path( ty.clone(), crate.get_lang_item_path(Span(), "drop"), "drop"), {}); + Trans_Enumerate_FillFrom_Path(out, crate, ::HIR::Path( ty.clone(), crate.get_lang_item_path(sp, "drop"), "drop"), {}); constructors_added = true; } } + + if( const auto* ity = tv.m_resolve.is_type_owned_box(ty) ) + { + // Reqire drop glue for inner type. + // - Should that already exist? + // Requires box_free lang item + Trans_Enumerate_FillFrom_Path(out, crate, ::HIR::GenericPath( crate.get_lang_item_path(sp, "box_free"), { ity->clone() } ), {});; + } } types_count = out.m_types.size(); } while(constructors_added); diff --git a/src/trans/mangling.cpp b/src/trans/mangling.cpp index ef41abed..0c3e5c46 100644 --- a/src/trans/mangling.cpp +++ b/src/trans/mangling.cpp @@ -51,14 +51,20 @@ namespace { } -::FmtLambda Trans_Mangle(const ::HIR::GenericPath& path) +::FmtLambda Trans_Mangle(const ::HIR::SimplePath& path) { return FMT_CB(ss, - ss << "_ZN" << path.m_path.m_crate_name.size() << path.m_path.m_crate_name; - for(const auto& comp : path.m_path.m_components) { + ss << "_ZN" << path.m_crate_name.size() << path.m_crate_name; + for(const auto& comp : path.m_components) { auto v = escape_str(comp); ss << v.size() << v; } + ); +} +::FmtLambda Trans_Mangle(const ::HIR::GenericPath& path) +{ + return FMT_CB(ss, + ss << Trans_Mangle(path.m_path); ss << emit_params(path.m_params); ); } diff --git a/src/trans/mangling.hpp b/src/trans/mangling.hpp index ad6c9add..e1b6e35e 100644 --- a/src/trans/mangling.hpp +++ b/src/trans/mangling.hpp @@ -10,11 +10,13 @@ #include <debug.hpp> namespace HIR { + class SimplePath; class GenericPath; class Path; class TypeRef; } +extern ::FmtLambda Trans_Mangle(const ::HIR::SimplePath& path); extern ::FmtLambda Trans_Mangle(const ::HIR::GenericPath& path); extern ::FmtLambda Trans_Mangle(const ::HIR::Path& path); extern ::FmtLambda Trans_Mangle(const ::HIR::TypeRef& ty); |