2012-07-18 20:59:03 +02:00
|
|
|
#pragma once
|
2012-02-04 14:50:25 +01:00
|
|
|
|
|
|
|
#include "eval.hh"
|
|
|
|
|
|
|
|
#define LocalNoInline(f) static f __attribute__((noinline)); f
|
|
|
|
#define LocalNoInlineNoReturn(f) static f __attribute__((noinline, noreturn)); f
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
LocalNoInlineNoReturn(void throwEvalError(const char * s))
|
|
|
|
{
|
|
|
|
throw EvalError(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s2))
|
|
|
|
{
|
|
|
|
throw TypeError(format(s) % s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EvalState::forceValue(Value & v)
|
|
|
|
{
|
|
|
|
if (v.type == tThunk) {
|
2013-03-14 17:21:13 +01:00
|
|
|
Env * env = v.thunk.env;
|
|
|
|
Expr * expr = v.thunk.expr;
|
2012-02-04 14:50:25 +01:00
|
|
|
try {
|
|
|
|
v.type = tBlackhole;
|
|
|
|
//checkInterrupt();
|
2013-03-14 17:21:13 +01:00
|
|
|
expr->eval(*this, *env, v);
|
2012-02-04 14:50:25 +01:00
|
|
|
} catch (Error & e) {
|
2013-03-14 17:21:13 +01:00
|
|
|
v.type = tThunk;
|
|
|
|
v.thunk.env = env;
|
|
|
|
v.thunk.expr = expr;
|
2012-02-04 14:50:25 +01:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v.type == tApp)
|
|
|
|
callFunction(*v.app.left, *v.app.right, v);
|
|
|
|
else if (v.type == tBlackhole)
|
|
|
|
throwEvalError("infinite recursion encountered");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void EvalState::forceAttrs(Value & v)
|
|
|
|
{
|
|
|
|
forceValue(v);
|
|
|
|
if (v.type != tAttrs)
|
|
|
|
throwTypeError("value is %1% while an attribute set was expected", showType(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void EvalState::forceList(Value & v)
|
|
|
|
{
|
|
|
|
forceValue(v);
|
|
|
|
if (v.type != tList)
|
|
|
|
throwTypeError("value is %1% while a list was expected", showType(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|