Skip to content

Commit

Permalink
chore: Update C++ language mappings in VSCode settings and add suppor…
Browse files Browse the repository at this point in the history
…t for *sn.confy files
  • Loading branch information
mauro-balades committed May 8, 2024
1 parent 0cf44e3 commit 6489be8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"span": "cpp",
"valarray": "cpp",
"expected": "cpp",
"cfenv": "cpp"
"cfenv": "cpp",
"*.ipp": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled",
"todo-tree.tree.scanMode": "workspace",
Expand Down
3 changes: 3 additions & 0 deletions sn.confy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project {

}
39 changes: 38 additions & 1 deletion src/app/cli.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

#include "cli.h"
#include <filesystem>

#include "app/cli.h"
#include "compiler/reports/error.h"
#include "compiler/frontend/location.h"

#define CONFY_USE_UTILS
#include "app/vendor/confy/src/confy.hpp"

namespace snowball {
namespace cli {
Expand All @@ -12,8 +19,38 @@ const Ctx CLI::parse(int argc, char** argv) {
ctx.build_mode = BuildMode::Build;
ctx.input_file = "tests/main.sn";
ctx.emit_type = EmitType::Llvm;
get_package_config(ctx, "");
return ctx;
}

// CONFY IMPLEMENTATION

class ConfyPackageType final : public confy::StringType {
public:
std::optional<std::string> validate(const std::string& value) const override {
if (value != "lib" && value != "exe" && value != "both") {
return "Invalid package type. Must be one of 'lib', 'exe' or 'both'";
}
return std::nullopt;
}
static std::shared_ptr<ConfyPackageType> create() {
return std::make_shared<ConfyPackageType>();
}
};

void CLI::get_package_config(Ctx& ctx, const std::string& path) {
static auto interface = confy::Interface::create({});
std::string config_path = path.empty() ? "sn.confy" : path;
auto config = confy::parse_file(interface, config_path);
bool hasError = false;
for (const auto& error : config.get_errors()) {
hasError = true;
auto err_loc = error.get_position();
auto loc = frontend::SourceLocation(err_loc.line, err_loc.column, 1, std::make_shared<frontend::SourceFile>(config_path));
auto e = E(error.get_message(), loc);
e.print();
}
}

}
}
3 changes: 3 additions & 0 deletions src/app/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __SNOWBALL_CLI_H__

#include "compiler/ctx.h"
#include "compiler/package.h"

namespace snowball {
namespace cli {
Expand All @@ -28,6 +29,8 @@ class CLI {
const Ctx parse(int argc, char** argv);
private:
void make_run();

void get_package_config(Ctx& ctx, const std::string& path = "");
};

}
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __SNOWBALL_CTX_H__

#include <filesystem>
#include "compiler/package.h"

namespace snowball {

Expand Down Expand Up @@ -51,6 +52,8 @@ struct Ctx {
BuildMode build_mode;
EmitType emit_type;
OptLevel opt_level = OptLevel::None;

PackageConfig package_config = std::nullopt;
};

}
Expand Down
9 changes: 5 additions & 4 deletions src/compiler/package.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@


#ifndef __SNOWBALL_CTX_H__
#define __SNOWBALL_CTX_H__
#ifndef __SNOWBALL_PACKAGE_CONFIG_H__
#define __SNOWBALL_PACKAGE_CONFIG_H__

#include <optional>
#include <vector>

namespace snowball {

Expand All @@ -21,11 +22,11 @@ struct PackageConfigBase {
struct Build {
std::vector<std::string> linkage_libs;
} build;
}
};

using PackageConfig = std::optional<PackageConfigBase>;

}

#endif // __SNOWBALL_CTX_H__
#endif // __SNOWBALL_PACKAGE_CONFIG_H__

0 comments on commit 6489be8

Please sign in to comment.