Started making object creation work
This commit is contained in:
parent
e8410e9464
commit
1e9dbd3018
7 changed files with 43 additions and 0 deletions
1
make.sh
1
make.sh
|
@ -7,5 +7,6 @@ gcc `find src/ -name '*.c'` \
|
||||||
submodules/utilitiec/build/lib/libScratchpad.a \
|
submodules/utilitiec/build/lib/libScratchpad.a \
|
||||||
submodules/utilitiec/build/lib/libhashmap.a \
|
submodules/utilitiec/build/lib/libhashmap.a \
|
||||||
submodules/utilitiec/build/lib/libsiphash.a \
|
submodules/utilitiec/build/lib/libsiphash.a \
|
||||||
|
submodules/utilitiec/build/lib/libTracingHeap.a \
|
||||||
-Isubmodules/utilitiec/src \
|
-Isubmodules/utilitiec/src \
|
||||||
-lm -ggdb -Wall -Wextra -pedantic -o bin/flup && echo "build successful"
|
-lm -ggdb -Wall -Wextra -pedantic -o bin/flup && echo "build successful"
|
||||||
|
|
|
@ -34,6 +34,9 @@ const BuiltinFunction standard_builtin_functions[] = {
|
||||||
|
|
||||||
int Interpreter_Create(Interpreter* self, DynamicArray* tokens)
|
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)) {
|
if (DynamicArray_Create(&self->call_frames, sizeof(CallFrame), 16, NULL)) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
@ -300,6 +303,20 @@ int Interpreter_GetParenthesizedRange(Interpreter* self, CallFrame* top_frame, s
|
||||||
return EXIT_SUCCESS;
|
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)
|
int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
|
||||||
{
|
{
|
||||||
size_t frame_count = DynamicArray_GetLength(&self->call_frames);
|
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:
|
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;
|
break;
|
||||||
|
|
||||||
|
@ -658,6 +680,7 @@ int Interpreter_Startup(Interpreter* self, CallFrame* root_frame)
|
||||||
|
|
||||||
self->implicit_char_type = char_type;
|
self->implicit_char_type = char_type;
|
||||||
self->implicit_base_type = base_type;
|
self->implicit_base_type = base_type;
|
||||||
|
self->native_list_type = list_type;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "../submodules/utilitiec/src/dynamicarray/dynamicarray.h"
|
#include "../submodules/utilitiec/src/dynamicarray/dynamicarray.h"
|
||||||
#include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h"
|
#include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h"
|
||||||
|
#include "../submodules/utilitiec/src/TracingHeap/TracingHeap.h"
|
||||||
|
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "callframe.h"
|
#include "callframe.h"
|
||||||
|
@ -20,9 +21,12 @@ struct Interpreter_s {
|
||||||
DynamicArray* tokens;
|
DynamicArray* tokens;
|
||||||
DynamicArray call_frames; // stores CallFrame
|
DynamicArray call_frames; // stores CallFrame
|
||||||
|
|
||||||
|
TracingHeap heap;
|
||||||
|
|
||||||
// global stuff
|
// global stuff
|
||||||
ObjectType* implicit_char_type;
|
ObjectType* implicit_char_type;
|
||||||
ObjectType* implicit_base_type;
|
ObjectType* implicit_base_type;
|
||||||
|
ObjectType* native_list_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
int Interpreter_Create(Interpreter* self, DynamicArray* tokens);
|
int Interpreter_Create(Interpreter* self, DynamicArray* tokens);
|
||||||
|
|
|
@ -43,3 +43,8 @@ int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribu
|
||||||
};
|
};
|
||||||
return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute);
|
return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ObjectType_GetAttributeCount(ObjectType* self)
|
||||||
|
{
|
||||||
|
return HashMap_Size(&self->attributes);
|
||||||
|
}
|
||||||
|
|
|
@ -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_DefineObjectAttribute(ObjectType* self, ObjectType* attribute_type, StringView attribute_name);
|
||||||
int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name);
|
int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name);
|
||||||
|
|
||||||
|
size_t ObjectType_GetAttributeCount(ObjectType* self);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
6
src/object.c
Normal file
6
src/object.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include "object.h"
|
||||||
|
|
||||||
|
size_t Object_AllocationSizeForType(ObjectType* otype)
|
||||||
|
{
|
||||||
|
return sizeof(Object) + sizeof(union ValueContent) * ObjectType_GetAttributeCount(otype);
|
||||||
|
}
|
|
@ -28,4 +28,6 @@ struct Object_s {
|
||||||
union ValueContent attributes[];
|
union ValueContent attributes[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
size_t Object_AllocationSizeForType(ObjectType* otype);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue