mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
partition fixes, main file fix
This commit is contained in:
parent
a97a6125de
commit
93ac5f8e33
8 changed files with 33 additions and 18 deletions
|
|
@ -29,6 +29,11 @@ inline void HandleParsingError(const std::string& message,
|
|||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleGeneralError(const std::string& message) {
|
||||
std::cout << "General Error: " << message << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void HandleInternalError(const std::string& message, const std::string& place) {
|
||||
std::cout << "Internal Error: " << message << " at " << place << ".\n";
|
||||
exit(1);
|
||||
|
|
|
|||
|
|
@ -194,8 +194,7 @@ struct ArrayExpression;
|
|||
struct PartitionName {
|
||||
BaseNode base;
|
||||
|
||||
std::vector<TypeIdentifier> path;
|
||||
NameIdentifier name;
|
||||
std::vector<AnyIdentifier> path; // name is last element of path
|
||||
};
|
||||
|
||||
struct NameExpression;
|
||||
|
|
|
|||
|
|
@ -1158,7 +1158,7 @@ void BuildVisitor::Visit(PartitionName* node) {
|
|||
}
|
||||
}
|
||||
|
||||
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||
node->path.push_back(parse_node.ChildByFieldName("name").GetValue());
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ void FindSymbolsVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
void FindSymbolsVisitor::Visit(PartitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
node->executable_id_ = namespace_visitor_.AddPartition(node->name.path, node->name.name, node);
|
||||
node->executable_id_ = namespace_visitor_.AddPartition(node->name.path, node);
|
||||
// TODO: typecheck error on same tests
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
|
|
|||
20
src/main.cpp
20
src/main.cpp
|
|
@ -37,7 +37,7 @@ int main(int argc, char** argv) { // TODO, only test version
|
|||
parser::ParseTree parse_tree(source);
|
||||
|
||||
if (!parse_tree.IsProperlyParsed()) {
|
||||
error_handling::HandleParsingError("There are some parsing errors in file.", {0, 0}, {0, 0});
|
||||
error_handling::HandleParsingError("There are some parsing errors in file", {0, 0}, {0, 0});
|
||||
}
|
||||
|
||||
std::unique_ptr<interpreter::tokens::SourceFile> source_file =
|
||||
|
|
@ -53,10 +53,6 @@ int main(int argc, char** argv) { // TODO, only test version
|
|||
interpreter::LinkSymbolsVisitor link_symbols_visitor(global_info);
|
||||
interpreter::TypeCheckVisitor type_check_visitor(global_info, type_context_manager);
|
||||
interpreter::TypedPrintVisitor typed_print_visitor(std::cout, type_context_manager);
|
||||
interpreter::ExecuteVisitor execute_visitor(global_info,
|
||||
type_context_manager,
|
||||
context_manager,
|
||||
nullptr); // TODO
|
||||
|
||||
build_visitor.VisitSourceFile(source_file.get());
|
||||
|
||||
|
|
@ -67,6 +63,20 @@ int main(int argc, char** argv) { // TODO, only test version
|
|||
link_symbols_visitor.VisitSourceFile(source_file.get());
|
||||
type_check_visitor.VisitSourceFile(source_file.get());
|
||||
|
||||
std::optional<utils::IdType> maybe_main_partition_id = global_info.FindPartition({"main"});
|
||||
|
||||
if (!maybe_main_partition_id.has_value()) {
|
||||
error_handling::HandleGeneralError("No main partition found");
|
||||
}
|
||||
|
||||
const info::GlobalInfo::PartitionInfo& main_partition =
|
||||
global_info.GetPartitionInfo(maybe_main_partition_id.value());
|
||||
|
||||
interpreter::ExecuteVisitor execute_visitor(global_info,
|
||||
type_context_manager,
|
||||
context_manager,
|
||||
main_partition.node);
|
||||
|
||||
std::cout << "\n---------------------------------- Typed -------------------------------------\n\n";
|
||||
typed_print_visitor.VisitSourceFile(source_file.get());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -554,11 +554,12 @@ void PrintVisitor::Visit(ArrayExpression* node) {
|
|||
|
||||
void PrintVisitor::Visit(PartitionName* node) {
|
||||
out_ << "[PartitionName] (";
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
out_ << "::";
|
||||
for (size_t i = 0; i < node->path.size(); ++i) {
|
||||
Visit(&node->path[i]);
|
||||
if (i + 1 < node->path.size()) {
|
||||
out_ << "::";
|
||||
}
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -782,11 +782,12 @@ void TypedPrintVisitor::Visit(PartitionName* node) {
|
|||
}
|
||||
|
||||
out_ << "] (";
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
out_ << "::";
|
||||
for (size_t i = 0; i < node->path.size(); ++i) {
|
||||
Visit(&node->path[i]);
|
||||
if (i + 1 < node->path.size()) {
|
||||
out_ << "::";
|
||||
}
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -567,7 +567,6 @@ void Visitor::Visit(PartitionName* node) {
|
|||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
}
|
||||
Visit(&node->name);
|
||||
}
|
||||
|
||||
void Visitor::Visit(NameExpression* node) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue