Fix allocator
This commit is contained in:
		
							parent
							
								
									1b1a5934f5
								
							
						
					
					
						commit
						e412a2e1d7
					
				| @ -154,11 +154,7 @@ impl mir::Expression { | |||||||
|                 allocated.extend(lhs.allocate(scope)); |                 allocated.extend(lhs.allocate(scope)); | ||||||
|                 allocated.extend(rhs.allocate(scope)); |                 allocated.extend(rhs.allocate(scope)); | ||||||
|             } |             } | ||||||
|             mir::ExprKind::FunctionCall(FunctionCall { parameters, .. }) => { |             mir::ExprKind::FunctionCall(fn_call) => allocated.extend(fn_call.allocate(&fn_call.name, scope)), | ||||||
|                 for param in parameters { |  | ||||||
|                     allocated.extend(param.allocate(scope)); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             mir::ExprKind::If(IfExpression(cond, then_ex, else_ex)) => { |             mir::ExprKind::If(IfExpression(cond, then_ex, else_ex)) => { | ||||||
|                 allocated.extend(cond.allocate(scope)); |                 allocated.extend(cond.allocate(scope)); | ||||||
|                 allocated.extend(then_ex.allocate(scope)); |                 allocated.extend(then_ex.allocate(scope)); | ||||||
| @ -174,13 +170,34 @@ impl mir::Expression { | |||||||
|             mir::ExprKind::CastTo(expression, _) => { |             mir::ExprKind::CastTo(expression, _) => { | ||||||
|                 allocated.extend(expression.allocate(scope)); |                 allocated.extend(expression.allocate(scope)); | ||||||
|             } |             } | ||||||
|             mir::ExprKind::AssociatedFunctionCall(_, FunctionCall { parameters, .. }) => { |             mir::ExprKind::AssociatedFunctionCall(ty, fn_call) => { | ||||||
|                 for param in parameters { |                 allocated.extend(fn_call.allocate(&format!("{}::{}", ty, fn_call.name), scope)) | ||||||
|                     allocated.extend(param.allocate(scope)); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         allocated |         allocated | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl mir::FunctionCall { | ||||||
|  |     fn allocate<'ctx, 'a>(&self, name: &String, scope: &mut AllocatorScope<'ctx, 'a>) -> Vec<Allocation> { | ||||||
|  |         let mut allocated = Vec::new(); | ||||||
|  | 
 | ||||||
|  |         for param in &self.parameters { | ||||||
|  |             allocated.extend(param.allocate(scope)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if self.return_type != TypeKind::Void { | ||||||
|  |             let allocation = scope | ||||||
|  |                 .block | ||||||
|  |                 .build_named( | ||||||
|  |                     name, | ||||||
|  |                     reid_lib::Instr::Alloca(self.return_type.get_type(scope.type_values)), | ||||||
|  |                 ) | ||||||
|  |                 .unwrap(); | ||||||
|  |             allocated.push(Allocation(name.clone(), self.return_type.clone(), allocation)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         allocated | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -1346,8 +1346,9 @@ fn codegen_function_call<'ctx, 'a>( | |||||||
| 
 | 
 | ||||||
|     let ptr = if ret_type_kind != TypeKind::Void { |     let ptr = if ret_type_kind != TypeKind::Void { | ||||||
|         let ptr = scope |         let ptr = scope | ||||||
|             .block |             .allocator | ||||||
|             .build_named(&call.name, Instr::Alloca(ret_type.clone())) |             .borrow_mut() | ||||||
|  |             .allocate(&call_name, &call.return_type) | ||||||
|             .unwrap(); |             .unwrap(); | ||||||
|         scope |         scope | ||||||
|             .block |             .block | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user