From c739e2058560ad018dcf68e16fa683ca404d548c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 16 Jun 2003 21:01:18 +0000 Subject: [PATCH] * Argument processing. --- src/eval.cc | 38 +++++++++++++++++++++++++++++++------- src/test-builder-2.sh | 5 ++++- src/test.cc | 13 +++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/eval.cc b/src/eval.cc index c96cf6467..e6a3478a1 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(, )", &eName, &eVal)) + throw badTerm("invalid argument", arg); + + string name = evalString(eName); + eVal = evalValue(eVal).e; + + char * s; + if (ATmatch(eVal, "Str()", &s)) { + env[name] = s; + } else if (ATmatch(eVal, "External()", &s)) { + env[name] = queryValuePath(parseHash(s)); + } else throw badTerm("invalid argument value", eVal); + + argsNF = ATappend(argsNF, + ATmake("Tup(Str(), )", 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(), External(), [])", diff --git a/src/test-builder-2.sh b/src/test-builder-2.sh index 25a66532f..010e1c805 100644 --- a/src/test-builder-2.sh +++ b/src/test-builder-2.sh @@ -1,5 +1,8 @@ #! /bin/sh +echo "builder 2" + mkdir $out || exit 1 cd $out || exit 1 -echo "Hello World" > bla +echo "Hallo Wereld" > bla +cat $src >> bla \ No newline at end of file diff --git a/src/test.cc b/src/test.cc index b37a16a1f..bf7ee191f 100644 --- a/src/test.cc +++ b/src/test.cc @@ -74,13 +74,18 @@ void runTests() Hash builder1 = addValue("./test-builder-1.sh"); - evalTest(ATmake("Exec(Str(), External(), [])", - thisSystem.c_str(), ((string) builder1).c_str())); + Expr e1 = ATmake("Exec(Str(), External(), [])", + thisSystem.c_str(), ((string) builder1).c_str()); + + evalTest(e1); Hash builder2 = addValue("./test-builder-2.sh"); - evalTest(ATmake("Exec(Str(), External(), [])", - thisSystem.c_str(), ((string) builder2).c_str())); + Expr e2 = ATmake( + "Exec(Str(), External(), [Tup(Str(\"src\"), )])", + thisSystem.c_str(), ((string) builder2).c_str(), e1); + + evalTest(e2); }