diff --git a/runtime/main.cpp b/runtime/main.cpp index f751e95..52e63b6 100644 --- a/runtime/main.cpp +++ b/runtime/main.cpp @@ -3,16 +3,16 @@ #include "rpc_server.hpp" #include "vm.hpp" #include "vm_provider.hpp" +#include #include +#include #include #include #include #include #include -bool print_stack_debug = true; - -int execute_file_and_exit(std::string filename) +int execute_file_and_exit(std::string filename, bool print_debug) { auto file = std::ifstream(); file.open(filename.c_str()); @@ -36,7 +36,7 @@ int execute_file_and_exit(std::string filename) { .flame_graph = false, .code_coverage = false, - .print_stack_debug = print_stack_debug, + .print_debug = print_debug, }); vm.run_until_done(); return 0; @@ -45,7 +45,27 @@ int execute_file_and_exit(std::string filename) int main(int argc, char** argv) { if (argc >= 3 && std::string(argv[1]) == "run") { - return execute_file_and_exit(argv[2]); + auto filename = std::string(); + bool print_debug = false; + + for (int i = 2; i < argc; ++i) { + auto arg = std::string(argv[i]); + if (arg == "--print-debug") { + print_debug = true; + } else { + if (!filename.empty()) { + std::cerr << std::format("error: >1 files specified\n"); + std::exit(1); + } + filename = arg; + } + } + if (filename.empty()) { + std::cerr << std::format("error: no file specified\n"); + std::exit(1); + } + + return execute_file_and_exit(argv[2], print_debug); } auto state = sliger::rpc::vm_provider::VmProvider(); diff --git a/runtime/vm.cpp b/runtime/vm.cpp index ef9aa5d..7e7fe48 100644 --- a/runtime/vm.cpp +++ b/runtime/vm.cpp @@ -30,7 +30,7 @@ void VM::run_n_instructions(size_t amount) void VM::run_instruction() { - if (this->opts.print_stack_debug) { + if (this->opts.print_debug) { // std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc, // maybe_op_to_string(this->program[this->pc]), // stack_repr_string(8)); @@ -281,7 +281,7 @@ void VM::run_instruction() void VM::run_builtin(Builtin builtin_id) { - if (this->opts.print_stack_debug) { + if (this->opts.print_debug) { std::cout << std::format("Running builtin {}\n", maybe_builtin_to_string(static_cast(builtin_id))); } diff --git a/runtime/vm.hpp b/runtime/vm.hpp index 206ebc6..7e7e3ae 100644 --- a/runtime/vm.hpp +++ b/runtime/vm.hpp @@ -141,7 +141,7 @@ private: struct VMOpts { bool flame_graph; bool code_coverage; - bool print_stack_debug; + bool print_debug; }; class VM { diff --git a/runtime/vm_provider.cpp b/runtime/vm_provider.cpp index 2c4fa7a..79c0c18 100644 --- a/runtime/vm_provider.cpp +++ b/runtime/vm_provider.cpp @@ -9,7 +9,7 @@ auto VmProvider::load_and_run(std::vector instructions) -> void { .flame_graph = true, .code_coverage = true, - .print_stack_debug = false, + .print_debug = false, }); vm.run_until_done(); this->vm = vm; diff --git a/slige-run.sh b/slige-run.sh index f0fc597..7490706 100755 --- a/slige-run.sh +++ b/slige-run.sh @@ -11,5 +11,5 @@ deno run --allow-read --allow-write compiler/main.ts $1 echo Running out.slgbc... -./runtime/build/sliger run out.slgbc +./runtime/build/sliger run out.slgbc ${@:2}