From a0e1ccef36bb5bbc0dbd5c027ef08fd677526f59 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Thu, 5 Feb 2026 23:13:55 +0000 Subject: [PATCH 1/6] cleanup --- .github/workflows/main.yml | 14 +++++++------- CMakeLists.txt | 22 ---------------------- src/CMakeLists.txt | 5 ----- src/t.cpp | 0 src/winter.h | 0 tests/CMakeLists.txt | 15 --------------- tests/fixture/test_file_1.txt | 3 --- tests/main.cpp | 10 ---------- 8 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 src/CMakeLists.txt delete mode 100644 src/t.cpp delete mode 100644 src/winter.h delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/fixture/test_file_1.txt delete mode 100644 tests/main.cpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 29b6e02..91ec566 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,10 +9,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.0 - unit_tests: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - - run: sudo apt-get install clang-19 - - run: cmake -DCMAKE_CXX_COMPILER=clang++-19 -DRUN_TESTS=true -B build && cmake --build build - - run: ./build/tests/test_exe + # unit_tests: + # runs-on: ubuntu-24.04 + # steps: + # - uses: actions/checkout@v4 + # - run: sudo apt-get install clang-19 + # - run: cmake -DCMAKE_CXX_COMPILER=clang++-19 -DRUN_TESTS=true -B build && cmake --build build + # - run: ./build/tests/test_exe diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9a2c307..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.30) -project(winter LANGUAGES CXX) - -option(RUN_TESTS "Run unit tests" OFF) - -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -add_compile_options(-g) -add_compile_options(-Wall) -add_compile_options(-Wextra) -add_compile_options(-Wconversion) -add_compile_options(-Wimplicit-fallthrough) - -add_subdirectory(src) -add_executable(winter src/main.cpp) -target_link_libraries(winter PUBLIC winter_src) - -if(RUN_TESTS) - message(STATUS "UNIT TESTS ENABLED") - add_subdirectory(tests) -endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 15d6ede..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -include_directories(${PROJECT_SOURCE_DIR}/src) - -add_library(winter_src STATIC - t.cpp -) diff --git a/src/t.cpp b/src/t.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/winter.h b/src/winter.h deleted file mode 100644 index e69de29..0000000 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 41d7177..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories(${PROJECT_SOURCE_DIR}/src) - -add_compile_options(-g) - -include(FetchContent) -fetchcontent_declare( - willow - GIT_REPOSITORY https://github.com/Ttibsi/willow - GIT_TAG main -) -fetchcontent_makeavailable(willow) - -add_executable(test_exe ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -target_include_directories(test_exe PRIVATE ${PROJECT_SOURCE_DIR}/src/winter) -target_link_libraries(test_exe PUBLIC winter_src willow) diff --git a/tests/fixture/test_file_1.txt b/tests/fixture/test_file_1.txt deleted file mode 100644 index 2a5d4b6..0000000 --- a/tests/fixture/test_file_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -This is some text - here is a newline and a tab -and another newline diff --git a/tests/main.cpp b/tests/main.cpp deleted file mode 100644 index 1ce393d..0000000 --- a/tests/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int main() { - Willow::PreCommitReporter reporter = {}; - - Willow::registerTests({}); - - return Willow::runTests(reporter); -} From 9749395c11eb2d77288b68a375355c58151f49d3 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Thu, 5 Feb 2026 23:14:22 +0000 Subject: [PATCH 2/6] setup meson --- meson.build | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..89cb806 --- /dev/null +++ b/meson.build @@ -0,0 +1,7 @@ +project('winter', 'cpp', default_options: ['cpp_std=c++23']) +cpp_flags = ['-Wall', '-Wextra', '-Wconversion', '-Wimplicit-fallthrough'] + +# src_files = [] +# winter_src = static_library('winter_src', src_files, cpp_args: cpp_flags) +# executable('winter', 'src/main.cpp', cpp_args: cpp_flags, link_with: winter_src) +executable('winter', 'src/main.cpp', cpp_args: cpp_flags) From d49af72129d954ce8c8c6190e70154e95fcf1cb2 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Thu, 5 Feb 2026 23:14:38 +0000 Subject: [PATCH 3/6] rewrite main --- src/main.cpp | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d273ea1..131bb37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,37 +2,39 @@ #include #include #include +#include -#include "winter.h" +using namespace std::literals::string_view_literals; -using namespace std::string_view_literals; +constexpr auto usage() -> int { + const std::string usage = + "Usage:\n" + " winter [options] [file...]"; -void usage() {} - -int main(int argc, char* argv[]) { - bool enable_debug; - std::string filename = ""; + std::println("{}", usage); + return 1; +} - const auto args = std::span(argv, argc); - if (args.size() == 1) { - usage(); - return 1; - } +constexpr auto default_output() -> int { + std::println("Winter: \x1b[31m\x1b[1mError: \x1b[0mNo input files"); + std::println("Compilation terminated"); + return 1; +} - for (auto&& elem : args) { - std::string_view str = std::string_view(elem); +auto main(int argc, char* argv[]) -> int { + auto args = std::vector(std::from_range, std::span {argv, argc}); - if (str == "-D"sv) { enable_debug = true; } - if (str.ends_with(".wtx"sv)) { filename = std::string(elem); } - } + bool enable_debug = false; + std::string file = ""; - if (filename.empty()) { - std::println("Error: No file provided"); - usage(); - return 1; + if (args.size() == 1) { return default_output(); } + for (auto&& arg : args) { + if (arg == "-D"sv) { enable_debug = true; } + if (arg.ends_with(".wtx"sv)) { file = arg; } + if (arg == "--help"sv) { return usage(); } } - // TODO: here goes the lexing/parsing etc + if (file.empty()) { return default_output(); } return 0; } From 75b78de91088b40952bcce1b8313d96f47cc39a2 Mon Sep 17 00:00:00 2001 From: ttibsi Date: Thu, 5 Feb 2026 23:14:57 +0000 Subject: [PATCH 4/6] tokens --- src/lexer.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/lexer.h diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..892d3c6 --- /dev/null +++ b/src/lexer.h @@ -0,0 +1,15 @@ +#include + +namespace Winter { + enum class TokenType {}; + + struct Token { + TokenType type; + std::size_t start; + std::size_t len; + + explicit Token(TokenType typ, std::size_t s, std::size_t l) : type(typ), start(s), len(l) {} + auto operator<=>(const Token&) const = default; + [[nodiscard]] std::string toString() const; + }; +} // namespace Winter From d89ed259c2a5857dc6094274746f8cba1da00d42 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Fri, 6 Feb 2026 15:22:30 +0000 Subject: [PATCH 5/6] Start setup for compiler object --- meson.build | 9 +++++---- src/compiler.cpp | 21 +++++++++++++++++++++ src/compiler.h | 18 ++++++++++++++++++ src/lexer.h | 1 + src/main.cpp | 6 ++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/compiler.cpp create mode 100644 src/compiler.h diff --git a/meson.build b/meson.build index 89cb806..ef01eba 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,8 @@ project('winter', 'cpp', default_options: ['cpp_std=c++23']) cpp_flags = ['-Wall', '-Wextra', '-Wconversion', '-Wimplicit-fallthrough'] -# src_files = [] -# winter_src = static_library('winter_src', src_files, cpp_args: cpp_flags) -# executable('winter', 'src/main.cpp', cpp_args: cpp_flags, link_with: winter_src) -executable('winter', 'src/main.cpp', cpp_args: cpp_flags) +src_files = [ + 'src/compiler.cpp' +] +winter_src = static_library('winter_src', src_files, cpp_args: cpp_flags) +executable('winter', 'src/main.cpp', cpp_args: cpp_flags, link_with: winter_src) diff --git a/src/compiler.cpp b/src/compiler.cpp new file mode 100644 index 0000000..e334fa5 --- /dev/null +++ b/src/compiler.cpp @@ -0,0 +1,21 @@ +#include "compiler.h" + +#include +#include +#include + +namespace Winter { + + constexpr auto getBinaryName(std::string_view filepath) -> std::string { + std::filesystem::path path(filepath); + return path.stem().string(); + } + + constexpr auto getSourceCode(std::string_view path) -> std::string { + std::ifstream ifs(path.data()); + std::stringstream buf_stream; + buf_stream << ifs.rdbuf(); + return buf_stream.str(); + } + +} // namespace Winter diff --git a/src/compiler.h b/src/compiler.h new file mode 100644 index 0000000..d0189eb --- /dev/null +++ b/src/compiler.h @@ -0,0 +1,18 @@ +#include +#include + +namespace Winter { + struct Compiler { + int status_code = 0; + std::string bin_name; + std::string src; + bool debug; + + explicit constexpr Compiler(std::string binary, std::string source, bool debug_mode) + : bin_name(binary), src(std::move(source)), debug(debug_mode) {} + }; + + constexpr auto getBinaryName(std::string_view filepath) -> std::string; + constexpr auto getSourceCode(std::string_view path) -> std::string; + +} // namespace Winter diff --git a/src/lexer.h b/src/lexer.h index 892d3c6..153d7b0 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1,4 +1,5 @@ #include +#include namespace Winter { enum class TokenType {}; diff --git a/src/main.cpp b/src/main.cpp index 131bb37..8614257 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,8 @@ #include #include +#include "compiler.h" + using namespace std::literals::string_view_literals; constexpr auto usage() -> int { @@ -27,6 +29,7 @@ auto main(int argc, char* argv[]) -> int { bool enable_debug = false; std::string file = ""; + // TODO: -o flag for binary name if (args.size() == 1) { return default_output(); } for (auto&& arg : args) { if (arg == "-D"sv) { enable_debug = true; } @@ -36,5 +39,8 @@ auto main(int argc, char* argv[]) -> int { if (file.empty()) { return default_output(); } + auto compiler = + Winter::Compiler(Winter::getBinaryName(file), Winter::getSourceCode(file), enable_debug); + return 0; } From bbb9df52cc021093de8c13f95c1f61b260dc4e21 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Fri, 6 Feb 2026 16:03:27 +0000 Subject: [PATCH 6/6] Remove constexpr --- src/compiler.cpp | 4 ++-- src/compiler.h | 4 ++-- src/lexer.h | 16 ---------------- 3 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 src/lexer.h diff --git a/src/compiler.cpp b/src/compiler.cpp index e334fa5..1501b30 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -6,12 +6,12 @@ namespace Winter { - constexpr auto getBinaryName(std::string_view filepath) -> std::string { + [[nodiscard]] auto getBinaryName(std::string_view filepath) -> std::string { std::filesystem::path path(filepath); return path.stem().string(); } - constexpr auto getSourceCode(std::string_view path) -> std::string { + [[nodiscard]] auto getSourceCode(std::string_view path) -> std::string { std::ifstream ifs(path.data()); std::stringstream buf_stream; buf_stream << ifs.rdbuf(); diff --git a/src/compiler.h b/src/compiler.h index d0189eb..942ae7f 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -12,7 +12,7 @@ namespace Winter { : bin_name(binary), src(std::move(source)), debug(debug_mode) {} }; - constexpr auto getBinaryName(std::string_view filepath) -> std::string; - constexpr auto getSourceCode(std::string_view path) -> std::string; + [[nodiscard]] auto getBinaryName(std::string_view filepath) -> std::string; + [[nodiscard]] auto getSourceCode(std::string_view path) -> std::string; } // namespace Winter diff --git a/src/lexer.h b/src/lexer.h deleted file mode 100644 index 153d7b0..0000000 --- a/src/lexer.h +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -namespace Winter { - enum class TokenType {}; - - struct Token { - TokenType type; - std::size_t start; - std::size_t len; - - explicit Token(TokenType typ, std::size_t s, std::size_t l) : type(typ), start(s), len(l) {} - auto operator<=>(const Token&) const = default; - [[nodiscard]] std::string toString() const; - }; -} // namespace Winter