This commit is contained in:
ProgramSnail 2023-05-18 22:27:55 +03:00
parent 273ac960fd
commit 9b3d2812ba
2 changed files with 20 additions and 6 deletions

View file

@ -385,10 +385,13 @@ void ExecuteVisitor::Visit(AccessExpression* node) {
// Other Expressions
// TODO: typeclass methods
// TODO
// TODO: typeclass functions
// TODO: builtin functions
// TODO: binary operator expression
void ExecuteVisitor::Visit(FunctionCallExpression* node) {
context_manager_.EnterContext();
if (node->prefix.has_value()) {
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix.value())) {
Visitor::Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix.value()));
@ -406,9 +409,20 @@ void ExecuteVisitor::Visit(FunctionCallExpression* node) {
} else {
// error
}
} else {
if (node->is_method_of_first_argument_) {
Visitor::Visit(node->arguments[0]);
context_manager_.DefineVariable(utils::ClassInternalVarName, current_value_);
}
// TODO
}
if (!node->function_id_.has_value()) {
// TODO: typeclass function
error_handling::HandleInternalError("Typeclass functions not implemented yet",
"ExecuteVisitor.FunctionCallExpression");
}
// TODO: typeclass functions
auto function_declaration = global_info_.GetFunctionInfo(node->function_id_.value()).declaration.value(); // checked in type_check_visitor
for (size_t i = 0; i < node->parameters.size(); ++i) {
@ -417,11 +431,10 @@ void ExecuteVisitor::Visit(FunctionCallExpression* node) {
context_manager_.DefineLocalType(function_declaration.parameters[i].type, node->parameters[i]->type_id_.value()); // TODO: check
}
// TODO: typeclass functions
auto maybe_function_definition = global_info_.GetFunctionInfo(node->function_id_.value()).definition;
if (maybe_function_definition.has_value()) {
for (size_t i = 0; i < node->arguments.size(); ++i) {
for (size_t i = (node->is_method_of_first_argument_ ? 1 : 0); i < node->arguments.size(); ++i) {
Visitor::Visit(node->arguments[i]);
// TODO: custom argument value types, references, etc.
current_value_ = context_manager_.ToModifiedValue(current_value_, utils::ValueType::Const);
@ -430,8 +443,8 @@ void ExecuteVisitor::Visit(FunctionCallExpression* node) {
Visit(maybe_function_definition.value().node);
} else {
// TODO: builtin functions, etc. (imports?)
error_handling::HandleRuntimeError("Function definition not found", node->base);
// TODO: functions, defined in typeclasses ??
}
context_manager_.ExitContext();

View file

@ -855,7 +855,8 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
global_info_.GetTypeInfo<info::definition::AnyType>(type_id);
if (!maybe_type_info.has_value()) { // TODO
error_handling::HandleInternalError("Implemented only for AnyType", "TypeCheckVisitor.TypeConstructor");
error_handling::HandleInternalError("Implemented only for AnyType",
"TypeCheckVisitor.TypeConstructor");
}
info::definition::AnyType& type_info = *maybe_type_info.value();