about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-10-10T23·18+0300
committerclbot <clbot@tvl.fyi>2022-10-11T00·07+0000
commit8e122574c238ec18644fbe49d18a8d204fff66e0 (patch)
tree9675d40b12177e410cd6a96c95346ba14d43094a
parent06ec4bebe7e3a9a06a7f300f0a9f7c090d809f08 (diff)
fix(tvix/eval): implement functor calling for non-tail-calls r/5098
Change-Id: I1113921c46010021b61c412d74d60193c156e0f1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6937
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/vm.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index c805b70218..9a8d07ea63 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -227,6 +227,21 @@ impl<'o> VM<'o> {
 
             Value::Thunk(t) => self.call_value(&t.value()),
 
+            // Attribute sets with a __functor attribute are callable.
+            Value::Attrs(ref attrs) => match attrs.select("__functor") {
+                None => Err(self.error(ErrorKind::NotCallable(callable.type_of()))),
+                Some(functor) => {
+                    // The functor receives the set itself as its first argument
+                    // and needs to be called with it. However, this call is
+                    // synthetic (i.e. there is no corresponding OpCall for the
+                    // first call in the bytecode.)
+                    self.push(callable.clone());
+                    self.call_value(functor)?;
+                    let primed = self.pop();
+                    self.call_value(&primed)
+                }
+            },
+
             // TODO: this isn't guaranteed to be a useful span, actually
             other => Err(self.error(ErrorKind::NotCallable(other.type_of()))),
         }