about summary refs log tree commit diff
path: root/tvix/eval/src/value
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value')
-rw-r--r--tvix/eval/src/value/function.rs16
-rw-r--r--tvix/eval/src/value/mod.rs1
-rw-r--r--tvix/eval/src/value/string.rs7
3 files changed, 22 insertions, 2 deletions
diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs
index 0923e1b1cba9..e58aab19c0e7 100644
--- a/tvix/eval/src/value/function.rs
+++ b/tvix/eval/src/value/function.rs
@@ -1,6 +1,7 @@
 //! This module implements the runtime representation of functions.
 use std::{
     cell::{Ref, RefCell, RefMut},
+    collections::HashMap,
     rc::Rc,
 };
 
@@ -9,6 +10,17 @@ use crate::{
     upvalues::{UpvalueCarrier, Upvalues},
 };
 
+use super::NixString;
+
+#[derive(Clone, Debug, PartialEq)]
+pub(crate) struct Formals {
+    /// Map from argument name, to whether that argument is required
+    pub(crate) arguments: HashMap<NixString, bool>,
+
+    /// Do the formals of this function accept extra arguments
+    pub(crate) ellipsis: bool,
+}
+
 /// The opcodes for a thunk or closure, plus the number of
 /// non-executable opcodes which are allowed after an OpClosure or
 /// OpThunk referencing it.  At runtime `Lambda` is usually wrapped
@@ -16,7 +28,6 @@ use crate::{
 /// quite large).
 #[derive(Debug, PartialEq)]
 pub struct Lambda {
-    // name: Option<NixString>,
     pub(crate) chunk: Chunk,
 
     /// Number of upvalues which the code in this Lambda closes
@@ -24,14 +35,15 @@ pub struct Lambda {
     /// runtime.  Information about the variables is emitted using
     /// data-carrying opcodes (see [`OpCode::DataLocalIdx`]).
     pub(crate) upvalue_count: usize,
+    pub(crate) formals: Option<Formals>,
 }
 
 impl Lambda {
     pub fn new_anonymous() -> Self {
         Lambda {
-            // name: None,
             chunk: Default::default(),
             upvalue_count: 0,
+            formals: None,
         }
     }
 
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index a1216452fbb5..78f4f5de67a4 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -20,6 +20,7 @@ use crate::opcode::StackIdx;
 use crate::vm::VM;
 pub use attrs::NixAttrs;
 pub use builtin::Builtin;
+pub(crate) use function::Formals;
 pub use function::{Closure, Lambda};
 pub use list::NixList;
 pub use path::canon_path;
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index d146ee4cec95..4caef653f2cc 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -1,5 +1,6 @@
 //! This module implements Nix language strings and their different
 //! backing implementations.
+use rnix::ast;
 use smol_str::SmolStr;
 use std::ffi::OsStr;
 use std::hash::Hash;
@@ -55,6 +56,12 @@ impl From<SmolStr> for NixString {
     }
 }
 
+impl From<ast::Ident> for NixString {
+    fn from(ident: ast::Ident) -> Self {
+        ident.ident_token().unwrap().text().into()
+    }
+}
+
 impl Hash for NixString {
     fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
         self.as_str().hash(state)