Changed to correct naming conventions

This commit is contained in:
Erin 2021-07-29 23:26:43 +02:00 committed by ondra05
parent b451503a27
commit 25a3c14145
2 changed files with 15 additions and 15 deletions

View file

@ -143,8 +143,8 @@ impl ExecEnv {
match kind { match kind {
// Arithmetic operators. // Arithmetic operators.
Add | Subtract | Multiply | Divide => { Add | Subtract | Multiply | Divide => {
let lhs = lhs.into_i32(); let lhs = lhs.to_i32();
let rhs = rhs.into_i32(); let rhs = rhs.to_i32();
let res = match kind { let res = match kind {
Add => lhs.checked_add(rhs), Add => lhs.checked_add(rhs),
@ -159,8 +159,8 @@ impl ExecEnv {
// Numeric comparisons. // Numeric comparisons.
Less | Greater => { Less | Greater => {
let lhs = lhs.into_i32(); let lhs = lhs.to_i32();
let rhs = rhs.into_i32(); let rhs = rhs.to_i32();
let res = match kind { let res = match kind {
Less => lhs < rhs, Less => lhs < rhs,
@ -182,8 +182,8 @@ impl ExecEnv {
// Logical connectives. // Logical connectives.
And | Or => { And | Or => {
let lhs = lhs.into_bool(); let lhs = lhs.to_bool();
let rhs = rhs.into_bool(); let rhs = rhs.to_bool();
let res = match kind { let res = match kind {
And => lhs && rhs, And => lhs && rhs,
Or => 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(), Literal(value) => value.clone(),
ExprKind::Cart(members) => Value::Cart( ExprKind::Cart(members) => Value::Cart(
members members
@ -257,13 +257,13 @@ impl ExecEnv {
instructions: code.to_owned(), instructions: code.to_owned(),
tape_len: tape_len tape_len: tape_len
.as_ref() .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))?, .unwrap_or(Ok(crate::brian::DEFAULT_TAPE_SIZE_LIMIT))?,
}), }),
); );
} }
StmtKind::If { cond, body } => { 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); return self.eval_stmts_hs(&body.block, true);
} }
} }

View file

@ -96,12 +96,12 @@ impl Value {
/// any IO errors will cause a panic. /// any IO errors will cause a panic.
pub fn bf_write(&self, stream: &mut impl Write) { pub fn bf_write(&self, stream: &mut impl Write) {
stream stream
.write_all(&[self.clone().into_i32() as u8]) .write_all(&[self.clone().to_i32() as u8])
.expect("Failed to write to Brainfuck input"); .expect("Failed to write to Brainfuck input");
} }
/// Coerce a value to an integer. /// Coerce a value to an integer.
pub fn into_i32(&self) -> i32 { pub fn to_i32(&self) -> i32 {
match self { match self {
Value::Abool(a) => *a as _, Value::Abool(a) => *a as _,
Value::Bool(b) => *b as _, Value::Bool(b) => *b as _,
@ -120,7 +120,7 @@ impl Value {
} }
/// Coerce a Value to a boolean. The conversion cannot fail. /// Coerce a Value to a boolean. The conversion cannot fail.
pub fn into_bool(&self) -> bool { pub fn to_bool(&self) -> bool {
match self { match self {
Value::Abool(b) => (*b).into(), Value::Abool(b) => (*b).into(),
Value::Bool(b) => *b, Value::Bool(b) => *b,
@ -136,14 +136,14 @@ impl Value {
pub fn index(&self, index: &Value) -> Rc<RefCell<Value>> { pub fn index(&self, index: &Value) -> Rc<RefCell<Value>> {
Rc::new(RefCell::new(match self { Rc::new(RefCell::new(match self {
Value::Nul => Value::Nul, 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( 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( Value::Bool(b) => Value::Int(
format!("{}", b) format!("{}", b)
.chars() .chars()
.nth(index.into_i32() as usize) .nth(index.to_i32() as usize)
.unwrap_or('?') as i32, .unwrap_or('?') as i32,
), ),
Value::Abool(b) => Value::Int(*b as i32), Value::Abool(b) => Value::Int(*b as i32),