Objects Compiled

This commit is contained in:
IlushaShurupov 2023-07-30 18:30:36 +03:00
parent ba95747ef9
commit 64e1f78739
52 changed files with 384 additions and 370 deletions

View file

@ -33,7 +33,7 @@ namespace obj {
Expression(Type type);
ExpressionChild* ExprChild(tp::String id);
ExpressionCall* ExprCall(tp::init_list<Expression*> args);
ExpressionCall* ExprCall(tp::InitialierList<Expression*> args);
};
struct ExpressionNew : public Expression {
@ -61,7 +61,7 @@ namespace obj {
struct ExpressionCall : public Expression {
Expression* mParent = NULL;
tp::Buffer<Expression*> mArgs;
ExpressionCall(Expression* mParent, tp::init_list<Expression*> args);
ExpressionCall(Expression* mParent, tp::InitialierList<Expression*> args);
};
struct ExpressionAriphm : public Expression {

View file

@ -16,13 +16,13 @@ namespace obj {
OpCode mOp = OpCode::NONE;
enum class ArgType {
enum class ArgType : tp::ualni {
NO_ARG,
PARAM,
CONST,
} mArgType = ArgType::NO_ARG;
enum class InstType {
enum class InstType : tp::ualni {
NONE,
JUMP,
JUMP_IF,
@ -38,7 +38,7 @@ namespace obj {
ConstObject* mConstData2 = NULL;
tp::alni mInstIdx = 0;
tp::List<Instruction>::Node* mInstTarget = NULL;
Instruction* mInstTarget = NULL;
Instruction();
Instruction(ConstObject* constData);
@ -46,7 +46,7 @@ namespace obj {
Instruction(OpCode op, ConstObject* constData);
Instruction(OpCode op, ConstObject* constData, ConstObject* constData2);
Instruction(OpCode op, tp::alni param, tp::alni nBytes);
Instruction(tp::List<Instruction>::Node* inst, InstType jump_type);
Instruction(Instruction* inst, InstType jump_type);
};
};
};

View file

@ -31,7 +31,7 @@ namespace obj {
tp::Buffer<Statement*> mStatements;
bool mPushToScopeStack = false;
StatementScope(tp::init_list<Statement*> statements, bool aPushToScopeStack);
StatementScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack);
};
struct StatementFuncDef : public Statement {
@ -39,7 +39,7 @@ namespace obj {
tp::String mFunctionId;
tp::Buffer<Statement*> mStatements;
StatementFuncDef(tp::String function_id, tp::init_list<tp::String> args, tp::init_list<Statement*> statements);
StatementFuncDef(tp::String function_id, tp::InitialierList<tp::String> args, tp::InitialierList<Statement*> statements);
};
struct StatementLocalDef : public Statement {
@ -101,14 +101,14 @@ namespace obj {
};
// Helpers
StatementFuncDef* StmDefFunc(tp::String id, tp::init_list<tp::String> args, tp::init_list<Statement*> stms);
StatementFuncDef* StmDefFunc(tp::String id, tp::InitialierList<tp::String> args, tp::InitialierList<Statement*> stms);
StatementLocalDef* StmDefLocal(tp::String id, Expression* value);
StatementCopy* StmCopy(Expression* left, Expression* right);
StatementPrint* StmPrint(Expression* target);
StatementReturn* StmReturn(Expression* obj);
StatementReturn* StmReturn();
StatementIf* StmIf(Expression* condition, StatementScope* on_true, StatementScope* on_false);
StatementScope* StmScope(tp::init_list<Statement*> statements, bool aPushToScopeStack);
StatementScope* StmScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack);
StatementWhile* StmWhile(Expression* condition, StatementScope* scope);
StatementIgnore* StmIgnore(Expression* expr);
StatementClassDef* StmClassDef(tp::String id, StatementScope* scope);

View file

@ -11,6 +11,8 @@
#include "core/typegroups.h"
#include "core/typemethods.h"
#include "Archiver.hpp"
//#include "interpreter/interpreter.h"
/* Steps to create custom Object:
@ -36,36 +38,48 @@ implement construct, destruct and copy methods */
namespace obj {
class Archiver : public tp::LocalConnection {
template<bool tRead>
class Archiver : public tp::ArchiverTemplate<tRead> {
tp::LocalConnection mConnection;
tp::ualni mAddress = 0;
tp::ualni mFirstNotWritten = 0;
public:
enum Type { SAVE, LOAD };
Archiver() = default;
Archiver(const char*, Type) {};
explicit Archiver(const char* location) {};
bool opened;
tp::ualni adress{};
// not yet writen address
// always offsets on write without specific address
tp::ualni avl_adress{};
void write_bytes(const tp::int1* in, tp::alni size, tp::alni adress = -1) {}
template <typename Type>
void write(Type* in, tp::alni adress = -1) {
write_bytes((tp::int1*) in, sizeof(Type), adress);
void writeBytes(const tp::int1* val, tp::ualni size) override {
mConnection.writeBytes(val, size);
incrementAddresses(size);
}
void read_bytes(tp::int1* in, tp::alni size, tp::alni adress = -1) {}
void readBytes(tp::int1* val, tp::ualni size) override {
mConnection.readBytes(val, size);
incrementAddresses(size);
}
template <typename Type>
void read(Type* in, tp::alni adress = -1) {
read_bytes((tp::int1*) in, sizeof(Type), adress);
tp::ualni getAddress() { return mAddress; }
void setAddress(tp::ualni addr) { mAddress = addr; }
tp::ualni getFreeAddress() { return mFirstNotWritten; }
void setFreeAddress(tp::ualni addr) { mFirstNotWritten = addr; }
bool isOpened() { return mConnection.getConnectionStatus().isOpened(); }
bool getSize() { return mConnection.size(); }
private:
void incrementAddresses(tp::ualni size) {
// if (mAddress + size > mFirstNotWritten) mFirstNotWritten = mAddress + size;
mAddress += size;
}
};
using ArchiverIn = Archiver<true>;
using ArchiverOut = Archiver<false>;
extern tp::ModuleManifest gModuleObjects;
extern struct objects_api* NDO;
@ -116,8 +130,8 @@ namespace obj {
typedef void (*object_copy)(Object* self, const Object* target);
typedef tp::alni(*object_save_size)(Object* self);
typedef void (*object_save)(Object*, Archiver&);
typedef void (*object_load)(Archiver&, Object*);
typedef void (*object_save)(Object*, ArchiverOut&);
typedef void (*object_load)(ArchiverIn&, Object*);
typedef bool (*object_compare)(Object*, Object*);
@ -130,7 +144,7 @@ namespace obj {
object_constructor constructor = NULL;
object_destructor destructor = NULL;
object_copy copy = NULL;
tp::alni size = NULL;
tp::alni size = 0;
const char* name;
const ObjectTypeConversions* convesions = NULL;
const ObjectTypeAriphmetics* ariphmetics = NULL;
@ -148,11 +162,11 @@ namespace obj {
#define SAVE_LOAD_MAX_CALLBACK_SLOTS 100
typedef void (pre_save_callback)(void* self, Archiver&);
typedef void (pre_load_callback)(void* self, Archiver&);
typedef void (post_save_callback)(void* self, Archiver&);
typedef void (post_load_callback)(void* self, Archiver&);
typedef tp::alni (slcb_size_callback)(void* self, Archiver&);
typedef void (pre_save_callback)(void* self, ArchiverOut&);
typedef void (pre_load_callback)(void* self, ArchiverIn&);
typedef void (post_save_callback)(void* self, ArchiverOut&);
typedef void (post_load_callback)(void* self, ArchiverIn&);
typedef tp::alni (slcb_size_callback)(void* self, ArchiverOut&);
struct save_load_callbacks {
void* self;
@ -213,8 +227,8 @@ namespace obj {
bool save(Object*, tp::String path, bool compressed = true);
Object* load(tp::String path);
tp::alni save(Archiver&, Object*);
Object* load(Archiver&, tp::alni file_adress);
tp::alni save(ArchiverOut&, Object*);
Object* load(ArchiverIn&, tp::alni file_adress);
};
Object* ndo_cast(const Object* in, const ObjectType* to_type);

View file

@ -29,8 +29,8 @@ namespace obj {
void delete_script(Script* script);
void reference_script(Script* script);
static void save_script_table_to_file(ScriptSection* self, Archiver& file);
static void load_script_table_from_file(ScriptSection* self, Archiver& file);
static tp::alni save_script_table_to_file_size(ScriptSection* self, Archiver& file);
static void save_script_table_to_file(ScriptSection* self, ArchiverOut& file);
static void load_script_table_from_file(ScriptSection* self, ArchiverIn& file);
static tp::alni save_script_table_to_file_size(ScriptSection* self, ArchiverOut& file);
};
};

View file

@ -21,7 +21,7 @@ namespace obj {
TypeGroups(bool is_group);
void addType(ObjectType* type, tp::init_list<const char*> path, tp::alni cur_arg = 0);
void addType(ObjectType* type, tp::InitialierList<const char*> path, tp::alni cur_arg = 0);
void setType(ObjectType* type);
bool isGroup();
Dict* getChilds();

View file

@ -23,7 +23,7 @@ namespace obj {
mutable Object* self = NULL;
Arg args[MAX_ARGS];
tp::int1 mNargs = NULL;
tp::int1 mNargs = 0;
void (*exec)(const TypeMethod* tm) = NULL;
@ -40,7 +40,7 @@ namespace obj {
enum : tp::int2 { MAX_TYPE_METHODS = 128 };
TypeMethod* methods[MAX_TYPE_METHODS];
tp::halni mNMethods = NULL;
tp::halni mNMethods = 0;
struct LookupKey {
tp::int2 key = -1;

View file

@ -16,7 +16,7 @@ namespace obj {
typedef struct { obj::Object* obj; tp::String id; } GlobalDef;
void exec(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::init_list<GlobalDef> globals2 = {});
void exec(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList<GlobalDef> globals2 = {});
void stepBytecode();
void stepBytecodeIn();
@ -24,6 +24,6 @@ namespace obj {
bool finished();
void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::init_list<GlobalDef> globals2 = {});
void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList<GlobalDef> globals2 = {});
};
};

View file

@ -121,7 +121,7 @@ namespace obj {
tp::halni len = 0;
OperandsInfo();
OperandsInfo(tp::init_list<Operand> list);
OperandsInfo(tp::InitialierList<Operand> list);
};
struct ParamsInfo {
@ -135,7 +135,7 @@ namespace obj {
tp::halni len = 0;
ParamsInfo();
ParamsInfo(tp::init_list<Param> list);
ParamsInfo(tp::InitialierList<Param> list);
};
struct OpInfo {

View file

@ -105,7 +105,7 @@ namespace obj {
struct Error {
tp::String mDescr = "No Description";
tp::alni mAdvanecedIdx = NULL;
tp::alni mAdvanecedIdx = 0;
Error() {}
Error(tp::String descr, tp::alni idx) {
@ -159,7 +159,7 @@ namespace obj {
BCgen::Expression* parseExprFUNC();
BCgen::Expression* parseExprChain(BCgen::Expression* prnt);
BCgen::Expression* parseExpr(tp::init_list<ExprType> expressions = {
BCgen::Expression* parseExpr(tp::InitialierList<ExprType> expressions = {
ExprType::BOOLEAN_NOT,
ExprType::BOOLEAN,
ExprType::Ariphm,
@ -178,7 +178,7 @@ namespace obj {
BCgen::Statement* parseStmCopy();
BCgen::Statement* parseStmClassDef();
BCgen::Statement* parseStm(tp::init_list<StmType> stm_types = {
BCgen::Statement* parseStm(tp::InitialierList<StmType> stm_types = {
StmType::DefFunc,
StmType::DefLocal,
StmType::Return,

View file

@ -11,8 +11,8 @@ namespace obj {
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);
static void save(ClassObject* self, ArchiverOut& file_self);
static void load(ArchiverIn& file_self, ClassObject* self);
DictObject* members;
@ -33,7 +33,7 @@ namespace obj {
template<typename Type>
Type* getMember(const tp::String& id) {
auto idx = members->presents(id);
if (idx) {
if (bool(idx)) {
return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData));
}
return NULL;

View file

@ -11,8 +11,8 @@ namespace obj {
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 void save(DictObject* self, ArchiverOut& file_self);
static void load(ArchiverIn& 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);
@ -21,7 +21,7 @@ namespace obj {
void remove(tp::String);
Object* get(tp::String);
tp::Map<tp::String, Object*>::Idx presents(tp::String);
Object* getSlotVal(tp::alni);
Object* getSlotVal(tp::Map<tp::String, Object*>::Idx);
const tp::Map<tp::String, Object*>& getItems() const;

View file

@ -17,7 +17,7 @@ namespace obj {
static void destructor(EnumObject* self);
static void copy(EnumObject* self, const EnumObject* in);
void init(tp::init_list<const char*> list);
void init(tp::InitialierList<const char*> list);
const char* getActiveName();
const char* getItemName(tp::uhalni idx);
@ -29,6 +29,6 @@ namespace obj {
static tp::alnf to_float(EnumObject* self);
static bool compare(EnumObject* first, EnumObject* second);
static EnumObject* create(tp::init_list<const char*> list);
static EnumObject* create(tp::InitialierList<const char*> list);
};
};

View file

@ -10,9 +10,9 @@ namespace obj {
static void destructor(InterpreterObject* self);
static void constructor(InterpreterObject* self);
static void load(Archiver& file_self, InterpreterObject* self);
static void load(ArchiverIn& file_self, InterpreterObject* self);
void exec(obj::ClassObject* self = NULL, tp::init_list<Interpreter::GlobalDef> globals = {});
void exec(obj::ClassObject* self = NULL, tp::InitialierList<Interpreter::GlobalDef> globals = {});
void debug();
bool running();
};

View file

@ -13,8 +13,8 @@ namespace obj {
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 void save(LinkObject* self, ArchiverOut& file_self);
static void load(ArchiverIn& 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);

View file

@ -19,8 +19,8 @@ namespace obj {
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 void load(ArchiverIn& file_self, ListObject* self);
static void save(ListObject* self, ArchiverOut& file_self);
static tp::alni save_size(ListObject* self);
const tp::List<Object*>& getItems() const;

View file

@ -15,8 +15,8 @@ namespace obj {
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 save(MethodObject* self, ArchiverOut& file_self);
static void load(ArchiverIn& file_self, obj::MethodObject* self);
static void Initialize();
static void UnInitialize();

View file

@ -1,22 +1,16 @@
#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();
};
#pragma once
#include "primitives/boolobject.h"
#include "primitives/classobject.h"
#include "primitives/colorobject.h"
#include "primitives/dictobject.h"
#include "primitives/enumobject.h"
#include "primitives/floatobject.h"
#include "primitives/interpreterobject.h"
#include "primitives/intobject.h"
#include "primitives/linkobject.h"
#include "primitives/listobject.h"
#include "primitives/methodobject.h"
#include "primitives/nullobject.h"
#include "primitives/stringobject.h"
#include "primitives/typeobject.h"