implementation of useful error messages

This commit is contained in:
vegowotenks 2024-10-10 18:59:17 +02:00
parent 2ce8200366
commit c12e763b28
14 changed files with 295 additions and 68 deletions

View file

@ -1,6 +1,7 @@
#include "interpreter.h"
#include "builtin-functions.h"
#include "object-type.h"
#include "error-message.h"
#include <stdio.h>
#include <stdalign.h>
@ -90,16 +91,17 @@ int Interpreter_ParseFunction(Interpreter* self, CallFrame* top_frame, size_t st
top_frame->instruction_pointer++;
if (parameter_type->type != TOKENTYPE_IDENTIFIER) {
// TODO: Error message
ErrorMessage_err("Expected identifier for parameter type-definition in function definition", self, top_frame);
return EXIT_FAILURE;
}
if (parameter_name->type != TOKENTYPE_IDENTIFIER) {
// TODO: Error message
ErrorMessage_err("Expected identifier for parameter name-declaration in function definition", self, top_frame);
return EXIT_FAILURE;
}
*pdef = CallFrame_Reserve(top_frame, sizeof(ParameterDefinition), alignof(ParameterDefinition));
if (*pdef == NULL) {
ErrorMessage_OutOfMemoryError("Failed to reserve memory for CallFrame in Function parsefunction", self, top_frame);
return ENOMEM;
}
@ -221,7 +223,7 @@ int Interpreter_CallBuiltinFunction(Interpreter* self, CallFrame* parent_frame,
StringView function_name = name->get.identifier;
for (size_t i = 0; self->builtin_names[i] != NULL; i++) {
if (StringView_Equal(function_name, StringView_FromString(self->builtin_names[i]))) {
return self->builtin_functions[i](parent_frame);
return self->builtin_functions[i](parent_frame, self);
}
}
@ -350,22 +352,22 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
case TOKENTYPE_EQUALITY:
{
return BuiltinFunction_Equality(top_frame);
return BuiltinFunction_Equality(top_frame, self);
}
case TOKENTYPE_PLUS:
{
BuiltinFunction_Plus(top_frame);
BuiltinFunction_Plus(top_frame, self);
break;
}
case TOKENTYPE_MINUS:
{
BuiltinFunction_Minus(top_frame);
BuiltinFunction_Minus(top_frame, self);
break;
}
case TOKENTYPE_MULTIPLY:
{
BuiltinFunction_Multiply(top_frame);
BuiltinFunction_Multiply(top_frame, self);
break;
}