Fixed all errors

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

View file

@ -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 {

View file

@ -176,11 +176,13 @@ impl Value {
Functio::Bf {
instructions,
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 } => {
params
.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>()
+ 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()))),
)
})