diff --git a/make.sh b/make.sh index 4539154..ec9025b 100644 --- a/make.sh +++ b/make.sh @@ -7,5 +7,6 @@ gcc `find src/ -name '*.c'` \ submodules/utilitiec/build/lib/libScratchpad.a \ submodules/utilitiec/build/lib/libhashmap.a \ submodules/utilitiec/build/lib/libsiphash.a \ + submodules/utilitiec/build/lib/libTracingHeap.a \ -Isubmodules/utilitiec/src \ -lm -ggdb -Wall -Wextra -pedantic -o bin/flup && echo "build successful" diff --git a/src/interpreter.c b/src/interpreter.c index 92f51a2..022bfc5 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -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; } diff --git a/src/interpreter.h b/src/interpreter.h index a204dbf..e86822d 100644 --- a/src/interpreter.h +++ b/src/interpreter.h @@ -3,6 +3,7 @@ #include "../submodules/utilitiec/src/dynamicarray/dynamicarray.h" #include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h" +#include "../submodules/utilitiec/src/TracingHeap/TracingHeap.h" #include "tokenizer.h" #include "callframe.h" @@ -20,9 +21,12 @@ struct Interpreter_s { DynamicArray* tokens; DynamicArray call_frames; // stores CallFrame + TracingHeap heap; + // global stuff ObjectType* implicit_char_type; ObjectType* implicit_base_type; + ObjectType* native_list_type; }; int Interpreter_Create(Interpreter* self, DynamicArray* tokens); diff --git a/src/object-type.c b/src/object-type.c index cee326d..3abc250 100644 --- a/src/object-type.c +++ b/src/object-type.c @@ -43,3 +43,8 @@ int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribu }; return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute); } + +size_t ObjectType_GetAttributeCount(ObjectType* self) +{ + return HashMap_Size(&self->attributes); +} diff --git a/src/object-type.h b/src/object-type.h index a4dcdfc..c9015cf 100644 --- a/src/object-type.h +++ b/src/object-type.h @@ -46,4 +46,6 @@ int ObjectType_Create(ObjectType* self, StringView name, ObjectType* supertype, int ObjectType_DefineObjectAttribute(ObjectType* self, ObjectType* attribute_type, StringView attribute_name); int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name); +size_t ObjectType_GetAttributeCount(ObjectType* self); + #endif diff --git a/src/object.c b/src/object.c new file mode 100644 index 0000000..4dd26fd --- /dev/null +++ b/src/object.c @@ -0,0 +1,6 @@ +#include "object.h" + +size_t Object_AllocationSizeForType(ObjectType* otype) +{ + return sizeof(Object) + sizeof(union ValueContent) * ObjectType_GetAttributeCount(otype); +} diff --git a/src/object.h b/src/object.h index 9c724db..fca9973 100644 --- a/src/object.h +++ b/src/object.h @@ -28,4 +28,6 @@ struct Object_s { union ValueContent attributes[]; }; +size_t Object_AllocationSizeForType(ObjectType* otype); + #endif