From a636c5926da74867b4c7f30b3a7cf9f69da0ce86 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 13 Feb 2022 00:58:50 +0100 Subject: [PATCH] Fixed all errors --- ablescript/src/interpret.rs | 4 ++-- ablescript/src/variables.rs | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index d1eb20c..a2239e2 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -273,7 +273,7 @@ impl ExecEnv { let mut value = 0; for _ in 0..READ_BITS { value <<= 1; - value += self.get_bit()? as i32; + value += self.get_bit()? as isize; } self.assign(assignable, Value::Int(value))?; @@ -644,7 +644,7 @@ mod tests { env.eval_expr(&Expr { kind: ExprKind::BinOp { lhs: Box::new(Expr { - kind: ExprKind::Literal(Value::Int(i32::MAX)), + kind: ExprKind::Literal(Value::Int(isize::MAX)), span: 1..1, }), rhs: Box::new(Expr { diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index cb5a9f6..198361c 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -176,11 +176,13 @@ impl Value { Functio::Bf { instructions, tape_len, - } => instructions.into_iter().map(|x| x as isize).sum::() * tape_len as isize, + } => { + instructions.into_iter().map(|x| x as isize).sum::() * tape_len as isize + } Functio::Able { params, body } => { params .into_iter() - .map(|x| x.bytes().map(|x| x as i32).sum::()) + .map(|x| x.bytes().map(|x| x as isize).sum::()) .sum::() + body.len() as isize } @@ -261,14 +263,14 @@ impl Value { ) .into_abool(), Functio::Able { params, body } => { - let str_to_i32 = - |x: String| -> i32 { x.as_bytes().into_iter().map(|x| *x as i32).sum() }; + let str_to_isize = + |x: String| -> isize { x.as_bytes().into_iter().map(|x| *x as isize).sum() }; - let params: i32 = params.into_iter().map(str_to_i32).sum(); - let body: i32 = body + let params: isize = params.into_iter().map(str_to_isize).sum(); + let body: isize = body .into_iter() .map(|x| format!("{:?}", x)) - .map(str_to_i32) + .map(str_to_isize) .sum(); Value::Int((params + body) % 3 - 1).into_abool() @@ -373,7 +375,7 @@ impl Value { .enumerate() .map(|(i, x)| { ( - Value::Int(i as i32 + 1), + Value::Int(i as isize + 1), Rc::new(RefCell::new(Value::Str(x.to_string()))), ) }) @@ -388,7 +390,7 @@ impl Value { .enumerate() .map(|(i, x)| { ( - Value::Int(i as i32 + 1), + Value::Int(i as isize + 1), Rc::new(RefCell::new(Value::Str(x))), ) }) @@ -399,7 +401,7 @@ impl Value { .enumerate() .map(|(i, x)| { ( - Value::Int(i as i32 + 1), + Value::Int(i as isize + 1), Rc::new(RefCell::new(Value::Str(format!("{:?}", x)))), ) }) @@ -427,7 +429,7 @@ impl Value { .enumerate() .map(|(i, x)| { ( - Value::Int(i as i32 + 1), + Value::Int(i as isize + 1), Rc::new(RefCell::new( char::from_u32(x as u32) .map(|x| Value::Str(x.to_string())) @@ -480,7 +482,7 @@ impl Value { } /// Get a lenght of a value - pub fn len(&self) -> i32 { + pub fn len(&self) -> isize { match self { Value::Nul => 0, Value::Str(s) => s.len() as _, @@ -508,9 +510,7 @@ impl Value { tape_len, } => (instructions.len() + tape_len) as _, Functio::Able { params, body } => (params.len() + format!("{:?}", body).len()) as _, - Functio::Builtin(b) => { - (std::mem::size_of_val(b.function.as_ref()) + b.arity) as i32 - } + Functio::Builtin(b) => (std::mem::size_of_val(b.function.as_ref()) + b.arity) as _, Functio::Chain { functios, kind } => { let (lhs, rhs) = *functios.clone(); match kind { @@ -746,7 +746,7 @@ impl ops::Div for Value { .enumerate() .map(|(i, x)| { ( - Value::Int(i as i32 + 1), + Value::Int(i as isize + 1), Rc::new(RefCell::new(Value::Str(x.to_owned()))), ) }) @@ -815,7 +815,7 @@ impl ops::Div for Value { .enumerate() .map(|(k, v)| { ( - Value::Int(k as i32 + 1), + Value::Int(k as isize + 1), Rc::new(RefCell::new(Value::Cart(v.iter().cloned().collect()))), ) })