mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 23:18:44 +00:00
constructors on heap, consuming match, move modifier in reference expression, .bring. keyword to return from block, some fixes
This commit is contained in:
parent
2556efcaba
commit
8a84cfff70
12 changed files with 128 additions and 34 deletions
|
|
@ -49,7 +49,16 @@ void ExecuteVisitor::Visit(FunctionDeclaration*) {} // no value
|
|||
void ExecuteVisitor::Visit(FunctionDefinitionStatement* node) { // visited on function call
|
||||
// Visit(node->definition.get());
|
||||
context_manager_.EnterContext();
|
||||
|
||||
returned_value_ = std::nullopt;
|
||||
Visitor::Visit(node->value);
|
||||
|
||||
if (returned_value_.has_value()) {
|
||||
current_value_ = returned_value_.value();
|
||||
} // else returned type = current_type_
|
||||
|
||||
returned_value_ = std::nullopt;
|
||||
|
||||
context_manager_.ExitContext();
|
||||
}
|
||||
|
||||
|
|
@ -308,20 +317,27 @@ void ExecuteVisitor::Visit(Block* node) {
|
|||
context_manager_.EnterContext();
|
||||
|
||||
for (auto& statement : node->statements) {
|
||||
returned_value_ = std::nullopt;
|
||||
brought_value_ = std::nullopt;
|
||||
Visitor::Visit(statement);
|
||||
if (returned_value_.has_value()) {
|
||||
current_value_ = returned_value_.value();
|
||||
returned_value_ = std::nullopt; // TODO: ?? ("return" exits only from one block)
|
||||
return;
|
||||
brought_value_ = std::nullopt;
|
||||
break;
|
||||
}
|
||||
if (brought_value_.has_value()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
context_manager_.ExitContext();
|
||||
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::InternalValue(info::value::Unit()),
|
||||
utils::ValueType::Tmp);
|
||||
if (brought_value_.has_value()) {
|
||||
current_value_ = brought_value_.value();
|
||||
brought_value_ = std::nullopt;
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::InternalValue(info::value::Unit()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(ScopedStatement* node) {
|
||||
|
|
@ -332,7 +348,7 @@ void ExecuteVisitor::Visit(LoopControlExpression& node) {
|
|||
active_loop_control_expression_ = node;
|
||||
|
||||
current_value_ = context_manager_.AddValue(info::value::InternalValue(info::value::Unit()),
|
||||
utils::ValueType::Tmp); // ??
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
// Operators
|
||||
|
|
@ -563,7 +579,15 @@ void ExecuteVisitor::Visit(VariantExpression* node) {
|
|||
|
||||
void ExecuteVisitor::Visit(ReturnExpression* node) {
|
||||
Visitor::Visit(node->expression);
|
||||
returned_value_ = current_value_;
|
||||
if (node->is_from_definition) {
|
||||
returned_value_ = current_value_;
|
||||
} else {
|
||||
brought_value_ = current_value_;
|
||||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::InternalValue(info::value::Unit()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue