use serde::{Serialize, Deserialize}; use shm_rs::lexer::lexer; use shm_rs::static_scheme::generator::RustCode; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; use shm_rs::serializator::serializator; #[derive(Serialize, Deserialize)] enum GeomType { Test, Ray{l: u64, w: u64}, Line(i64, i64, i64), } #[derive(Serialize, Deserialize)] struct Levels { name: String, ch_a: Option, ch_b: i64, g_type: Vec, } #[derive(Serialize, Deserialize)] struct CommonLevels { lvl: Levels } fn main() { let curdir = std::env::current_dir().unwrap(); //curdir.push("examples/test3.shm"); println!("{}", curdir.display()); // let lex = lexer::Lexer::from_file(curdir).unwrap(); let schm = init::SchemeInit::new_with_path(curdir).unwrap(); let res = schm.run_from_file("examples/test3.shm", None).unwrap(); let resser = res.get("test1").unwrap().clone(); println!("{:?}", res); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/test2.shm"); let lex = lexer::Lexer::from_file(curdir).unwrap(); let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dyn_res = environment::DynEnvironment::run(&lex, dynenv).unwrap(); let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap(); //println!("dynproc:\n{:?}\n", dyn_res); let serialized = serde_json::to_string(&ret).unwrap(); println!("Result:\n{}", serialized); let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap(); let lvls = Levels { name: "testing1234".to_string(), ch_a: Some(100), ch_b: 2, g_type: vec![GeomType::Line(4, 6, 5), GeomType::Ray{l: 56, w: 44}, GeomType::Test], }; let cl = CommonLevels{lvl: lvls}; let serialized_nat = serde_json::to_string(&cl).unwrap(); println!("nat:{}", serialized_nat); println!("ser:{}", serialized); if serialized != serialized_nat { println!("not equal"); } let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]); println!("Structures: "); match resser.generate_rust_structs(&mut rc) { Ok(_) => { println!("{}", rc); }, Err(e) => { println!("{}", e); } } }