|
1 |
| -use super::{pointed_type, PlaceTy}; |
| 1 | +use super::{array_get_address, array_get_item, pointed_type, PlaceTy}; |
2 | 2 |
|
3 | 3 | use crate::{
|
4 | 4 | assembly::MethodCompileCtx,
|
@@ -164,39 +164,19 @@ pub fn place_elem_body_index<'tcx>(
|
164 | 164 | )
|
165 | 165 | }
|
166 | 166 | }
|
167 |
| - TyKind::Array(element, _length) => { |
168 |
| - let element = ctx.monomorphize(*element); |
169 |
| - let element_type = ctx.type_from_cache(element); |
170 |
| - let array_type = ctx.type_from_cache(curr_ty); |
171 |
| - let array_dotnet = array_type.as_class_ref().expect("Non array type"); |
172 |
| - let arr_ref = ctx.nref(array_type); |
| 167 | + TyKind::Array(element, _length) => { |
173 | 168 | let index = ctx.alloc_node(cilly::CILNode::IntCast {
|
174 | 169 | input: index,
|
175 | 170 | target: Int::USize,
|
176 | 171 | extend: cilly::cilnode::ExtendKind::ZeroExtend,
|
177 | 172 | });
|
178 | 173 | let index = CILNode::V2(index);
|
179 |
| - if body_ty_is_by_adress(element, ctx) { |
180 |
| - let elem_ptr = ctx.nptr(element_type); |
181 |
| - let mref = MethodRef::new( |
182 |
| - array_dotnet, |
183 |
| - ctx.alloc_string("get_Address"), |
184 |
| - ctx.sig([arr_ref, Type::Int(Int::USize)], elem_ptr), |
185 |
| - MethodKind::Instance, |
186 |
| - vec![].into(), |
187 |
| - ); |
188 |
| - let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]); |
189 |
| - ((element).into(), ops) |
| 174 | + if body_ty_is_by_adress(*element, ctx) { |
| 175 | + let mref = array_get_address(ctx,*element,curr_ty); |
| 176 | + ((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index])) |
190 | 177 | } else {
|
191 |
| - let mref = MethodRef::new( |
192 |
| - array_dotnet, |
193 |
| - ctx.alloc_string("get_Item"), |
194 |
| - ctx.sig([arr_ref, Type::Int(Int::USize)], element_type), |
195 |
| - MethodKind::Instance, |
196 |
| - vec![].into(), |
197 |
| - ); |
198 |
| - let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]); |
199 |
| - ((element).into(), ops) |
| 178 | + let mref = array_get_item(ctx,*element,curr_ty); |
| 179 | + ((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index])) |
200 | 180 | }
|
201 | 181 | }
|
202 | 182 | _ => {
|
@@ -287,32 +267,12 @@ pub fn place_elem_body<'tcx>(
|
287 | 267 | }
|
288 | 268 | }
|
289 | 269 | TyKind::Array(element, _length) => {
|
290 |
| - let element_ty = ctx.monomorphize(*element); |
291 |
| - let element = ctx.type_from_cache(element_ty); |
292 |
| - let array_type = ctx.type_from_cache(curr_ty); |
293 |
| - let array_dotnet = array_type.as_class_ref().expect("Non array type"); |
294 |
| - let arr_ref = ctx.nref(array_type); |
295 |
| - if body_ty_is_by_adress(element_ty, ctx) { |
296 |
| - let elem_ptr = ctx.nptr(element); |
297 |
| - let mref = MethodRef::new( |
298 |
| - array_dotnet, |
299 |
| - ctx.alloc_string("get_Address"), |
300 |
| - ctx.sig([arr_ref, Type::Int(Int::USize)], elem_ptr), |
301 |
| - MethodKind::Instance, |
302 |
| - vec![].into(), |
303 |
| - ); |
304 |
| - let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]); |
305 |
| - ((element_ty).into(), ops) |
| 270 | + if body_ty_is_by_adress(*element, ctx) { |
| 271 | + let mref = array_get_address(ctx,*element,curr_ty); |
| 272 | + ((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index])) |
306 | 273 | } else {
|
307 |
| - let mref = MethodRef::new( |
308 |
| - array_dotnet, |
309 |
| - ctx.alloc_string("get_Item"), |
310 |
| - ctx.sig([arr_ref, Type::Int(Int::USize)], element), |
311 |
| - MethodKind::Instance, |
312 |
| - vec![].into(), |
313 |
| - ); |
314 |
| - let ops = call!(ctx.alloc_methodref(mref), [parrent_node, index]); |
315 |
| - ((element_ty).into(), ops) |
| 274 | + let mref = array_get_item(ctx,*element,curr_ty); |
| 275 | + ((*element).into(), call!(ctx.alloc_methodref(mref), [parrent_node, index])) |
316 | 276 | }
|
317 | 277 | }
|
318 | 278 | _ => {
|
|
0 commit comments