fix(furdb): improve program execution
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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 <cstddef>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
+18
-5
@@ -5,14 +5,27 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user