diff options
author | Ben Burdette <bburdette@gmail.com> | 2021-04-28 15:50:11 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2021-04-28 15:50:11 -0600 |
commit | f32c687f03e9764e55831d894b719fdf0104cf25 (patch) | |
tree | 245eb04a4d06180d33620211d2d8f352446315f4 /src/libcmd/command.cc | |
parent | 57c2dd5d8581f37392df369493b00794b619304e (diff) |
move repl.cc to libcmd for linkage
Diffstat (limited to 'src/libcmd/command.cc')
-rw-r--r-- | src/libcmd/command.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 644c9c3b0..d790bb51d 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,7 @@ void StoreCommand::run() run(getStore()); } +/* EvalCommand::EvalCommand() { addFlag({ @@ -77,6 +78,42 @@ ref<EvalState> EvalCommand::getEvalState() } return ref<EvalState>(evalState); } +*/ +EvalCommand::EvalCommand() +{ + addFlag({ + .longName = "debugger", + .description = "start an interactive environment if evaluation fails", + .handler = {&startReplOnEvalErrors, true}, + }); +} +// ref<EvalState> EvalCommand::getEvalState() +// { +// if (!evalState) +// evalState = std::make_shared<EvalState>(searchPath, getStore()); +// return ref<EvalState>(evalState); +// } +extern std::function<void(const Error & error, const std::map<std::string, Value *> & env)> debuggerHook; + +ref<EvalState> EvalCommand::getEvalState() +{ + if (!evalState) { + evalState = std::make_shared<EvalState>(searchPath, getStore()); + if (startReplOnEvalErrors) + debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const std::map<std::string, Value *> & env) { + printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what()); + runRepl(evalState, env); + }; + } + return ref<EvalState>(evalState); +} + +EvalCommand::~EvalCommand() +{ + if (evalState) + evalState->printStats(); +} + RealisedPathsCommand::RealisedPathsCommand(bool recursive) : recursive(recursive) |