mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 16:58:45 +00:00
fixes, part of execute_visitor
This commit is contained in:
parent
802b736e15
commit
6e487c8fd9
6 changed files with 79 additions and 47 deletions
|
|
@ -63,11 +63,29 @@ void ExecuteVisitor::Visit(PartitionStatement* node) {
|
|||
void ExecuteVisitor::Visit(TypeConstructorPatternParameter* node) {} // handled in TypeConstructorPattern
|
||||
|
||||
// TODO
|
||||
// TODO: non-variant constructor patterns
|
||||
void ExecuteVisitor::Visit(TypeConstructorPattern* node) {
|
||||
// TODO: not only tuples
|
||||
Visit(node->constructor.get()); // TODO: ?? check is same constructor_id ??
|
||||
for (auto& parameter : node->parameters) { // TODO: pass parameters separately
|
||||
Visitor::Visit(parameter.value); // handle TypeConstructorPatternParameter
|
||||
if (!node->constructor->constructor_id_.has_value()) { // checked in typeckeck visitor ??
|
||||
error_handling::HandleRuntimeError("Type constructor pattern constructor name not found", node->base);
|
||||
}
|
||||
|
||||
utils::IdType constructor_id = node->constructor->constructor_id_.value();
|
||||
|
||||
// TODO: not only variants
|
||||
info::value::VariantValue* value_info =
|
||||
ExtractValue<info::value::VariantValue>(current_value_, node->base);
|
||||
|
||||
if (constructor_id != value_info->current_constructor) {
|
||||
case_matched_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// <--
|
||||
|
||||
// extract named parameters ??
|
||||
for (size_t i = 0; i < node->parameters.size(); ++i) { // not visit if case not matched inside ??
|
||||
current_value_ = value_info->value.fields[i].second;
|
||||
Visitor::Visit(node->parameters[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +137,7 @@ void ExecuteVisitor::Visit(Match* node) {
|
|||
utils::ValueType::Tmp);
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
info::value::OptionalValue(context_manager_.GetValueManager()),
|
||||
info::value::OptionalValue(std::nullopt, context_manager_.GetValueManager()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +163,7 @@ void ExecuteVisitor::Visit(Condition* node) {
|
|||
Visitor::Visit(node->statements[node->conditions.size()]);
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
info::value::OptionalValue(context_manager_.GetValueManager()),
|
||||
info::value::OptionalValue(std::nullopt, context_manager_.GetValueManager()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
|
@ -360,7 +378,7 @@ void ExecuteVisitor::Visit(AccessExpression* node) {
|
|||
Visitor::Visit(node->id);
|
||||
long long index = *ExtractInternalValue<long long>(current_value_, node->base); // TODO: size_t
|
||||
|
||||
if (index < 0 || index >= array_value->elements.size()) {
|
||||
if (index < 0 || index >= (long long)array_value->elements.size()) {
|
||||
error_handling::HandleRuntimeError("Access index out of range", node->base);
|
||||
}
|
||||
|
||||
|
|
@ -436,8 +454,14 @@ void ExecuteVisitor::Visit(VariantExpression* node) {
|
|||
Visitor::Visit(node->expressions[i]);
|
||||
info::value::OptionalValue* expression_value = ExtractValue<info::value::OptionalValue>(current_value_, node->base);
|
||||
if (expression_value->value.has_value()) {
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields
|
||||
{{std::nullopt, expression_value->value.value()}};
|
||||
|
||||
info::value::TupleValue variant_tuple =
|
||||
info::value::TupleValue(std::move(fields), context_manager_.GetValueManager());
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::VariantValue>(
|
||||
info::value::VariantValue(expression_value->value.value(), i, context_manager_.GetValueManager()),
|
||||
info::value::VariantValue(std::move(variant_tuple), i),
|
||||
utils::ValueType::Tmp);
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
|
|
@ -448,7 +472,7 @@ void ExecuteVisitor::Visit(VariantExpression* node) {
|
|||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue<info::value::OptionalValue>(
|
||||
info::value::OptionalValue(context_manager_.GetValueManager()),
|
||||
info::value::OptionalValue(std::nullopt, context_manager_.GetValueManager()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
|
|
@ -581,13 +605,23 @@ void ExecuteVisitor::Visit(VariantName* node) {
|
|||
|
||||
for (size_t i = 0; i < node->names.size(); ++i) {
|
||||
if (i == maybe_variant_value.value()->current_constructor) {
|
||||
// TODO if (fields_count.empty()) ... else ...
|
||||
if (maybe_variant_value.value()->value.fields.empty()) {
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::InternalValue(info::value::Unit()),
|
||||
utils::IsConstModifierToValueType(is_const_definition_.value()));
|
||||
// TODO: check, that same with typecheck
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue(
|
||||
maybe_variant_value.value()->value,
|
||||
utils::IsConstModifierToValueType(is_const_definition_.value()));
|
||||
}
|
||||
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::OptionalValue(maybe_variant_value.value()->value, context_manager_.GetValueManager()),
|
||||
utils::IsConstModifierToValueType(is_const_definition_.value())); // TODO ??
|
||||
info::value::OptionalValue(current_value_, context_manager_.GetValueManager()),
|
||||
utils::IsConstModifierToValueType(is_const_definition_.value()));
|
||||
} else {
|
||||
current_value_ = context_manager_.AddValue(
|
||||
info::value::OptionalValue(context_manager_.GetValueManager()),
|
||||
info::value::OptionalValue(std::nullopt, context_manager_.GetValueManager()),
|
||||
utils::IsConstModifierToValueType(is_const_definition_.value()));
|
||||
}
|
||||
|
||||
|
|
@ -722,9 +756,10 @@ void ExecuteVisitor::CheckPattern(Pattern& node, const BaseNode& base_node) {
|
|||
break;
|
||||
case 1:
|
||||
Visitor::Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
if (!context_manager_.EqualValues(current_value_, value)) { // TODO
|
||||
case_matched_ = false;
|
||||
}
|
||||
error_handling::HandleInternalError("Unimplemented EqualValues", "ExecuteVisitor.CheckPattern");
|
||||
// if (!context_manager_.EqualValues(current_value_, value)) { // TODO
|
||||
// case_matched_ = false;
|
||||
// }
|
||||
break;
|
||||
case 2:
|
||||
Visit(std::get<std::unique_ptr<TypeConstructorPattern>>(node).get());
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ void TypeCheckVisitor::Visit(TypeConstructorPatternParameter* node) {} // Handle
|
|||
// TODO
|
||||
void TypeCheckVisitor::Visit(TypeConstructorPattern* node) { // TODO: match named constructor
|
||||
if (!node->constructor->constructor_id_.has_value()) {
|
||||
error_handling::HandleTypecheckError("Type constructor pattern name not found", node->base);
|
||||
error_handling::HandleTypecheckError("Type constructor pattern constructor name not found", node->base);
|
||||
}
|
||||
|
||||
if (!node->constructor->type_id_.has_value()) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ std::optional<utils::IdType> TupleValue::GetFieldValue(const std::string& name)
|
|||
//
|
||||
|
||||
std::optional<utils::IdType> VariantValue::GetFieldValue(const std::string& name) {
|
||||
return value_manager_->GetAnyValue(value)->GetFieldValue(name); // TODO: TupleType ??
|
||||
return value.GetFieldValue(name);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue