Tokenizing and printing

This commit is contained in:
vegowotenks 2024-10-01 10:53:26 +02:00
parent 371eca6269
commit b5912b95f7
5 changed files with 259 additions and 1 deletions

50
src/interpreter.c Normal file
View file

@ -0,0 +1,50 @@
#include "interpreter.h"
static int CallFrame_Create(CallFrame* self, FlupFunctionAlternative* f)
{
if (DynamicArray_Create(&self->stack, sizeof(Value), 8, NULL)) {
return ENOMEM;
}
self->function = f;
self->instruction_pointer = f->body_token_start;
return EXIT_SUCCESS;
}
static FlupFunctionAlternative* FlupFunctionAlternative_Malloc(size_t condition_token_start, size_t condition_token_end, size_t body_token_start, size_t body_token_end)
{
FlupFunctionAlternative* a = malloc(sizeof(FlupFunctionAlternative));
a->next = NULL;
a->condition_token_start = condition_token_start;
a->condition_token_end = condition_token_end;
a->body_token_start = body_token_start;
a->body_token_end = body_token_end;
return a;
}
int Interpreter_Create(Interpreter* self, DynamicArray* tokens)
{
if (DynamicArray_Create(&self->call_frames, sizeof(CallFrame), 16, NULL)) {
return ENOMEM;
}
self->tokens = tokens;
return EXIT_SUCCESS;
}
int Interpreter_Interpret(Interpreter* self)
{
CallFrame* first_frame;
DynamicArray_AppendEmpty(&self->call_frames, (void**) &first_frame);
if (CallFrame_Create(first_frame, )) {
return ENOMEM;
}
return EXIT_SUCCESS;
}
void Interpreter_Destroy(Interpreter* self)
{
DynamicArray_Destroy(&self->call_frames);
}