Compare commits

..

No commits in common. "2ce8200366d45bd997a3661527266b9d876c2e95" and "647f739d083c6df928d6d735e29cff4a507066bd" have entirely different histories.

7 changed files with 6 additions and 127 deletions

View file

@ -5,7 +5,5 @@ gcc `find src/ -name '*.c'` \
submodules/utilitiec/build/lib/liballocator-interface.a \
submodules/utilitiec/build/lib/libStringView.a \
submodules/utilitiec/build/lib/libScratchpad.a \
submodules/utilitiec/build/lib/libhashmap.a \
submodules/utilitiec/build/lib/libsiphash.a \
-Isubmodules/utilitiec/src \
-lm -ggdb -Wall -Wextra -pedantic -o bin/flup && echo "build successful"
-lm -ggdb -Wall -Wextra -pedantic -o bin/flup

View file

@ -53,21 +53,6 @@ int CallFrame_DefineVariable(CallFrame* self, StringView name, Value value)
return EXIT_SUCCESS;
}
int CallFrame_DefineObjectType(CallFrame* self, ObjectType* type)
{
FlupType* t = CallFrame_Reserve(self, sizeof(FlupType), alignof(FlupType));
if (t == NULL) {
return ENOMEM;
}
t->type = type;
// prepend to linked list
t->next = self->types;
self->types = t;
return EXIT_SUCCESS;
}
int CallFrame_StackPop(CallFrame* self, Value* dest)
{

View file

@ -27,11 +27,6 @@
#include "../submodules/utilitiec/src/StringView/StringView.h"
#include "../submodules/utilitiec/src/Scratchpad/Scratchpad.h"
typedef struct FlupType_s {
ObjectType* type;
struct FlupType_s* next;
} FlupType;
typedef struct CallFrame_s {
size_t instruction_pointer;
/* ip = condition start : start
@ -39,11 +34,9 @@ typedef struct CallFrame_s {
*
*/
FlupFunction* self_function;
FlupFunctionAlternative* alternative;
FlupFunction* functions; // functions defined in this callframe
FlupVariable* variables; // variables defined in this callframe
FlupType* types; // types defined in this callframe
DynamicArray stack; // Value
Scratchpad memory_pad;
} CallFrame;
@ -52,7 +45,6 @@ int CallFrame_Create(CallFrame* self, FlupFunction* self_function);
void CallFrame_Destroy(CallFrame* self);
int CallFrame_DefineVariable(CallFrame* self, StringView name, Value value);
int CallFrame_DefineObjectType(CallFrame* self, ObjectType* type);
int CallFrame_StackPop(CallFrame* self, Value* dest);
int CallFrame_StackPush(CallFrame* self, Value* value);
FlupVariable* CallFrame_FindVariable(CallFrame* self, StringView name);

View file

@ -1,6 +1,5 @@
#include "interpreter.h"
#include "builtin-functions.h"
#include "object-type.h"
#include <stdio.h>
#include <stdalign.h>
@ -485,11 +484,6 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
top_frame->instruction_pointer++;
break;
case TOKENTYPE_STRING:
{
}
break;
case TOKENTYPE_PIPE:
case TOKENTYPE_SEMICOLON:
case TOKENTYPE_LEFT_BRACE:
@ -506,6 +500,7 @@ int Interpreter_ExecuteNext(Interpreter* self, size_t stop_token)
case TOKENTYPE_COMMA:
case TOKENTYPE_LEFT_PAREN:
case TOKENTYPE_RIGHT_PAREN:
case TOKENTYPE_STRING:
fprintf(stderr, "Unexpected token with type: %s, continuing with next token...\n", TokenType_ToString(t->type));
top_frame->instruction_pointer++;
break;
@ -625,40 +620,6 @@ int Interpreter_Run(Interpreter* self)
return EXIT_SUCCESS;
}
int Interpreter_Startup(Interpreter* self, CallFrame* root_frame)
{
ObjectType* base_type = CallFrame_Reserve(root_frame, sizeof(ObjectType), alignof(ObjectType));
if (ObjectType_Create(base_type, StringView_FromString("Base"), base_type, 0, NULL)) {
return ENOMEM;
}
ObjectType* list_type = CallFrame_Reserve(root_frame, sizeof(ObjectType), alignof(ObjectType));
if (ObjectType_Create(list_type, StringView_FromString("List"), base_type, 2, NULL)) {
return ENOMEM;
}
if (ObjectType_DefineObjectAttribute(list_type, base_type, StringView_FromString("value"))) {
return ENOMEM;
}
if (ObjectType_DefineObjectAttribute(list_type, list_type, StringView_FromString("tail"))) {
return ENOMEM;
}
if (CallFrame_DefineObjectType(root_frame, list_type)) {
return ENOMEM;
}
ObjectType* char_type = CallFrame_Reserve(root_frame, sizeof(ObjectType), alignof(ObjectType));
if (ObjectType_Create(char_type, StringView_FromString("Char"), base_type, 2, NULL)) {
return ENOMEM;
}
if (ObjectType_DefinePrimitiveAttribute(list_type, VALUETYPE_BYTE, StringView_FromString("char"))) {
return ENOMEM;
}
self->implicit_char_type = char_type;
self->implicit_base_type = base_type;
return EXIT_SUCCESS;
}
int Interpreter_Interpret(Interpreter* self)
{
CallFrame* first_frame;

View file

@ -19,10 +19,6 @@ struct Interpreter_s {
DynamicArray* tokens;
DynamicArray call_frames; // stores CallFrame
// global stuff
ObjectType* implicit_char_type;
ObjectType* implicit_base_type;
};
int Interpreter_Create(Interpreter* self, DynamicArray* tokens);

View file

@ -1,45 +0,0 @@
#include "object-type.h"
int ObjectType_Create(ObjectType* self, StringView name, ObjectType* supertype, size_t attribute_count_guess, allocator_t* allocator)
{
struct HashMapConfig config = HashMap_DefaultConfig();
config.allocator = allocator;
int hashmap_code = HashMap_Create(&self->attributes, &config, attribute_count_guess * (1 / config.load_factor) + 1);
if (hashmap_code) {
return hashmap_code;
}
self->name = name;
self->reference_count = 0;
supertype->reference_count++;
return EXIT_SUCCESS;
}
void ObjectType_Destroy(ObjectType* self)
{
self->supertype->reference_count--;
// TODO: Emit a warning when there are still references?
HashMap_Destroy(&self->attributes);
}
int ObjectType_DefineObjectAttribute(ObjectType* self, ObjectType* attribute_type, StringView attribute_name)
{
ObjectTypeAttribute attribute = {
.name = attribute_name,
VALUETYPE_OBJECT,
attribute_type,
HashMap_Size(&self->attributes),
};
return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute);
}
int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name)
{
ObjectTypeAttribute attribute = {
.name = attribute_name,
attribute_type,
NULL,
HashMap_Size(&self->attributes),
};
return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute);
}

View file

@ -1,3 +1,5 @@
/*
* This code is part of the programming language flup
* flup comes with ABSOLUTELY NO WARRANTY and is licensed under AGPL-3.0 or later.
@ -23,27 +25,17 @@
#include "../submodules/utilitiec/src/hashmap/hashmap.h"
#include "../submodules/utilitiec/src/StringView/StringView.h"
typedef struct ObjectType_s ObjectType;
#include "value.h"
typedef struct ObjectTypeAttribute_s {
StringView name;
enum ValueType type;
ObjectType* object_type; // only active if there type is VALUETYPE_OBJECT
uint32_t index;
} ObjectTypeAttribute;
struct ObjectType_s {
typedef struct ObjectType_s {
hashmap_t attributes; // map of (char* name) -> (ObjectTypeAttribute entry)
StringView name;
size_t reference_count; // count of references from subtypes and object instances
struct ObjectType_s* supertype;
};
void ObjectType_Destroy(ObjectType* self);
int ObjectType_Create(ObjectType* self, StringView name, ObjectType* supertype, size_t attribute_count_guess, allocator_t* allocator);
int ObjectType_DefineObjectAttribute(ObjectType* self, ObjectType* attribute_type, StringView attribute_name);
int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name);
} ObjectType;
#endif