repl: Add auto-listening capabilities -auto-lt (#405)

Closes #403
This commit is contained in:
Tyler Wilding 2021-05-01 10:33:41 -04:00 committed by GitHub
parent 8cc63ff35c
commit 44fa183922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View File

@ -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
- ./out/build/Debug/bin/goalc.exe -auto-lt

View File

@ -31,7 +31,7 @@ Compiler::Compiler(std::unique_ptr<ReplWrapper> 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)

View File

@ -23,7 +23,7 @@ enum class ReplStatus { OK, WANT_EXIT, WANT_RELOAD };
class Compiler {
public:
Compiler(std::unique_ptr<ReplWrapper> 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<FunctionEnv> compile_top_level_function(const std::string& name,

View File

@ -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<Compiler>(std::make_unique<ReplWrapper>());
status = compiler->execute_repl();
status = compiler->execute_repl(auto_listen);
if (status == ReplStatus::WANT_RELOAD) {
fmt::print("Reloading compiler...\n");
}