feat(tvix/value): add runtime representation of simple lists
There might be more logic in the future to encapsulate different backing implementations of lists as well. Change-Id: Ib7064fab48bf88b0c8913b0ecfa2108177c7c9fd Reviewed-on: https://cl.tvl.fyi/c/depot/+/6093 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
6f13c16f28
commit
c67747cbe1
2 changed files with 19 additions and 0 deletions
14
tvix/eval/src/value/list.rs
Normal file
14
tvix/eval/src/value/list.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/// This module implements Nix lists.
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use super::Value;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct NixList(pub Vec<Value>);
|
||||||
|
|
||||||
|
impl Display for NixList {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
// TODO(tazjin): format lists properly
|
||||||
|
f.write_fmt(format_args!("<list({})>", self.0.len()))
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,12 @@ use std::fmt::Display;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
mod attrs;
|
mod attrs;
|
||||||
|
mod list;
|
||||||
mod string;
|
mod string;
|
||||||
|
|
||||||
use crate::errors::{Error, EvalResult};
|
use crate::errors::{Error, EvalResult};
|
||||||
pub use attrs::NixAttrs;
|
pub use attrs::NixAttrs;
|
||||||
|
pub use list::NixList;
|
||||||
pub use string::NixString;
|
pub use string::NixString;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
@ -18,6 +20,7 @@ pub enum Value {
|
||||||
Float(f64),
|
Float(f64),
|
||||||
String(NixString),
|
String(NixString),
|
||||||
Attrs(Rc<NixAttrs>),
|
Attrs(Rc<NixAttrs>),
|
||||||
|
List(NixList),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
|
@ -37,6 +40,7 @@ impl Value {
|
||||||
Value::Float(_) => "float",
|
Value::Float(_) => "float",
|
||||||
Value::String(_) => "string",
|
Value::String(_) => "string",
|
||||||
Value::Attrs(_) => "set",
|
Value::Attrs(_) => "set",
|
||||||
|
Value::List(_) => "list",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +75,7 @@ impl Display for Value {
|
||||||
Value::Float(num) => f.write_fmt(format_args!("{}", num)),
|
Value::Float(num) => f.write_fmt(format_args!("{}", num)),
|
||||||
Value::String(s) => s.fmt(f),
|
Value::String(s) => s.fmt(f),
|
||||||
Value::Attrs(attrs) => attrs.fmt(f),
|
Value::Attrs(attrs) => attrs.fmt(f),
|
||||||
|
Value::List(list) => list.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue