diff --git a/src/interpret.rs b/src/interpret.rs index f4052ab6..bf3e49e5 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -143,8 +143,8 @@ impl ExecEnv { match kind { // Arithmetic operators. Add | Subtract | Multiply | Divide => { - let lhs = lhs.into_i32(); - let rhs = rhs.into_i32(); + let lhs = lhs.to_i32(); + let rhs = rhs.to_i32(); let res = match kind { Add => lhs.checked_add(rhs), @@ -159,8 +159,8 @@ impl ExecEnv { // Numeric comparisons. Less | Greater => { - let lhs = lhs.into_i32(); - let rhs = rhs.into_i32(); + let lhs = lhs.to_i32(); + let rhs = rhs.to_i32(); let res = match kind { Less => lhs < rhs, @@ -182,8 +182,8 @@ impl ExecEnv { // Logical connectives. And | Or => { - let lhs = lhs.into_bool(); - let rhs = rhs.into_bool(); + let lhs = lhs.to_bool(); + let rhs = rhs.to_bool(); let res = match kind { And => lhs && rhs, Or => lhs || rhs, @@ -193,7 +193,7 @@ impl ExecEnv { } } } - Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()), + Not(expr) => Bool(!self.eval_expr(expr)?.to_bool()), Literal(value) => value.clone(), ExprKind::Cart(members) => Value::Cart( members @@ -257,13 +257,13 @@ impl ExecEnv { instructions: code.to_owned(), tape_len: tape_len .as_ref() - .map(|tape_len| self.eval_expr(tape_len).map(|v| v.into_i32() as usize)) + .map(|tape_len| self.eval_expr(tape_len).map(|v| v.to_i32() as usize)) .unwrap_or(Ok(crate::brian::DEFAULT_TAPE_SIZE_LIMIT))?, }), ); } StmtKind::If { cond, body } => { - if self.eval_expr(cond)?.into_bool() { + if self.eval_expr(cond)?.to_bool() { return self.eval_stmts_hs(&body.block, true); } } diff --git a/src/variables.rs b/src/variables.rs index 3fda15dc..499c6343 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -96,12 +96,12 @@ impl Value { /// any IO errors will cause a panic. pub fn bf_write(&self, stream: &mut impl Write) { stream - .write_all(&[self.clone().into_i32() as u8]) + .write_all(&[self.clone().to_i32() as u8]) .expect("Failed to write to Brainfuck input"); } /// Coerce a value to an integer. - pub fn into_i32(&self) -> i32 { + pub fn to_i32(&self) -> i32 { match self { Value::Abool(a) => *a as _, Value::Bool(b) => *b as _, @@ -120,7 +120,7 @@ impl Value { } /// Coerce a Value to a boolean. The conversion cannot fail. - pub fn into_bool(&self) -> bool { + pub fn to_bool(&self) -> bool { match self { Value::Abool(b) => (*b).into(), Value::Bool(b) => *b, @@ -136,14 +136,14 @@ impl Value { pub fn index(&self, index: &Value) -> Rc> { Rc::new(RefCell::new(match self { Value::Nul => Value::Nul, - Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), + Value::Str(s) => Value::Int(s.as_bytes()[index.to_i32() as usize] as i32), Value::Int(i) => Value::Int( - (format!("{}", i).as_bytes()[index.into_i32() as usize] - b'0') as i32, + (format!("{}", i).as_bytes()[index.to_i32() as usize] - b'0') as i32, ), Value::Bool(b) => Value::Int( format!("{}", b) .chars() - .nth(index.into_i32() as usize) + .nth(index.to_i32() as usize) .unwrap_or('?') as i32, ), Value::Abool(b) => Value::Int(*b as i32),