Remove old useless example
This commit is contained in:
		
							parent
							
								
									990d8cb448
								
							
						
					
					
						commit
						287ab69d32
					
				| @ -1,186 +0,0 @@ | ||||
| use std::path::PathBuf; | ||||
| 
 | ||||
| use reid::mir::{self, *}; | ||||
| use reid_lib::Context; | ||||
| 
 | ||||
| fn main() { | ||||
|     let fibonacci_name = "fibonacci".to_owned(); | ||||
|     let fibonacci_n = "N".to_owned(); | ||||
| 
 | ||||
|     let fibonacci = FunctionDefinition { | ||||
|         name: fibonacci_name.clone(), | ||||
|         is_pub: false, | ||||
|         is_imported: false, | ||||
|         return_type: TypeKind::I32, | ||||
|         parameters: vec![(fibonacci_n.clone(), TypeKind::I32)], | ||||
|         kind: FunctionDefinitionKind::Local( | ||||
|             Block { | ||||
|                 statements: vec![Statement( | ||||
|                     StmtKind::Expression(Expression( | ||||
|                         ExprKind::If(IfExpression( | ||||
|                             // If N < 3
 | ||||
|                             Box::new(Expression( | ||||
|                                 ExprKind::BinOp( | ||||
|                                     BinaryOperator::Cmp(CmpOperator::GT), | ||||
|                                     Box::new(Expression( | ||||
|                                         ExprKind::Variable(NamedVariableRef( | ||||
|                                             TypeKind::I32, | ||||
|                                             "N".to_string(), | ||||
|                                             Default::default(), | ||||
|                                         )), | ||||
|                                         Default::default(), | ||||
|                                     )), | ||||
|                                     Box::new(Expression( | ||||
|                                         ExprKind::Literal(Literal::I32(2)), | ||||
|                                         Default::default(), | ||||
|                                     )), | ||||
|                                 ), | ||||
|                                 Default::default(), | ||||
|                             )), | ||||
|                             // Then
 | ||||
|                             Block { | ||||
|                                 statements: vec![], | ||||
|                                 return_expression: Some(( | ||||
|                                     ReturnKind::Hard, | ||||
|                                     // return fibonacci(n-1) + fibonacci(n-2)
 | ||||
|                                     Box::new(Expression( | ||||
|                                         ExprKind::BinOp( | ||||
|                                             BinaryOperator::Add, | ||||
|                                             // fibonacci(n-1)
 | ||||
|                                             Box::new(Expression( | ||||
|                                                 ExprKind::FunctionCall(FunctionCall { | ||||
|                                                     name: fibonacci_name.clone(), | ||||
|                                                     return_type: TypeKind::I32, | ||||
|                                                     parameters: vec![Expression( | ||||
|                                                         ExprKind::BinOp( | ||||
|                                                             BinaryOperator::Minus, | ||||
|                                                             Box::new(Expression( | ||||
|                                                                 ExprKind::Variable( | ||||
|                                                                     NamedVariableRef( | ||||
|                                                                         TypeKind::I32, | ||||
|                                                                         fibonacci_n.clone(), | ||||
|                                                                         Default::default(), | ||||
|                                                                     ), | ||||
|                                                                 ), | ||||
|                                                                 Default::default(), | ||||
|                                                             )), | ||||
|                                                             Box::new(Expression( | ||||
|                                                                 ExprKind::Literal(Literal::I32(1)), | ||||
|                                                                 Default::default(), | ||||
|                                                             )), | ||||
|                                                         ), | ||||
|                                                         Default::default(), | ||||
|                                                     )], | ||||
|                                                 }), | ||||
|                                                 Default::default(), | ||||
|                                             )), | ||||
|                                             // fibonacci(n-2)
 | ||||
|                                             Box::new(Expression( | ||||
|                                                 ExprKind::FunctionCall(FunctionCall { | ||||
|                                                     name: fibonacci_name.clone(), | ||||
|                                                     return_type: TypeKind::I32, | ||||
|                                                     parameters: vec![Expression( | ||||
|                                                         ExprKind::BinOp( | ||||
|                                                             BinaryOperator::Minus, | ||||
|                                                             Box::new(Expression( | ||||
|                                                                 ExprKind::Variable( | ||||
|                                                                     NamedVariableRef( | ||||
|                                                                         TypeKind::I32, | ||||
|                                                                         fibonacci_n.clone(), | ||||
|                                                                         Default::default(), | ||||
|                                                                     ), | ||||
|                                                                 ), | ||||
|                                                                 Default::default(), | ||||
|                                                             )), | ||||
|                                                             Box::new(Expression( | ||||
|                                                                 ExprKind::Literal(Literal::I32(2)), | ||||
|                                                                 Default::default(), | ||||
|                                                             )), | ||||
|                                                         ), | ||||
|                                                         Default::default(), | ||||
|                                                     )], | ||||
|                                                 }), | ||||
|                                                 Default::default(), | ||||
|                                             )), | ||||
|                                         ), | ||||
|                                         Default::default(), | ||||
|                                     )), | ||||
|                                 )), | ||||
|                                 meta: Default::default(), | ||||
|                             }, | ||||
|                             // No else-block
 | ||||
|                             None, | ||||
|                         )), | ||||
|                         Default::default(), | ||||
|                     )), | ||||
|                     Default::default(), | ||||
|                 )], | ||||
|                 // return 1
 | ||||
|                 return_expression: Some(( | ||||
|                     ReturnKind::Soft, | ||||
|                     Box::new(Expression( | ||||
|                         ExprKind::Literal(Literal::I32(1)), | ||||
|                         Default::default(), | ||||
|                     )), | ||||
|                 )), | ||||
|                 meta: Default::default(), | ||||
|             }, | ||||
|             Default::default(), | ||||
|         ), | ||||
|     }; | ||||
| 
 | ||||
|     let main = FunctionDefinition { | ||||
|         name: "main".to_owned(), | ||||
|         is_pub: false, | ||||
|         is_imported: false, | ||||
|         return_type: TypeKind::I32, | ||||
|         parameters: vec![], | ||||
|         kind: FunctionDefinitionKind::Local( | ||||
|             Block { | ||||
|                 statements: vec![], | ||||
|                 return_expression: Some(( | ||||
|                     ReturnKind::Soft, | ||||
|                     Box::new(Expression( | ||||
|                         ExprKind::FunctionCall(FunctionCall { | ||||
|                             name: fibonacci_name.clone(), | ||||
|                             return_type: TypeKind::I32, | ||||
|                             parameters: vec![Expression( | ||||
|                                 ExprKind::Literal(Literal::I32(5)), | ||||
|                                 Default::default(), | ||||
|                             )], | ||||
|                         }), | ||||
|                         Default::default(), | ||||
|                     )), | ||||
|                 )), | ||||
|                 meta: Default::default(), | ||||
|             }, | ||||
|             Default::default(), | ||||
|         ), | ||||
|     }; | ||||
| 
 | ||||
|     let mir_context = mir::Context { | ||||
|         modules: vec![Module { | ||||
|             name: "test module".to_owned(), | ||||
|             module_id: SourceModuleId::default(), | ||||
|             imports: vec![], | ||||
|             functions: vec![fibonacci, main], | ||||
|             typedefs: Vec::new(), | ||||
|             path: None, | ||||
|             is_main: true, | ||||
|         }], | ||||
|         base: PathBuf::new(), | ||||
|     }; | ||||
|     println!("test1"); | ||||
| 
 | ||||
|     let context = Context::new("testcodegen"); | ||||
|     let codegen = mir_context.codegen(&context); | ||||
|     println!("test2"); | ||||
| 
 | ||||
|     codegen.compile(); | ||||
|     println!("test3"); | ||||
| 
 | ||||
|     // match codegen_module.module.print_to_string() {
 | ||||
|     //     Ok(v) => println!("{}", v),
 | ||||
|     //     Err(e) => println!("Err: {:?}", e),
 | ||||
|     // }
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user