feat: better incorporation of variables defined by DAT
This commit is contained in:
parent
921136e91e
commit
23f3f0b070
1 changed files with 33 additions and 6 deletions
39
src/main.rs
39
src/main.rs
|
@ -34,16 +34,43 @@ fn main() -> Result<()> {
|
||||||
None => panic!(),
|
None => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"ADD" => accumulator += &ops[1].clone().parse::<i64>().unwrap(),
|
"ADD" => {
|
||||||
"SUB" => accumulator -= &ops[1].clone().parse::<i64>().unwrap(),
|
let addition = ops[1].clone().parse::<i64>();
|
||||||
|
if addition.is_ok() {
|
||||||
|
accumulator -= addition.unwrap();
|
||||||
|
} else {
|
||||||
|
match memory.get(&ops[1].clone()) {
|
||||||
|
Some(value) => accumulator += *value,
|
||||||
|
None => panic!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"SUB" => {
|
||||||
|
let subtract = ops[1].clone().parse::<i64>();
|
||||||
|
if subtract.is_ok() {
|
||||||
|
accumulator -= subtract.unwrap();
|
||||||
|
} else {
|
||||||
|
match memory.get(&ops[1].clone()) {
|
||||||
|
Some(value) => accumulator -= *value,
|
||||||
|
None => panic!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
"HLT" => std::process::exit(0),
|
"HLT" => std::process::exit(0),
|
||||||
&_ => {
|
&_ => {
|
||||||
match ops[1].as_str() {
|
match ops[1].as_str() {
|
||||||
"DAT" => {
|
"DAT" => {
|
||||||
memory.insert(
|
if ops.get(2).is_some() {
|
||||||
ops[0].clone(),
|
memory.insert(
|
||||||
ops[2].clone().parse::<i64>().unwrap(),
|
ops[0].clone(),
|
||||||
);
|
ops[2].clone().parse::<i64>().unwrap(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
memory.insert(
|
||||||
|
ops[0].clone(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&_ => {
|
&_ => {
|
||||||
panic!()
|
panic!()
|
||||||
|
|
Loading…
Reference in a new issue