Skip to content

Commit

Permalink
Fix transform_condition (was using Brnez for default instead of Breqz)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsso committed Jul 29, 2021
1 parent c634f1a commit 1f65306
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 16 additions & 0 deletions myps/test-scripts/factory/gas.myps
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions translator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand Down
6 changes: 3 additions & 3 deletions translator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1f65306

Please sign in to comment.