diff --git a/src/interpreter/types.rs b/src/interpreter/types.rs index e23878b..c55e432 100644 --- a/src/interpreter/types.rs +++ b/src/interpreter/types.rs @@ -23,3 +23,27 @@ impl From 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() + } +} diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 357aacb..1650aef 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -12,8 +12,5 @@ fn test_one_equality() { } fn run_check_result_eq_bool(code: &str, value: bool) { - assert_eq!( - run(code).unwrap(), - types::Value::Primitive(types::Primitive::Bool(value)) - ) + assert_eq!(run(code).unwrap(), types::Value::bool(value)) }