summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-11-02 16:31:35 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-11-02 16:31:35 +0000
commitadf9a45469f55258446d383333aa2ca79cfb0536 (patch)
tree26fc7e4ac62f45385b78f468c1cbc96426c78d71
parentc8268ca9917061466a3448028ea524d9842e1ac9 (diff)
downloadguix-adf9a45469f55258446d383333aa2ca79cfb0536.tar.gz
* Primops: baseNameOf, toString.
-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 c58a06dff8..38a1d81fcf 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 1c37a0b7ba..c24ca4d9c4 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 f86f9eb38d..7d060124b7 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 41b572c688..e48883b0bb 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 */