Objects Initial
This commit is contained in:
parent
0f639ba3b1
commit
94057d2a66
76 changed files with 7895 additions and 17 deletions
24
Objects/public/primitives/boolobject.h
Normal file
24
Objects/public/primitives/boolobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
49
Objects/public/primitives/classobject.h
Normal file
49
Objects/public/primitives/classobject.h
Normal 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;
|
||||
}
|
||||
};
|
||||
};
|
||||
24
Objects/public/primitives/colorobject.h
Normal file
24
Objects/public/primitives/colorobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
31
Objects/public/primitives/dictobject.h
Normal file
31
Objects/public/primitives/dictobject.h
Normal 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;
|
||||
};
|
||||
};
|
||||
34
Objects/public/primitives/enumobject.h
Normal file
34
Objects/public/primitives/enumobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
26
Objects/public/primitives/floatobject.h
Normal file
26
Objects/public/primitives/floatobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
19
Objects/public/primitives/interpreterobject.h
Normal file
19
Objects/public/primitives/interpreterobject.h
Normal 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();
|
||||
};
|
||||
};
|
||||
25
Objects/public/primitives/intobject.h
Normal file
25
Objects/public/primitives/intobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
29
Objects/public/primitives/linkobject.h
Normal file
29
Objects/public/primitives/linkobject.h
Normal 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;
|
||||
};
|
||||
|
||||
};
|
||||
36
Objects/public/primitives/listobject.h
Normal file
36
Objects/public/primitives/listobject.h
Normal 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;
|
||||
};
|
||||
};
|
||||
28
Objects/public/primitives/methodobject.h
Normal file
28
Objects/public/primitives/methodobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
32
Objects/public/primitives/nullobject.h
Normal file
32
Objects/public/primitives/nullobject.h
Normal 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()
|
||||
|
||||
};
|
||||
22
Objects/public/primitives/primitives.h
Normal file
22
Objects/public/primitives/primitives.h
Normal 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();
|
||||
};
|
||||
24
Objects/public/primitives/stringobject.h
Normal file
24
Objects/public/primitives/stringobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
13
Objects/public/primitives/typeobject.h
Normal file
13
Objects/public/primitives/typeobject.h
Normal 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);
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue