6#include "eval-error.hh"
23 if (!
p)
throw std::bad_alloc();
36 if (!*valueAllocCache) {
37 *valueAllocCache = GC_malloc_many(
sizeof(Value));
38 if (!*valueAllocCache)
throw std::bad_alloc();
43 void *
p = *valueAllocCache;
44 *valueAllocCache = GC_NEXT(
p);
56Env & EvalState::allocEnv(
size_t size)
59 nrValuesInEnvs += size;
66 if (!*env1AllocCache) {
67 *env1AllocCache = GC_malloc_many(
sizeof(
Env) +
sizeof(
Value *));
68 if (!*env1AllocCache)
throw std::bad_alloc();
71 void *
p = *env1AllocCache;
72 *env1AllocCache = GC_NEXT(
p);
77 env = (Env *)
allocBytes(
sizeof(Env) + size *
sizeof(Value *));
89 Env * env = v.payload.thunk.env;
90 assert(env || v.isBlackhole());
91 Expr * expr = v.payload.thunk.expr;
96 expr->eval(*
this, *env, v);
98 ExprBlackHole::throwInfiniteRecursionError(*
this, v);
100 v.mkThunk(env, expr);
101 tryFixupBlackHolePos(v, pos);
106 callFunction(*v.payload.app.left, *v.payload.app.right, v, pos);
110[[gnu::always_inline]]
111inline void EvalState::forceAttrs(
Value & v,
const PosIdx pos, std::string_view errorCtx)
113 forceAttrs(v, [&]() {
return pos; }, errorCtx);
117template <
typename Callable>
118[[gnu::always_inline]]
119inline void EvalState::forceAttrs(
Value & v, Callable getPos, std::string_view errorCtx)
121 PosIdx pos = getPos();
123 if (v.type() != nAttrs) {
125 "expected a set but found %1%: %2%",
127 ValuePrinter(*
this, v, errorPrintOptions)
128 ).withTrace(pos, errorCtx).debugThrow();
133[[gnu::always_inline]]
134inline void EvalState::forceList(
Value & v,
const PosIdx pos, std::string_view errorCtx)
139 "expected a list but found %1%: %2%",
141 ValuePrinter(*
this, v, errorPrintOptions)
142 ).withTrace(pos, errorCtx).debugThrow();
146[[gnu::always_inline]]
148 if (callDepth > settings.maxCallDepth)
149 error<EvalError>(
"stack overflow; max-call-depth exceeded").atPos(pos).debugThrow();
void forceValue(Value &v, const PosIdx pos)
Definition eval-inline.hh:86
Value * allocValue()
Definition eval-inline.hh:29
CallDepth addCallDepth(const PosIdx pos)
Definition eval-inline.hh:147
void * allocBytes(size_t n)
Definition eval-inline.hh:15
std::shared_ptr< T > p
Definition lexer.l:1269
Common printing functions for the Nix language.