diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-19 16:38:45 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-19 16:38:45 +0800 |
commit | da1552c48ebc9ae2c0a9a891bdb01491dffb0ff3 (patch) | |
tree | 4c90a0181a4617aa56946d6f6e65e760ed91a4f3 /src/mir/from_hir.cpp | |
parent | 18442f4a3a3d5fc838f4703651b6f925d3e0c2f2 (diff) | |
download | mrust-da1552c48ebc9ae2c0a9a891bdb01491dffb0ff3.tar.gz |
MIR Gen Match - Rough Slice and SplitSlice support
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 4a4b84e7..9d71ea01 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -280,28 +280,43 @@ namespace { (SplitSlice, // These are only refutable if T is [T] bool ty_is_array = false; - m_builder.with_val_type(sp, lval, [&ty_is_array](const auto& ty){ - ty_is_array = ty.m_data.is_Array(); + unsigned int array_size = 0; + m_builder.with_val_type(sp, lval, [&ty_is_array,&array_size](const auto& ty){ + if( ty.m_data.is_Array() ) { + array_size = ty.m_data.as_Array().size_val; + ty_is_array = true; + } + else { + ty_is_array = false; + } }); if( ty_is_array ) { - // TODO: Assert array size - //for(unsigned int i = 0; i < e.leading.size(); i ++) - //{ - // auto idx = 0 + i; - // destructure_from_ex(sp, e.leading[i], ::MIR::LValue::make_Index({ box$( lval.clone() ), box$(lval_idx) }), allow_refutable ); - //} - //for(unsigned int i = 0; i < e.trailing.size(); i ++) - //{ - // auto idx = 0 + i; - // destructure_from_ex(sp, e.leading[i], ::MIR::LValue::make_Index({ box$( lval.clone() ), box$(lval_idx) }), allow_refutable ); - //} - TODO(sp, "Destructure array using SplitSlice - " << pat); + assert(array_size >= e.leading.size() + e.trailing.size()); + for(unsigned int i = 0; i < e.leading.size(); i ++) + { + unsigned int idx = 0 + i; + destructure_from_ex(sp, e.leading[i], ::MIR::LValue::make_Field({ box$(lval.clone()), idx }), allow_refutable ); + } + for(unsigned int i = 0; i < e.trailing.size(); i ++) + { + unsigned int idx = array_size - e.trailing.size() + i; + destructure_from_ex(sp, e.trailing[i], ::MIR::LValue::make_Field({ box$(lval.clone()), idx }), allow_refutable ); + } } else { ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); - TODO(sp, "Destructure slice using SplitSlice - " << pat); + // TODO: Acquire the slice size variable. + for(unsigned int i = 0; i < e.leading.size(); i ++) + { + unsigned int idx = i; + destructure_from_ex(sp, e.leading[i], ::MIR::LValue::make_Field({ box$(lval.clone()), idx }), allow_refutable ); + } + if( e.trailing.size() > 0 ) + { + TODO(sp, "Destructure slice using SplitSlice with trailing - " << pat); + } } ) ) |