diff options
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 6 | ||||
-rw-r--r-- | tvix/eval/src/value/mod.rs | 15 | ||||
-rw-r--r-- | tvix/eval/src/value/string.rs | 2 | ||||
-rw-r--r-- | tvix/eval/src/vm.rs | 4 |
4 files changed, 21 insertions, 6 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 69688d3c5122..1658d69c7ee7 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -34,3 +34,9 @@ impl Display for NixAttrs { f.write_str("}") } } + +impl PartialEq for NixAttrs { + fn eq(&self, _other: &Self) -> bool { + todo!("attrset equality") + } +} diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 628eefb8fdd8..ea0c89e6b6c4 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -1,18 +1,23 @@ //! This module implements the backing representation of runtime //! values in the Nix language. use std::fmt::Display; - -use crate::errors::{Error, EvalResult}; +use std::rc::Rc; mod attrs; mod string; -#[derive(Clone, Copy, Debug, PartialEq)] +use crate::errors::{Error, EvalResult}; +use attrs::NixAttrs; +use string::NixString; + +#[derive(Clone, Debug, PartialEq)] pub enum Value { Null, Bool(bool), Integer(i64), Float(f64), + String(NixString), + Attrs(Rc<NixAttrs>), } impl Value { @@ -30,6 +35,8 @@ impl Value { Value::Bool(_) => "bool", Value::Integer(_) => "int", Value::Float(_) => "float", + Value::String(_) => "string", + Value::Attrs(_) => "set", } } @@ -52,6 +59,8 @@ impl Display for Value { Value::Bool(false) => f.write_str("false"), Value::Integer(num) => f.write_fmt(format_args!("{}", num)), Value::Float(num) => f.write_fmt(format_args!("{}", num)), + Value::String(s) => s.fmt(f), + Value::Attrs(attrs) => attrs.fmt(f), } } } diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index c123fc3ee132..7e6f5ecf3bd3 100644 --- a/tvix/eval/src/value/string.rs +++ b/tvix/eval/src/value/string.rs @@ -3,7 +3,7 @@ use std::fmt::Display; /// This module implements Nix language strings and their different /// backing implementations. -#[derive(Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq)] pub struct NixString(String); impl Display for NixString { diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 6841ac4706b3..9a718500b5f1 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -36,7 +36,7 @@ impl VM { (Value::Float(f1), Value::Integer(i2)) => Ok(NumberPair::Floats(f1, i2 as f64)), - _ => Err(Error::TypeError { + (v1, v2) => Err(Error::TypeError { expected: "number (either int or float)", actual: if v1.is_number() { v2.type_of() @@ -105,7 +105,7 @@ impl VM { (Value::Float(f), Value::Integer(i)) | (Value::Integer(i), Value::Float(f)) => f == (i as f64), - _ => v2 == v2, + (v1, v2) => v1 == v2, }; self.push(Value::Bool(eq)) |