aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/repl.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-06-16 23:10:09 +0200
committereldritch horrors <pennae@lix.systems>2024-06-17 19:46:44 +0000
commitad5366c2ad43216ac9a61ccb1477ff9859d1a75c (patch)
treee986b1f0e9510641279bba164b36bae9a96be6be /src/libcmd/repl.cc
parentb8f49a8eaf619df6d228f2e0f9814c4a5fa4aec5 (diff)
libexpr: pass Exprs as references, not pointers
almost all places where Exprs are passed as pointers expect the pointers to be non-null. pass them as references to encode this constraint in the type system as well (and also communicate that Exprs must not be freed). Change-Id: Ia98f166fec3c23151f906e13acb4a0954a5980a2
Diffstat (limited to 'src/libcmd/repl.cc')
-rw-r--r--src/libcmd/repl.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 24ab8acb9..99abbe44b 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -155,7 +155,7 @@ struct NixRepl
void reloadFiles();
void addAttrsToScope(Value & attrs);
void addVarToScope(const Symbol name, Value & v);
- Expr * parseString(std::string s);
+ Expr & parseString(std::string s);
void evalString(std::string s, Value & v);
void loadDebugTraceEnv(DebugTrace & dt);
@@ -428,9 +428,9 @@ StringSet NixRepl::completePrefix(const std::string & prefix)
auto expr = cur.substr(0, dot);
auto cur2 = cur.substr(dot + 1);
- Expr * e = parseString(expr);
+ Expr & e = parseString(expr);
Value v;
- e->eval(*state, *env, v);
+ e.eval(*state, *env, v);
state->forceAttrs(v, noPos, "while evaluating an attrset for the purpose of completion (this error should not be displayed; file an issue?)");
for (auto & i : *v.attrs) {
@@ -821,7 +821,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
line[p + 1] != '=' &&
isVarName(name = removeWhitespace(line.substr(0, p))))
{
- Expr * e = parseString(line.substr(p + 1));
+ Expr & e = parseString(line.substr(p + 1));
Value & v(*state->allocValue());
v.mkThunk(env, e);
addVarToScope(state->symbols.create(name), v);
@@ -946,7 +946,7 @@ Value * NixRepl::getReplOverlaysEvalFunction()
auto code =
#include "repl-overlays.nix.gen.hh"
;
- auto expr = state->parseExprFromString(
+ auto & expr = state->parseExprFromString(
code,
SourcePath(evalReplInitFilesPath),
state->staticBaseEnv
@@ -1054,7 +1054,7 @@ Value * NixRepl::bindingsToAttrs()
}
-Expr * NixRepl::parseString(std::string s)
+Expr & NixRepl::parseString(std::string s)
{
return state->parseExprFromString(std::move(s), state->rootPath(CanonPath::fromCwd()), staticEnv);
}
@@ -1062,16 +1062,16 @@ Expr * NixRepl::parseString(std::string s)
void NixRepl::evalString(std::string s, Value & v)
{
- Expr * e = parseString(s);
- e->eval(*state, *env, v);
+ Expr & e = parseString(s);
+ e.eval(*state, *env, v);
state->forceValue(v, v.determinePos(noPos));
}
Value * NixRepl::evalFile(SourcePath & path)
{
- auto expr = state->parseExprFromFile(path, staticEnv);
+ auto & expr = state->parseExprFromFile(path, staticEnv);
Value * result(state->allocValue());
- expr->eval(*state, *env, *result);
+ expr.eval(*state, *env, *result);
state->forceValue(*result, result->determinePos(noPos));
return result;
}