From 44fa1839225a0d4548b174585b21948b3a6917aa Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 1 May 2021 10:33:41 -0400 Subject: [PATCH] repl: Add auto-listening capabilities `-auto-lt` (#405) Closes #403 --- Taskfile.yml | 4 ++-- goalc/compiler/Compiler.cpp | 6 +++++- goalc/compiler/Compiler.h | 2 +- goalc/main.cpp | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 8ce4505b6e..e850426289 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,7 +6,7 @@ tasks: - python ./third-party/run-clang-format/run-clang-format.py -r common decompiler game goalc test -i run-game: cmds: - - ./out/build/Debug/bin/gk.exe -fakeiso -debug + - ./out/build/Debug/bin/gk.exe -fakeiso -debug -nodisplay repl: cmds: - - ./out/build/Debug/bin/goalc.exe \ No newline at end of file + - ./out/build/Debug/bin/goalc.exe -auto-lt \ No newline at end of file diff --git a/goalc/compiler/Compiler.cpp b/goalc/compiler/Compiler.cpp index 901d4e37be..fbc999084d 100644 --- a/goalc/compiler/Compiler.cpp +++ b/goalc/compiler/Compiler.cpp @@ -31,7 +31,7 @@ Compiler::Compiler(std::unique_ptr repl) } } -ReplStatus Compiler::execute_repl() { +ReplStatus Compiler::execute_repl(bool auto_listen) { // init repl m_repl->print_welcome_message(); auto examples = m_repl->examples; @@ -45,6 +45,10 @@ ReplStatus Compiler::execute_repl() { m_repl->get_repl().set_highlighter_callback( std::bind(&Compiler::repl_coloring, this, _1, _2, std::cref(regex_colors))); + if (auto_listen) { + m_listener.connect_to_target(); + } + while (!m_want_exit && !m_want_reload) { try { // 1). get a line from the user (READ) diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index 9e862cee88..65bbf30bbf 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -23,7 +23,7 @@ enum class ReplStatus { OK, WANT_EXIT, WANT_RELOAD }; class Compiler { public: Compiler(std::unique_ptr repl = nullptr); - ReplStatus execute_repl(); + ReplStatus execute_repl(bool auto_listen = false); goos::Interpreter& get_goos() { return m_goos; } FileEnv* compile_object_file(const std::string& name, goos::Object code, bool allow_emit); std::unique_ptr compile_top_level_function(const std::string& name, diff --git a/goalc/main.cpp b/goalc/main.cpp index 5216f15e80..60432a6c2c 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -29,15 +29,17 @@ int main(int argc, char** argv) { std::string argument; bool verbose = false; + bool auto_listen = false; for (int i = 1; i < argc; i++) { if (std::string("-v") == argv[i]) { verbose = true; - break; } - if (std::string("-cmd") == argv[i] && i < argc - 1) { argument = argv[++i]; } + if (std::string("-auto-lt") == argv[i]) { + auto_listen = true; + } } setup_logging(verbose); @@ -50,7 +52,7 @@ int main(int argc, char** argv) { ReplStatus status = ReplStatus::WANT_RELOAD; while (status == ReplStatus::WANT_RELOAD) { compiler = std::make_unique(std::make_unique()); - status = compiler->execute_repl(); + status = compiler->execute_repl(auto_listen); if (status == ReplStatus::WANT_RELOAD) { fmt::print("Reloading compiler...\n"); }