diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-24T13·39+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-24T13·39+0000 |
commit | 943ab38a0d0969004de231a6b3e89df88ffc6ccf (patch) | |
tree | 10852ca08d48ce59858ebc64702f1de8b7b51629 /src | |
parent | f41297fdcecaa1ba12d238d1754457d319426579 (diff) |
* Refactoring: move strictEval to libexpr.
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/eval.cc | 43 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 4 | ||||
-rw-r--r-- | src/nix-instantiate/main.cc | 45 |
3 files changed, 48 insertions, 44 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c4f5d7f5d64d..07f53a56c7bc 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -584,6 +584,49 @@ Expr evalFile(EvalState & state, const Path & path) } +Expr strictEvalExpr(EvalState & state, Expr e) +{ + e = evalExpr(state, e); + + ATermList as; + + if (matchAttrs(e, as)) { + ATermList as2 = ATempty; + for (ATermIterator i(as); i; ++i) { + ATerm name; Expr e; ATerm pos; + if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */ + as2 = ATinsert(as2, makeBind(name, strictEvalExpr(state, e), pos)); + } + return makeAttrs(ATreverse(as2)); + } + + ATermList formals; + ATerm body, pos; + + if (matchFunction(e, formals, body, pos)) { + ATermList formals2 = ATempty; + + for (ATermIterator i(formals); i; ++i) { + Expr name; ValidValues valids; ATerm dummy; + if (!matchFormal(*i, name, valids, dummy)) abort(); + + ATermList valids2; + if (matchValidValues(valids, valids2)) { + ATermList valids3 = ATempty; + for (ATermIterator j(valids2); j; ++j) + valids3 = ATinsert(valids3, strictEvalExpr(state, *j)); + valids = makeValidValues(ATreverse(valids3)); + } + + formals2 = ATinsert(formals2, makeFormal(name, valids, dummy)); + } + return makeFunction(ATreverse(formals2), body, pos); + } + + return e; +} + + /* Yes, this is a really bad idea... */ extern "C" { unsigned long AT_calcAllocatedSize(); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index ff050b398680..58e6b40d7780 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -47,6 +47,10 @@ Expr evalExpr(EvalState & state, Expr e); /* Evaluate an expression read from the given file to normal form. */ Expr evalFile(EvalState & state, const Path & path); +/* Evaluate an expression, and recursively evaluate list elements and + attributes. */ +Expr strictEvalExpr(EvalState & state, Expr e); + /* Specific results. */ string evalString(EvalState & state, Expr e); Path evalPath(EvalState & state, Expr e); diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc index 29a28c3d8343..5eaaf5b2a844 100644 --- a/src/nix-instantiate/main.cc +++ b/src/nix-instantiate/main.cc @@ -135,56 +135,13 @@ static void printResult(EvalState & state, Expr e, } -Expr strictEval(EvalState & state, Expr e) -{ - e = evalExpr(state, e); - - ATermList as; - - if (matchAttrs(e, as)) { - ATermList as2 = ATempty; - for (ATermIterator i(as); i; ++i) { - ATerm name; Expr e; ATerm pos; - if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */ - as2 = ATinsert(as2, makeBind(name, strictEval(state, e), pos)); - } - return makeAttrs(ATreverse(as2)); - } - - ATermList formals; - ATerm body, pos; - - if (matchFunction(e, formals, body, pos)) { - ATermList formals2 = ATempty; - - for (ATermIterator i(formals); i; ++i) { - Expr name; ValidValues valids; ATerm dummy; - if (!matchFormal(*i, name, valids, dummy)) abort(); - - ATermList valids2; - if (matchValidValues(valids, valids2)) { - ATermList valids3 = ATempty; - for (ATermIterator j(valids2); j; ++j) - valids3 = ATinsert(valids3, strictEval(state, *j)); - valids = makeValidValues(ATreverse(valids3)); - } - - formals2 = ATinsert(formals2, makeFormal(name, valids, dummy)); - } - return makeFunction(ATreverse(formals2), body, pos); - } - - return e; -} - - Expr doEval(EvalState & state, string attrPath, bool parseOnly, bool strict, const ATermMap & autoArgs, Expr e) { e = findAlongAttrPath(state, attrPath, autoArgs, e); if (!parseOnly) if (strict) - e = strictEval(state, e); + e = strictEvalExpr(state, e); else e = evalExpr(state, e); return e; |