Objects Initial

This commit is contained in:
IlushaShurupov 2023-07-24 21:55:19 +03:00
parent 00bc875846
commit 803ce23169
76 changed files with 7895 additions and 17 deletions

View file

@ -0,0 +1,24 @@
#pragma once
#include "core/object.h"
namespace obj {
struct BoolObject : Object {
tp::alni val;
static ObjectType TypeData;
static void constructor(BoolObject* self);
static void copy(BoolObject* self, const BoolObject* in);
static BoolObject* create(bool in);
static void from_int(BoolObject* self, tp::alni in);
static void from_float(BoolObject* self, tp::alnf in);
static void from_string(BoolObject* self, tp::String in);
static tp::String to_string(BoolObject* self);
static tp::alni to_int(BoolObject* self);
static tp::alnf to_float(BoolObject* self);
};
};

View file

@ -0,0 +1,49 @@
#pragma once
#include "primitives/dictobject.h"
namespace obj {
struct ClassObject : Object {
static ObjectType TypeData;
static void copy(ClassObject* self, const ClassObject* in);
static void destructor(ClassObject* self);
static void constructor(ClassObject* self);
static tp::alni save_size(ClassObject* self);
static void save(ClassObject* self, Archiver& file_self);
static void load(Archiver& file_self, ClassObject* self);
DictObject* members;
void addMember(Object* obj, tp::String id);
void createMember(tp::String type, tp::String id);
template<typename Type>
Type* createMember(tp::String id) {
auto out = NDO->create(Type::TypeData.name);
addMember(out, id);
#ifdef OBJECT_REF_COUNT
NDO->destroy(out);
#endif // OBJECT_REF_COUNT
return (Type*) out;
}
template<typename Type>
Type* getMember(const tp::String& id) {
auto idx = members->presents(id);
if (idx) {
return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData));
}
return NULL;
}
template<typename Type>
Type* getMemberAssert(const tp::String& id) {
auto out = getMember<Type>(id);
assert(out && "invalid member access");
return out;
}
};
};

View file

@ -0,0 +1,24 @@
#pragma once
#include "core/object.h"
#include "Color.hpp"
namespace obj {
struct ColorObject : Object {
tp::RGBA mCol;
static ObjectType TypeData;
static ObjectTypeAriphmetics TypeAriphm;
static void constructor(Object* self);
static void copy(ColorObject* self, const ColorObject* in);
static void from_int(ColorObject* self, tp::alni in);
static void from_float(ColorObject* self, tp::alnf in);
static tp::String to_string(ColorObject* self);
static ColorObject* create(tp::RGBA in);
};
};

View file

@ -0,0 +1,31 @@
#pragma once
#include "core/object.h"
namespace obj {
struct DictObject : Object {
static ObjectType TypeData;
static void copy(Object* self, const Object* in);
static void destructor(Object* self);
static void constructor(Object* self);
static tp::alni save_size(DictObject* self);
static void save(DictObject* self, Archiver& file_self);
static void load(Archiver& file_self, DictObject* self);
static tp::Buffer<Object*> childs_retrival(DictObject* self);
static tp::alni allocated_size(DictObject* self);
static tp::alni allocated_size_recursive(DictObject* self);
void put(tp::String, Object*);
void remove(tp::String);
Object* get(tp::String);
tp::Map<tp::String, Object*>::Idx presents(tp::String);
Object* getSlotVal(tp::alni);
const tp::Map<tp::String, Object*>& getItems() const;
private:
tp::Map<tp::String, Object*> items;
};
};

View file

@ -0,0 +1,34 @@
#pragma once
#include "core/object.h"
namespace obj {
struct EnumObject : Object {
// one entry is 2 * sizeof(alni) in size
tp::uhalni active;
tp::uhalni nentries;
tp::alni* entries;
static ObjectType TypeData;
static void constructor(EnumObject* self);
static void destructor(EnumObject* self);
static void copy(EnumObject* self, const EnumObject* in);
void init(tp::init_list<const char*> list);
const char* getActiveName();
const char* getItemName(tp::uhalni idx);
static void from_int(EnumObject* self, tp::alni in);
static void from_float(EnumObject* self, tp::alnf in);
static void from_string(EnumObject* self, tp::String in);
static tp::String to_string(EnumObject* self);
static tp::alni to_int(EnumObject* self);
static tp::alnf to_float(EnumObject* self);
static bool compare(EnumObject* first, EnumObject* second);
static EnumObject* create(tp::init_list<const char*> list);
};
};

View file

@ -0,0 +1,26 @@
#pragma once
#include "core/object.h"
namespace obj {
struct FloatObject : Object {
tp::alnf val;
static ObjectType TypeData;
static ObjectTypeAriphmetics TypeAriphm;
static void constructor(FloatObject* self);
static void copy(FloatObject* self, const FloatObject* in);
static FloatObject* create(tp::alnf in);
static void from_int(FloatObject* self, tp::alni in);
static void from_float(FloatObject* self, tp::alnf in);
static void from_string(FloatObject* self, tp::String in);
static tp::String to_string(FloatObject* self);
static tp::alni to_int(FloatObject* self);
static tp::alnf to_float(FloatObject* self);
};
};

View file

@ -0,0 +1,19 @@
#pragma once
#include "interpreter/interpreter.h"
#include "primitives/classobject.h"
namespace obj {
struct InterpreterObject : ClassObject {
static ObjectType TypeData;
Interpreter mInterpreter;
static void destructor(InterpreterObject* self);
static void constructor(InterpreterObject* self);
static void load(Archiver& file_self, InterpreterObject* self);
void exec(obj::ClassObject* self = NULL, tp::init_list<Interpreter::GlobalDef> globals = {});
void debug();
bool running();
};
};

