Made Clippy happy (so he will not kill us in sleep)

This commit is contained in:
Erin 2021-12-08 22:56:12 +01:00 committed by ondra05
parent 8993e78ee6
commit 920ff99a7f
2 changed files with 20 additions and 20 deletions

View file

@ -205,7 +205,7 @@ impl ExecEnv {
} => {
self.decl_var(
&ident.ident,
Value::Functio(Functio::AbleFunctio {
Value::Functio(Functio::Able {
params: params.iter().map(|ident| ident.ident.to_owned()).collect(),
body: body.block.to_owned(),
}),
@ -218,7 +218,7 @@ impl ExecEnv {
} => {
self.decl_var(
&ident.ident,
Value::Functio(Functio::BfFunctio {
Value::Functio(Functio::Bf {
instructions: code.to_owned(),
tape_len: tape_len
.as_ref()
@ -351,7 +351,7 @@ impl ExecEnv {
.collect::<Result<Vec<_>, Error>>()?;
match func {
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
} => {
@ -377,7 +377,7 @@ impl ExecEnv {
.write_all(&output)
.expect("Failed to write to stdout");
}
Functio::AbleFunctio { params, body } => {
Functio::Able { params, body } => {
if params.len() != args.len() {
return Err(Error {
kind: ErrorKind::MismatchedArgumentError,

View file

@ -36,11 +36,11 @@ impl From<Abool> for bool {
#[derive(Debug, PartialEq, Clone, Hash)]
pub enum Functio {
BfFunctio {
Bf {
instructions: Vec<u8>,
tape_len: usize,
},
AbleFunctio {
Able {
params: Vec<String>,
body: Vec<Stmt>,
},
@ -103,11 +103,11 @@ impl Value {
// BfFunctio - Sum of lengths of instructions and length of tape
// AbleFunctio - Sum of argument count and body length
// Eval - Length of input code
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
} => (instructions.len() + tape_len) as _,
Functio::AbleFunctio { params, body } => {
Functio::Able { params, body } => {
(params.len() + format!("{:?}", body).len()) as _
}
Functio::Eval(s) => s.len() as _,
@ -166,14 +166,14 @@ impl Value {
}
Value::Abool(a) => a,
Value::Functio(f) => match f {
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
} => Value::Int(
(instructions.iter().map(|x| *x as usize).sum::<usize>() * tape_len) as _,
)
.into_abool(),
Functio::AbleFunctio { params, body } => {
Functio::Able { params, body } => {
let str_to_i32 =
|x: String| -> i32 { x.as_bytes().into_iter().map(|x| *x as i32).sum() };
@ -201,12 +201,12 @@ impl Value {
/// Coerce a value to a functio.
pub fn into_functio(self) -> Functio {
match self {
Value::Nul => Functio::AbleFunctio {
Value::Nul => Functio::Able {
body: vec![],
params: vec![],
},
Value::Str(s) => Functio::Eval(s),
Value::Int(i) => Functio::BfFunctio {
Value::Int(i) => Functio::Bf {
instructions: {
let instruction_mappings = b"[]+-,.<>";
std::iter::successors(Some(i as usize), |i| {
@ -260,7 +260,7 @@ impl Value {
Value::Bool(b) => Value::Str(b.to_string()).into_cart(),
Value::Abool(a) => Value::Str(a.to_string()).into_cart(),
Value::Functio(f) => match f {
Functio::AbleFunctio { params, body } => {
Functio::Able { params, body } => {
let params: Cart = params
.into_iter()
.enumerate()
@ -296,7 +296,7 @@ impl Value {
cart
}
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
} => {
@ -494,25 +494,25 @@ impl ops::Not for Value {
Abool::Always => Abool::Never,
}),
Value::Functio(f) => Value::Functio(match f {
Functio::BfFunctio {
Functio::Bf {
mut instructions,
tape_len,
} => {
instructions.reverse();
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
}
}
Functio::AbleFunctio {
Functio::Able {
mut params,
mut body,
} => {
params.reverse();
body.reverse();
Functio::AbleFunctio { params, body }
Functio::Able { params, body }
}
Functio::Eval(code) => Functio::Eval(code.chars().rev().collect()),
}),
@ -575,7 +575,7 @@ impl Display for Value {
Value::Bool(v) => write!(f, "{}", v),
Value::Abool(v) => write!(f, "{}", v),
Value::Functio(v) => match v {
Functio::BfFunctio {
Functio::Bf {
instructions,
tape_len,
} => {
@ -587,7 +587,7 @@ impl Display for Value {
.expect("Brainfuck functio source should be UTF-8")
)
}
Functio::AbleFunctio { params, body } => {
Functio::Able { params, body } => {
write!(
f,
"({}) -> {:?}",