forked from lix-project/lix
* Some preliminaries towards NIX-45.
This commit is contained in:
parent
ae55e79541
commit
dc719e6ba5
3 changed files with 35 additions and 10 deletions
|
@ -29,6 +29,19 @@ static Expr substArgs(Expr body, ATermList formals, Expr arg)
|
||||||
ATermMap subs(ATgetLength(formals) * 2);
|
ATermMap subs(ATgetLength(formals) * 2);
|
||||||
Expr undefined = makeUndefined();
|
Expr undefined = makeUndefined();
|
||||||
|
|
||||||
|
/* ({x ? E1; y ? E2, z}: E3) {x = E4; z = E5;}
|
||||||
|
|
||||||
|
=> let {x = E4; y = E2; z = E5; body = E3; }
|
||||||
|
|
||||||
|
=> subst(E3, s)
|
||||||
|
s = {
|
||||||
|
R = rec {x = E4; y = E2; z = E5}
|
||||||
|
x -> R.x
|
||||||
|
y -> R.y
|
||||||
|
z -> R.z
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/* Get the formal arguments. */
|
/* Get the formal arguments. */
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Expr name, def;
|
Expr name, def;
|
||||||
|
@ -278,7 +291,7 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||||
if (matchVar(e, name)) {
|
if (matchVar(e, name)) {
|
||||||
ATerm primOp = state.primOps.get(name);
|
ATerm primOp = state.primOps.get(name);
|
||||||
if (!primOp)
|
if (!primOp)
|
||||||
throw Error(format("impossible: undefined variable `%1%'") % name);
|
throw Error(format("impossible: undefined variable `%1%'") % aterm2String(name));
|
||||||
int arity;
|
int arity;
|
||||||
ATermBlob fun;
|
ATermBlob fun;
|
||||||
if (!matchPrimOpDef(primOp, arity, fun)) abort();
|
if (!matchPrimOpDef(primOp, arity, fun)) abort();
|
||||||
|
@ -509,9 +522,16 @@ Expr evalFile(EvalState & state, const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Yes, this is a really bad idea... */
|
||||||
|
extern "C" {
|
||||||
|
unsigned long AT_calcAllocatedSize();
|
||||||
|
}
|
||||||
|
|
||||||
void printEvalStats(EvalState & state)
|
void printEvalStats(EvalState & state)
|
||||||
{
|
{
|
||||||
debug(format("evaluated %1% expressions, %2% cache hits, %3%%% efficiency")
|
printMsg(lvlInfo,
|
||||||
|
format("evaluated %1% expressions, %2% cache hits, %3%%% efficiency, used %4% ATerm bytes")
|
||||||
% state.nrEvaluated % state.nrCached
|
% state.nrEvaluated % state.nrCached
|
||||||
% ((float) state.nrCached / (float) state.nrEvaluated * 100));
|
% ((float) state.nrCached / (float) state.nrEvaluated * 100)
|
||||||
|
% AT_calcAllocatedSize());
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ static void getDerivations(EvalState & state, Expr e,
|
||||||
format("evaluating attribute `%1%'") % aterm2String(*i));
|
format("evaluating attribute `%1%'") % aterm2String(*i));
|
||||||
if (getDerivation(state, drvMap.get(*i), drvs, doneExprs)) {
|
if (getDerivation(state, drvMap.get(*i), drvs, doneExprs)) {
|
||||||
/* If the value of this attribute is itself an
|
/* If the value of this attribute is itself an
|
||||||
attribute self, should we recurse into it?
|
attribute set, should we recurse into it?
|
||||||
=> Only if it has a `recurseForDerivations = true'
|
=> Only if it has a `recurseForDerivations = true'
|
||||||
attribute. */
|
attribute. */
|
||||||
ATermList es;
|
ATermList es;
|
||||||
|
|
|
@ -226,6 +226,8 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
|
//if (subs.size() == 0) return e;
|
||||||
|
|
||||||
ATerm name, pos, e2;
|
ATerm name, pos, e2;
|
||||||
|
|
||||||
/* As an optimisation, don't substitute in subterms known to be
|
/* As an optimisation, don't substitute in subterms known to be
|
||||||
|
@ -255,7 +257,7 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||||
subs2.remove(name);
|
subs2.remove(name);
|
||||||
}
|
}
|
||||||
return makeFunction(
|
return makeFunction(
|
||||||
(ATermList) substitute(subs, (ATerm) formals),
|
(ATermList) substitute(subs2, (ATerm) formals),
|
||||||
substitute(subs2, body), pos);
|
substitute(subs2, body), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,13 +329,16 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e)
|
||||||
ATermMap defs2(defs);
|
ATermMap defs2(defs);
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Expr deflt;
|
Expr deflt;
|
||||||
if (!matchNoDefFormal(*i, name))
|
if (!matchNoDefFormal(*i, name) &&
|
||||||
if (matchDefFormal(*i, name, deflt))
|
!matchDefFormal(*i, name, deflt))
|
||||||
checkVarDefs2(done, defs, deflt);
|
abort();
|
||||||
else
|
|
||||||
abort();
|
|
||||||
defs2.set(name, (ATerm) ATempty);
|
defs2.set(name, (ATerm) ATempty);
|
||||||
}
|
}
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr deflt;
|
||||||
|
if (matchDefFormal(*i, name, deflt))
|
||||||
|
checkVarDefs2(done, defs2, deflt);
|
||||||
|
}
|
||||||
checkVarDefs2(done, defs2, body);
|
checkVarDefs2(done, defs2, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue