type_check_visitor value types maybe fixed

This commit is contained in:
ProgramSnail 2023-05-22 19:14:17 +03:00
parent 6bf64acc4d
commit 43b2993e2a
5 changed files with 76 additions and 65 deletions

View file

@ -509,7 +509,7 @@ void ExecuteVisitor::Visit(FunctionCallExpression* node) {
if (maybe_internal_type.has_value()) {
if (HandleBuiltinTypeFunctionCall(node, maybe_internal_type.value())) {
context_manager_.ExitContext();
return; // TODO: always return from end of function
return; // TODO: return from end of function
}
error_handling::HandleRuntimeError("Type function definition not found (builtin type)", node->base);
}
@ -995,6 +995,8 @@ bool ExecuteVisitor::HandleBuiltinTypeFunctionCall(FunctionCallExpression* node,
info::type::InternalType type) {
const std::string& name = node->name;
error_handling::DebugPrint(name);
if (utils::IsBuiltinFunction(name)) {
std::vector<info::value::InternalValue*> arguments;
arguments.reserve(node->arguments.size());
@ -1009,8 +1011,8 @@ bool ExecuteVisitor::HandleBuiltinTypeFunctionCall(FunctionCallExpression* node,
arguments.push_back(ExtractValue<info::value::InternalValue>(current_value_, node->base));
}
// error_handling::DebugPrint(info::type::ToString(type));
// std::cout << std::endl;
error_handling::DebugPrint(info::type::ToString(type));
std::cout << std::endl;
switch (type) {
case info::type::InternalType::Float:
@ -1035,10 +1037,22 @@ bool ExecuteVisitor::HandleBuiltinTypeFunctionCall(FunctionCallExpression* node,
info::value::InternalValue(1.0),
utils::ValueType::Tmp);
} else if (name == "+=") {
// TODO
error_handling::HandleInternalError("+= not implemented yet (float)",
"ExecuteVisitor.HandleBuiltinTypeFunctionCall",
&node->base);
*arguments[0]->GetValue<double>().value() += *arguments[1]->GetValue<double>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
} else if (name == "-=") {
*arguments[0]->GetValue<double>().value() -= *arguments[1]->GetValue<double>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
} else if (name == "*=") {
*arguments[0]->GetValue<double>().value() *= *arguments[1]->GetValue<double>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
} else if (name == "/=") {
*arguments[0]->GetValue<double>().value() /= *arguments[1]->GetValue<double>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
@ -1063,7 +1077,7 @@ bool ExecuteVisitor::HandleBuiltinTypeFunctionCall(FunctionCallExpression* node,
current_value_ = context_manager_.AddValue(
info::value::InternalValue(*arguments[0]->GetValue<int64_t>().value() / *arguments[1]->GetValue<int64_t>().value()),
utils::ValueType::Tmp);
} else if (name == "mod") { // TODO: best implementation of mod (read % specification)
} else if (name == "mod") { // TODO: better implementation of mod (read % specification)
current_value_ = context_manager_.AddValue(
info::value::InternalValue(*arguments[0]->GetValue<int64_t>().value() % *arguments[1]->GetValue<int64_t>().value()),
utils::ValueType::Tmp);
@ -1076,10 +1090,17 @@ bool ExecuteVisitor::HandleBuiltinTypeFunctionCall(FunctionCallExpression* node,
info::value::InternalValue(1),
utils::ValueType::Tmp);
} else if (name == "+=") {
// TODO
error_handling::HandleInternalError("+= not implemented yet (int)",
"ExecuteVisitor.HandleBuiltinTypeFunctionCall",
&node->base);
*arguments[0]->GetValue<int64_t>().value() += *arguments[1]->GetValue<int64_t>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
} else if (name == "-=") {
*arguments[0]->GetValue<int64_t>().value() += *arguments[1]->GetValue<int64_t>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);
} else if (name == "*=") {
*arguments[0]->GetValue<int64_t>().value() += *arguments[1]->GetValue<int64_t>().value();
current_value_ = context_manager_.AddValue(
info::value::InternalValue(info::value::Unit()),
utils::ValueType::Tmp);