Function negation

pull/1/head
ondra05 2021-12-07 21:18:45 +01:00
parent 2faf90430e
commit 2d1d0eef5e
1 changed files with 21 additions and 1 deletions

View File

@ -443,7 +443,27 @@ impl ops::Not for Value {
Abool::Sometimes => Abool::Sometimes,
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(
c.into_iter()
.map(|(k, v)| (v.borrow().clone(), Rc::new(RefCell::new(k))))