add ::new_variable

This commit is contained in:
numzero 2025-04-19 14:35:13 +03:00
parent 0c01a4a958
commit febe0e9dd8
2 changed files with 13 additions and 5 deletions

View File

@ -55,10 +55,20 @@ pub enum Constant {
String(String),
}
impl Location {
pub fn new_variable(name: impl Into<String>) -> Self {
Self::Variable { name: name.into() }
}
}
impl Expression {
pub fn new_constant(value: impl Into<Constant>) -> Self {
Self::Constant(value.into())
}
pub fn new_variable(name: impl Into<String>) -> Self {
Self::Variable(Location::new_variable(name))
}
}
impl From<()> for Constant {

View File

@ -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);