View file

@ -0,0 +1,25 @@
#pragma once
#include "core/object.h"
namespace obj {
struct IntObject : Object {
tp::alni val;
static ObjectType TypeData;
static ObjectTypeAriphmetics TypeAriphm;
static void constructor(Object* self);
static void copy(IntObject* self, const IntObject* in);
static IntObject* create(tp::alni in);
static void from_int(Object* self, tp::alni in);
static void from_float(Object* self, tp::alnf in);
static void from_string(Object* self, tp::String in);
static tp::String to_string(Object* self);
static tp::alni to_int(Object* self);
static tp::alnf to_float(Object* self);
};
};

View file

@ -0,0 +1,29 @@
#pragma once
#include "core/object.h"
namespace obj {
struct LinkObject : Object {
static ObjectType TypeData;
static void constructor(Object* self);
static void destructor(LinkObject* self);
static void copy(Object* self, const Object* in);
static LinkObject* create(Object* in);
static tp::alni save_size(LinkObject* self);
static void save(LinkObject* self, Archiver& file_self);
static void load(Archiver& file_self, LinkObject* self);
static tp::alni allocated_size(LinkObject* self);
static tp::alni allocated_size_recursive(LinkObject* self);
static tp::Buffer<Object*> childs_retrival(LinkObject* self);
Object* getLink();
void setLink(Object* obj);
private:
Object* link;
};
};

View file

@ -0,0 +1,36 @@
#pragma once
#include "core/object.h"
namespace obj {
enum ListMethods {
LISTOBJECT_PUSH_BACK,
LISTOBJECT_GET_LENGTH,
};
struct ListObject : Object {
static ObjectType TypeData;
static void constructor(Object* self);
static void copy(Object* self, const Object* in);
static void destructor(Object* self);
static tp::alni allocated_size_recursive(ListObject* self);
static tp::alni allocated_size(ListObject* self);
static tp::Buffer<Object*> childs_retrival(ListObject* self);
static void load(Archiver& file_self, ListObject* self);
static void save(ListObject* self, Archiver& file_self);
static tp::alni save_size(ListObject* self);
const tp::List<Object*>& getItems() const;
void pushBack(Object* obj);
void pushFront(Object* obj);
void popBack();
void delNode(tp::List<Object*>::Node*);
private:
tp::List<Object*> items;
};
};

View file

@ -0,0 +1,28 @@
#pragma once
#include "primitives/stringobject.h"
#include "interpreter/script.h"
namespace obj {
struct MethodObject : Object {
static ObjectType TypeData;
Script* mScript;
static void constructor(MethodObject* self);
static void copy(MethodObject* self, MethodObject* in);
static void destructor(MethodObject* self);
static tp::alni save_size(MethodObject* self);
static void save(MethodObject* self,Archiver& file_self);
static void load(Archiver& file_self, obj::MethodObject* self);
static void Initialize();
static void UnInitialize();
void compile();
static MethodObject* create(tp::String script);
};
};

View file

@ -0,0 +1,32 @@
#pragma once
#include "core/object.h"
namespace obj {
extern struct NullObject* NdoNull_globalInstance;
struct NullObject : Object {
static void destructor(Object* self);
static ObjectType TypeData;
static void uninit();
static Object* null_return() {
if (!NdoNull_globalInstance) {
NdoNull_globalInstance = (NullObject*) NDO->create("null");
obj::NDO->refinc(NdoNull_globalInstance);
}
return (Object*) NdoNull_globalInstance;
}
static Object* null_return_ref() {
obj::NDO->refinc(null_return());
return NdoNull_globalInstance;
}
};
#define NDO_NULL obj::NullObject::null_return()
#define NDO_NULL_REF obj::NullObject::null_return_ref()
};

View file

@ -0,0 +1,22 @@
#pragma once
#include "primitives/dictobject.h"
#include "primitives/intobject.h"
#include "primitives/linkobject.h"
#include "primitives/listobject.h"
#include "primitives/nullobject.h"
#include "primitives/stringobject.h"
#include "primitives/boolobject.h"
#include "primitives/floatobject.h"
#include "primitives/enumobject.h"
#include "primitives/classobject.h"
#include "primitives/colorobject.h"
#include "primitives/methodobject.h"
#include "primitives/interpreterobject.h"
#include "primitives/typeobject.h"
namespace obj {
void primitives_define_types();
void primitives_uninitialize();
};

View file

@ -0,0 +1,24 @@
#pragma once
#include "core/object.h"
namespace obj {
struct StringObject : Object {
tp::String val;
static ObjectType TypeData;
static void constructor(Object* self);
static void destructor(StringObject* self);
static void copy(Object* self, const Object* in);
static StringObject* create(tp::String in);
static void from_int(StringObject* self, tp::alni in);
static void from_float(StringObject* self, tp::alnf in);
static void from_string(StringObject* self, tp::String in);
static tp::String to_string(StringObject* self);
static tp::alni to_int(StringObject* self);
static tp::alnf to_float(StringObject* self);
};
};

View file

@ -0,0 +1,13 @@
#pragma once
#include "core/object.h"
namespace obj {
struct TypeObject : Object {
static ObjectType TypeData;
const ObjectType* mTypeRef;
static TypeObject* create(const ObjectType* type);
};
};