Fix linking associated functions, fix other examples
This commit is contained in:
		
							parent
							
								
									ea6458dddc
								
							
						
					
					
						commit
						bd8994bb37
					
				| @ -1,6 +1,5 @@ | |||||||
| // Arithmetic, function calls and imports! | // Arithmetic, function calls and imports! | ||||||
| 
 | 
 | ||||||
| import std::allocate; |  | ||||||
| import std::print; | import std::print; | ||||||
| 
 | 
 | ||||||
| fn other() -> i16 { | fn other() -> i16 { | ||||||
| @ -9,7 +8,7 @@ fn other() -> i16 { | |||||||
| 
 | 
 | ||||||
| fn main() -> u32 { | fn main() -> u32 { | ||||||
| 
 | 
 | ||||||
|   let mut v = (allocate(4) as *u32); |   let mut v = (malloc(4) as *u32); | ||||||
|   v[0] = other() as u32; |   v[0] = other() as u32; | ||||||
| 
 | 
 | ||||||
|   return v[0]; |   return v[0]; | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| // Arithmetic, function calls and imports! | // Arithmetic, function calls and imports! | ||||||
| 
 | 
 | ||||||
| fn main() -> u8 { | fn main() -> u8 { | ||||||
|     let mut ptr = u8::alloca(4); |     let mut ptr = u8::malloc(4); | ||||||
| 
 | 
 | ||||||
|     ptr[0] = 5; |     ptr[0] = 5; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -254,18 +254,19 @@ impl mir::Module { | |||||||
|                 .collect(); |                 .collect(); | ||||||
| 
 | 
 | ||||||
|             let is_main = self.is_main && function.name == "main"; |             let is_main = self.is_main && function.name == "main"; | ||||||
|             let module_name = if let Some(module) = function.source { |             let module_prefix = if let Some(module) = function.source { | ||||||
|                 if module == self.module_id { |                 if module == self.module_id { | ||||||
|                     format!("reid.{}", self.name) |                     format!("reid.{}.", self.name) | ||||||
|                 } else { |                 } else { | ||||||
|                     format!("reid.{}", modules.get(&module).unwrap().name) |                     format!("reid.{}.", modules.get(&module).unwrap().name) | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 format!("reid.intrinsic") |                 format!("reid.intrinsic.") | ||||||
|             }; |             }; | ||||||
|  |             let full_name = format!("{}{}::{}", module_prefix, ty, function.name); | ||||||
|             let func = match &function.kind { |             let func = match &function.kind { | ||||||
|                 mir::FunctionDefinitionKind::Local(_, _) => Some(module.function( |                 mir::FunctionDefinitionKind::Local(_, _) => Some(module.function( | ||||||
|                     &format!("{}.{}.{}", module_name, ty, function.name), |                     &full_name, | ||||||
|                     None, |                     None, | ||||||
|                     function.return_type.get_type(&type_values), |                     function.return_type.get_type(&type_values), | ||||||
|                     param_types, |                     param_types, | ||||||
| @ -277,7 +278,7 @@ impl mir::Module { | |||||||
|                     }, |                     }, | ||||||
|                 )), |                 )), | ||||||
|                 mir::FunctionDefinitionKind::Extern(imported) => Some(module.function( |                 mir::FunctionDefinitionKind::Extern(imported) => Some(module.function( | ||||||
|                     &function.linkage_name.clone().unwrap_or(function.name.clone()), |                     &full_name, | ||||||
|                     None, |                     None, | ||||||
|                     function.return_type.get_type(&type_values), |                     function.return_type.get_type(&type_values), | ||||||
|                     param_types, |                     param_types, | ||||||
|  | |||||||
| @ -321,7 +321,7 @@ impl<'map> Pass for LinkerPass<'map> { | |||||||
|                             ty.clone(), |                             ty.clone(), | ||||||
|                             FunctionDefinition { |                             FunctionDefinition { | ||||||
|                                 name: func_name.clone(), |                                 name: func_name.clone(), | ||||||
|                                 linkage_name: Some(format!("{}.{}", ty, func_name)), |                                 linkage_name: Some(format!("{}::{}", ty, func_name)), | ||||||
|                                 is_pub: false, |                                 is_pub: false, | ||||||
|                                 is_imported: false, |                                 is_imported: false, | ||||||
|                                 return_type, |                                 return_type, | ||||||
|  | |||||||
| @ -149,6 +149,6 @@ fn associated_functions() { | |||||||
|     test( |     test( | ||||||
|         include_str!("../../examples/associated_functions.reid"), |         include_str!("../../examples/associated_functions.reid"), | ||||||
|         "test", |         "test", | ||||||
|         Some(32), |         Some(4), | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user