From 665982049d26b6aa60038f3e6b63a1d8067ef97c Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Mon, 17 Aug 2026 11:20:44 +0200 Subject: [PATCH] fix(furdb): improve program execution --- furdb/include/context.hpp | 5 ++++- furdb/src/command.cpp | 13 +++++++++++++ furdb/src/context.cpp | 23 ++++++++++++++++++----- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/furdb/include/context.hpp b/furdb/include/context.hpp index 9da9f96..fd3944f 100644 --- a/furdb/include/context.hpp +++ b/furdb/include/context.hpp @@ -13,7 +13,10 @@ struct context { furvm::function_h mainFunction; bool running = true; - bool halt = false; + bool halt = true; + + void kill() const; + void init(); void run(); diff --git a/furdb/src/command.cpp b/furdb/src/command.cpp index 8512abb..c464d08 100644 --- a/furdb/src/command.cpp +++ b/furdb/src/command.cpp @@ -2,6 +2,7 @@ #include "furvm/executor.hpp" #include "furvm/function.hpp" +#include "furvm/instruction.hpp" #include "furvm/module.hpp" #include "furvm/thing.hpp" @@ -9,6 +10,7 @@ #include #include #include +#include #include command_info command::parse(std::string_view line) { @@ -55,6 +57,17 @@ void quit_command::execute(context& ctx, const command_info& info) { } void run_command::execute(context& ctx, const command_info& info) { + if (!ctx.executor->done()) { + std::cout << "A program is currently running, do you want to kill it? (y/N) "; + std::string answer; + if (!std::getline(std::cin, answer)) { + ctx.running = false; + return; + } + if (answer != "y" && answer != "Y" && answer != "yes") return; + ctx.kill(); + } + std::cout << "Running the program\n"; ctx.run(); } diff --git a/furdb/src/context.cpp b/furdb/src/context.cpp index f93068d..852e2fe 100644 --- a/furdb/src/context.cpp +++ b/furdb/src/context.cpp @@ -5,14 +5,27 @@ #include #include +void context::kill() const { + while (!executor->done()) + executor->pop_frame(); +} + +void context::init() { + kill(); + executor->push_frame(mod, *mainFunction); + executor->clear_flags(); +} + void context::run() { - if ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) - executor->push_frame(mod, *mainFunction); - while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done && !halt) { + if (executor->done()) init(); + executor->unsuspend(); + + halt = false; + while (!executor->done() && !halt) executor->step(); - } - if ((executor->flags() & furvm::executor_flags::Done) == furvm::executor_flags::Done) { + if (executor->done()) { std::cout << "Execution finished\n"; + halt = true; } }