diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-11 16:53:42 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-11 16:53:42 +0800 |
commit | 4a588dfb1a5dd5e4b7ec32171583d01858c51f20 (patch) | |
tree | 0c523ff39fa41e11a0d5c3105e67674fd388ae61 | |
parent | 88cf7e2448a2916988fe2c909e1b4365cd17aed4 (diff) | |
download | mrust-4a588dfb1a5dd5e4b7ec32171583d01858c51f20.tar.gz |
MIR - Work on _Unsize, requires changing coercion code to emit Unsize op higher
-rw-r--r-- | src/mir/from_hir.cpp | 30 | ||||
-rw-r--r-- | src/mir/mir.hpp | 4 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 8749ba1c..187fdc53 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1392,7 +1392,35 @@ namespace { { TRACE_FUNCTION_F("_Unsize"); this->visit_node_ptr(node.m_value); - TODO(node.span(), "MIR _Unsize to " << node.m_res_type); + auto ptr_lval = m_builder.lvalue_or_temp( node.m_value->m_res_type, m_builder.get_result(node.span()) ); + + if( !node.m_res_type.m_data.is_Borrow() ) { + BUG(node.span(), "MIR _Unsize with invalid type, requires output to be &-ptr, got " << node.m_res_type); + } + if( !node.m_value->m_res_type.m_data.is_Borrow() ) { + BUG(node.span(), "MIR _Unsize with invalid type, requires input to be &-ptr, got " << node.m_value->m_res_type); + } + const auto& ty_out = *node.m_res_type.m_data.as_Borrow().inner; + const auto& ty_in = *node.m_value->m_res_type.m_data.as_Borrow().inner; + + TU_MATCH_DEF( ::HIR::TypeRef::Data, (ty_out.m_data), (e), + ( + TODO(node.span(), "MIR _Unsize to " << ty_out); + ), + (TraitObject, + // TODO: Obtain the vtable if the destination is a trait object + // vtable exists as an unnamable associated type + + ::HIR::Path vtable { ty_in.clone(), e.m_trait.m_path.clone(), "#vtable" }; + ::HIR::TypeRef vtable_type { {} }; + auto vtable_lval = m_builder.lvalue_or_temp( + ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, mv$(vtable_type)), + ::MIR::RValue( ::MIR::Constant::make_ItemAddr(mv$(vtable)) ) + ); + + m_builder.set_result( node.span(), ::MIR::RValue::make_MakeDst({ mv$(ptr_lval), mv$(vtable_lval) }) ); + ) + ) } void visit(::HIR::ExprNode_Index& node) override { diff --git a/src/mir/mir.hpp b/src/mir/mir.hpp index 52f17a7d..0b7aebd0 100644 --- a/src/mir/mir.hpp +++ b/src/mir/mir.hpp @@ -118,6 +118,10 @@ TAGGED_UNION(RValue, Use, (DstMeta, struct { LValue val; }), + (MakeDst, struct { + LValue ptr_val; + LValue meta_val; + }), (Tuple, struct { ::std::vector<LValue> vals; }), |