about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-10T17·31+0300
committertazjin <tazjin@tvl.su>2022-08-25T11·11+0000
commitfb3d024d75fe4f6760ef616fe8dfd307b7d7b688 (patch)
tree3f86d2c9ed5eac5d7f949424a943249a550c93a3 /tvix/eval/src/vm.rs
parent322ce36cea732619c50220fc93f0eba51cf2eb8d (diff)
feat(tvix/eval): implement string concatenation r/4472
Change-Id: If61066e59232b2bad42b5cb5f0f2d9b9c416be8b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6137
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 3afda7a966eb..9a65668caa23 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -67,7 +67,19 @@ impl VM {
                     self.push(c);
                 }
 
-                OpCode::OpAdd => arithmetic_op!(self, +),
+                OpCode::OpAdd => {
+                    let b = self.pop();
+                    let a = self.pop();
+
+                    let result = if let (Value::String(s1), Value::String(s2)) = (&a, &b) {
+                        Value::String(s1.concat(s2))
+                    } else {
+                        arithmetic_op!(b, a, +)
+                    };
+
+                    self.push(result)
+                }
+
                 OpCode::OpSub => arithmetic_op!(self, -),
                 OpCode::OpMul => arithmetic_op!(self, *),
                 OpCode::OpDiv => arithmetic_op!(self, /),