mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 23:18:44 +00:00
part of execute_visitor, fixes
This commit is contained in:
parent
5167986ddf
commit
e1b9d42da1
5 changed files with 78 additions and 12 deletions
|
|
@ -34,14 +34,14 @@ void ExecuteVisitor::Visit(Namespace* node) { // never used ??
|
|||
void ExecuteVisitor::Visit(ImportStatement* node) {} // no value
|
||||
void ExecuteVisitor::Visit(AliasDefinitionStatement* node) {} // no value
|
||||
|
||||
void ExecuteVisitor::Visit(VariableDefinitionStatement* node) {
|
||||
void ExecuteVisitor::Visit(VariableDefinitionStatement* node) { // visited on function call
|
||||
Visitor::Visit(node->name);
|
||||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(FunctionDeclaration* node) {} // no value
|
||||
|
||||
void ExecuteVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||
void ExecuteVisitor::Visit(FunctionDefinitionStatement* node) { // visited on function call
|
||||
// Visit(node->definition.get());
|
||||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
|
@ -64,7 +64,9 @@ void ExecuteVisitor::Visit(TypeConstructorPatternParameter* node) {
|
|||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
||||
// TODO
|
||||
void ExecuteVisitor::Visit(TypeConstructorPattern* node) {
|
||||
// TODO: not only tuples
|
||||
Visit(node->constructor.get());
|
||||
for (auto& parameter : node->parameters) {
|
||||
Visit(¶meter);
|
||||
|
|
@ -90,11 +92,23 @@ void ExecuteVisitor::Visit(Match* node) {
|
|||
|
||||
void ExecuteVisitor::Visit(Condition* node) {
|
||||
for (size_t i = 0; i < node->conditions.size(); ++i) {
|
||||
Visitor::Visit(node->conditions[i]);
|
||||
if (HandleCondition(node->conditions[i], node->base)) {
|
||||
Visitor::Visit(node->statements[i]);
|
||||
|
||||
if (node->statements.size() == node->conditions.size()) {
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
info::value::OptionalValue(current_value_),
|
||||
utils::ValueType::Tmp); // take value type from current_value_ ??
|
||||
}
|
||||
return; // current_value_ passed from statement
|
||||
}
|
||||
}
|
||||
if (node->statements.size() > node->conditions.size()) {
|
||||
Visitor::Visit(node->statements[node->conditions.size()]);
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
info::value::OptionalValue(),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +129,7 @@ void ExecuteVisitor::Visit(DoWhileLoop* node) {
|
|||
} while(HandleCondition(node->condition, node->base));
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::ArrayValue>(
|
||||
info::value::ArrayValue(result, false),
|
||||
info::value::ArrayValue(std::move(result), false),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +150,7 @@ void ExecuteVisitor::Visit(WhileLoop* node) {
|
|||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::ArrayValue>(
|
||||
info::value::ArrayValue(result, false),
|
||||
info::value::ArrayValue(std::move(result), false),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
void ExecuteVisitor::Visit(ForLoop* node) {
|
||||
|
|
@ -164,7 +178,7 @@ void ExecuteVisitor::Visit(ForLoop* node) {
|
|||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::ArrayValue>(
|
||||
info::value::ArrayValue(result, false),
|
||||
info::value::ArrayValue(std::move(result), false),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
|
@ -185,13 +199,16 @@ void ExecuteVisitor::Visit(LoopLoop* node) {
|
|||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::ArrayValue>(
|
||||
info::value::ArrayValue(result, false),
|
||||
info::value::ArrayValue(std::move(result), false),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
// Statements, expressions, blocks, etc. -----------------
|
||||
|
||||
void ExecuteVisitor::Visit(Block* node) {
|
||||
// type_info_context_manager_.EnterContext(); // not needed ??
|
||||
context_manager_.EnterContext();
|
||||
|
||||
for (auto& statement : node->statements) {
|
||||
return_value_ = std::nullopt;
|
||||
Visitor::Visit(statement);
|
||||
|
|
@ -200,6 +217,9 @@ void ExecuteVisitor::Visit(Block* node) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
// context_manager_.ExitContext();
|
||||
// type_info_context_manager_.ExitContext(); // not needed ??
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::InternalValue>(
|
||||
info::value::InternalValue(info::value::Unit()),
|
||||
utils::ValueType::Tmp);
|
||||
|
|
@ -288,8 +308,9 @@ void ExecuteVisitor::Visit(TupleExpression* node) {
|
|||
fields.push_back({std::nullopt, current_value_});
|
||||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::TupleValue>(info::value::TupleValue(std::move(fields)),
|
||||
utils::ValueType::Tmp);
|
||||
current_value_ = context_manager_.AddValue<info::value::TupleValue>(
|
||||
info::value::TupleValue(std::move(fields)),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
|
@ -316,7 +337,9 @@ void ExecuteVisitor::Visit(TypeConstructorParameter* node) {
|
|||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
||||
// TODO
|
||||
void ExecuteVisitor::Visit(TypeConstructor* node) {
|
||||
// TODO: not only tuples
|
||||
Visit(node->constructor.get());
|
||||
for (auto& parameter : node->parameters) {
|
||||
Visit(¶meter);
|
||||
|
|
@ -330,9 +353,17 @@ void ExecuteVisitor::Visit(LambdaFunction* node) {
|
|||
}
|
||||
|
||||
void ExecuteVisitor::Visit(ArrayExpression* node) {
|
||||
std::vector<utils::IdType> elements;
|
||||
|
||||
elements.reserve(node->elements.size());
|
||||
for (auto& element : node->elements) {
|
||||
Visitor::Visit(element);
|
||||
elements.push_back(current_value_);
|
||||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::ArrayValue>(
|
||||
info::value::ArrayValue(std::move(elements), true), // maybe size not fixed??
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
// Name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue