From 1f6530620b5988d672bdfc3614c88d4fc20beeee Mon Sep 17 00:00:00 2001 From: Nils Olsson Date: Thu, 29 Jul 2021 14:16:43 -0700 Subject: [PATCH] Fix transform_condition (was using Brnez for default instead of Breqz) --- myps/test-scripts/factory/gas.myps | 16 ++++++++++++++++ translator/src/lib.rs | 6 ++++-- translator/src/main.rs | 6 +++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/myps/test-scripts/factory/gas.myps b/myps/test-scripts/factory/gas.myps index 5cc6ceb..face91e 100644 --- a/myps/test-scripts/factory/gas.myps +++ b/myps/test-scripts/factory/gas.myps @@ -18,22 +18,26 @@ loop: if db.Setting != 0: # (a) batch read temperature and pressure from furnace (tF/pF) db.Setting = 2 + yield() fix nF = AdvFurnace.all.TotalMoles.avg tF = AdvFurnace.all.Temperature.avg pF = AdvFurnace.all.Pressure.avg # (b) read tank temperatures db.Setting = 3 + yield() tC = tankC.Temperature tH = tankH.Temperature # (c) read targets (tT/pT), db.Setting = 4 + yield() tT = tTSrc.Setting pT = pTSrc.Setting # (d) calculate moles to remove and add from C and H (nR/nC/nH) db.Setting = 5 + yield() tag partD: nT = pT*vF/(R*tT) tTnT = tT*nT @@ -48,6 +52,7 @@ loop: # (e) remove nR, mix nC and nH db.Setting = 6 + yield() tag parthE: def kP = 0.06 def kD = 0.02 @@ -69,7 +74,17 @@ loop: fix eFPrev = 0 # fix F error (prev) fix eCPrev = 0 # fix C error (prev) fix eHPrev = 0 # fix H error (prev) + db.Setting = eF + yield() + db.Setting = eC + yield() + db.Setting = eH + yield() + db.Setting = 999 + yield() while eF > 0.1 or eC > 0.1 or eH > 0.1: + db.Setting = 1234 + yield() uF = (kP * eF) + (kD * (eF - eFPrev) / dt) AdvFurnace.all.SettingOutput = uF # set furnace out @@ -95,6 +110,7 @@ loop: # (f) input the nC and nH gas (can the necessary run time be calculated?) db.Setting = 7 + yield() AdvFurnace.all.SettingInput = 100 while PipeAnalyzer.all.TotalMoles.avg > 0: yield() diff --git a/translator/src/lib.rs b/translator/src/lib.rs index 5cd2cab..f74d3bb 100644 --- a/translator/src/lib.rs +++ b/translator/src/lib.rs @@ -255,12 +255,12 @@ impl Translator { Stmt::Snez([_, a]) => Stmt::Breqz([a, c]), _ => { cond_stmts.push(cond_stmt); - Stmt::Brnez([cond_num.into(), c]) + Stmt::Breqz([cond_num.into(), c]) }, }; cond_stmts.push(cond_stmt); } else { - let cond_stmt = Stmt::Brnez([cond_num.into(), c]); + let cond_stmt = Stmt::Breqz([cond_num.into(), c]); cond_stmts.push(cond_stmt); } cond_stmts @@ -379,6 +379,8 @@ impl Translator { shift_scopes(&mut body_lines, cond_stmts.len()); // Push backwards jump body_lines.push({ + println!("BODY_LINES {} {:?}", body_lines.len(), body_lines); + println!("COND_STMTS {} {:?}", cond_stmts.len(), cond_stmts); let jump_by = -((body_lines.len() + cond_stmts.len()) as i64); let jump_back = Arg::LineRel(jump_by.into()); let stmt = Stmt::Jr([jump_back]); diff --git a/translator/src/main.rs b/translator/src/main.rs index 0438352..2b2a879 100644 --- a/translator/src/main.rs +++ b/translator/src/main.rs @@ -5,7 +5,7 @@ fn main() { let myps_path = std::env::args().skip(1).next().unwrap(); let program_item = myps::lexer::lex_file(&myps_path).unwrap(); - println!("{:#?}", program_item); + // println!("{:#?}", program_item); // println!("================================================================================"); let mut translator = Translator::default(); @@ -73,8 +73,8 @@ fn main() { } println!("--------------------------------------------------------------------------------"); for (_i, line) in mips.lines.iter().enumerate() { - println!("{:>w$}: {}", _i, line, w = w); - // println!("{}", line); + // println!("{:>w$}: {}", _i, line, w = w); + println!("{}", line); } // println!("{}", mips.interference_graph()); // for (i, (index, (s, e))) in mips.analyze_lifetimes().iter().enumerate() {