use serde::{Serialize, Deserialize}; use shm_rs::scheme_composer::composer::from_struct; use shm_rs::static_scheme::generator::RustCode; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; use shm_rs::serializator::serializator; pub const TEST_ULONG: u128 = 123; pub const TEST_LONG: i128 = 123; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TestStruct { pub f1: i128, pub f2: u128, pub f3: i128, pub f4: u128, pub f5: Vec, pub f6: Vec } fn main() { let curdir = std::env::current_dir().unwrap(); println!("{}", curdir.display()); let schm = init::SchemeInit::new_with_path(curdir).unwrap(); let res = schm.run_from_file("examples/scheme_longint/test_long_init.shm", None).unwrap(); let resser = res.get("test_long").unwrap().clone(); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/scheme_longint/test_long_data.shm"); // let lex = lexer::Lexer::from_file(curdir).unwrap(); let (_dynenv, dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap(); // let dynenv = environment::DynEnvironment::new_root(resser.clone()); //let dyn_res = environment::DynEnvironment::run(&lex, dynenv).unwrap(); let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap(); let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]); println!("Structures: "); match resser.generate_rust_structs(&mut rc) { Ok(_) => { let out = rc.to_string(); println!("{}", out); }, Err(e) => { panic!("{}", e); } } let serialized = serde_json::to_string(&ret).unwrap(); // control let ctrl_struct = TestStruct { f1: 4, f2: 128, f3: TEST_LONG, f4: TEST_ULONG, f5: vec![5, -7, 8], f6: vec![44, 33, 22] }; let ctrl_struct_ser = serde_json::to_string(&ctrl_struct).unwrap(); println!("Control:\n{}\n", ctrl_struct_ser); println!("Serialized Result:\n{}", serialized); let deserialized: TestStruct = serde_json::from_str(&serialized).unwrap(); println!("Deserialized result: \n{:?}", deserialized); if ctrl_struct_ser != serialized { panic!("not equal"); } else { println!("OK"); } let resser2 = from_struct(deserialized, resser); let resout = resser2.unwrap(); println!("{}", resout); }