Make borrows work as function parameters as well
This commit is contained in:
		
							parent
							
								
									2e829bc8a9
								
							
						
					
					
						commit
						8da32c25c5
					
				| @ -27,6 +27,7 @@ pub enum TypeKind { | ||||
|     String, | ||||
|     Array(Box<TypeKind>, u64), | ||||
|     Custom(String), | ||||
|     Borrow(Box<TypeKind>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Clone)] | ||||
|  | ||||
| @ -24,6 +24,10 @@ impl Parse for Type { | ||||
|             }; | ||||
|             stream.expect(Token::BracketClose)?; | ||||
|             TypeKind::Array(Box::new(inner.0), length) | ||||
|         } else if let Some(Token::Et) = stream.peek() { | ||||
|             stream.expect(Token::Et)?; | ||||
|             let inner = stream.parse::<Type>()?; | ||||
|             TypeKind::Borrow(Box::new(inner.0)) | ||||
|         } else { | ||||
|             if let Some(Token::Identifier(ident)) = stream.next() { | ||||
|                 match &*ident { | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| use std::path::PathBuf; | ||||
| use std::{path::PathBuf, process}; | ||||
| 
 | ||||
| use crate::{ | ||||
|     ast::{self}, | ||||
| @ -287,6 +287,9 @@ impl From<ast::TypeKind> for mir::TypeKind { | ||||
|             } | ||||
|             ast::TypeKind::String => mir::TypeKind::StringPtr, | ||||
|             ast::TypeKind::Custom(name) => mir::TypeKind::CustomType(name.clone()), | ||||
|             ast::TypeKind::Borrow(type_kind) => { | ||||
|                 mir::TypeKind::Borrow(Box::new(mir::TypeKind::from(*type_kind.clone()))) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -360,7 +360,7 @@ impl mir::Module { | ||||
|                 stack_values.insert( | ||||
|                     p_name.clone(), | ||||
|                     StackValue( | ||||
|                         StackValueKind::Immutable(alloca), | ||||
|                         StackValueKind::Mutable(alloca), | ||||
|                         TypeKind::Ptr(Box::new(p_ty.clone())), | ||||
|                     ), | ||||
|                 ); | ||||
|  | ||||
| @ -162,7 +162,7 @@ impl FunctionDefinition { | ||||
|                     param.0.clone(), | ||||
|                     ScopeVariable { | ||||
|                         ty: param_t, | ||||
|                         mutable: false, | ||||
|                         mutable: true, | ||||
|                     }, | ||||
|                 ) | ||||
|                 .or(Err(ErrorKind::VariableAlreadyDefined(param.0.clone()))); | ||||
|  | ||||
							
								
								
									
										13
									
								
								reid_src/borrow_hard.reid
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								reid_src/borrow_hard.reid
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| // Arithmetic, function calls and imports! | ||||
| 
 | ||||
| fn changer(param: &u32) { | ||||
|   *param = 17; | ||||
| } | ||||
| 
 | ||||
| fn main() -> u32 { | ||||
|   let mut value = 6; | ||||
| 
 | ||||
|   changer(&value); | ||||
| 
 | ||||
|   return value; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user