Function negation

This commit is contained in:
Erin 2021-12-07 21:18:45 +01:00 committed by ondra05
parent 6ee12a7c91
commit 65bb29d401

View file

@ -443,7 +443,27 @@ impl ops::Not for Value {
Abool::Sometimes => Abool::Sometimes, Abool::Sometimes => Abool::Sometimes,
Abool::Always => Abool::Never, Abool::Always => Abool::Never,
}), }),
Value::Functio(_) => todo!(), Value::Functio(f) => Value::Functio(match f {
Functio::BfFunctio {
mut instructions,
tape_len,
} => {
instructions.reverse();
Functio::BfFunctio {
instructions,
tape_len,
}
}
Functio::AbleFunctio {
mut params,
mut body,
} => {
params.reverse();
body.reverse();
Functio::AbleFunctio { params, body }
}
Functio::Eval(code) => Functio::Eval(code.chars().rev().collect()),
}),
Value::Cart(c) => Value::Cart( Value::Cart(c) => Value::Cart(
c.into_iter() c.into_iter()
.map(|(k, v)| (v.borrow().clone(), Rc::new(RefCell::new(k)))) .map(|(k, v)| (v.borrow().clone(), Rc::new(RefCell::new(k))))