diff --git a/src/ast.rs b/src/ast.rs index 9beac82..3ef4eb6 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -39,7 +39,7 @@ pub struct BlockStatement { #[derive(Debug, Eq, Clone, PartialEq)] pub enum Statement { ReturnStatement(Expression), - LetStatement { name: Expression, value: Expression }, + LetStatement { name: Box, value: Box }, } #[derive(Debug, Eq, Clone, PartialEq)] diff --git a/src/evaluator.rs b/src/evaluator.rs index 9e0c289..8d03695 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -157,12 +157,12 @@ impl Evaluator { Object::Return(Box::new(result_object)) } Statement::LetStatement { name, value } => { - let let_name = match name { + let let_name = match *name { Expression::Identifier(identifier_name) => identifier_name, _ => panic!(), }; - let result_object = self.eval(AstNode::Expression(value)); + let result_object = self.eval(AstNode::Expression(*value)); self.context.insert(let_name.clone(), result_object.clone()); result_object } diff --git a/src/parser.rs b/src/parser.rs index a74fbe4..d95c528 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -80,7 +80,7 @@ impl Parser { return None; } - let name = self.parse_identifier()?; + let name = Box::new(self.parse_identifier()?); self.advance_tokens(); @@ -91,7 +91,7 @@ impl Parser { self.advance_tokens(); - let value = self.parse_expression(Precedence::Lowest)?; + let value = Box::new(self.parse_expression(Precedence::Lowest)?); self.advance_tokens(); diff --git a/tests/parser.rs b/tests/parser.rs index 3d9a75a..ed4625b 100644 --- a/tests/parser.rs +++ b/tests/parser.rs @@ -31,8 +31,8 @@ fn given_let_statements_with_single_integers_shold_parse_correctly() { let expected_int = expected_ints.get(idx).unwrap(); let expected_statement = AstNode::Statement(Statement::LetStatement { - name: Expression::Identifier(expected_identifier.to_string()), - value: Expression::Int(expected_int.to_string().parse().unwrap()), + name: Box::new(Expression::Identifier(expected_identifier.to_string())), + value: Box::new(Expression::Int(expected_int.to_string().parse().unwrap())), }); assert_eq!(*statement, expected_statement);