about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fix-ng/eval.cc2
-rw-r--r--src/fix-ng/fix.cc4
-rw-r--r--src/fix-ng/primops.cc19
-rw-r--r--src/fix-ng/primops.hh9
4 files changed, 30 insertions, 4 deletions
diff --git a/src/fix-ng/eval.cc b/src/fix-ng/eval.cc
index c58a06dff8d9..38a1d81fcfe4 100644
--- a/src/fix-ng/eval.cc
+++ b/src/fix-ng/eval.cc
@@ -145,6 +145,8 @@ Expr evalExpr2(EvalState & state, Expr e)
             string primop(s1);
             if (primop == "import") return primImport(state, e2);
             if (primop == "derivation") return primDerivation(state, e2);
+            if (primop == "toString") return primToString(state, e2);
+            if (primop == "baseNameOf") return primBaseNameOf(state, e2);
             else throw badTerm("undefined variable/primop", e1);
         }
 
diff --git a/src/fix-ng/fix.cc b/src/fix-ng/fix.cc
index 1c37a0b7ba20..c24ca4d9c4da 100644
--- a/src/fix-ng/fix.cc
+++ b/src/fix-ng/fix.cc
@@ -30,10 +30,6 @@ static Path searchPath(const Paths & searchDirs, const Path & relPath)
 #if 0
 static Expr evalExpr2(EvalState & state, Expr e)
 {
-    /* Conditional. */
-    if (ATmatch(e, "If(<term>, <term>, <term>)", &e1, &e2, &e3)) {
-    }
-
     /* Ad-hoc function for string matching. */
     if (ATmatch(e, "HasSubstr(<term>, <term>)", &e1, &e2)) {
         e1 = evalExpr(state, e1);
diff --git a/src/fix-ng/primops.cc b/src/fix-ng/primops.cc
index f86f9eb38d7b..7d060124b74c 100644
--- a/src/fix-ng/primops.cc
+++ b/src/fix-ng/primops.cc
@@ -204,3 +204,22 @@ Expr primDerivation(EvalState & state, Expr args)
 
     return makeAttrs(attrs);
 }
+
+
+Expr primBaseNameOf(EvalState & state, Expr arg)
+{
+    string s = evalString(state, arg);
+    return ATmake("Str(<str>)", baseNameOf(s).c_str());
+}
+
+
+Expr primToString(EvalState & state, Expr arg)
+{
+    arg = evalExpr(state, arg);
+    char * s;
+    if (ATmatch(arg, "Str(<str>)", &s) ||
+        ATmatch(arg, "Path(<str>)", &s) ||
+        ATmatch(arg, "Uri(<str>)", &s))
+        return ATmake("Str(<str>)", s);
+    else throw badTerm("cannot coerce to string", arg);
+}
diff --git a/src/fix-ng/primops.hh b/src/fix-ng/primops.hh
index 41b572c688d9..e48883b0bb01 100644
--- a/src/fix-ng/primops.hh
+++ b/src/fix-ng/primops.hh
@@ -19,4 +19,13 @@ Expr primImport(EvalState & state, Expr arg);
 Expr primDerivation(EvalState & state, Expr args);
 
 
+/* Return the base name of the given string, i.e., everything
+   following the last slash. */
+Expr primBaseNameOf(EvalState & state, Expr arg);
+
+
+/* Convert the argument (which can be a path or a uri) to a string. */
+Expr primToString(EvalState & state, Expr arg);
+
+
 #endif /* !__PRIMOPS_H */