2003-11-18 12:06:07 +00:00
|
|
|
#include "nixexpr.hh"
|
2005-01-19 16:39:47 +00:00
|
|
|
#include "derivations.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
#include "util.hh"
|
2006-09-05 08:54:48 +00:00
|
|
|
#include "aterm.hh"
|
2003-10-30 16:11:24 +00:00
|
|
|
|
2004-10-29 11:22:49 +00:00
|
|
|
#include "nixexpr-ast.hh"
|
|
|
|
#include "nixexpr-ast.cc"
|
2004-10-26 22:54:26 +00:00
|
|
|
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2004-04-05 22:27:41 +00:00
|
|
|
string showPos(ATerm pos)
|
|
|
|
{
|
2004-10-26 22:54:26 +00:00
|
|
|
ATerm path;
|
2004-04-05 22:27:41 +00:00
|
|
|
int line, column;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchNoPos(pos)) return "undefined position";
|
|
|
|
if (!matchPos(pos, path, line, column))
|
2004-04-05 22:27:41 +00:00
|
|
|
throw badTerm("position expected", pos);
|
2004-10-26 22:54:26 +00:00
|
|
|
return (format("`%1%', line %2%") % aterm2String(path) % line).str();
|
2004-04-05 22:27:41 +00:00
|
|
|
}
|
2003-11-03 20:30:40 +00:00
|
|
|
|
|
|
|
|
2003-10-30 16:11:24 +00:00
|
|
|
ATerm bottomupRewrite(TermFun & f, ATerm e)
|
|
|
|
{
|
2004-01-15 20:23:55 +00:00
|
|
|
checkInterrupt();
|
|
|
|
|
2003-10-30 16:11:24 +00:00
|
|
|
if (ATgetType(e) == AT_APPL) {
|
|
|
|
AFun fun = ATgetAFun(e);
|
|
|
|
int arity = ATgetArity(fun);
|
2006-05-02 14:07:28 +00:00
|
|
|
ATerm args[arity];
|
2003-10-30 16:11:24 +00:00
|
|
|
|
2006-05-02 14:07:28 +00:00
|
|
|
for (int i = 0; i < arity; ++i)
|
|
|
|
args[i] = bottomupRewrite(f, ATgetArgument(e, i));
|
2003-10-30 16:11:24 +00:00
|
|
|
|
2006-05-02 14:07:28 +00:00
|
|
|
e = (ATerm) ATmakeApplArray(fun, args);
|
2003-10-30 16:11:24 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 11:59:35 +00:00
|
|
|
else if (ATgetType(e) == AT_LIST) {
|
2003-10-30 16:11:24 +00:00
|
|
|
ATermList in = (ATermList) e;
|
|
|
|
ATermList out = ATempty;
|
|
|
|
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(in); i; ++i)
|
|
|
|
out = ATinsert(out, bottomupRewrite(f, *i));
|
2003-10-30 16:11:24 +00:00
|
|
|
|
2003-11-03 11:59:35 +00:00
|
|
|
e = (ATerm) ATreverse(out);
|
2003-10-30 16:11:24 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 11:59:35 +00:00
|
|
|
return f(e);
|
2003-10-30 16:11:24 +00:00
|
|
|
}
|
2003-10-31 17:09:31 +00:00
|
|
|
|
|
|
|
|
2004-04-05 22:27:41 +00:00
|
|
|
void queryAllAttrs(Expr e, ATermMap & attrs, bool withPos)
|
2003-10-31 17:09:31 +00:00
|
|
|
{
|
|
|
|
ATermList bnds;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchAttrs(e, bnds))
|
2006-07-19 15:36:15 +00:00
|
|
|
throw TypeError("attribute set expected");
|
2003-10-31 17:09:31 +00:00
|
|
|
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(bnds); i; ++i) {
|
2004-10-26 22:54:26 +00:00
|
|
|
ATerm name;
|
2003-10-31 17:09:31 +00:00
|
|
|
Expr e;
|
2004-04-05 22:27:41 +00:00
|
|
|
ATerm pos;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
|
|
|
attrs.set(name, withPos ? makeAttrRHS(e, pos) : e);
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expr queryAttr(Expr e, const string & name)
|
|
|
|
{
|
2004-04-05 22:27:41 +00:00
|
|
|
ATerm dummy;
|
|
|
|
return queryAttr(e, name, dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expr queryAttr(Expr e, const string & name, ATerm & pos)
|
|
|
|
{
|
|
|
|
ATermList bnds;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchAttrs(e, bnds))
|
2006-07-19 15:36:15 +00:00
|
|
|
throw TypeError("attribute set expected");
|
2004-04-05 22:27:41 +00:00
|
|
|
|
|
|
|
for (ATermIterator i(bnds); i; ++i) {
|
2004-10-26 22:54:26 +00:00
|
|
|
ATerm name2, pos2;
|
2004-04-05 22:27:41 +00:00
|
|
|
Expr e;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchBind(*i, name2, e, pos2))
|
2004-04-05 22:27:41 +00:00
|
|
|
abort(); /* can't happen */
|
2004-10-26 22:54:26 +00:00
|
|
|
if (aterm2String(name2) == name) {
|
2004-04-05 22:27:41 +00:00
|
|
|
pos = pos2;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-03 20:30:40 +00:00
|
|
|
Expr makeAttrs(const ATermMap & attrs)
|
2003-10-31 17:09:31 +00:00
|
|
|
{
|
2003-11-16 18:31:29 +00:00
|
|
|
ATermList bnds = ATempty;
|
2006-05-04 12:21:08 +00:00
|
|
|
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
|
2004-04-05 22:27:41 +00:00
|
|
|
Expr e;
|
|
|
|
ATerm pos;
|
2006-05-04 12:21:08 +00:00
|
|
|
if (!matchAttrRHS(i->value, e, pos))
|
2004-04-05 22:27:41 +00:00
|
|
|
abort(); /* can't happen */
|
2006-05-04 12:21:08 +00:00
|
|
|
bnds = ATinsert(bnds, makeBind(i->key, e, pos));
|
2004-04-05 22:27:41 +00:00
|
|
|
}
|
2006-05-02 17:51:50 +00:00
|
|
|
return makeAttrs(bnds);
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 21:39:02 +00:00
|
|
|
Expr substitute(const Substitution & subs, Expr e)
|
2003-10-31 17:09:31 +00:00
|
|
|
{
|
2004-01-15 20:23:55 +00:00
|
|
|
checkInterrupt();
|
|
|
|
|
2006-05-02 13:39:55 +00:00
|
|
|
//if (subs.size() == 0) return e;
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
ATerm name, pos, e2;
|
2003-10-31 17:09:31 +00:00
|
|
|
|
* The recent change in nixpkgs of calling `stdenv.mkDerivation'
instead of `derivation' triggered a huge slowdown in the Nix
expression evaluator. Total execution time of `nix-env -qa' went up
by a factor of 60 or so.
This scalability problem was caused by expressions such as
(x: y: ... x ...) a b
where `a' is a large term (say, the one in
`all-packages-generic.nix'). Then the first beta-reduction would
produce
(y: ... a ...) b
by substituting `a' for `x'. The second beta-reduction would then
substitute `b' for `y' into the body `... a ...', which is a large
term due to `a', and thus causes a large traversal to be performed
by substitute() in the second reduction. This is however entirely
redundant, since `a' cannot contain free variables (since we never
substitute below a weak head normal form).
The solution is to wrap substituted terms into a `Closed'
constructor, i.e.,
subst(subs, Var(x)) = Closed(e) iff subs[x] = e
have substitution not descent into closed terms,
subst(subs, Closed(x)) = Closed(x)
and otherwise ignore them for evaluation,
eval(Closed(x)) = eval(x).
* Fix a typo that caused incorrect substitutions to be performed in
simple lambdas, e.g., `(x: x: x) a' would reduce to `(x: a)'.
2004-03-30 15:05:35 +00:00
|
|
|
/* As an optimisation, don't substitute in subterms known to be
|
|
|
|
closed. */
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchClosed(e, e2)) return e;
|
* The recent change in nixpkgs of calling `stdenv.mkDerivation'
instead of `derivation' triggered a huge slowdown in the Nix
expression evaluator. Total execution time of `nix-env -qa' went up
by a factor of 60 or so.
This scalability problem was caused by expressions such as
(x: y: ... x ...) a b
where `a' is a large term (say, the one in
`all-packages-generic.nix'). Then the first beta-reduction would
produce
(y: ... a ...) b
by substituting `a' for `x'. The second beta-reduction would then
substitute `b' for `y' into the body `... a ...', which is a large
term due to `a', and thus causes a large traversal to be performed
by substitute() in the second reduction. This is however entirely
redundant, since `a' cannot contain free variables (since we never
substitute below a weak head normal form).
The solution is to wrap substituted terms into a `Closed'
constructor, i.e.,
subst(subs, Var(x)) = Closed(e) iff subs[x] = e
have substitution not descent into closed terms,
subst(subs, Closed(x)) = Closed(x)
and otherwise ignore them for evaluation,
eval(Closed(x)) = eval(x).
* Fix a typo that caused incorrect substitutions to be performed in
simple lambdas, e.g., `(x: x: x) a' would reduce to `(x: a)'.
2004-03-30 15:05:35 +00:00
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchVar(e, name)) {
|
2006-05-02 21:39:02 +00:00
|
|
|
Expr sub = subs.lookup(name);
|
|
|
|
if (sub == makeRemoved()) sub = 0;
|
2005-07-19 11:48:05 +00:00
|
|
|
Expr wrapped;
|
|
|
|
/* Add a "closed" wrapper around terms that aren't already
|
|
|
|
closed. The check is necessary to prevent repeated
|
|
|
|
wrapping, e.g., closed(closed(closed(...))), which kills
|
|
|
|
caching. */
|
|
|
|
return sub ? (matchClosed(sub, wrapped) ? sub : makeClosed(sub)) : e;
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In case of a function, filter out all variables bound by this
|
|
|
|
function. */
|
|
|
|
ATermList formals;
|
2006-08-04 17:07:13 +00:00
|
|
|
ATerm body;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchFunction(e, formals, body, pos)) {
|
2006-05-04 12:21:08 +00:00
|
|
|
ATermMap map(ATgetLength(formals));
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(formals); i; ++i) {
|
2006-07-24 15:16:03 +00:00
|
|
|
ATerm d1, d2;
|
|
|
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
2006-05-02 21:39:02 +00:00
|
|
|
map.set(name, makeRemoved());
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
2006-05-02 21:39:02 +00:00
|
|
|
Substitution subs2(&subs, &map);
|
2004-10-26 22:54:26 +00:00
|
|
|
return makeFunction(
|
2006-05-02 13:39:55 +00:00
|
|
|
(ATermList) substitute(subs2, (ATerm) formals),
|
2004-04-05 22:27:41 +00:00
|
|
|
substitute(subs2, body), pos);
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchFunction1(e, name, body, pos)) {
|
2006-05-04 12:21:08 +00:00
|
|
|
ATermMap map(1);
|
2006-05-02 21:39:02 +00:00
|
|
|
map.set(name, makeRemoved());
|
|
|
|
return makeFunction1(name, substitute(Substitution(&subs, &map), body), pos);
|
2004-03-28 20:34:22 +00:00
|
|
|
}
|
|
|
|
|
2003-11-01 19:10:19 +00:00
|
|
|
/* Idem for a mutually recursive attribute set. */
|
2004-02-02 21:39:33 +00:00
|
|
|
ATermList rbnds, nrbnds;
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchRec(e, rbnds, nrbnds)) {
|
2006-05-04 12:21:08 +00:00
|
|
|
ATermMap map(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
2004-02-03 14:45:34 +00:00
|
|
|
for (ATermIterator i(rbnds); i; ++i)
|
2006-05-02 21:39:02 +00:00
|
|
|
if (matchBind(*i, name, e2, pos)) map.set(name, makeRemoved());
|
2004-02-16 09:18:35 +00:00
|
|
|
else abort(); /* can't happen */
|
|
|
|
for (ATermIterator i(nrbnds); i; ++i)
|
2006-05-02 21:39:02 +00:00
|
|
|
if (matchBind(*i, name, e2, pos)) map.set(name, makeRemoved());
|
2004-02-16 09:18:35 +00:00
|
|
|
else abort(); /* can't happen */
|
2004-10-26 22:54:26 +00:00
|
|
|
return makeRec(
|
2006-05-02 21:39:02 +00:00
|
|
|
(ATermList) substitute(Substitution(&subs, &map), (ATerm) rbnds),
|
2004-10-26 22:54:26 +00:00
|
|
|
(ATermList) substitute(subs, (ATerm) nrbnds));
|
2003-11-01 19:10:19 +00:00
|
|
|
}
|
2003-10-31 17:09:31 +00:00
|
|
|
|
|
|
|
if (ATgetType(e) == AT_APPL) {
|
|
|
|
AFun fun = ATgetAFun(e);
|
|
|
|
int arity = ATgetArity(fun);
|
2006-05-02 14:07:28 +00:00
|
|
|
ATerm args[arity];
|
2006-05-02 21:39:02 +00:00
|
|
|
bool changed = false;
|
2003-10-31 17:09:31 +00:00
|
|
|
|
2006-05-02 21:39:02 +00:00
|
|
|
for (int i = 0; i < arity; ++i) {
|
|
|
|
ATerm arg = ATgetArgument(e, i);
|
|
|
|
args[i] = substitute(subs, arg);
|
|
|
|
if (args[i] != arg) changed = true;
|
|
|
|
}
|
2003-10-31 17:09:31 +00:00
|
|
|
|
2006-05-02 21:39:02 +00:00
|
|
|
return changed ? (ATerm) ATmakeApplArray(fun, args) : e;
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ATgetType(e) == AT_LIST) {
|
2006-05-02 14:07:28 +00:00
|
|
|
unsigned int len = ATgetLength((ATermList) e);
|
|
|
|
ATerm es[len];
|
|
|
|
ATermIterator i((ATermList) e);
|
|
|
|
for (unsigned int j = 0; i; ++i, ++j)
|
|
|
|
es[j] = substitute(subs, *i);
|
2003-10-31 17:09:31 +00:00
|
|
|
ATermList out = ATempty;
|
2006-05-02 14:07:28 +00:00
|
|
|
for (unsigned int j = len; j; --j)
|
|
|
|
out = ATinsert(out, es[j - 1]);
|
|
|
|
return (ATerm) out;
|
2003-10-31 17:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
2003-11-05 16:27:40 +00:00
|
|
|
|
|
|
|
|
2005-11-04 15:17:05 +00:00
|
|
|
/* We use memoisation to prevent exponential complexity on heavily
|
|
|
|
shared ATerms (remember, an ATerm is a graph, not a tree!). Note
|
|
|
|
that using an STL set is fine here wrt to ATerm garbage collection
|
|
|
|
since all the ATerms in the set are already reachable from
|
|
|
|
somewhere else. */
|
|
|
|
static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e)
|
2004-02-03 14:45:34 +00:00
|
|
|
{
|
2005-11-04 15:17:05 +00:00
|
|
|
if (done.find(e) != done.end()) return;
|
|
|
|
done.insert(e);
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
ATerm name, pos, value;
|
2004-02-03 14:45:34 +00:00
|
|
|
ATermList formals;
|
2004-10-25 16:54:56 +00:00
|
|
|
ATerm with, body;
|
2004-02-03 14:45:34 +00:00
|
|
|
ATermList rbnds, nrbnds;
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
if (matchVar(e, name)) {
|
2004-02-03 14:45:34 +00:00
|
|
|
if (!defs.get(name))
|
2006-07-19 15:36:15 +00:00
|
|
|
throw EvalError(format("undefined variable `%1%'")
|
2004-02-03 14:45:34 +00:00
|
|
|
% aterm2String(name));
|
|
|
|
}
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
else if (matchFunction(e, formals, body, pos)) {
|
2004-02-03 14:45:34 +00:00
|
|
|
ATermMap defs2(defs);
|
|
|
|
for (ATermIterator i(formals); i; ++i) {
|
2006-07-24 16:35:34 +00:00
|
|
|
ATerm d1, d2;
|
2006-07-24 15:16:03 +00:00
|
|
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
2004-02-03 14:45:34 +00:00
|
|
|
defs2.set(name, (ATerm) ATempty);
|
|
|
|
}
|
2006-05-02 13:39:55 +00:00
|
|
|
for (ATermIterator i(formals); i; ++i) {
|
2006-07-24 16:35:34 +00:00
|
|
|
ATerm valids, deflt;
|
2006-07-11 10:29:52 +00:00
|
|
|
set<Expr> done2;
|
2006-08-04 17:07:13 +00:00
|
|
|
if (!matchFormal(*i, name, valids, deflt)) abort();
|
2006-07-24 16:35:34 +00:00
|
|
|
checkVarDefs2(done, defs, valids);
|
|
|
|
checkVarDefs2(done2, defs2, deflt);
|
2006-05-02 13:39:55 +00:00
|
|
|
}
|
2006-07-11 10:29:52 +00:00
|
|
|
set<Expr> done2;
|
|
|
|
checkVarDefs2(done2, defs2, body);
|
2004-03-28 20:34:22 +00:00
|
|
|
}
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
else if (matchFunction1(e, name, body, pos)) {
|
2004-03-28 20:34:22 +00:00
|
|
|
ATermMap defs2(defs);
|
|
|
|
defs2.set(name, (ATerm) ATempty);
|
2006-07-11 10:29:52 +00:00
|
|
|
set<Expr> done2;
|
|
|
|
checkVarDefs2(done2, defs2, body);
|
2004-02-03 14:45:34 +00:00
|
|
|
}
|
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
else if (matchRec(e, rbnds, nrbnds)) {
|
2005-11-04 15:17:05 +00:00
|
|
|
checkVarDefs2(done, defs, (ATerm) nrbnds);
|
2004-02-03 14:45:34 +00:00
|
|
|
ATermMap defs2(defs);
|
|
|
|
for (ATermIterator i(rbnds); i; ++i) {
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
2004-02-03 14:45:34 +00:00
|
|
|
defs2.set(name, (ATerm) ATempty);
|
|
|
|
}
|
2004-02-16 09:18:35 +00:00
|
|
|
for (ATermIterator i(nrbnds); i; ++i) {
|
2004-10-26 22:54:26 +00:00
|
|
|
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
2004-02-16 09:18:35 +00:00
|
|
|
defs2.set(name, (ATerm) ATempty);
|
|
|
|
}
|
2006-07-11 10:29:52 +00:00
|
|
|
set<Expr> done2;
|
|
|
|
checkVarDefs2(done2, defs2, (ATerm) rbnds);
|
2004-02-03 14:45:34 +00:00
|
|
|
}
|
2004-10-25 16:54:56 +00:00
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
else if (matchWith(e, with, body, pos)) {
|
2004-10-25 16:54:56 +00:00
|
|
|
/* We can't check the body without evaluating the definitions
|
|
|
|
(which is an arbitrary expression), so we don't do that
|
|
|
|
here but only when actually evaluating the `with'. */
|
2005-11-04 15:17:05 +00:00
|
|
|
checkVarDefs2(done, defs, with);
|
2004-10-25 16:54:56 +00:00
|
|
|
}
|
2004-02-03 14:45:34 +00:00
|
|
|
|
|
|
|
else if (ATgetType(e) == AT_APPL) {
|
|
|
|
int arity = ATgetArity(ATgetAFun(e));
|
|
|
|
for (int i = 0; i < arity; ++i)
|
2005-11-04 15:17:05 +00:00
|
|
|
checkVarDefs2(done, defs, ATgetArgument(e, i));
|
2004-02-03 14:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (ATgetType(e) == AT_LIST)
|
|
|
|
for (ATermIterator i((ATermList) e); i; ++i)
|
2005-11-04 15:17:05 +00:00
|
|
|
checkVarDefs2(done, defs, *i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void checkVarDefs(const ATermMap & defs, Expr e)
|
|
|
|
{
|
|
|
|
set<Expr> done;
|
|
|
|
checkVarDefs2(done, defs, e);
|
2004-02-03 14:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-05 16:27:40 +00:00
|
|
|
Expr makeBool(bool b)
|
|
|
|
{
|
2004-10-26 22:54:26 +00:00
|
|
|
return b ? eTrue : eFalse;
|
2004-10-26 17:01:35 +00:00
|
|
|
}
|
2006-07-19 15:36:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
string showType(Expr e)
|
|
|
|
{
|
|
|
|
ATerm t1, t2, t3;
|
|
|
|
ATermList l1;
|
2006-10-03 14:55:54 +00:00
|
|
|
ATermBlob b1;
|
2006-07-19 15:36:15 +00:00
|
|
|
int i1;
|
|
|
|
if (matchStr(e, t1)) return "a string";
|
|
|
|
if (matchPath(e, t1)) return "a path";
|
|
|
|
if (matchNull(e)) return "null";
|
|
|
|
if (matchInt(e, i1)) return "an integer";
|
|
|
|
if (matchBool(e, t1)) return "a boolean";
|
|
|
|
if (matchFunction(e, l1, t1, t2)) return "a function";
|
|
|
|
if (matchFunction1(e, t1, t2, t3)) return "a function";
|
|
|
|
if (matchAttrs(e, l1)) return "an attribute set";
|
|
|
|
if (matchList(e, l1)) return "a list";
|
2006-10-03 14:55:54 +00:00
|
|
|
if (matchPrimOp(e, i1, b1, l1)) return "a partially applied built-in function";
|
2006-07-19 15:36:15 +00:00
|
|
|
if (matchContext(e, l1, t1)) return "a context containing " + showType(t1);
|
|
|
|
return "an unknown type";
|
|
|
|
}
|
|
|
|
|
2006-07-28 14:01:29 +00:00
|
|
|
|
|
|
|
string showValue(Expr e)
|
|
|
|
{
|
|
|
|
ATerm s;
|
|
|
|
int i;
|
|
|
|
if (matchStr(e, s)) {
|
|
|
|
string t = aterm2String(s), u;
|
|
|
|
for (string::iterator i = t.begin(); i != t.end(); ++i)
|
|
|
|
if (*i == '\"' || *i == '\\') u += "\\" + *i;
|
|
|
|
else if (*i == '\n') u += "\\n";
|
|
|
|
else if (*i == '\r') u += "\\r";
|
|
|
|
else if (*i == '\t') u += "\\t";
|
|
|
|
else u += *i;
|
|
|
|
return "\"" + u + "\"";
|
|
|
|
}
|
|
|
|
if (matchPath(e, s)) return aterm2String(s);
|
|
|
|
if (matchNull(e)) return "null";
|
|
|
|
if (matchInt(e, i)) return (format("%1%") % i).str();
|
|
|
|
if (e == eTrue) return "true";
|
|
|
|
if (e == eFalse) return "false";
|
|
|
|
/* !!! incomplete */
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|