about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 94410e2bda..883e99ad0d 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -949,6 +949,20 @@ static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector
     return makeStr(s, PathSet());
 }
 
+static Expr prim_ExprToString ( EvalState & state, const ATermVector & args)
+{
+	return makeStr ( atPrint ( evalExpr ( state, args [ 0 ] ) ) );
+}
+
+static Expr prim_StringToExpr ( EvalState & state, const ATermVector & args)
+{
+	string s;
+	PathSet l;
+	if (! matchStr ( evalExpr ( state, args[0] ), s, l )) {
+		throw EvalError("__stringToExpr needs string argument!");
+	}
+	return toATerm ( s );
+}
 
 /*************************************************************
  * Primop registration
@@ -975,6 +989,10 @@ void EvalState::addPrimOps()
     addPrimOp("throw", 1, prim_throw);
     addPrimOp("__getEnv", 1, prim_getEnv);
     addPrimOp("__trace", 2, prim_trace);
+    
+    // Expr <-> String
+    addPrimOp("__exprToString", 1, prim_ExprToString);
+    addPrimOp("__stringToExpr", 1, prim_StringToExpr);
 
     addPrimOp("relativise", 2, prim_relativise);