flup/src/object-type.h

51 lines
2 KiB
C

/*
* This code is part of the programming language flup
* flup comes with ABSOLUTELY NO WARRANTY and is licensed under AGPL-3.0 or later.
* Copyright (C) 2024 VegOwOtenks
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FLUP_OBJECTTYPE_H
#define FLUP_OBJECTTYPE_H
#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 {
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);
size_t ObjectType_GetAttributeCount(ObjectType* self);
#endif