feat(tvix/eval): introduce initial Lambda
type
Change-Id: Ifa9766f5ffeff99e926936bafd697e885e733b78 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6238 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
3ed40b4eea
commit
d57366a6c2
2 changed files with 18 additions and 0 deletions
12
tvix/eval/src/value/lambda.rs
Normal file
12
tvix/eval/src/value/lambda.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
//! This module implements the runtime representation of functions.
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use crate::chunk::Chunk;
|
||||||
|
|
||||||
|
use super::NixString;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Lambda {
|
||||||
|
name: Option<NixString>,
|
||||||
|
chunk: Rc<Chunk>,
|
||||||
|
}
|
|
@ -4,11 +4,13 @@ use std::rc::Rc;
|
||||||
use std::{fmt::Display, path::PathBuf};
|
use std::{fmt::Display, path::PathBuf};
|
||||||
|
|
||||||
mod attrs;
|
mod attrs;
|
||||||
|
mod lambda;
|
||||||
mod list;
|
mod list;
|
||||||
mod string;
|
mod string;
|
||||||
|
|
||||||
use crate::errors::{ErrorKind, EvalResult};
|
use crate::errors::{ErrorKind, EvalResult};
|
||||||
pub use attrs::NixAttrs;
|
pub use attrs::NixAttrs;
|
||||||
|
pub use lambda::Lambda;
|
||||||
pub use list::NixList;
|
pub use list::NixList;
|
||||||
pub use string::NixString;
|
pub use string::NixString;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ pub enum Value {
|
||||||
Path(PathBuf),
|
Path(PathBuf),
|
||||||
Attrs(Rc<NixAttrs>),
|
Attrs(Rc<NixAttrs>),
|
||||||
List(NixList),
|
List(NixList),
|
||||||
|
Lambda(Lambda),
|
||||||
|
|
||||||
// Internal values that, while they technically exist at runtime,
|
// Internal values that, while they technically exist at runtime,
|
||||||
// are never returned to or created directly by users.
|
// are never returned to or created directly by users.
|
||||||
|
@ -46,6 +49,7 @@ impl Value {
|
||||||
Value::Path(_) => "path",
|
Value::Path(_) => "path",
|
||||||
Value::Attrs(_) => "set",
|
Value::Attrs(_) => "set",
|
||||||
Value::List(_) => "list",
|
Value::List(_) => "list",
|
||||||
|
Value::Lambda(_) => "lambda",
|
||||||
|
|
||||||
// Internal types
|
// Internal types
|
||||||
Value::AttrPath(_) | Value::Blackhole | Value::NotFound => "internal",
|
Value::AttrPath(_) | Value::Blackhole | Value::NotFound => "internal",
|
||||||
|
@ -123,6 +127,7 @@ impl Display for Value {
|
||||||
Value::Path(p) => p.display().fmt(f),
|
Value::Path(p) => p.display().fmt(f),
|
||||||
Value::Attrs(attrs) => attrs.fmt(f),
|
Value::Attrs(attrs) => attrs.fmt(f),
|
||||||
Value::List(list) => list.fmt(f),
|
Value::List(list) => list.fmt(f),
|
||||||
|
Value::Lambda(_) => f.write_str("lambda"), // TODO: print position
|
||||||
|
|
||||||
// Nix prints floats with a maximum precision of 5 digits
|
// Nix prints floats with a maximum precision of 5 digits
|
||||||
// only.
|
// only.
|
||||||
|
@ -158,6 +163,7 @@ impl PartialEq for Value {
|
||||||
|
|
||||||
// Everything else is either incomparable (e.g. internal
|
// Everything else is either incomparable (e.g. internal
|
||||||
// types) or false.
|
// types) or false.
|
||||||
|
// TODO(tazjin): mirror Lambda equality behaviour
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue