about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-24T08·00+0300
committertazjin <tazjin@tvl.su>2022-09-02T12·59+0000
commite0f1356ae31783664f597b33f8b69b060a9e3033 (patch)
tree54dc3a82429b2844b2c443ab9eb0911fc78f1615 /tvix/eval/src/value/mod.rs
parent64746388e2c81c3dac7f520c40a4c4aacb3dc376 (diff)
feat(tvix/eval): add initial representation of builtins r/4585
Builtins are represented as a Rust function pointer that accepts a
vector of arguments, which represents variable arity builtins.

Change-Id: Ibab7e662a646caf1172695d876d2f55e187c03dd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6251
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r--tvix/eval/src/value/mod.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index 2177ca26d904..bf07c5d326d0 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -4,12 +4,14 @@ use std::rc::Rc;
 use std::{fmt::Display, path::PathBuf};
 
 mod attrs;
+mod builtin;
 mod lambda;
 mod list;
 mod string;
 
 use crate::errors::{ErrorKind, EvalResult};
 pub use attrs::NixAttrs;
+pub use builtin::Builtin;
 pub use lambda::Lambda;
 pub use list::NixList;
 pub use string::NixString;
@@ -26,6 +28,7 @@ pub enum Value {
     Attrs(Rc<NixAttrs>),
     List(NixList),
     Lambda(Lambda),
+    Builtin(Builtin),
 
     // Internal values that, while they technically exist at runtime,
     // are never returned to or created directly by users.
@@ -49,7 +52,7 @@ impl Value {
             Value::Path(_) => "path",
             Value::Attrs(_) => "set",
             Value::List(_) => "list",
-            Value::Lambda(_) => "lambda",
+            Value::Lambda(_) | Value::Builtin(_) => "lambda",
 
             // Internal types
             Value::AttrPath(_) | Value::Blackhole | Value::NotFound => "internal",
@@ -128,6 +131,7 @@ impl Display for Value {
             Value::Attrs(attrs) => attrs.fmt(f),
             Value::List(list) => list.fmt(f),
             Value::Lambda(_) => f.write_str("lambda"), // TODO: print position
+            Value::Builtin(builtin) => builtin.fmt(f),
 
             // Nix prints floats with a maximum precision of 5 digits
             // only.