Started making object creation work

This commit is contained in:
vegowotenks 2024-10-18 17:00:09 +02:00
parent e8410e9464
commit 1e9dbd3018
7 changed files with 43 additions and 0 deletions

View file

@ -34,6 +34,9 @@ const BuiltinFunction standard_builtin_functions[] = {
int Interpreter_Create(Interpreter* self, DynamicArray* tokens)
{
if (TracingHeap_Create(&self->heap, NULL)) {
return EXIT_FAILURE;
}
if (DynamicArray_Create(&self->call_frames, sizeof(CallFrame), 16, NULL)) {
return ENOMEM;
}
@ -300,6 +303,20 @@ int Interpreter_GetParenthesizedRange(Interpreter* self, CallFrame* top_frame, s
return EXIT_SUCCESS;
}
Object* _Interpreter_MakeObject(Interpreter* self, ObjectType* otype)
{
size_t object_size = Object_AllocationSizeForType(otype);
Object* new_object = TracingHeap_Allocate(&self->heap, object_size);
return new_object;
}
static int _Interpreter_ConstructString(Interpreter* self, StringView view)
{
Object* string_head = _Interpreter_MakeObject(self, self->native_list_type);
return EXIT_SUCCESS;
}
int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
{
size_t frame_count = DynamicArray_GetLength(&self->call_frames);
@ -489,6 +506,11 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
case TOKENTYPE_STRING:
{
StringView v = StringView_Slice(t->get.identifier, 1, t->get.identifier.length - 1); // drop the "s
int construct_code = _Interpreter_ConstructString(self, v);
if (construct_code) {
return construct_code;
}
}
break;
@ -658,6 +680,7 @@ int Interpreter_Startup(Interpreter* self, CallFrame* root_frame)
self->implicit_char_type = char_type;
self->implicit_base_type = base_type;
self->native_list_type = list_type;
return EXIT_SUCCESS;
}