Skip to content

Commit

Permalink
chore: remove redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
caelansar committed Dec 17, 2023
1 parent d85ce46 commit 256a8fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Evaluator {
alternative,
} => {
let cond = self.eval_expression(condition)?;
self.eval_if_expression(cond, consequence, alternative)
self.eval_if_expression(&cond, consequence, alternative)
}
ast::Expression::For {
condition,
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Evaluator {

fn eval_if_expression(
&mut self,
cond: Object,
cond: &Object,
consequence: &ast::BlockStatement,
alternative: &Option<ast::BlockStatement>,
) -> Option<Object> {
Expand All @@ -284,7 +284,7 @@ impl Evaluator {

let mut cond = self.eval_expression(condition)?;

while cond.clone().into() {
while (&cond).into() {
rv = self.eval_block_statements(consequence);
match rv {
Some(Object::Return(_)) => return rv,
Expand Down
19 changes: 9 additions & 10 deletions src/eval/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ pub struct CompiledFunction {
pub(crate) num_params: usize,
}

impl From<Object> for bool {
fn from(value: Object) -> Self {
match value {
Object::Bool(b) => b,
Object::Null => false,
_ => true,
}
}
}

impl From<&Object> for bool {
fn from(value: &Object) -> Self {
match value {
Expand Down Expand Up @@ -198,6 +188,15 @@ fn cstring_should_work() {
assert_eq!(CString("aabb".into()), s1 + s2);
}

#[test]
fn object_bool_should_work() {
let b1 = &Object::Bool(true);
let b2 = &Object::Bool(false);

assert_eq!(true, b1.into());
assert_eq!(false, b2.into());
}

#[test]
fn object_display_should_work() {
assert_eq!("123", Object::Int(123).to_string());
Expand Down

0 comments on commit 256a8fe

Please sign in to comment.