Add constructors for Value type enum variants

This commit is contained in:
bad 2022-04-05 23:12:13 +02:00
parent 2c2cb00e2e
commit df22460010
2 changed files with 25 additions and 4 deletions

View file

@ -23,3 +23,27 @@ impl From<astnode::Literal> for Value {
) )
} }
} }
impl Value {
pub fn int(i: i32) -> Value {
Value::Primitive(Primitive::Int(i))
}
pub fn float(f: f32) -> Value {
Value::Primitive(Primitive::Float(f))
}
pub fn bool(b: bool) -> Value {
Value::Primitive(Primitive::Bool(b))
}
pub fn null() -> Value {
Value::Primitive(Primitive::Null)
}
}
impl Default for Value {
fn default() -> Self {
Self::null()
}
}

View file

@ -12,8 +12,5 @@ fn test_one_equality() {
} }
fn run_check_result_eq_bool(code: &str, value: bool) { fn run_check_result_eq_bool(code: &str, value: bool) {
assert_eq!( assert_eq!(run(code).unwrap(), types::Value::bool(value))
run(code).unwrap(),
types::Value::Primitive(types::Primitive::Bool(value))
)
} }