aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2020-06-19 14:22:06 -0400
committerMatthew Bauer <mjbauer95@gmail.com>2020-06-19 14:22:06 -0400
commit2796b01e863bf3a6d28cc89bb46c6388d8b73fbc (patch)
tree20fec553f605b3a6f7474cd337eb457c9a8a56f1 /src/libexpr/eval.cc
parent5e631e3304aaf00b912c12025debfd35942a0ca9 (diff)
parent424bb5819f736af7413c343d462663474222eaac (diff)
Merge remote-tracking branch 'origin/master' into substitute-other-storedir
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 8e71db2b8..b90a64357 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -161,12 +161,12 @@ const Value *getPrimOp(const Value &v) {
}
-string showType(const Value & v)
+string showType(ValueType type)
{
- switch (v.type) {
+ switch (type) {
case tInt: return "an integer";
- case tBool: return "a boolean";
- case tString: return v.string.context ? "a string with context" : "a string";
+ case tBool: return "a Boolean";
+ case tString: return "a string";
case tPath: return "a path";
case tNull: return "null";
case tAttrs: return "a set";
@@ -175,14 +175,27 @@ string showType(const Value & v)
case tApp: return "a function application";
case tLambda: return "a function";
case tBlackhole: return "a black hole";
+ case tPrimOp: return "a built-in function";
+ case tPrimOpApp: return "a partially applied built-in function";
+ case tExternal: return "an external value";
+ case tFloat: return "a float";
+ }
+ abort();
+}
+
+
+string showType(const Value & v)
+{
+ switch (v.type) {
+ case tString: return v.string.context ? "a string with context" : "a string";
case tPrimOp:
return fmt("the built-in function '%s'", string(v.primOp->name));
case tPrimOpApp:
return fmt("the partially applied built-in function '%s'", string(getPrimOp(v)->primOp->name));
case tExternal: return v.external->showType();
- case tFloat: return "a float";
+ default:
+ return showType(v.type);
}
- abort();
}
@@ -323,6 +336,7 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
, sOutputHash(symbols.create("outputHash"))
, sOutputHashAlgo(symbols.create("outputHashAlgo"))
, sOutputHashMode(symbols.create("outputHashMode"))
+ , sRecurseForDerivations(symbols.create("recurseForDerivations"))
, repair(NoRepair)
, store(store)
, baseEnv(allocEnv(128))
@@ -471,14 +485,21 @@ Value * EvalState::addConstant(const string & name, Value & v)
Value * EvalState::addPrimOp(const string & name,
size_t arity, PrimOpFun primOp)
{
+ auto name2 = string(name, 0, 2) == "__" ? string(name, 2) : name;
+ Symbol sym = symbols.create(name2);
+
+ /* Hack to make constants lazy: turn them into a application of
+ the primop to a dummy value. */
if (arity == 0) {
+ auto vPrimOp = allocValue();
+ vPrimOp->type = tPrimOp;
+ vPrimOp->primOp = new PrimOp(primOp, 1, sym);
Value v;
- primOp(*this, noPos, nullptr, v);
+ mkApp(v, *vPrimOp, *vPrimOp);
return addConstant(name, v);
}
+
Value * v = allocValue();
- string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name;
- Symbol sym = symbols.create(name2);
v->type = tPrimOp;
v->primOp = new PrimOp(primOp, arity, sym);
staticBaseEnv.vars[symbols.create(name)] = baseEnvDispl;