forked from lix-project/lix
* Memoize strict evaluation.
This commit is contained in:
parent
5011588459
commit
05879db628
|
@ -672,7 +672,10 @@ Expr evalFile(EvalState & state, const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr strictEvalExpr(EvalState & state, Expr e, bool canonicalise)
|
static Expr strictEvalExpr(EvalState & state, Expr e, ATermMap & nfs);
|
||||||
|
|
||||||
|
|
||||||
|
static Expr strictEvalExpr_(EvalState & state, Expr e, ATermMap & nfs)
|
||||||
{
|
{
|
||||||
e = evalExpr(state, e);
|
e = evalExpr(state, e);
|
||||||
|
|
||||||
|
@ -682,13 +685,8 @@ Expr strictEvalExpr(EvalState & state, Expr e, bool canonicalise)
|
||||||
for (ATermIterator i(as); i; ++i) {
|
for (ATermIterator i(as); i; ++i) {
|
||||||
ATerm name; Expr e; ATerm pos;
|
ATerm name; Expr e; ATerm pos;
|
||||||
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
||||||
as2 = ATinsert(as2, makeBind(name, strictEvalExpr(state, e, canonicalise),
|
as2 = ATinsert(as2, makeBind(name, strictEvalExpr(state, e, nfs), pos));
|
||||||
canonicalise ? makeNoPos() : pos));
|
|
||||||
}
|
}
|
||||||
if (canonicalise) {
|
|
||||||
|
|
||||||
}
|
|
||||||
/* !!! sort attributes if canonicalise == true */
|
|
||||||
return makeAttrs(ATreverse(as2));
|
return makeAttrs(ATreverse(as2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +694,7 @@ Expr strictEvalExpr(EvalState & state, Expr e, bool canonicalise)
|
||||||
if (matchList(e, es)) {
|
if (matchList(e, es)) {
|
||||||
ATermList es2 = ATempty;
|
ATermList es2 = ATempty;
|
||||||
for (ATermIterator i(es); i; ++i)
|
for (ATermIterator i(es); i; ++i)
|
||||||
es2 = ATinsert(es2, strictEvalExpr(state, *i, canonicalise));
|
es2 = ATinsert(es2, strictEvalExpr(state, *i, nfs));
|
||||||
return makeList(ATreverse(es2));
|
return makeList(ATreverse(es2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,21 +711,40 @@ Expr strictEvalExpr(EvalState & state, Expr e, bool canonicalise)
|
||||||
if (matchValidValues(valids, valids2)) {
|
if (matchValidValues(valids, valids2)) {
|
||||||
ATermList valids3 = ATempty;
|
ATermList valids3 = ATempty;
|
||||||
for (ATermIterator j(valids2); j; ++j)
|
for (ATermIterator j(valids2); j; ++j)
|
||||||
valids3 = ATinsert(valids3, strictEvalExpr(state, *j, canonicalise));
|
valids3 = ATinsert(valids3, strictEvalExpr(state, *j, nfs));
|
||||||
valids = makeValidValues(ATreverse(valids3));
|
valids = makeValidValues(ATreverse(valids3));
|
||||||
}
|
}
|
||||||
|
|
||||||
formals2 = ATinsert(formals2, makeFormal(name, valids, dummy));
|
formals2 = ATinsert(formals2, makeFormal(name, valids, dummy));
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeFunction(ATreverse(formals2), body,
|
return makeFunction(ATreverse(formals2), body, pos);
|
||||||
canonicalise ? makeNoPos() : pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Expr strictEvalExpr(EvalState & state, Expr e, ATermMap & nfs)
|
||||||
|
{
|
||||||
|
Expr nf = nfs.get(e);
|
||||||
|
if (nf) return nf;
|
||||||
|
|
||||||
|
nf = strictEvalExpr_(state, e, nfs);
|
||||||
|
|
||||||
|
nfs.set(e, nf);
|
||||||
|
|
||||||
|
return nf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr strictEvalExpr(EvalState & state, Expr e)
|
||||||
|
{
|
||||||
|
ATermMap strictNormalForms;
|
||||||
|
return strictEvalExpr(state, e, strictNormalForms);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Yes, this is a really bad idea... */
|
/* Yes, this is a really bad idea... */
|
||||||
extern "C" {
|
extern "C" {
|
||||||
unsigned long AT_calcAllocatedSize();
|
unsigned long AT_calcAllocatedSize();
|
||||||
|
|
|
@ -56,8 +56,7 @@ Expr evalFile(EvalState & state, const Path & path);
|
||||||
attributes. If `canonicalise' is true, we remove things like
|
attributes. If `canonicalise' is true, we remove things like
|
||||||
position information and make sure that attribute sets are in
|
position information and make sure that attribute sets are in
|
||||||
sorded order. */
|
sorded order. */
|
||||||
Expr strictEvalExpr(EvalState & state, Expr e,
|
Expr strictEvalExpr(EvalState & state, Expr e);
|
||||||
bool canonicalise = false);
|
|
||||||
|
|
||||||
/* Specific results. */
|
/* Specific results. */
|
||||||
string evalString(EvalState & state, Expr e, PathSet & context);
|
string evalString(EvalState & state, Expr e, PathSet & context);
|
||||||
|
|
Loading…
Reference in a new issue