This commit is contained in:
ProgramSnail 2023-05-17 18:29:39 +03:00
parent b723fd6a65
commit 3abac1b643
6 changed files with 27 additions and 18 deletions

View file

@ -23,7 +23,6 @@ public:
struct PartitionInfo { struct PartitionInfo {
std::vector<std::string> path; std::vector<std::string> path;
std::string name;
interpreter::tokens::PartitionStatement* node = nullptr; interpreter::tokens::PartitionStatement* node = nullptr;
}; };
@ -75,8 +74,9 @@ public:
definition::Constructor&& constructor_info, definition::Constructor&& constructor_info,
const interpreter::tokens::BaseNode& base_node); const interpreter::tokens::BaseNode& base_node);
utils::IdType AddPartition(const std::vector<std::string>& path, // including name utils::IdType AddPartition(const std::vector<std::string>& path,
interpreter::tokens::PartitionStatement* node); interpreter::tokens::PartitionStatement* node,
const interpreter::tokens::BaseNode& base_node);
std::optional<utils::IdType> FindNamespaceId(const std::optional<std::vector<std::string>>& path); std::optional<utils::IdType> FindNamespaceId(const std::optional<std::vector<std::string>>& path);

View file

@ -131,7 +131,7 @@ private:
const std::vector<Key>& path, const std::vector<Key>& path,
size_t path_position) { size_t path_position) {
if (path_position == path.size()) { if (path_position == path.size()) {
if (vertex.value.has_value()) { if (!vertex.value.has_value()) {
return std::nullopt; return std::nullopt;
} }
return &vertex.value.value(); return &vertex.value.value();

View file

@ -156,7 +156,7 @@ void FindSymbolsVisitor::Visit(TypeclassDefinitionStatement* node) {
} }
void FindSymbolsVisitor::Visit(PartitionStatement* node) { void FindSymbolsVisitor::Visit(PartitionStatement* node) {
node->executable_id_ = namespace_visitor_.AddPartition(node->name.path, node); node->executable_id_ = namespace_visitor_.AddPartition(node->name.path, node, node->base);
} }
// Definition parts // Definition parts

View file

@ -281,23 +281,25 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& co
} }
utils::IdType GlobalInfo::NamespaceVisitor::AddPartition(const std::vector<std::string>& path, utils::IdType GlobalInfo::NamespaceVisitor::AddPartition(const std::vector<std::string>& path,
interpreter::tokens::PartitionStatement* node) { interpreter::tokens::PartitionStatement* node,
const interpreter::tokens::BaseNode& base_node) {
PartitionInfo partition; PartitionInfo partition;
partition.path.reserve(current_path_.size() + path.size() - 1); partition.path.reserve(current_path_.size() + path.size());
partition.path = current_path_; partition.path = current_path_;
for (size_t i = 0; i + 1 < path.size(); ++i) { for (auto& path_name : path) {
partition.path.push_back(path[i]); partition.path.push_back(path_name);
} }
partition.name = path.back();
partition.node = node; partition.node = node;
utils::IdType id = global_info_.partitions_.size(); utils::IdType id = global_info_.partitions_.size();
global_info_.partitions_.push_back(partition); global_info_.partitions_.push_back(partition);
global_info_.partitions_trie_.Insert(partition.path, id); if (!global_info_.partitions_trie_.Insert(partition.path, id)) {
error_handling::HandleNamesError("Partition with this name already exists", base_node);
}
return id; return id;
} }

View file

@ -843,6 +843,7 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
utils::IdType constructor_id = node->constructor->constructor_id_.value(); utils::IdType constructor_id = node->constructor->constructor_id_.value();
// TODO: take type_id_ ??
info::definition::Constructor constructor_info = global_info_.GetConstructorInfo(constructor_id); info::definition::Constructor constructor_info = global_info_.GetConstructorInfo(constructor_id);
utils::IdType type_id = constructor_info.type_id; utils::IdType type_id = constructor_info.type_id;
@ -912,6 +913,10 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
current_type_ = TypeInContext(current_type_, context); current_type_ = TypeInContext(current_type_, context);
current_type_ = context_manager_.AddValue(
info::type::DefinedType(type_id, current_type_, type_info.modifier, context_manager_.GetValueManager()),
utils::ValueType::Tmp);
node->base.type_ = current_type_; node->base.type_ = current_type_;
} }

View file

@ -123,13 +123,15 @@ typeclass Enum =
// //
decl ( -- ) : Int -> Int -> Int_0 decl ( -- ) : Int -> Int -> Int_0
def ( -- ) : begin end = { // def ( -- ) : begin end = {
var current = begin // var current = begin
return (while current < end do { // return (while current < end do {
; current += 1 // ; current += 1
return current - 1 // return current - 1
}) // })
} // }
decl print : String -> Unit
decl func : String -> Int decl func : String -> Int
def func : s = { def func : s = {