Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 0 additions & 22 deletions CMakeLists.txt

This file was deleted.

8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions src/CMakeLists.txt

This file was deleted.

21 changes: 21 additions & 0 deletions src/compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "compiler.h"

#include <filesystem>
#include <fstream>
#include <sstream>

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
18 changes: 18 additions & 0 deletions src/compiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <string>
#include <string_view>

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
50 changes: 29 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,45 @@
#include <span>
#include <string>
#include <string_view>
#include <vector>

#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::string_view>(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;
}
Empty file removed src/t.cpp
Empty file.
Empty file removed src/winter.h
Empty file.
15 changes: 0 additions & 15 deletions tests/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fixture/test_file_1.txt

This file was deleted.

10 changes: 0 additions & 10 deletions tests/main.cpp

This file was deleted.

Loading