about summary refs log tree commit diff
path: root/src/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16T21·01+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16T21·01+0000
commitc739e2058560ad018dcf68e16fa683ca404d548c (patch)
treecd7b5f89850ee9c1179840f839f8e23cea8e59b5 /src/eval.cc
parent727beb798a701ff546adc65030f1562b87283947 (diff)
* Argument processing.
Diffstat (limited to 'src/eval.cc')
-rw-r--r--src/eval.cc38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/eval.cc b/src/eval.cc
index c96cf6467ecc..e6a3478a1551 100644
--- a/src/eval.cc
+++ b/src/eval.cc
@@ -165,7 +165,7 @@ static Hash computeDerived(Hash sourceHash, string targetName,
 
     /* Register targetHash -> targetPath.  !!! this should be in
        values.cc. */
-    setDB(nixDB, dbNFs, sourceHash, targetName);
+    setDB(nixDB, dbRefs, targetHash, targetName);
 
     /* Register that targetHash was produced by evaluating
        sourceHash; i.e., that targetHash is a normal form of
@@ -227,6 +227,34 @@ static Hash evalExternal(Expr e)
 }
 
 
+/* Evaluate a list of arguments into normal form. */
+void evalArgs(ATermList args, ATermList & argsNF, Environment & env)
+{
+    argsNF = ATempty;
+
+    while (!ATisEmpty(args)) {
+        ATerm eName, eVal, arg = ATgetFirst(args);
+        if (!ATmatch(arg, "Tup(<term>, <term>)", &eName, &eVal))
+            throw badTerm("invalid argument", arg);
+
+        string name = evalString(eName);
+        eVal = evalValue(eVal).e;
+
+        char * s;
+        if (ATmatch(eVal, "Str(<str>)", &s)) {
+            env[name] = s;
+        } else if (ATmatch(eVal, "External(<str>)", &s)) {
+            env[name] = queryValuePath(parseHash(s));
+        } else throw badTerm("invalid argument value", eVal);
+
+        argsNF = ATappend(argsNF,
+            ATmake("Tup(Str(<str>), <term>)", name.c_str(), eVal));
+
+        args = ATgetNext(args);
+    }
+}
+
+
 /* Evaluate an expression. */
 EvalResult evalValue(Expr e)
 {
@@ -263,12 +291,8 @@ EvalResult evalValue(Expr e)
         Hash prog = evalExternal(eProg);
 
         Environment env;
-        while (!ATisEmpty(args)) {
-            debug("arg");
-            Expr arg = ATgetFirst(args);
-            throw badTerm("foo", arg);
-            args = ATgetNext(args);
-        }
+        ATermList argsNF;
+        evalArgs(args, argsNF, env);
 
         Hash sourceHash = hashExpr(
             ATmake("Exec(Str(<str>), External(<str>), [])",