Get inner arrays working
This commit is contained in:
		
							parent
							
								
									a62f9db422
								
							
						
					
					
						commit
						c723ba7b4a
					
				| @ -392,7 +392,6 @@ impl Builder { | ||||
|                 Instr::Alloca(_, _) => Ok(()), | ||||
|                 Instr::Load(ptr, load_ty) => { | ||||
|                     let ptr_ty = ptr.get_type(&self)?; | ||||
|                     dbg!(&ptr_ty, &load_ty); | ||||
|                     if let Type::Ptr(ptr_ty_inner) = ptr_ty { | ||||
|                         if *ptr_ty_inner == load_ty { | ||||
|                             Ok(()) | ||||
| @ -414,11 +413,9 @@ impl Builder { | ||||
|                 Instr::ArrayAlloca(_, _) => Ok(()), | ||||
|                 Instr::GetElemPtr(ptr_val, _) => { | ||||
|                     let ptr_ty = ptr_val.get_type(&self)?; | ||||
|                     dbg!(&ptr_ty); | ||||
|                     match ptr_ty { | ||||
|                         Type::Ptr(inner) => match *inner { | ||||
|                             Type::Array(_, _) => Ok(()), | ||||
|                             _ => Err(()), | ||||
|                         }, | ||||
|                         Type::Ptr(_) => Ok(()), | ||||
|                         _ => Err(()), | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
| @ -411,10 +411,10 @@ impl InstructionValue { | ||||
|                     let Type::Ptr(inner_ty) = instr_ty else { | ||||
|                         panic!("GetStructElemPtr on non-pointer! ({:?})", &instr_ty) | ||||
|                     }; | ||||
|                     let Type::Array(elem_ty, _) = *inner_ty else { | ||||
|                         panic!("GetStructElemPtr on non-struct! ({:?})", &inner_ty) | ||||
|                     }; | ||||
|                     Ok(Type::Ptr(Box::new(*elem_ty.clone()))) | ||||
|                     match *inner_ty { | ||||
|                         Type::Array(elem_ty, _) => Ok(Type::Ptr(Box::new(*elem_ty.clone()))), | ||||
|                         _ => Ok(*inner_ty), | ||||
|                     } | ||||
|                 } | ||||
|                 GetStructElemPtr(instr, idx) => { | ||||
|                     let instr_ty = instr.get_type(builder)?; | ||||
|  | ||||
| @ -645,7 +645,7 @@ impl mir::Expression { | ||||
|             } | ||||
|             mir::ExprKind::Indexed(expression, val_t, idx_expr) => { | ||||
|                 let StackValue(kind, array_ty) = expression | ||||
|                     .codegen(scope, &state.load(true)) | ||||
|                     .codegen(scope, &state.load(false)) | ||||
|                     .expect("array returned none!"); | ||||
|                 let idx = idx_expr | ||||
|                     .codegen(scope, &state.load(true)) | ||||
| @ -657,6 +657,7 @@ impl mir::Expression { | ||||
|                     .build(Instr::Constant(ConstValue::U32(0))) | ||||
|                     .unwrap(); | ||||
| 
 | ||||
|                 dbg!(&self, &val_t); | ||||
|                 let ptr = scope | ||||
|                     .block | ||||
|                     .build(Instr::GetElemPtr(kind.instr(), vec![first, idx])) | ||||
| @ -667,14 +668,18 @@ impl mir::Expression { | ||||
|                     panic!(); | ||||
|                 }; | ||||
| 
 | ||||
|                 let elem_value = scope | ||||
|                     .block | ||||
|                     .build(Instr::Load( | ||||
|                         ptr, | ||||
|                         val_t.get_type(scope.type_values, scope.types), | ||||
|                     )) | ||||
|                     .unwrap() | ||||
|                     .maybe_location(&mut scope.block, location); | ||||
|                 let elem_value = if state.should_load { | ||||
|                     scope | ||||
|                         .block | ||||
|                         .build(Instr::Load( | ||||
|                             ptr, | ||||
|                             val_t.get_type(scope.type_values, scope.types), | ||||
|                         )) | ||||
|                         .unwrap() | ||||
|                         .maybe_location(&mut scope.block, location) | ||||
|                 } else { | ||||
|                     ptr | ||||
|                 }; | ||||
| 
 | ||||
|                 Some(StackValue(kind.derive(elem_value), *elem_ty)) | ||||
|             } | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| // Arithmetic, function calls and imports! | ||||
| 
 | ||||
| fn main() -> u16 { | ||||
|   let a = [ 5, 3, 2 ]; | ||||
|   let a = [[ 5, 3, 2 ]]; | ||||
| 
 | ||||
|   return a[1]; | ||||
|   return a[0][1]; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user