forked from lix-project/lix
remove fakeEnv stuff and instead use last context from the stack
This commit is contained in:
parent
7954a18a48
commit
bc67cb5ad1
|
@ -775,12 +775,30 @@ valmap * mapStaticEnvBindings(const StaticEnv &se, const Env &env)
|
||||||
evaluator. So here are some helper functions for throwing
|
evaluator. So here are some helper functions for throwing
|
||||||
exceptions. */
|
exceptions. */
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, EvalState &evalState))
|
||||||
{
|
{
|
||||||
auto error = EvalError(s, s2);
|
auto error = EvalError(s, s2);
|
||||||
|
|
||||||
if (debuggerHook && expr)
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
debuggerHook(&error, env, *expr);
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const string & s2, EvalState &evalState))
|
||||||
|
{
|
||||||
|
auto error = EvalError({
|
||||||
|
.msg = hintfmt(s, s2),
|
||||||
|
.errPos = pos
|
||||||
|
});
|
||||||
|
|
||||||
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,25 +815,32 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, const string & s3, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const string & s2, const string & s3, EvalState &evalState))
|
||||||
{
|
|
||||||
auto error = EvalError(s, s2, s3);
|
|
||||||
|
|
||||||
if (debuggerHook && expr)
|
|
||||||
debuggerHook(&error, env, *expr);
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const string & s2, const string & s3, Env & env, Expr *expr))
|
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
auto error = EvalError({
|
||||||
.msg = hintfmt(s, s2, s3),
|
.msg = hintfmt(s, s2, s3),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
});
|
||||||
|
|
||||||
if (debuggerHook && expr)
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
debuggerHook(&error, env, *expr);
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, const string & s3, EvalState &evalState))
|
||||||
|
{
|
||||||
|
auto error = EvalError({
|
||||||
|
.msg = hintfmt(s, s2, s3),
|
||||||
|
.errPos = noPos
|
||||||
|
});
|
||||||
|
|
||||||
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -834,45 +859,37 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, EvalState &evalState))
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
auto error = TypeError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
});
|
||||||
|
|
||||||
if (debuggerHook && expr)
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
debuggerHook(&error, env, *expr);
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v, Env & env, Expr *expr))
|
|
||||||
|
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v, EvalState &evalState))
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
auto error = TypeError({
|
||||||
.msg = hintfmt(s, v),
|
.msg = hintfmt(s, v),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
});
|
||||||
|
|
||||||
if (debuggerHook && expr)
|
if (debuggerHook && !evalState.debugTraces.empty()) {
|
||||||
debuggerHook(&error, env, *expr);
|
DebugTrace &last = evalState.debugTraces.front();
|
||||||
|
debuggerHook(&error, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const string &s2, Env & env, Expr *expr))
|
|
||||||
// {
|
|
||||||
// auto error = TypeError({
|
|
||||||
// .msg = hintfmt(s, s2),
|
|
||||||
// .errPos = pos
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (debuggerHook && expr)
|
|
||||||
// debuggerHook(&error, env, *expr);
|
|
||||||
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2, Env & env, Expr *expr))
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
auto error = TypeError({
|
||||||
|
@ -886,13 +903,6 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v, Env & env, Expr *expr))
|
|
||||||
// {
|
|
||||||
// auto error = TypeError({
|
|
||||||
// .msg = hintfmt(s, showType(v))
|
|
||||||
// .errPos = e ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, const string & s1, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, const string & s1, Env & env, Expr *expr))
|
||||||
{
|
{
|
||||||
auto error = AssertionError({
|
auto error = AssertionError({
|
||||||
|
@ -2053,8 +2063,8 @@ NixInt EvalState::forceInt(Value & v, const Pos & pos)
|
||||||
{
|
{
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nInt)
|
if (v.type() != nInt)
|
||||||
throwTypeError(pos, "value is %1% while an integer was expected", v,
|
throwTypeError(pos, "value is %1% while an integer was expected", v, *this);
|
||||||
fakeEnv(1), 0);
|
|
||||||
return v.integer;
|
return v.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2066,7 +2076,7 @@ NixFloat EvalState::forceFloat(Value & v, const Pos & pos)
|
||||||
return v.integer;
|
return v.integer;
|
||||||
else if (v.type() != nFloat)
|
else if (v.type() != nFloat)
|
||||||
throwTypeError(pos, "value is %1% while a float was expected", v,
|
throwTypeError(pos, "value is %1% while a float was expected", v,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
return v.fpoint;
|
return v.fpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2076,7 +2086,7 @@ bool EvalState::forceBool(Value & v, const Pos & pos)
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nBool)
|
if (v.type() != nBool)
|
||||||
throwTypeError(pos, "value is %1% while a Boolean was expected", v,
|
throwTypeError(pos, "value is %1% while a Boolean was expected", v,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2092,7 +2102,7 @@ void EvalState::forceFunction(Value & v, const Pos & pos)
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nFunction && !isFunctor(v))
|
if (v.type() != nFunction && !isFunctor(v))
|
||||||
throwTypeError(pos, "value is %1% while a function was expected", v,
|
throwTypeError(pos, "value is %1% while a function was expected", v,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2101,7 +2111,7 @@ std::string_view EvalState::forceString(Value & v, const Pos & pos)
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nString) {
|
if (v.type() != nString) {
|
||||||
throwTypeError(pos, "value is %1% while a string was expected", v,
|
throwTypeError(pos, "value is %1% while a string was expected", v,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
}
|
}
|
||||||
return v.string.s;
|
return v.string.s;
|
||||||
}
|
}
|
||||||
|
@ -2152,10 +2162,10 @@ std::string_view EvalState::forceStringNoCtx(Value & v, const Pos & pos)
|
||||||
if (v.string.context) {
|
if (v.string.context) {
|
||||||
if (pos)
|
if (pos)
|
||||||
throwEvalError(pos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')",
|
throwEvalError(pos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')",
|
||||||
v.string.s, v.string.context[0], fakeEnv(1), 0);
|
v.string.s, v.string.context[0], *this);
|
||||||
else
|
else
|
||||||
throwEvalError("the string '%1%' is not allowed to refer to a store path (such as '%2%')",
|
throwEvalError("the string '%1%' is not allowed to refer to a store path (such as '%2%')",
|
||||||
v.string.s, v.string.context[0], fakeEnv(1), 0);
|
v.string.s, v.string.context[0], *this);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -2210,8 +2220,7 @@ BackedStringView EvalState::coerceToString(const Pos & pos, Value & v, PathSet &
|
||||||
return std::move(*maybeString);
|
return std::move(*maybeString);
|
||||||
auto i = v.attrs->find(sOutPath);
|
auto i = v.attrs->find(sOutPath);
|
||||||
if (i == v.attrs->end())
|
if (i == v.attrs->end())
|
||||||
throwTypeError(pos, "cannot coerce a set to a string",
|
throwTypeError(pos, "cannot coerce a set to a string", *this);
|
||||||
fakeEnv(1), 0);
|
|
||||||
return coerceToString(pos, *i->value, context, coerceMore, copyToStore);
|
return coerceToString(pos, *i->value, context, coerceMore, copyToStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2240,8 +2249,7 @@ BackedStringView EvalState::coerceToString(const Pos & pos, Value & v, PathSet &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throwTypeError(pos, "cannot coerce %1% to a string", v,
|
throwTypeError(pos, "cannot coerce %1% to a string", v, *this);
|
||||||
fakeEnv(1), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2250,7 +2258,7 @@ string EvalState::copyPathToStore(PathSet & context, const Path & path)
|
||||||
if (nix::isDerivation(path))
|
if (nix::isDerivation(path))
|
||||||
throwEvalError("file names are not allowed to end in '%1%'",
|
throwEvalError("file names are not allowed to end in '%1%'",
|
||||||
drvExtension,
|
drvExtension,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
|
|
||||||
Path dstPath;
|
Path dstPath;
|
||||||
auto i = srcToStore.find(path);
|
auto i = srcToStore.find(path);
|
||||||
|
@ -2276,7 +2284,7 @@ Path EvalState::coerceToPath(const Pos & pos, Value & v, PathSet & context)
|
||||||
string path = coerceToString(pos, v, context, false, false).toOwned();
|
string path = coerceToString(pos, v, context, false, false).toOwned();
|
||||||
if (path == "" || path[0] != '/')
|
if (path == "" || path[0] != '/')
|
||||||
throwEvalError(pos, "string '%1%' doesn't represent an absolute path", path,
|
throwEvalError(pos, "string '%1%' doesn't represent an absolute path", path,
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2358,7 +2366,7 @@ bool EvalState::eqValues(Value & v1, Value & v2)
|
||||||
throwEvalError("cannot compare %1% with %2%",
|
throwEvalError("cannot compare %1% with %2%",
|
||||||
showType(v1),
|
showType(v1),
|
||||||
showType(v2),
|
showType(v2),
|
||||||
fakeEnv(1), 0);
|
*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue