aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2021-12-20 12:32:21 -0700
committerBen Burdette <bburdette@gmail.com>2021-12-20 12:32:21 -0700
commitf317019edda7afac8590e68d4d979b03a2cdbf62 (patch)
tree7720ebe8cc936b5d801acdad65d34591b6ef615e /src
parentc151a9b4262dfc5fc251ed0ebcf862731b0f795c (diff)
:d error
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/command.cc2
-rw-r--r--src/libcmd/command.hh2
-rw-r--r--src/libcmd/repl.cc93
-rw-r--r--src/libexpr/eval.hh1
-rw-r--r--src/libexpr/parser.y5
5 files changed, 86 insertions, 17 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index 2e00b42ff..b37959a2e 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -82,7 +82,7 @@ ref<EvalState> EvalCommand::getEvalState()
if (expr.staticenv)
{
auto vm = mapStaticEnvBindings(*expr.staticenv.get(), env);
- runRepl(evalState, *vm);
+ runRepl(evalState, ref<const Error>(&error), *vm);
}
};
}
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh
index 0d847d255..e27ee2e9e 100644
--- a/src/libcmd/command.hh
+++ b/src/libcmd/command.hh
@@ -314,6 +314,8 @@ void printClosureDiff(
void runRepl(
ref<EvalState> evalState,
+ std::optional<ref<const Error>> debugError,
const std::map<std::string, Value *> & extraEnv);
+
}
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 910f0f694..0eea2389b 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -50,6 +50,8 @@ struct NixRepl
ref<EvalState> state;
Bindings * autoArgs;
+ std::optional<ref<const Error>> debugError;
+
Strings loadedFiles;
const static int envSize = 32768;
@@ -70,6 +72,7 @@ struct NixRepl
void loadFile(const Path & path);
void loadFlake(const std::string & flakeRef);
void initEnv();
+ void loadFiles();
void reloadFiles();
void addAttrsToScope(Value & attrs);
void addVarToScope(const Symbol & name, Value * v);
@@ -199,6 +202,9 @@ namespace {
void NixRepl::mainLoop(const std::vector<std::string> & files)
{
+ std::cout << "iinitial mainLoop; " << std::endl;
+ // printStaticEnvBindings(*staticEnv, 0);
+
string error = ANSI_RED "error:" ANSI_NORMAL " ";
notice("Welcome to Nix " + nixVersion + ". Type :? for help.\n");
@@ -207,7 +213,7 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
loadedFiles.push_back(i);
}
- reloadFiles();
+ loadFiles();
if (!loadedFiles.empty()) notice("");
// Allow nix-repl specific settings in .inputrc
@@ -225,6 +231,9 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
std::string input;
+ std::cout << "pre MAINLOOP; " << std::endl;
+ // printStaticEnvBindings(*staticEnv, 0);
+
while (true) {
// When continuing input from previous lines, don't print a prompt, just align to the same
// number of chars as the prompt.
@@ -415,21 +424,40 @@ bool NixRepl::processLine(string line)
std::cout
<< "The following commands are available:\n"
<< "\n"
- << " <expr> Evaluate and print expression\n"
- << " <x> = <expr> Bind expression to variable\n"
- << " :a <expr> Add attributes from resulting set to scope\n"
- << " :b <expr> Build derivation\n"
- << " :e <expr> Open package or function in $EDITOR\n"
- << " :i <expr> Build derivation, then install result into current profile\n"
- << " :l <path> Load Nix expression and add it to scope\n"
- << " :lf <ref> Load Nix flake and add it to scope\n"
- << " :p <expr> Evaluate and print expression recursively\n"
- << " :q Exit nix-repl\n"
- << " :r Reload all files\n"
- << " :s <expr> Build dependencies of derivation, then start nix-shell\n"
- << " :t <expr> Describe result of evaluation\n"
- << " :u <expr> Build derivation, then start nix-shell\n"
- << " :doc <expr> Show documentation of a builtin function\n";
+ << " <expr> Evaluate and print expression\n"
+ << " <x> = <expr> Bind expression to variable\n"
+ << " :a <expr> Add attributes from resulting set to scope\n"
+ << " :b <expr> Build derivation\n"
+ << " :e <expr> Open package or function in $EDITOR\n"
+ << " :i <expr> Build derivation, then install result into current profile\n"
+ << " :l <path> Load Nix expression and add it to scope\n"
+ << " :lf <ref> Load Nix flake and add it to scope\n"
+ << " :p <expr> Evaluate and print expression recursively\n"
+ << " :q Exit nix-repl\n"
+ << " :r Reload all files\n"
+ << " :s <expr> Build dependencies of derivation, then start nix-shell\n"
+ << " :t <expr> Describe result of evaluation\n"
+ << " :u <expr> Build derivation, then start nix-shell\n"
+ << " :doc <expr> Show documentation of a builtin function\n"
+ << " :d <cmd> Debug mode commands\n"
+ << " :d stack Show call stack\n"
+ << " :d stack <int> Detail for step N\n"
+ << " :d error Show current error\n";
+ }
+
+ else if (command == ":d" || command == ":debug") {
+ std::cout << "debug: '" << arg << "'" << std::endl;
+ if (arg == "stack") {
+ }
+ else if (arg == "error") {
+ if (this->debugError.has_value()) {
+ showErrorInfo(std::cout, (*debugError)->info(), true);
+ }
+ else
+ {
+ notice("error information not available");
+ }
+ }
}
else if (command == ":a" || command == ":add") {
@@ -561,11 +589,13 @@ bool NixRepl::processLine(string line)
line[p + 1] != '=' &&
isVarName(name = removeWhitespace(string(line, 0, p))))
{
+ std::cout << "isvarname" << std::endl;
Expr * e = parseString(string(line, p + 1));
Value *v = new Value(*state->allocValue());
v->mkThunk(env, e);
addVarToScope(state->symbols.create(name), v);
} else {
+ std::cout << "evalstring" << std::endl;
Value v;
evalString(line, v);
printValue(std::cout, v, 1) << std::endl;
@@ -623,6 +653,12 @@ void NixRepl::reloadFiles()
{
initEnv();
+ loadFiles();
+}
+
+
+void NixRepl::loadFiles()
+{
Strings old = loadedFiles;
loadedFiles.clear();
@@ -649,12 +685,28 @@ void NixRepl::addVarToScope(const Symbol & name, Value * v)
{
if (displ >= envSize)
throw Error("environment full; cannot add more variables");
+ if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end())
+ staticEnv->vars.erase(oldVar);
staticEnv->vars.emplace_back(name, displ);
staticEnv->sort();
env->values[displ++] = v;
varNames.insert((string) name);
+ notice("Added variable to scope: %1%", name);
+
}
+// version from master.
+// void NixRepl::addVarToScope(const Symbol & name, Value & v)
+// {
+// if (displ >= envSize)
+// throw Error("environment full; cannot add more variables");
+// if (auto oldVar = staticEnv.find(name); oldVar != staticEnv.vars.end())
+// staticEnv.vars.erase(oldVar);
+// staticEnv.vars.emplace_back(name, displ);
+// staticEnv.sort();
+// env->values[displ++] = &v;
+// varNames.insert((string) name);
+// }
Expr * NixRepl::parseString(string s)
{
@@ -665,8 +717,11 @@ Expr * NixRepl::parseString(string s)
void NixRepl::evalString(string s, Value & v)
{
+ std::cout << "pre partstirns:l" << std::endl;
Expr * e = parseString(s);
+ std::cout << "pre e->eval" << std::endl;
e->eval(*state, *env, v);
+ std::cout << "prev fv" << std::endl;
state->forceValue(v);
}
@@ -817,10 +872,13 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
void runRepl(
ref<EvalState> evalState,
+ std::optional<ref<const Error>> debugError,
const std::map<std::string, Value *> & extraEnv)
{
auto repl = std::make_unique<NixRepl>(evalState);
+ repl->debugError = debugError;
+
repl->initEnv();
std::set<std::string> names;
@@ -834,6 +892,9 @@ void runRepl(
printError(hintfmt("The following extra variables are in scope: %s\n", concatStringsSep(", ", names)).str());
// printError("The following extra variables are in scope: %s\n", concatStringsSep(", ", names));
+ std::cout << " pre repl->mainLoop({});" << std::endl;
+ // printStaticEnvBindings(*repl->staticEnv, 0);
+
repl->mainLoop({});
}
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 485c2df83..4b3e7d69a 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -26,6 +26,7 @@ typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args,
extern std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook;
void printStaticEnvBindings(const Expr &expr);
+void printStaticEnvBindings(const StaticEnv &se, int lvl = 0);
struct PrimOp
{
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 58af0df7d..066dc4ecc 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -21,6 +21,7 @@
#include "nixexpr.hh"
#include "eval.hh"
#include "globals.hh"
+#include <iostream>
namespace nix {
@@ -615,6 +616,10 @@ Expr * EvalState::parse(const char * text, FileOrigin origin,
if (res) throw ParseError(data.error.value());
+ std::cout << " data.result->bindVars(staticEnv); " << std::endl;
+
+ // printStaticEnvBindings(*staticEnv, 0);
+
data.result->bindVars(staticEnv);
return data.result;