From 0f4310cbca4d3de772bf62b339bf964ab74f2ae0 Mon Sep 17 00:00:00 2001 From: Gin <65128789+GinOwO@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:52:07 +0530 Subject: [PATCH] Fix Windows bugs (#6) Co-authored-by: Gin <65128789+KThankYou@users.noreply.github.com> --- CMakeLists.txt | 4 ++++ resources/qss/dark.qss | 6 ++++++ resources/qss/light.qss | 24 ++++++++++++++++++++++++ src/main/interpreter.cpp | 19 ++++++++++++++----- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index baa4fc5..5d8b3b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,10 @@ qt_add_executable(Caelum src/ui/outputview.h src/ui/outputview.cpp src/ui/outputview.ui ) +if(WIN32) + set_property(TARGET Caelum PROPERTY WIN32_EXECUTABLE true) +endif() + target_link_libraries(Caelum PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_include_directories(Caelum PRIVATE diff --git a/resources/qss/dark.qss b/resources/qss/dark.qss index b57cc7e..4a79a87 100644 --- a/resources/qss/dark.qss +++ b/resources/qss/dark.qss @@ -197,3 +197,9 @@ QStatusBar { QToolTip { background-color: black; color: white; border: 1px solid white; } + +QMessageBox { + background-color: rgb(42, 42, 42); /* Dark background color */ + color: rgb(255, 255, 255); /* Text color */ +} + diff --git a/resources/qss/light.qss b/resources/qss/light.qss index 1ae5544..e64e7d5 100644 --- a/resources/qss/light.qss +++ b/resources/qss/light.qss @@ -183,3 +183,27 @@ QMenu::item:selected { QToolTip { background-color: black; color: white; border: 1px solid white; } + +QHeaderView { + background-color: rgb(42, 42, 42); /* Dark background color */ + color: rgb(255, 255, 255); /* Text color */ + border-color: rgb(58, 58, 58); + border-style: solid; + border-width: 1px; +} + +QHeaderView::section { + background-color: rgb(42, 42, 42); /* Dark background color */ + color: rgb(255, 255, 255); /* Text color */ + padding: 4px; /* Adjust padding as needed */ + border-color: rgb(58, 58, 58); + border-style: solid; + border-width: 1px; + border-bottom: none; /* Remove the bottom border to separate sections */ +} + +/* Hover effect for the header section (column) */ +QHeaderView::section:hover { + background-color: rgb(58, 58, 58); /* Hover background color */ + color: rgb(255, 255, 255); /* Hover text color */ +} diff --git a/src/main/interpreter.cpp b/src/main/interpreter.cpp index cd7adeb..a47aa21 100644 --- a/src/main/interpreter.cpp +++ b/src/main/interpreter.cpp @@ -121,6 +121,7 @@ unsigned long long Interpreter::POP(){ */ void Interpreter::execute(){ if(code.size() == 0) throw Exception::BadSyntaxException("Code not built"); + size_t backup_ptr = ptr; this->output.clear(); int cnt, i, type, lineNum, memTemp1, memTemp2; unsigned long long a, b, val; @@ -222,29 +223,37 @@ void Interpreter::execute(){ } } - catch(Exception::HaltException){return;} + catch(Exception::HaltException){ + ptr = backup_ptr; + return; + } catch(Exception::BadInstructionException){ + ptr = backup_ptr; throw Exception::BadSyntaxException("Bad instruction at line "+std::to_string(lineNum)); } catch(Exception::UnknownException){ + ptr = backup_ptr; throw Exception::BadSyntaxException("Unknown error at line "+std::to_string(lineNum)); } catch(Exception::PointerOutOfBoundsException){ + ptr = backup_ptr; throw Exception::BadSyntaxException("Pointer out of bounds at line "+std::to_string(lineNum)); } catch(Exception::StackUnderflowException){ + ptr = backup_ptr; throw Exception::BadSyntaxException("Popping from empty stack at line "+std::to_string(lineNum)); } - } + } + ptr = backup_ptr; } void Interpreter::build(const std::string& instructions){ + size_t h = std::hash{}(instructions); + if(hash == h) return; this->code.clear(); this->labelMap.clear(); this->callStack = std::stack(); unsigned long long i=0, j=0; - size_t h = std::hash{}(instructions); - if(hash == h) return; std::string label, op, op1, op2, instr; std::stringstream ss(instructions); @@ -323,7 +332,7 @@ void Interpreter::build(const std::string& instructions){ i++; } if(!this->labelMap.count(ptr)) throw Exception::MissingGlobalException(); - ptr = this->labelMap[ptr]; + ptr = this->labelMap[ptr]; // TODO backup ptr for next run this->resolveLabels(); hash = h; }