extended name removed, dereference added, unary operators removed, fixes

This commit is contained in:
ProgramSnail 2023-05-13 13:11:12 +03:00
parent e62144feac
commit 79bd30c1ee
20 changed files with 101 additions and 274 deletions

View file

@ -337,27 +337,6 @@ void ExecuteVisitor::Visit(BinaryOperatorExpression* node) {
context_manager_.ExitContext();
}
// TODO: methods??
void ExecuteVisitor::Visit(UnaryOperatorExpression* node) {
context_manager_.EnterContext();
auto maybe_function_definition = namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(node->function_id_).definition;
if (maybe_function_definition.has_value()) {
Visitor::Visit(node->expression);
// TODO: custom argument value types, references, etc.
current_value_ = context_manager_.ToModifiedValue(current_value_, utils::ValueType::Const);
context_manager_.DefineVariable(maybe_function_definition.value().argument_names[0], current_value_);
Visit(maybe_function_definition.value().node);
} else {
// TODO: builtin operators, etc. (imports?)
error_handling::HandleRuntimeError("Unary operator definition not found", node->base);
}
context_manager_.ExitContext();
}
void ExecuteVisitor::Visit(ReferenceExpression* node) {
// TODO: check, that there is no references to "Tmp"??
Visit(node->expression.get());
@ -495,7 +474,7 @@ void ExecuteVisitor::Visit(TypeConstructor* node) {
Visitor::Visit(parameter.value);
// TODO: copy/move parameters
fields.push_back(
{ parameter.name.has_value() ? std::optional<std::string>(parameter.name.value().name) : std::nullopt,
{ parameter.name.has_value() ? std::optional<std::string>(parameter.name.value()) : std::nullopt,
current_value_ });
}
@ -532,7 +511,7 @@ void ExecuteVisitor::Visit(NameExpression* node) { // TODO: check
}
std::optional<utils::IdType> maybe_variable_value =
context_manager_.GetVariableInfo(node->names[0].name);
context_manager_.GetVariableInfo(node->names[0]);
if (!maybe_variable_value.has_value()) {
error_handling::HandleRuntimeError("Variable not found", node->base);
@ -544,9 +523,9 @@ void ExecuteVisitor::Visit(NameExpression* node) { // TODO: check
utils::ValueType variable_value_type = context_manager_.GetValueType(current_value_);
for (size_t i = 1; i < node->names.size(); ++i) {
std::optional<utils::IdType> maybe_field_value = context_manager_.GetAnyValue(current_value_)->GetFieldValue(node->names[i].name); // TODO
std::optional<utils::IdType> maybe_field_value = context_manager_.GetAnyValue(current_value_)->GetFieldValue(node->names[i]); // TODO
if (!maybe_field_value.has_value()) {
error_handling::HandleRuntimeError("Variable field not found", node->names[i].base);
error_handling::HandleRuntimeError("Variable field not found", node->base);
}
current_value_ = maybe_field_value.value();
@ -749,7 +728,7 @@ void ExecuteVisitor::CheckPattern(Pattern& node, const BaseNode& base_node) {
switch (node.index()) {
case 0:
value = context_manager_.ToModifiedValue(value, utils::ValueType::Const); // ??
if (!context_manager_.DefineVariable(std::get<std::unique_ptr<ExtendedName>>(node)->name,
if (!context_manager_.DefineVariable(*std::get<std::unique_ptr<NameIdentifier>>(node),
value)) {
error_handling::HandleRuntimeError("Can't redifine variable", base_node);
}