fix(furdb): improve program execution
This commit is contained in:
@@ -13,7 +13,10 @@ struct context {
|
|||||||
furvm::function_h mainFunction;
|
furvm::function_h mainFunction;
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
bool halt = false;
|
bool halt = true;
|
||||||
|
|
||||||
|
void kill() const;
|
||||||
|
void init();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "furvm/executor.hpp"
|
#include "furvm/executor.hpp"
|
||||||
#include "furvm/function.hpp"
|
#include "furvm/function.hpp"
|
||||||
|
#include "furvm/instruction.hpp"
|
||||||
#include "furvm/module.hpp"
|
#include "furvm/module.hpp"
|
||||||
#include "furvm/thing.hpp"
|
#include "furvm/thing.hpp"
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
command_info command::parse(std::string_view line) {
|
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) {
|
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();
|
ctx.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-6
@@ -5,14 +5,27 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void context::run() {
|
void context::kill() const {
|
||||||
if ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done)
|
while (!executor->done())
|
||||||
executor->push_frame(mod, *mainFunction);
|
executor->pop_frame();
|
||||||
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done && !halt) {
|
|
||||||
executor->step();
|
|
||||||
}
|
}
|
||||||
if ((executor->flags() & furvm::executor_flags::Done) == furvm::executor_flags::Done) {
|
|
||||||
|
void context::init() {
|
||||||
|
kill();
|
||||||
|
executor->push_frame(mod, *mainFunction);
|
||||||
|
executor->clear_flags();
|
||||||
|
}
|
||||||
|
|
||||||
|
void context::run() {
|
||||||
|
if (executor->done()) init();
|
||||||
|
executor->unsuspend();
|
||||||
|
|
||||||
|
halt = false;
|
||||||
|
while (!executor->done() && !halt)
|
||||||
|
executor->step();
|
||||||
|
if (executor->done()) {
|
||||||
std::cout << "Execution finished\n";
|
std::cout << "Execution finished\n";
|
||||||
|
halt = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user