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 3cdca1666a
commit 3c98caf2d6
2 changed files with 20 additions and 20 deletions

View file

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

View file

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