about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-07-28T16·03+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-07-28T16·03+0000
commit4661282fde9f37780877fbeeb34b06b0c221e6bf (patch)
tree234537580ad8a9f51b0738cd990aa35c31247b54 /src/libexpr
parentc11839d7b24993f9639d59f9fa3420e8ccc22e02 (diff)
* `nix-instantiate ... --arg NAME VALUE': allow arguments to be passed
  to functions from the command line.
* nix-build: started removing backticks.

Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/attr-path.cc2
-rw-r--r--src/libexpr/eval.cc15
-rw-r--r--src/libexpr/eval.hh6
-rw-r--r--src/libexpr/get-drvs.cc13
-rw-r--r--src/libexpr/get-drvs.hh2
5 files changed, 23 insertions, 15 deletions
diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc
index 274f49ceab09..63bb1e554041 100644
--- a/src/libexpr/attr-path.cc
+++ b/src/libexpr/attr-path.cc
@@ -33,7 +33,7 @@ Expr findAlongAttrPath(EvalState & state, const string & attrPath, Expr e)
         if (string2Int(attr, attrIndex)) apType = apIndex;
 
         /* Evaluate the expression. */
-        e = evalExpr(state, autoCallFunction(evalExpr(state, e)));
+        e = evalExpr(state, autoCallFunction(evalExpr(state, e), ATermMap(1)));
 
         /* It should evaluate to either an attribute set or an
            expression, according to what is specified in the
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 6c78356db8ef..834b15cbdf76 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -287,20 +287,27 @@ static ATerm concatStrings(EvalState & state, const ATermVector & args)
 }
 
 
-Expr autoCallFunction(Expr e)
+Expr autoCallFunction(Expr e, const ATermMap & args)
 {
     ATermList formals;
     ATerm body, pos;
+    
     if (matchFunction(e, formals, body, pos)) {
+        ATermMap actualArgs(128);
+        
         for (ATermIterator i(formals); i; ++i) {
-            Expr name, def; ATerm values, def2;
+            Expr name, def, value; ATerm values, def2;
             if (!matchFormal(*i, name, values, def2)) abort();
-            if (!matchDefaultValue(def2, def))
+            if ((value = args.get(name)))
+                actualArgs.set(name, makeAttrRHS(value, makeNoPos()));
+            else if (!matchDefaultValue(def2, def))
                 throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
                     % aterm2String(name));
         }
-        e = makeCall(e, makeAttrs(ATermMap(0)));
+        
+        e = makeCall(e, makeAttrs(actualArgs));
     }
+    
     return e;
 }
 
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 018c6b726bd4..ff050b398680 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -60,9 +60,9 @@ string coerceToStringWithContext(EvalState & state,
 Expr wrapInContext(ATermList context, Expr e);
 
 /* Automatically call a function for which each argument has a default
-   value.  Note: result is a call, not a normal form; it should be
-   evaluated by calling evalExpr(). */
-Expr autoCallFunction(Expr e);
+   value or has a binding in the `args' map.  Note: result is a call,
+   not a normal form; it should be evaluated by calling evalExpr(). */
+Expr autoCallFunction(Expr e, const ATermMap & args);
 
 /* Print statistics. */
 void printEvalStats(EvalState & state);
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc
index 0afc7bd6d186..07dd88e4c7b8 100644
--- a/src/libexpr/get-drvs.cc
+++ b/src/libexpr/get-drvs.cc
@@ -121,9 +121,10 @@ static string addToPath(const string & s1, const string & s2)
 
 
 static void getDerivations(EvalState & state, Expr e,
-    const string & pathPrefix, DrvInfos & drvs, Exprs & doneExprs)
+    const string & pathPrefix, const ATermMap & autoArgs,
+    DrvInfos & drvs, Exprs & doneExprs)
 {
-    e = evalExpr(state, autoCallFunction(evalExpr(state, e)));
+    e = evalExpr(state, autoCallFunction(evalExpr(state, e), autoArgs));
 
     /* Process the expression. */
     ATermList es;
@@ -152,7 +153,7 @@ static void getDerivations(EvalState & state, Expr e,
                     queryAllAttrs(e, attrs, false);
                     Expr e2 = attrs.get(toATerm("recurseForDerivations"));
                     if (e2 && evalBool(state, e2))
-                        getDerivations(state, e, pathPrefix2, drvs, doneExprs);
+                        getDerivations(state, e, pathPrefix2, autoArgs, drvs, doneExprs);
                 }
             }
         }
@@ -167,7 +168,7 @@ static void getDerivations(EvalState & state, Expr e,
                 format("evaluating list element"));
             string pathPrefix2 = addToPath(pathPrefix, (format("%1%") % n).str());
             if (getDerivation(state, *i, pathPrefix2, drvs, doneExprs))
-                getDerivations(state, *i, pathPrefix2, drvs, doneExprs);
+                getDerivations(state, *i, pathPrefix2, autoArgs, drvs, doneExprs);
         }
         return;
     }
@@ -177,8 +178,8 @@ static void getDerivations(EvalState & state, Expr e,
 
 
 void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
-    DrvInfos & drvs)
+    const ATermMap & autoArgs, DrvInfos & drvs)
 {
     Exprs doneExprs;
-    getDerivations(state, e, pathPrefix, drvs, doneExprs);
+    getDerivations(state, e, pathPrefix, autoArgs, drvs, doneExprs);
 }
diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh
index 84ffe25cabfe..75f6bcf9d796 100644
--- a/src/libexpr/get-drvs.hh
+++ b/src/libexpr/get-drvs.hh
@@ -50,7 +50,7 @@ typedef list<DrvInfo> DrvInfos;
 bool getDerivation(EvalState & state, Expr e, DrvInfo & drv);
 
 void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
-    DrvInfos & drvs);
+    const ATermMap & autoArgs, DrvInfos & drvs);
 
 
 #endif /* !__GET_DRVS_H */