diff --git a/src/ast.rs b/src/ast.rs index 3db94b7..79aeb6f 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -55,10 +55,20 @@ pub enum Constant { String(String), } +impl Location { + pub fn new_variable(name: impl Into) -> Self { + Self::Variable { name: name.into() } + } +} + impl Expression { pub fn new_constant(value: impl Into) -> Self { Self::Constant(value.into()) } + + pub fn new_variable(name: impl Into) -> Self { + Self::Variable(Location::new_variable(name)) + } } impl From<()> for Constant { diff --git a/src/twopass.rs b/src/twopass.rs index e1067de..2b29286 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -407,7 +407,7 @@ mod tests { args: vec![], body: vec![ Statement::Assign { - target: Location::Variable { name: "x".into() }, + target: Location::new_variable("x"), source: Box::new(Expression::new_constant(1)), }, Statement::Local { @@ -415,13 +415,11 @@ mod tests { init: Some(Box::new(Expression::new_constant(2))), }, Statement::Assign { - target: Location::Variable { name: "x".into() }, + target: Location::new_variable("x"), source: Box::new(Expression::new_constant(3)), }, ], - ret: Some(Box::new(Expression::Variable(Location::Variable { - name: "x".into(), - }))), + ret: Some(Box::new(Expression::new_variable("x"))), }; let env = crate::types::Table::default(); let testee = build(&testee);