about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-09-21T20·20+0200
committersterni <sternenseemann@systemli.org>2022-09-22T23·12+0000
commit64d3efcc2ce055ffe45034ed169569ece961f04d (patch)
tree1e3f199b768182684f8dc85d1513d0d4ff671a98 /tvix/eval/src/vm.rs
parent55459f02fcdca8612673f2df8ba54cb995ae06b6 (diff)
fix(tvix/eval): handle thunks in arithmetic builtins r/4960
The simplest solution seems to be to pass references to arithmetic_op!()
which avoids the moving annoyance we had to deal with in the
builtins (no more popping!). We then use .force() to force the values
and dereference any Thunks (which arithmetic_op! doesn't do for us).

Change-Id: I0eb8ad60e80a0b3ba9d9f411e973ef8bcf136989
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6724
Tested-by: BuildkiteCI
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 52627a1fea14..d6a24ebf86d4 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -71,7 +71,7 @@ macro_rules! arithmetic_op {
     ( $self:ident, $op:tt ) => {{
         let b = $self.pop();
         let a = $self.pop();
-        let result = fallible!($self, arithmetic_op!(a, b, $op));
+        let result = fallible!($self, arithmetic_op!(&a, &b, $op));
         $self.push(result);
     }};
 
@@ -79,8 +79,8 @@ macro_rules! arithmetic_op {
         match ($a, $b) {
             (Value::Integer(i1), Value::Integer(i2)) => Ok(Value::Integer(i1 $op i2)),
             (Value::Float(f1), Value::Float(f2)) => Ok(Value::Float(f1 $op f2)),
-            (Value::Integer(i1), Value::Float(f2)) => Ok(Value::Float(i1 as f64 $op f2)),
-            (Value::Float(f1), Value::Integer(i2)) => Ok(Value::Float(f1 $op i2 as f64)),
+            (Value::Integer(i1), Value::Float(f2)) => Ok(Value::Float(*i1 as f64 $op f2)),
+            (Value::Float(f1), Value::Integer(i2)) => Ok(Value::Float(f1 $op *i2 as f64)),
 
             (v1, v2) => Err(ErrorKind::TypeError {
                 expected: "number (either int or float)",
@@ -264,7 +264,7 @@ impl<'o> VM<'o> {
                     let result = if let (Value::String(s1), Value::String(s2)) = (&a, &b) {
                         Value::String(s1.concat(s2))
                     } else {
-                        fallible!(self, arithmetic_op!(a, b, +))
+                        fallible!(self, arithmetic_op!(&a, &b, +))
                     };
 
                     self.push(result)