* Argument processing.

This commit is contained in:
Eelco Dolstra 2003-06-16 21:01:18 +00:00
parent 727beb798a
commit c739e20585
3 changed files with 44 additions and 12 deletions

View file

@ -165,7 +165,7 @@ static Hash computeDerived(Hash sourceHash, string targetName,
/* Register targetHash -> targetPath. !!! this should be in /* Register targetHash -> targetPath. !!! this should be in
values.cc. */ values.cc. */
setDB(nixDB, dbNFs, sourceHash, targetName); setDB(nixDB, dbRefs, targetHash, targetName);
/* Register that targetHash was produced by evaluating /* Register that targetHash was produced by evaluating
sourceHash; i.e., that targetHash is a normal form of 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. */ /* Evaluate an expression. */
EvalResult evalValue(Expr e) EvalResult evalValue(Expr e)
{ {
@ -263,12 +291,8 @@ EvalResult evalValue(Expr e)
Hash prog = evalExternal(eProg); Hash prog = evalExternal(eProg);
Environment env; Environment env;
while (!ATisEmpty(args)) { ATermList argsNF;
debug("arg"); evalArgs(args, argsNF, env);
Expr arg = ATgetFirst(args);
throw badTerm("foo", arg);
args = ATgetNext(args);
}
Hash sourceHash = hashExpr( Hash sourceHash = hashExpr(
ATmake("Exec(Str(<str>), External(<str>), [])", ATmake("Exec(Str(<str>), External(<str>), [])",

View file

@ -1,5 +1,8 @@
#! /bin/sh #! /bin/sh
echo "builder 2"
mkdir $out || exit 1 mkdir $out || exit 1
cd $out || exit 1 cd $out || exit 1
echo "Hello World" > bla echo "Hallo Wereld" > bla
cat $src >> bla

View file

@ -74,13 +74,18 @@ void runTests()
Hash builder1 = addValue("./test-builder-1.sh"); Hash builder1 = addValue("./test-builder-1.sh");
evalTest(ATmake("Exec(Str(<str>), External(<str>), [])", Expr e1 = ATmake("Exec(Str(<str>), External(<str>), [])",
thisSystem.c_str(), ((string) builder1).c_str())); thisSystem.c_str(), ((string) builder1).c_str());
evalTest(e1);
Hash builder2 = addValue("./test-builder-2.sh"); Hash builder2 = addValue("./test-builder-2.sh");
evalTest(ATmake("Exec(Str(<str>), External(<str>), [])", Expr e2 = ATmake(
thisSystem.c_str(), ((string) builder2).c_str())); "Exec(Str(<str>), External(<str>), [Tup(Str(\"src\"), <term>)])",
thisSystem.c_str(), ((string) builder2).c_str(), e1);
evalTest(e2);
} }