Fixed all errors

This commit is contained in:
Erin 2022-02-13 00:58:50 +01:00 committed by ondra05
parent bf0e64c26a
commit a636c5926d
2 changed files with 19 additions and 19 deletions

View file

@ -273,7 +273,7 @@ impl ExecEnv {
let mut value = 0; let mut value = 0;
for _ in 0..READ_BITS { for _ in 0..READ_BITS {
value <<= 1; value <<= 1;
value += self.get_bit()? as i32; value += self.get_bit()? as isize;
} }
self.assign(assignable, Value::Int(value))?; self.assign(assignable, Value::Int(value))?;
@ -644,7 +644,7 @@ mod tests {
env.eval_expr(&Expr { env.eval_expr(&Expr {
kind: ExprKind::BinOp { kind: ExprKind::BinOp {
lhs: Box::new(Expr { lhs: Box::new(Expr {
kind: ExprKind::Literal(Value::Int(i32::MAX)), kind: ExprKind::Literal(Value::Int(isize::MAX)),
span: 1..1, span: 1..1,
}), }),
rhs: Box::new(Expr { rhs: Box::new(Expr {

View file

@ -176,11 +176,13 @@ impl Value {
Functio::Bf { Functio::Bf {
instructions, instructions,
tape_len, tape_len,
} => instructions.into_iter().map(|x| x as isize).sum::<isize>() * tape_len as isize, } => {
instructions.into_iter().map(|x| x as isize).sum::<isize>() * tape_len as isize
}
Functio::Able { params, body } => { Functio::Able { params, body } => {
params params
.into_iter() .into_iter()
.map(|x| x.bytes().map(|x| x as i32).sum::<i32>()) .map(|x| x.bytes().map(|x| x as isize).sum::<isize>())
.sum::<isize>() .sum::<isize>()
+ body.len() as isize + body.len() as isize
} }
@ -261,14 +263,14 @@ impl Value {
) )
.into_abool(), .into_abool(),
Functio::Able { params, body } => { Functio::Able { params, body } => {
let str_to_i32 = let str_to_isize =
|x: String| -> i32 { x.as_bytes().into_iter().map(|x| *x as i32).sum() }; |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 params: isize = params.into_iter().map(str_to_isize).sum();
let body: i32 = body let body: isize = body
.into_iter() .into_iter()
.map(|x| format!("{:?}", x)) .map(|x| format!("{:?}", x))
.map(str_to_i32) .map(str_to_isize)
.sum(); .sum();
Value::Int((params + body) % 3 - 1).into_abool() Value::Int((params + body) % 3 - 1).into_abool()
@ -373,7 +375,7 @@ impl Value {
.enumerate() .enumerate()
.map(|(i, x)| { .map(|(i, x)| {
( (
Value::Int(i as i32 + 1), Value::Int(i as isize + 1),
Rc::new(RefCell::new(Value::Str(x.to_string()))), Rc::new(RefCell::new(Value::Str(x.to_string()))),
) )
}) })
@ -388,7 +390,7 @@ impl Value {
.enumerate() .enumerate()
.map(|(i, x)| { .map(|(i, x)| {
( (
Value::Int(i as i32 + 1), Value::Int(i as isize + 1),
Rc::new(RefCell::new(Value::Str(x))), Rc::new(RefCell::new(Value::Str(x))),
) )
}) })
@ -399,7 +401,7 @@ impl Value {
.enumerate() .enumerate()
.map(|(i, x)| { .map(|(i, x)| {
( (
Value::Int(i as i32 + 1), Value::Int(i as isize + 1),
Rc::new(RefCell::new(Value::Str(format!("{:?}", x)))), Rc::new(RefCell::new(Value::Str(format!("{:?}", x)))),
) )
}) })
@ -427,7 +429,7 @@ impl Value {
.enumerate() .enumerate()
.map(|(i, x)| { .map(|(i, x)| {
( (
Value::Int(i as i32 + 1), Value::Int(i as isize + 1),
Rc::new(RefCell::new( Rc::new(RefCell::new(
char::from_u32(x as u32) char::from_u32(x as u32)
.map(|x| Value::Str(x.to_string())) .map(|x| Value::Str(x.to_string()))
@ -480,7 +482,7 @@ impl Value {
} }
/// Get a lenght of a value /// Get a lenght of a value
pub fn len(&self) -> i32 { pub fn len(&self) -> isize {
match self { match self {
Value::Nul => 0, Value::Nul => 0,
Value::Str(s) => s.len() as _, Value::Str(s) => s.len() as _,
@ -508,9 +510,7 @@ impl Value {
tape_len, tape_len,
} => (instructions.len() + tape_len) as _, } => (instructions.len() + tape_len) as _,
Functio::Able { params, body } => (params.len() + format!("{:?}", body).len()) as _, Functio::Able { params, body } => (params.len() + format!("{:?}", body).len()) as _,
Functio::Builtin(b) => { Functio::Builtin(b) => (std::mem::size_of_val(b.function.as_ref()) + b.arity) as _,
(std::mem::size_of_val(b.function.as_ref()) + b.arity) as i32
}
Functio::Chain { functios, kind } => { Functio::Chain { functios, kind } => {
let (lhs, rhs) = *functios.clone(); let (lhs, rhs) = *functios.clone();
match kind { match kind {
@ -746,7 +746,7 @@ impl ops::Div for Value {
.enumerate() .enumerate()
.map(|(i, x)| { .map(|(i, x)| {
( (
Value::Int(i as i32 + 1), Value::Int(i as isize + 1),
Rc::new(RefCell::new(Value::Str(x.to_owned()))), Rc::new(RefCell::new(Value::Str(x.to_owned()))),
) )
}) })
@ -815,7 +815,7 @@ impl ops::Div for Value {
.enumerate() .enumerate()
.map(|(k, v)| { .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()))), Rc::new(RefCell::new(Value::Cart(v.iter().cloned().collect()))),
) )
}) })