|
| 1 | +use lib::typechecker::typechecker; |
| 2 | +use lib::types::{Class, Expr, FieldDecl, MethodDecl, Prg, Stmt, Type}; |
| 3 | +use serde_json::Value; |
| 4 | +use std::fs::File; |
| 5 | +use std::io::Read; |
1 | 6 | use tracing::info;
|
2 | 7 |
|
3 | 8 | fn main() -> color_eyre::Result<()> {
|
4 | 9 | color_eyre::install()?;
|
5 | 10 | tracing_subscriber::fmt::init();
|
6 | 11 | info!("Hello RustyJ!");
|
7 | 12 | lib::hi();
|
| 13 | + //let mut file = File::open("tests/If-AST.json")?; |
| 14 | + //let mut ast_string = String::new(); |
| 15 | + |
| 16 | + //file.read_to_string(&mut ast_string)?; |
| 17 | + //let ast_value: Value = serde_json::from_str(&ast_string)?; |
| 18 | + //println!("{:#?}", ast_value); |
| 19 | + //let ast: Class = serde_json::from_value(ast_value.clone())?; |
| 20 | + //println!("{:#?}", ast); |
| 21 | + let class: Class = Class { |
| 22 | + name: "test".to_string(), |
| 23 | + fields: vec![], |
| 24 | + methods: vec![MethodDecl { |
| 25 | + name: "f".to_string(), |
| 26 | + params: vec![(Type::Char, "c".to_string())], |
| 27 | + retType: Type::Bool, |
| 28 | + body: Stmt::Block(vec![ |
| 29 | + Stmt::If( |
| 30 | + Expr::Binary( |
| 31 | + "==".to_string(), |
| 32 | + Box::new(Expr::LocalOrFieldVar("c".to_string())), |
| 33 | + Box::new(Expr::Char('a')), |
| 34 | + ), |
| 35 | + Box::new(Stmt::Return(Expr::Bool(true))), |
| 36 | + None, |
| 37 | + ), |
| 38 | + Stmt::Return(Expr::Bool(false)), |
| 39 | + ]), |
| 40 | + }], |
| 41 | + }; |
| 42 | + |
| 43 | + let program: Prg = vec![class.clone()]; |
| 44 | + let mut typechecker = typechecker::TypeChecker::new(program); |
| 45 | + typechecker |
| 46 | + .unwrap() |
| 47 | + .check_program() |
| 48 | + .expect("TODO: panic message"); |
| 49 | + |
| 50 | + // Create a new json file |
| 51 | + let mut file = File::create("typed_if-test-local.json")?; |
| 52 | + |
| 53 | + serde_json::to_writer_pretty(&mut file, &class)?; |
| 54 | + |
| 55 | + //let typed_ast_string = serde_json::to_string_pretty(&ast)?; |
| 56 | + |
| 57 | + //let mut file = File::create("typed_if-ast.txt")?; |
| 58 | + //file.write_all(typed_ast_string.as_bytes())?; |
8 | 59 | Ok(())
|
9 | 60 | }
|
0 commit comments