about summary refs log tree commit diff
path: root/tvix/eval/src/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r--tvix/eval/src/builtins/mod.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
new file mode 100644
index 000000000000..62bfd145c0a9
--- /dev/null
+++ b/tvix/eval/src/builtins/mod.rs
@@ -0,0 +1,26 @@
+//! This module implements the builtins exposed in the Nix language.
+//!
+//! See //tvix/eval/docs/builtins.md for a some context on the
+//! available builtins in Nix.
+
+use std::collections::HashMap;
+
+use crate::value::{Builtin, Value};
+
+macro_rules! builtin {
+    ( $map:ident, $name:literal, $arity:literal, $body:expr ) => {
+        $map.insert($name, Value::Builtin(Builtin::new($name, $arity, $body)));
+    };
+}
+
+/// Set of Nix builtins that are globally available.
+pub fn global_builtins() -> HashMap<&'static str, Value> {
+    let mut globals = HashMap::new();
+
+    builtin!(globals, "toString", 1, |args| {
+        // TODO: toString is actually not the same as Display
+        Ok(Value::String(format!("{}", args[0]).into()))
+    });
+
+    globals
+}