about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.exp1
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.nix1
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.exp1
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.nix1
-rw-r--r--tvix/eval/src/value/string.rs6
-rw-r--r--tvix/eval/src/vm.rs14
6 files changed, 23 insertions, 1 deletions
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.exp
new file mode 100644
index 000000000000..cd4bc1ab64cc
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.exp
@@ -0,0 +1 @@
+"hello world"
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.nix
new file mode 100644
index 000000000000..1fc708929989
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concat-strings.nix
@@ -0,0 +1 @@
+"hello " + "world"
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.exp
new file mode 100644
index 000000000000..cd4bc1ab64cc
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.exp
@@ -0,0 +1 @@
+"hello world"
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.nix
new file mode 100644
index 000000000000..125b0859ac42
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-interpol.nix
@@ -0,0 +1 @@
+"hello ${"world"}"
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index 72f146765778..1b4f349f1ac5 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -63,6 +63,12 @@ impl NixString {
             Cow::Owned(s) => Cow::Owned(format!("\"{}\"", s)),
         }
     }
+
+    pub fn concat(&self, other: &Self) -> Self {
+        let mut s = self.as_str().to_owned();
+        s.push_str(other.as_str());
+        NixString::Heap(s)
+    }
 }
 
 fn nix_escape_char(ch: char) -> Option<&'static str> {
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, /),