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/meson.build b/meson.build new file mode 100644 index 0000000..ef01eba --- /dev/null +++ b/meson.build @@ -0,0 +1,8 @@ +project('winter', 'cpp', default_options: ['cpp_std=c++23']) +cpp_flags = ['-Wall', '-Wextra', '-Wconversion', '-Wimplicit-fallthrough'] + +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/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/compiler.cpp b/src/compiler.cpp new file mode 100644 index 0000000..1501b30 --- /dev/null +++ b/src/compiler.cpp @@ -0,0 +1,21 @@ +#include "compiler.h" + +#include +#include +#include + +namespace Winter { + + [[nodiscard]] auto getBinaryName(std::string_view filepath) -> std::string { + std::filesystem::path path(filepath); + return path.stem().string(); + } + + [[nodiscard]] 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..942ae7f --- /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) {} + }; + + [[nodiscard]] auto getBinaryName(std::string_view filepath) -> std::string; + [[nodiscard]] auto getSourceCode(std::string_view path) -> std::string; + +} // namespace Winter diff --git a/src/main.cpp b/src/main.cpp index d273ea1..8614257 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,37 +2,45 @@ #include #include #include +#include -#include "winter.h" +#include "compiler.h" -using namespace std::string_view_literals; +using namespace std::literals::string_view_literals; -void usage() {} +constexpr auto usage() -> int { + const std::string usage = + "Usage:\n" + " winter [options] [file...]"; -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; + // TODO: -o flag for binary name + 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(); } + + auto compiler = + Winter::Compiler(Winter::getBinaryName(file), Winter::getSourceCode(file), enable_debug); return 0; } 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); -}