From edf0548046e8c88651a207a92ffb642b892ec729 Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Sun, 30 Jul 2023 18:30:36 +0300 Subject: [PATCH] Objects Compiled --- CMakeLists.txt | 8 +- Modules/public/Archiver.hpp | 21 ----- Objects/CMakeLists.txt | 8 +- Objects/{tests => applications}/TestEntry.cpp | 19 ++-- Objects/{tests => applications}/test.cpp | 0 Objects/private/compiler/expression.cpp | 4 +- Objects/private/compiler/function.cpp | 14 +-- Objects/private/compiler/instruction.cpp | 3 +- Objects/private/compiler/statement.cpp | 8 +- .../primitives.cpp => core/module.cpp} | 70 ++++++++------- Objects/private/core/object.cpp | 20 ----- Objects/private/core/objectsave.cpp | 86 ++++++++++--------- Objects/private/core/scriptsection.cpp | 75 ++++++++-------- Objects/private/core/typegroups.cpp | 2 +- Objects/private/core/typemethods.cpp | 2 +- Objects/private/interpreter/interpreter.cpp | 4 +- Objects/private/interpreter/opcodes.cpp | 4 +- Objects/private/interpreter/operandsstack.cpp | 2 + Objects/private/parser/parser.cpp | 39 ++++++--- Objects/private/primitives/boolobject.cpp | 8 +- Objects/private/primitives/classobject.cpp | 8 +- Objects/private/primitives/colorobject.cpp | 8 +- Objects/private/primitives/dictobject.cpp | 25 +++--- Objects/private/primitives/enumobject.cpp | 22 ++--- Objects/private/primitives/floatobject.cpp | 8 +- .../private/primitives/interpreterobject.cpp | 4 +- Objects/private/primitives/intobject.cpp | 8 +- Objects/private/primitives/linkobject.cpp | 10 +-- Objects/private/primitives/listobject.cpp | 20 +++-- Objects/private/primitives/methodobject.cpp | 10 +-- Objects/private/primitives/stringobject.cpp | 8 +- Objects/private/primitives/typeobject.cpp | 10 +-- Objects/public/compiler/expression.h | 4 +- Objects/public/compiler/instruction.h | 8 +- Objects/public/compiler/statement.h | 8 +- Objects/public/core/object.h | 76 +++++++++------- Objects/public/core/scriptsection.h | 6 +- Objects/public/core/typegroups.h | 2 +- Objects/public/core/typemethods.h | 4 +- Objects/public/interpreter/interpreter.h | 4 +- Objects/public/interpreter/opcodes.h | 4 +- Objects/public/parser/parser.h | 6 +- Objects/public/primitives/classobject.h | 6 +- Objects/public/primitives/dictobject.h | 6 +- Objects/public/primitives/enumobject.h | 4 +- Objects/public/primitives/interpreterobject.h | 4 +- Objects/public/primitives/linkobject.h | 4 +- Objects/public/primitives/listobject.h | 4 +- Objects/public/primitives/methodobject.h | 4 +- Objects/public/primitives/primitives.h | 38 ++++---- Objects/tests/Tests.cpp | 9 ++ Strings/public/Strings.hpp | 15 ++++ 52 files changed, 384 insertions(+), 370 deletions(-) rename Objects/{tests => applications}/TestEntry.cpp (78%) rename Objects/{tests => applications}/test.cpp (100%) rename Objects/private/{primitives/primitives.cpp => core/module.cpp} (60%) create mode 100644 Objects/tests/Tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 147af07..94a5c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ project(Types) add_compile_definitions(MEM_DEBUG) +set(EXTERNALS ../Externals) + add_subdirectory(Modules) add_subdirectory(Utils) add_subdirectory(Containers) @@ -18,11 +20,7 @@ add_subdirectory(Allocators) add_subdirectory(Strings) add_subdirectory(Tokenizer) add_subdirectory(CommandLine) - -set(EXTERNALS ../Externals) add_subdirectory(Externals) - add_subdirectory(Connection) add_subdirectory(Graphics) - -#add_subdirectory(Objects) +add_subdirectory(Objects) diff --git a/Modules/public/Archiver.hpp b/Modules/public/Archiver.hpp index 825bb1b..ba66bc2 100644 --- a/Modules/public/Archiver.hpp +++ b/Modules/public/Archiver.hpp @@ -115,27 +115,6 @@ namespace tp { incrementAddresses(size); } - template - static void test() { - const tType val; - tType res; - - res.change(); - - ArchiverExample write; - ArchiverExample read; - - write % val; - - for (auto i = 0; i < tMaxMemory; i++) read.mBuff[i] = write.mBuff[i]; - - read % res; - - if (val != res) { - throw "test failed"; - } - } - public: int1 mBuff[tMaxMemory]{}; diff --git a/Objects/CMakeLists.txt b/Objects/CMakeLists.txt index a8e81b5..602e29a 100644 --- a/Objects/CMakeLists.txt +++ b/Objects/CMakeLists.txt @@ -15,11 +15,11 @@ target_include_directories(${PROJECT_NAME} PUBLIC ./public/) target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Tokenizer CommandLine Connection) ### -------------------------- Applications -------------------------- ### -add_executable(osc ./applications/Compiler.cpp) -add_executable(osi ./applications/Interpreter.cpp) +#add_executable(osc ./applications/Compiler.cpp) +#add_executable(osi ./applications/Interpreter.cpp) -target_link_libraries(osc ${PROJECT_NAME}) -target_link_libraries(osi ${PROJECT_NAME}) +#target_link_libraries(osc ${PROJECT_NAME}) +#target_link_libraries(osi ${PROJECT_NAME}) ### -------------------------- Tests -------------------------- ### enable_testing() diff --git a/Objects/tests/TestEntry.cpp b/Objects/applications/TestEntry.cpp similarity index 78% rename from Objects/tests/TestEntry.cpp rename to Objects/applications/TestEntry.cpp index c625e7e..960c1b0 100644 --- a/Objects/tests/TestEntry.cpp +++ b/Objects/applications/TestEntry.cpp @@ -1,37 +1,34 @@ -#include "MethodObject/methodobject.h" +#include "primitives/methodobject.h" #include "primitives/primitives.h" -#include "Interpreter/Interpreter.h" +#include "interpreter/interpreter.h" -#include "log.h" +#include "compiler/function.h" -#include "ByteCodeGen/Function.h" - -using namespace osc; using namespace tp; using namespace obj; void TestCompile(ByteCode& bytecode) { using namespace BCgen; - Genereate(bytecode, + Genereate(bytecode, StmScope({ StmDefFunc("main", {}, { StmDefLocal("i1", ExprConst(1)), StmDefLocal("i2", ExprConst(2)), - StmDefFunc("add", {"first", "second"}, { - StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second"))) - }), + //StmDefFunc("add", {"first", "second"}, { + // StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second"))) + //}), StmPrint(ExprLocal("i1")), StmPrint(ExprConst(" + ")), StmPrint(ExprLocal("i2")), StmPrint(ExprConst(" = ")), - + StmPrint(ExprFunc("add")->ExprCall({ ExprLocal("i1"), ExprLocal("i2") })), StmPrint(ExprConst("\n")), diff --git a/Objects/tests/test.cpp b/Objects/applications/test.cpp similarity index 100% rename from Objects/tests/test.cpp rename to Objects/applications/test.cpp diff --git a/Objects/private/compiler/expression.cpp b/Objects/private/compiler/expression.cpp index 48a8390..322a8c5 100644 --- a/Objects/private/compiler/expression.cpp +++ b/Objects/private/compiler/expression.cpp @@ -11,7 +11,7 @@ ExpressionChild* Expression::ExprChild(tp::String id) { return new ExpressionChild(this, id); } -ExpressionCall* Expression::ExprCall(tp::init_list args) { +ExpressionCall* Expression::ExprCall(tp::InitialierList args) { return new ExpressionCall(this, args); } @@ -51,7 +51,7 @@ ExpressionBoolean::ExpressionBoolean(Expression* invert) : Expression(Type::BOOLEAN), mLeft(invert), mBoolType(BoolType::NOT){ } -ExpressionCall::ExpressionCall(Expression * mParent, tp::init_list args) : Expression(Type::CALL), mParent(mParent) { +ExpressionCall::ExpressionCall(Expression * mParent, tp::InitialierList args) : Expression(Type::CALL), mParent(mParent) { mArgs = args; } diff --git a/Objects/private/compiler/function.cpp b/Objects/private/compiler/function.cpp index 014da8f..6342b90 100644 --- a/Objects/private/compiler/function.cpp +++ b/Objects/private/compiler/function.cpp @@ -73,8 +73,8 @@ void FunctionDefinition::EvalStatement(Statement* stm) { auto jump_inst = inst(Instruction(NULL, Instruction::InstType::JUMP)); auto end_mark = inst(Instruction()); - jump_if_inst->data.mInstTarget = end_mark; - jump_inst->data.mInstTarget = check_mark; + jump_if_inst->data.mInstTarget = &end_mark->data; + jump_inst->data.mInstTarget = &check_mark->data; break; } @@ -98,8 +98,8 @@ void FunctionDefinition::EvalStatement(Statement* stm) { auto end_mark = inst(Instruction()); - jump_if_inst->data.mInstTarget = else_mark; - jump_inst->data.mInstTarget = end_mark; + jump_if_inst->data.mInstTarget = &else_mark->data; + jump_inst->data.mInstTarget = &end_mark->data; break; } @@ -396,11 +396,11 @@ void writeParam(ByteCode& out, tp::alni& idx, tp::int1* data, tp::alni size) { } } -tp::alni calcOffset(tp::List::Node* jump_inst, tp::List::Node* to) { +tp::alni calcOffset(tp::List::Node* jump_inst, Instruction* to) { tp::alni offset = 0; - bool reversed = jump_inst->data.mInstIdx > to->data.mInstIdx; + bool reversed = jump_inst->data.mInstIdx > to->mInstIdx; auto iter_node = reversed ? jump_inst : jump_inst->next; - while (iter_node != to) { + while (&iter_node->data != to) { offset += instSize(iter_node->data); iter_node = reversed ? iter_node->prev : iter_node->next; } diff --git a/Objects/private/compiler/instruction.cpp b/Objects/private/compiler/instruction.cpp index 90e2705..8f84870 100644 --- a/Objects/private/compiler/instruction.cpp +++ b/Objects/private/compiler/instruction.cpp @@ -1,4 +1,5 @@ +#include "NewPlacement.hpp" #include "compiler/instruction.h" using namespace obj; @@ -24,6 +25,6 @@ Instruction::Instruction(OpCode op, tp::alni param, tp::alni nBytes) : mOp(op), mParam(param), mArgType(ArgType::PARAM), mParamBytes(nBytes), mInstType(InstType::EXEC) { } -Instruction::Instruction(tp::List::Node* inst, InstType jump_type): mInstTarget(inst) { +Instruction::Instruction(Instruction* inst, InstType jump_type): mInstTarget(inst) { mInstType = jump_type; } \ No newline at end of file diff --git a/Objects/private/compiler/statement.cpp b/Objects/private/compiler/statement.cpp index 4d7e671..12f442f 100644 --- a/Objects/private/compiler/statement.cpp +++ b/Objects/private/compiler/statement.cpp @@ -5,7 +5,7 @@ using namespace obj; using namespace BCgen; -StatementFuncDef::StatementFuncDef(tp::String function_id, tp::init_list args, tp::init_list statements) { +StatementFuncDef::StatementFuncDef(tp::String function_id, tp::InitialierList args, tp::InitialierList statements) { mType = Type::DEF_FUNC; mArgs = args; mStatements = statements; @@ -36,7 +36,7 @@ StatementPrint::StatementPrint(Expression* target) : mTarget(target) { mType = Type::PRINT; } -StatementScope::StatementScope(tp::init_list statements, bool aPushToScopeStack) { +StatementScope::StatementScope(tp::InitialierList statements, bool aPushToScopeStack) { mType = Type::SCOPE; mStatements = statements; mPushToScopeStack = aPushToScopeStack; @@ -67,7 +67,7 @@ StatementClassDef::StatementClassDef(tp::String class_id, StatementScope* scope) } // helpers -StatementFuncDef* obj::BCgen::StmDefFunc(tp::String id, tp::init_list args, tp::init_list stms) { +StatementFuncDef* obj::BCgen::StmDefFunc(tp::String id, tp::InitialierList args, tp::InitialierList stms) { return new StatementFuncDef(id, args, stms); } @@ -99,7 +99,7 @@ StatementIf* obj::BCgen::StmIf(Expression* condition, StatementScope* on_true, S return new StatementIf(condition, on_true, on_false); } -StatementScope* obj::BCgen::StmScope(tp::init_list statements, bool aPushToScopeStack = false) { +StatementScope* obj::BCgen::StmScope(tp::InitialierList statements, bool aPushToScopeStack = false) { return new StatementScope(statements, aPushToScopeStack); } diff --git a/Objects/private/primitives/primitives.cpp b/Objects/private/core/module.cpp similarity index 60% rename from Objects/private/primitives/primitives.cpp rename to Objects/private/core/module.cpp index 5591845..22286c2 100644 --- a/Objects/private/primitives/primitives.cpp +++ b/Objects/private/core/module.cpp @@ -1,29 +1,29 @@ -#pragma once - #include "NewPlacement.hpp" -#include "primitives/primitives.h" - #include "Tokenizer.hpp" -void obj::primitives_uninitialize() { - obj::NullObject::uninit(); - obj::MethodObject::UnInitialize(); -} +#include "compiler/function.h" -void obj::primitives_define_types() { - - using namespace obj; - using namespace tp; +#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" - static bool initialized = false; - if (initialized) { - return; - } - - DEBUG_ASSERT(NDO && "Objects library is not initialized"); +using namespace obj; +using namespace tp; +static void defineTypes() { NDO->define(&DictObject::TypeData); NDO->define(&IntObject::TypeData); NDO->define(&LinkObject::TypeData); @@ -37,7 +37,9 @@ void obj::primitives_define_types() { NDO->define(&ColorObject::TypeData); NDO->define(&InterpreterObject::TypeData); NDO->define(&TypeObject::TypeData); +} +static void defineGroups() { NDO->type_groups.addType(&DictObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&IntObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&LinkObject::TypeData, {"Primitives"}); @@ -50,26 +52,28 @@ void obj::primitives_define_types() { NDO->type_groups.addType(&ClassObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&ColorObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&InterpreterObject::TypeData, { "scripting" }); - - obj::MethodObject::Initialize(); - - initialized = true; } -namespace obj { - objects_api* objects_init(); - void objects_finalize(); -}; -static bool objInit() { - obj::objects_init(); - obj::primitives_define_types(); +static bool init(const tp::ModuleManifest*) { + if (!NDO) NDO = new objects_api(); + obj::BCgen::init(); + + MethodObject::Initialize(); + + defineTypes(); + defineGroups(); + return true; } -static void objDeinit() { - obj::primitives_uninitialize(); - obj::objects_finalize(); +static void deinit(const tp::ModuleManifest*) { + + NullObject::uninit(); + MethodObject::UnInitialize(); + + obj::BCgen::deinit(); + delete NDO; } static tp::ModuleManifest* sModuleDependencies[] = { @@ -80,4 +84,4 @@ static tp::ModuleManifest* sModuleDependencies[] = { NULL }; -tp::ModuleManifest obj::gModuleObjects = tp::ModuleManifest("Objects", objInit, objDeinit, sModuleDependencies); \ No newline at end of file +tp::ModuleManifest obj::gModuleObjects = tp::ModuleManifest("Objects", init, deinit, sModuleDependencies); \ No newline at end of file diff --git a/Objects/private/core/object.cpp b/Objects/private/core/object.cpp index c121ddb..c2f8f90 100644 --- a/Objects/private/core/object.cpp +++ b/Objects/private/core/object.cpp @@ -227,24 +227,4 @@ namespace obj { } return NULL; } - - objects_api* objects_init() { - if (!NDO) { - NDO = new objects_api(); - } - - obj::BCgen::init(); - - return NDO; - } - - void objects_finalize() { - - if (NDO) { - delete NDO; - } - - obj::BCgen::deinit(); - } - }; \ No newline at end of file diff --git a/Objects/private/core/objectsave.cpp b/Objects/private/core/objectsave.cpp index 138f741..6b24f1c 100644 --- a/Objects/private/core/objectsave.cpp +++ b/Objects/private/core/objectsave.cpp @@ -1,5 +1,6 @@ +#include "NewPlacement.hpp" #include "core/object.h" #include "HeapAllocatorGlobal.hpp" @@ -30,7 +31,7 @@ namespace obj { } memh->down = NULL; - memh->flags = NULL; + memh->flags = 0; #ifdef OBJECT_REF_COUNT memh->refc = (tp::alni) 1; @@ -185,7 +186,7 @@ namespace obj { return objsize_file_recursive_util(self, self->type); } - void object_recursive_save(Archiver& ndf, Object* self, const ObjectType* type) { + void object_recursive_save(ArchiverOut& ndf, Object* self, const ObjectType* type) { if (type->base) { object_recursive_save(ndf, self, type->base); } @@ -196,48 +197,48 @@ namespace obj { } } - tp::alni objects_api::save(Archiver& ndf, Object* in) { + tp::alni objects_api::save(ArchiverOut& ndf, Object* in) { // if already saved return file_adress if (NDO_MEMH_FROM_NDO(in)->flags != -1) { return NDO_MEMH_FROM_NDO(in)->flags; } // save write adress for parent save function call - tp::alni tmp_adress = ndf.adress; + tp::alni tmp_adress = ndf.getAddress(); // save requested object to first available adress - tp::alni save_adress = ndf.avl_adress; + tp::alni save_adress = ndf.getFreeAddress(); // save file_adress in memhead NDO_MEMH_FROM_NDO(in)->flags = save_adress; // update write adress - ndf.adress = save_adress; + ndf.setAddress(save_adress); // save file object header ObjectFileHead ofh = { 0, getrefc(in) }; - ndf.write(&ofh); - tp::String(in->type->name).save(&ndf); + ndf << ofh; + ndf << tp::String(in->type->name); // allocate for object file header - ndf.avl_adress += sizeof(ObjectFileHead) + tp::String::Logic::calcLength(in->type->name) + 1; + ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + tp::String::Logic::calcLength(in->type->name) + 1); // calc max size needed for saving all hierarchy of types tp::alni file_alloc_size = objsize_file_util(in, in->type); // offes first available adress - ndf.avl_adress += file_alloc_size; + ndf.setFreeAddress(ndf.getFreeAddress() + file_alloc_size); object_recursive_save(ndf, in, in->type); // restore adress for parent save function - ndf.adress = tmp_adress; + ndf.setAddress(tmp_adress); // return addres of saved object in file space return save_adress; } - void object_recursive_load(Archiver& ndf, Object* out, const ObjectType* type) { + void object_recursive_load(ArchiverIn& ndf, Object* out, const ObjectType* type) { if (type->base) { object_recursive_load(ndf, out, type->base); } @@ -248,22 +249,23 @@ namespace obj { } } - Object* objects_api::load(Archiver& ndf, tp::alni file_adress) { + Object* objects_api::load(ArchiverIn& ndf, tp::alni file_adress) { // check if already saved if (((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress) { return ((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress; } - // save read adress - tp::alni parent_file_adress = ndf.adress; + // save read address + tp::alni parent_file_adress = ndf.getAddress(); - // set read adress - ndf.adress = file_adress; + // set read address + ndf.setAddress(file_adress); ObjectFileHead ofh; - ndf.read(&ofh); + ndf >> ofh; + tp::String type_name; - type_name.load(&ndf); + ndf >> type_name; const ObjectType* object_type = NDO->types.get(type_name); Object* out = ObjectMemAllocate(object_type); @@ -277,40 +279,40 @@ namespace obj { // save heap adress in "loaded_file" ((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress = out; - // loads recursivelly + // loads recursively object_recursive_load(ndf, out, object_type); - // restore read adress for parent call to continue - ndf.adress = parent_file_adress; + // restore read address for parent call to continue + ndf.setAddress(parent_file_adress); // return heap memory adress return out; } bool objects_api::save(Object* in, tp::String path, bool compressed) { - Archiver ndf(path.read(), Archiver::SAVE); + ArchiverOut ndf(path.read()); - if (!ndf.opened) { + if (!ndf.isOpened()) { return false; } clear_object_flags(); - // save vesion info + // save version info ObjectsFileHeader header; - ndf.write(&header); + ndf << header; - ndf.avl_adress = ndf.adress; + ndf.setFreeAddress(ndf.getAddress()); // pre allocate for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { if (sl_callbacks[i]) { DEBUG_ASSERT(sl_callbacks[i]->size); - ndf.avl_adress += sl_callbacks[i]->size(sl_callbacks[i]->self, ndf); + ndf.setFreeAddress(ndf.getFreeAddress() + sl_callbacks[i]->size(sl_callbacks[i]->self, ndf)); } } - // presave + // pre-save for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { if (sl_callbacks[i] && sl_callbacks[i]->pre_save) { sl_callbacks[i]->pre_save(sl_callbacks[i]->self, ndf); @@ -319,15 +321,13 @@ namespace obj { save(ndf, in); - // postsave + // post-save for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { if (sl_callbacks[i] && sl_callbacks[i]->post_save) { sl_callbacks[i]->post_save(sl_callbacks[i]->self, ndf); } } - ndf.disconnect(); - // TODO : add compression /* if (compressed) { @@ -354,24 +354,28 @@ namespace obj { File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD); */ - Archiver ndf(path.read(), Archiver::LOAD); + ArchiverIn ndf(path.read()); - if (!ndf.opened) { + if (!ndf.isOpened()) { return NULL; } - // check for compability + // check for compatibility ObjectsFileHeader current_header; ObjectsFileHeader loaded_header(false); - ndf.read(&loaded_header); + + ndf >> loaded_header; + if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) { return NULL; } - ndf.adress = 0; - loaded_file = (tp::int1*) malloc(ndf.size()); - ndf.read_bytes(loaded_file, ndf.size()); - ndf.adress = sizeof(ObjectsFileHeader); + ndf.setAddress(0); + + loaded_file = (tp::int1*) malloc(ndf.getSize()); + ndf.readBytes(loaded_file, ndf.getSize()); + + ndf.setAddress(sizeof(ObjectsFileHeader)); // preload for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { @@ -380,7 +384,7 @@ namespace obj { } } - Object* out = load(ndf, ndf.adress); + Object* out = load(ndf, ndf.getAddress()); // post for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { diff --git a/Objects/private/core/scriptsection.cpp b/Objects/private/core/scriptsection.cpp index 6af3c54..030e95d 100644 --- a/Objects/private/core/scriptsection.cpp +++ b/Objects/private/core/scriptsection.cpp @@ -74,14 +74,14 @@ tp::alni ScriptSection::get_script_file_adress(Script* in) { return get_script_head_store_adress(in); } -tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, Archiver& file) { +tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, ArchiverOut& file) { tp::alni size = 0; size += 5; // header size += sizeof(tp::alni); // scripts length for (auto iter : self->mScripts) { - set_script_head_store_adress(iter.data(), file.adress + size); + set_script_head_store_adress(iter.data(), file.getAddress() + size); size += sizeof(tp::alni); // scripts string obj ref size += sizeof(tp::alni); // constants length @@ -91,7 +91,8 @@ tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, Arch } // instructions - size += iter->mBytecode.mInstructions.saveSize(); + ASSERT(false) + // size += iter->mBytecode.mInstructions.saveSize(); } size += sizeof(tp::alni); // objects mem offset @@ -99,124 +100,126 @@ tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, Arch return size; } -void ScriptSection::save_script_table_to_file(ScriptSection* self, Archiver& file) { +void ScriptSection::save_script_table_to_file(ScriptSection* self, ArchiverOut& file) { // header - file.write_bytes("/scr/", 5); + file.writeBytes("/scr/", 5); // scripts length tp::alni scripts_count = self->mScripts.length(); - file.write(&scripts_count); + file << scripts_count; for (auto iter : self->mScripts) { // scripts string obj ref auto obj_addres = obj::NDO->save(file, iter->mReadable); - file.write(&obj_addres); + file << obj_addres; // constants length tp::alni consts_count = iter->mBytecode.mConstants.size(); - file.write(&consts_count); + file << consts_count; for (auto const_obj : iter->mBytecode.mConstants) { // constant object addres auto obj_addres = obj::NDO->save(file, const_obj.data()); - file.write(&obj_addres); + file << obj_addres; } // mInstructions - iter->mBytecode.mInstructions.save(file); + ASSERT(false) + file << iter->mBytecode.mInstructions; } // header - file.write_bytes("/scr/", 5); + file.writeBytes("/scr/", 5); - tp::alni objects_mem_offset = file.avl_adress; - file.write(&objects_mem_offset); + tp::alni objects_mem_offset = file.getFreeAddress(); + file << objects_mem_offset; } -void load_constants(ScriptSection* self, Archiver& file, tp::alni start_addr) { - auto addres = file.adress; +void load_constants(ScriptSection* self, ArchiverIn& file, tp::alni start_addr) { + auto addres = file.getAddress(); - file.adress = start_addr; - file.adress += 5; // header + file.setAddress(start_addr); + file.setAddress( start_addr + 5); // header tp::alni scripts_count; - file.read(&scripts_count); + file >> scripts_count; for (tp::alni i = 0; i < scripts_count; i++) { - auto script = self->get_scritp_from_file_adress(file.adress); + auto script = self->get_scritp_from_file_adress(file.getAddress()); // script text tp::alni str_addr; - file.read(&str_addr); + file >> str_addr; script->mReadable = NDO_CAST(obj::StringObject, obj::NDO->load(file, str_addr)); - file.adress += sizeof(tp::alni); // constants length + file.setAddress(file.getAddress() + sizeof(tp::alni)); // constants length for (auto const_obj : script->mBytecode.mConstants) { tp::alni consts_addr; - file.read(&consts_addr); + file >> consts_addr; const_obj.data() = obj::NDO->load(file, consts_addr); } // instructions - file.adress += script->mBytecode.mInstructions.saveSize(); + ASSERT(false) + //file.setAddress(file.getAddress() + script->mBytecode.mInstructions.saveSize()); } - file.adress = addres; + file.setAddress(addres); } -void ScriptSection::load_script_table_from_file(ScriptSection* self, Archiver& file) { +void ScriptSection::load_script_table_from_file(ScriptSection* self, ArchiverIn& file) { for (auto iter : self->mScripts) { set_script_head_store_adress(iter.data(), -1); } - auto section_start_addr = file.adress; + auto section_start_addr = file.getAddress(); // header - file.adress += 5; + file.setAddress(file.getAddress() + 5); // scripts length tp::alni scripts_count; - file.read(&scripts_count); + file >> scripts_count; for (tp::alni i = 0; i < scripts_count; i++) { auto new_script = self->createScript(); - set_script_head_store_adress(new_script, file.adress); + set_script_head_store_adress(new_script, file.getAddress()); // scripts text - file.adress += sizeof(tp::alni); + file.setAddress(file.getAddress() + sizeof(tp::alni)); // constants length tp::alni consts_count; - file.read(&consts_count); + file >> consts_count; new_script->mBytecode.mConstants.reserve(consts_count); for (tp::alni j = 0; j < consts_count; j++) { // constant object addres tp::alni consts_addr; - file.read(&consts_addr); + file >> consts_addr; // skiping //new_script->mBytecode.mConstants[j] = obj::NDO->load(file, consts_addr); } // mInstructions - new_script->mBytecode.mInstructions.load(file); + file >> new_script->mBytecode.mInstructions; } load_constants(self, file, section_start_addr); // header - file.adress += 5; + file.setAddress(file.getAddress() + 5); tp::alni objects_mem_offset; - file.read(&objects_mem_offset); + file >> objects_mem_offset; - file.adress = objects_mem_offset; + file.setAddress(objects_mem_offset); } Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) { diff --git a/Objects/private/core/typegroups.cpp b/Objects/private/core/typegroups.cpp index e98af62..b666233 100644 --- a/Objects/private/core/typegroups.cpp +++ b/Objects/private/core/typegroups.cpp @@ -31,7 +31,7 @@ void obj::TypeGroups::setType(ObjectType* type) { this->type = type; } -void obj::TypeGroups::addType(ObjectType* type, tp::init_list path, tp::alni cur_dir_idx) { +void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList path, tp::alni cur_dir_idx) { DEBUG_ASSERT(is_group); tp::alni dir_len = (tp::alni) path.size(); diff --git a/Objects/private/core/typemethods.cpp b/Objects/private/core/typemethods.cpp index d756d2a..1b22194 100644 --- a/Objects/private/core/typemethods.cpp +++ b/Objects/private/core/typemethods.cpp @@ -61,7 +61,7 @@ tp::int2 TypeMethods::presents(tp::String id) const { return -1; } -TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, tp::string id) { +TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, tp::String id) { tp::int2 depth = 0; tp::int2 idx = 0; diff --git a/Objects/private/interpreter/interpreter.cpp b/Objects/private/interpreter/interpreter.cpp index 7978c18..bf3a660 100644 --- a/Objects/private/interpreter/interpreter.cpp +++ b/Objects/private/interpreter/interpreter.cpp @@ -36,7 +36,7 @@ tp::uint2 param(ByteCode* bytecode) { return loadConstDataIdx(bytecode); } -void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::init_list globals2) { +void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList globals2) { if (!method->mScript->mBytecode.mInstructions.size()) { return; } @@ -561,7 +561,7 @@ void Interpreter::stepBytecodeIn() { } } -void Interpreter::execAll(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::init_list globals2) { +void Interpreter::execAll(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList globals2) { if (!method->mScript->mBytecode.mInstructions.size()) { return; } diff --git a/Objects/private/interpreter/opcodes.cpp b/Objects/private/interpreter/opcodes.cpp index b630b9e..db9df0b 100644 --- a/Objects/private/interpreter/opcodes.cpp +++ b/Objects/private/interpreter/opcodes.cpp @@ -15,7 +15,7 @@ using namespace obj; add(opcode, { #name, #desc, ops, params } ); OpcodeInfos::OperandsInfo::OperandsInfo() {} -OpcodeInfos::OperandsInfo::OperandsInfo(tp::init_list list) { +OpcodeInfos::OperandsInfo::OperandsInfo(tp::InitialierList list) { DEBUG_ASSERT(MAX_OPERANDS >= list.size()); for (auto item : list) { buff[len] = item; @@ -24,7 +24,7 @@ OpcodeInfos::OperandsInfo::OperandsInfo(tp::init_list list) { } OpcodeInfos::ParamsInfo::ParamsInfo() {} -OpcodeInfos::ParamsInfo::ParamsInfo(tp::init_list list) { +OpcodeInfos::ParamsInfo::ParamsInfo(tp::InitialierList list) { DEBUG_ASSERT(MAX_PARAMS >= list.size()); for (auto item : list) { buff[len] = item; diff --git a/Objects/private/interpreter/operandsstack.cpp b/Objects/private/interpreter/operandsstack.cpp index e037360..75799d8 100644 --- a/Objects/private/interpreter/operandsstack.cpp +++ b/Objects/private/interpreter/operandsstack.cpp @@ -1,4 +1,6 @@ +#include "NewPlacement.hpp" + #include "interpreter/operandsstack.h" using namespace obj; diff --git a/Objects/private/parser/parser.cpp b/Objects/private/parser/parser.cpp index dacd225..255b883 100644 --- a/Objects/private/parser/parser.cpp +++ b/Objects/private/parser/parser.cpp @@ -91,9 +91,8 @@ Parser::Parser() { tp::String to_string(const char* stream, tp::alni len) { tp::String out; - out.reserve(len + 1); - tp::memcp(out.get_writable(), stream, len); - out.get_writable()[len] = '\0'; + out.resize(len); + tp::memCopy(out.write(), stream, len); return out; } @@ -259,8 +258,10 @@ READ_ARG: auto out = prnt->ExprCall({}); out->mArgs.reserve(args.length()); + ualni idx = 0; for (auto arg : args) { - out->mArgs[arg.idx()] = arg.data(); + out->mArgs[idx] = arg.data(); + idx++; } return out; @@ -268,7 +269,7 @@ READ_ARG: Expression* Parser::parseExprAriphm() { - tp::init_list expessions = { + tp::InitialierList expessions = { ExprType::Compound, ExprType::NEW, ExprType::LOCAL, @@ -333,7 +334,7 @@ PRECEDENCE: Expression* Parser::parseExprBOOLEAN() { - tp::init_list expessions = { + tp::InitialierList expessions = { ExprType::Compound, ExprType::NEW, ExprType::LOCAL, @@ -412,7 +413,7 @@ PRECEDENCE: Expression* Parser::parseExprBOOLEAN_NOT() { CHECK(tokRead() == Token::BOOL_NOT, {}); - tp::init_list exprs = { + tp::InitialierList exprs = { ExprType::Compound, ExprType::BOOLEAN, ExprType::Ariphm, @@ -473,7 +474,7 @@ Expression* Parser::parseExprChain(Expression* prnt) { return prnt; } -Expression* Parser::parseExpr(tp::init_list expressions) { +Expression* Parser::parseExpr(tp::InitialierList expressions) { Expression* out = NULL; @@ -604,8 +605,11 @@ READ_ARG: auto func_def = StmDefFunc(name.token, {}, {}); func_def->mArgs.reserve(args.length()); + + ualni idx = 0; for (auto iter : args) { - func_def->mArgs[iter.idx()] = iter.data(); + func_def->mArgs[idx] = iter.data(); + idx++; } StatementScope* scope = parseScope(true); @@ -614,8 +618,11 @@ READ_ARG: }); func_def->mStatements.reserve(scope->mStatements.size()); + + idx = 0; for (auto stm : scope->mStatements) { - func_def->mStatements[stm.idx()] = stm.data(); + func_def->mStatements[idx] = stm.data(); + idx++; } delete scope; @@ -753,7 +760,7 @@ Statement* Parser::parseStmClassDef() { return StmClassDef(id.token, scope); } -Statement* Parser::parseStm(tp::init_list stm_types) { +Statement* Parser::parseStm(tp::InitialierList stm_types) { Statement* out = NULL; List errors; @@ -865,8 +872,11 @@ READ_STM: } out->mStatements.reserve(stms.length()); + + ualni idx = 0; for (auto stm : stms) { - out->mStatements[stm.idx()] = stm.data(); + out->mStatements[idx] = stm.data(); + idx++; } return out; @@ -896,8 +906,11 @@ Parser::Resault Parser::parse(const tp::String& oscript) { } while (tokInputLeft()); mRes.scope->mStatements.reserve(stms.length()); + + ualni idx = 0; for (auto stm : stms) { - mRes.scope->mStatements[stm.idx()] = stm.data(); + mRes.scope->mStatements[idx] = stm.data(); + idx++; } return mRes; diff --git a/Objects/private/primitives/boolobject.cpp b/Objects/private/primitives/boolobject.cpp index 8d1bd3a..f63f16f 100644 --- a/Objects/private/primitives/boolobject.cpp +++ b/Objects/private/primitives/boolobject.cpp @@ -47,12 +47,12 @@ static alni save_size(BoolObject* self) { return sizeof(alni); } -static void save(BoolObject* self, Archiver& file_self) { - file_self.write(&self->val); +static void save(BoolObject* self, ArchiverOut& file_self) { + file_self << self->val; } -static void load(Archiver& file_self, BoolObject* self) { - file_self.read(&self->val); +static void load(ArchiverIn& file_self, BoolObject* self) { + file_self >> self->val; } struct ObjectTypeConversions BoolObjectTypeConversions = { diff --git a/Objects/private/primitives/classobject.cpp b/Objects/private/primitives/classobject.cpp index 2bfad9d..6baaf87 100644 --- a/Objects/private/primitives/classobject.cpp +++ b/Objects/private/primitives/classobject.cpp @@ -37,15 +37,15 @@ alni ClassObject::save_size(ClassObject* self) { return sizeof(alni); // dict object adress } -void ClassObject::save(ClassObject* self, Archiver& file_self) { +void ClassObject::save(ClassObject* self, ArchiverOut& file_self) { // save dictobject alni ndo_object_adress = NDO->save(file_self, self->members); - file_self.write(&ndo_object_adress); + file_self << ndo_object_adress; } -void ClassObject::load(Archiver& file_self, ClassObject* self) { +void ClassObject::load(ArchiverIn& file_self, ClassObject* self) { alni ndo_object_adress; - file_self.read(&ndo_object_adress); + file_self >> ndo_object_adress; self->members = NDO_CAST(DictObject, NDO->load(file_self, ndo_object_adress)); } diff --git a/Objects/private/primitives/colorobject.cpp b/Objects/private/primitives/colorobject.cpp index 587c663..6419878 100644 --- a/Objects/private/primitives/colorobject.cpp +++ b/Objects/private/primitives/colorobject.cpp @@ -37,12 +37,12 @@ static alni save_size(ColorObject* self) { return sizeof(tp::RGBA); } -static void save(ColorObject* self, Archiver& file_self) { - file_self.write(&self->mCol); +static void save(ColorObject* self, ArchiverOut& file_self) { + file_self << self->mCol; } -static void load(Archiver& file_self, ColorObject* self) { - file_self.read(&self->mCol); +static void load(ArchiverIn& file_self, ColorObject* self) { + file_self >> self->mCol; } struct ObjectTypeConversions ColorObjectTypeConversions = { diff --git a/Objects/private/primitives/dictobject.cpp b/Objects/private/primitives/dictobject.cpp index 483c625..c6b8e9e 100644 --- a/Objects/private/primitives/dictobject.cpp +++ b/Objects/private/primitives/dictobject.cpp @@ -52,39 +52,39 @@ alni DictObject::save_size(DictObject* self) { return save_size; } -void DictObject::save(DictObject* self, Archiver& file_self) { +void DictObject::save(DictObject* self, ArchiverOut& file_self) { // write size alni len = self->items.size(); - file_self.write(&len); + file_self << len; // save hashmap pairs for (auto item : self->items) { // item val alni ndo_object_adress = NDO->save(file_self, item->val); - file_self.write(&ndo_object_adress); + file_self << ndo_object_adress; // item key - item->key.save(&file_self); + file_self << item->key; } } -void DictObject::load(Archiver& file_self, DictObject* self) { +void DictObject::load(ArchiverIn& file_self, DictObject* self) { new (&self->items) tp::Map(); alni len; - file_self.read(&len); + file_self >> len; for (alni i = 0; i < len; i++) { // read val alni ndo_object_adress; - file_self.read(&ndo_object_adress); + file_self >> ndo_object_adress; Object* val = NDO->load(file_self, ndo_object_adress); // read key value String key; - key.load(&file_self); + file_self >> key; // add to dictinary self->items.put(key, val); @@ -103,11 +103,12 @@ tp::Buffer DictObject::childs_retrival(DictObject* self) { } alni DictObject::allocated_size(DictObject* self) { - alni out = self->items.sizeAllocatedMem(); + ASSERT(false) + // alni out = self->items.sizeAllocatedMem(); for (auto item : self->items) { - out += item->key.sizeAllocatedMem(); + // out += item->key.sizeAllocatedMem(); } - return out; + // return out; return 0; } @@ -141,7 +142,7 @@ tp::Map::Idx DictObject::presents(tp::String str) { return items.presents(str); } -Object* DictObject::getSlotVal(tp::alni idx) { +Object* DictObject::getSlotVal(tp::Map::Idx idx) { return items.getSlotVal(idx); } diff --git a/Objects/private/primitives/enumobject.cpp b/Objects/private/primitives/enumobject.cpp index bc6523e..67eacb3 100644 --- a/Objects/private/primitives/enumobject.cpp +++ b/Objects/private/primitives/enumobject.cpp @@ -28,7 +28,7 @@ void EnumObject::copy(EnumObject* self, const EnumObject* in) { tp::memCopy(self->entries, in->entries, self->nentries * ENV_ALNI_SIZE_B); } -void obj::EnumObject::init(tp::init_list list) { +void obj::EnumObject::init(tp::InitialierList list) { if (entries) free(entries); @@ -116,34 +116,34 @@ static alni save_size(EnumObject* self) { return sizeof(uhalni) + sizeof(uhalni) + sizeof(alni) * self->nentries; } -static void save(EnumObject* self, Archiver& file_self) { +static void save(EnumObject* self, ArchiverOut& file_self) { if (!self->entries) { uhalni empty_code = -1; - file_self.write(&empty_code); + file_self << empty_code; return; } - file_self.write(&self->active); - file_self.write(&self->nentries); - file_self.write_bytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); + file_self << self->active; + file_self << self->nentries; + file_self.writeBytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); } -static void load(Archiver& file_self, EnumObject* self) { - file_self.read(&self->active); +static void load(ArchiverIn& file_self, EnumObject* self) { + file_self >> self->active; if (self->active == -1) { self->nentries = 0; self->entries = NULL; return; } - file_self.read(&self->nentries); + file_self >> self->nentries; self->entries = (alni*) malloc(self->nentries * ENV_ALNI_SIZE_B); - file_self.read_bytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); + file_self.readBytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); } bool obj::EnumObject::compare(EnumObject* first, EnumObject* second) { return first->entries != NULL && second->entries != NULL && first->active == second->active; } -EnumObject* obj::EnumObject::create(tp::init_list list) { +EnumObject* obj::EnumObject::create(tp::InitialierList list) { auto enum_object = (EnumObject*)obj::NDO->create("enum"); enum_object->init(list); return enum_object; diff --git a/Objects/private/primitives/floatobject.cpp b/Objects/private/primitives/floatobject.cpp index 470273f..019fd66 100644 --- a/Objects/private/primitives/floatobject.cpp +++ b/Objects/private/primitives/floatobject.cpp @@ -47,12 +47,12 @@ static alni save_size(FloatObject* self) { return sizeof(alnf); } -static void save(FloatObject* self, Archiver& file_self) { - file_self.write(&self->val); +static void save(FloatObject* self, ArchiverOut& file_self) { + file_self << self->val; } -static void load(Archiver& file_self, FloatObject* self) { - file_self.read(&self->val); +static void load(ArchiverIn& file_self, FloatObject* self) { + file_self >> self->val; } struct ObjectTypeConversions FloatObjectTypeConversions = { diff --git a/Objects/private/primitives/interpreterobject.cpp b/Objects/private/primitives/interpreterobject.cpp index 8732922..55a15b9 100644 --- a/Objects/private/primitives/interpreterobject.cpp +++ b/Objects/private/primitives/interpreterobject.cpp @@ -19,13 +19,13 @@ void InterpreterObject::destructor(InterpreterObject* self) { self->mInterpreter.~Interpreter(); } -void InterpreterObject::load(Archiver& file_self, InterpreterObject* self) { +void InterpreterObject::load(ArchiverIn& file_self, InterpreterObject* self) { new (&self->mInterpreter) Interpreter(); } bool InterpreterObject::running() { return !mInterpreter.finished(); } -void InterpreterObject::exec(obj::ClassObject* self, tp::init_list globals) { +void InterpreterObject::exec(obj::ClassObject* self, tp::InitialierList globals) { if (running()) { return; diff --git a/Objects/private/primitives/intobject.cpp b/Objects/private/primitives/intobject.cpp index 06de36a..9aa004e 100644 --- a/Objects/private/primitives/intobject.cpp +++ b/Objects/private/primitives/intobject.cpp @@ -49,12 +49,12 @@ static alni save_size(IntObject* self) { return sizeof(alni); } -static void save(IntObject* self, Archiver& file_self) { - file_self.write(&self->val); +static void save(IntObject* self, ArchiverOut& file_self) { + file_self << self->val; } -static void load(Archiver& file_self, IntObject* self) { - file_self.read(&self->val); +static void load(ArchiverIn& file_self, IntObject* self) { + file_self >> self->val; } struct ObjectTypeConversions IntObjectTypeConversions = { diff --git a/Objects/private/primitives/linkobject.cpp b/Objects/private/primitives/linkobject.cpp index fb10d8b..462c77b 100644 --- a/Objects/private/primitives/linkobject.cpp +++ b/Objects/private/primitives/linkobject.cpp @@ -28,21 +28,21 @@ alni LinkObject::save_size(LinkObject* self) { return sizeof(alni); } -void LinkObject::save(LinkObject* self, Archiver& file_self) { +void LinkObject::save(LinkObject* self, ArchiverOut& file_self) { if (self->link != NULL) { alni link_object_save_adress = NDO->save(file_self, self->link); - file_self.write(&link_object_save_adress); + file_self << link_object_save_adress; } else { alni null = -1; - file_self.write(&null); + file_self << null; } } -void LinkObject::load(Archiver& file_self, LinkObject* self) { +void LinkObject::load(ArchiverIn& file_self, LinkObject* self) { alni saved_object_adress; - file_self.read(&saved_object_adress); + file_self >> saved_object_adress; if (saved_object_adress == -1) { self->link = NULL; diff --git a/Objects/private/primitives/listobject.cpp b/Objects/private/primitives/listobject.cpp index cd6b3f5..58d7461 100644 --- a/Objects/private/primitives/listobject.cpp +++ b/Objects/private/primitives/listobject.cpp @@ -38,25 +38,25 @@ alni ListObject::save_size(ListObject* self) { return (len + 1) * sizeof(alni); } -void ListObject::save(ListObject* self, Archiver& file_self) { +void ListObject::save(ListObject* self, ArchiverOut& file_self) { alni len = self->items.length(); - file_self.write(&len); + file_self << len; for (auto item : self->items) { alni ndo_object_adress = NDO->save(file_self, item.data()); - file_self.write(&ndo_object_adress); + file_self << ndo_object_adress; } } -void ListObject::load(Archiver& file_self, ListObject* self) { +void ListObject::load(ArchiverIn& file_self, ListObject* self) { new (&self->items) tp::List(); alni len; - file_self.read(&len); + file_self >> len; for (alni i = 0; i < len; i++) { alni ndo_object_adress; - file_self.read(&ndo_object_adress); + file_self >> ndo_object_adress; self->items.pushBack(NDO->load(file_self, ndo_object_adress)); } } @@ -78,11 +78,13 @@ alni ListObject::allocated_size(ListObject* self) { } alni ListObject::allocated_size_recursive(ListObject* self) { - alni out = self->items.sizeAllocatedMem(); + ASSERT(false) + //alni out = self->items.sizeAllocatedMem(); for (auto item : self->items) { - out += NDO->objsize_ram_recursive_util(item.data(), item->type); + //out += NDO->objsize_ram_recursive_util(item.data(), item->type); } - return out; + // return out; + return 0; } void ListObject::pushBack(Object* obj) { diff --git a/Objects/private/primitives/methodobject.cpp b/Objects/private/primitives/methodobject.cpp index 876c3f3..7a7f375 100644 --- a/Objects/private/primitives/methodobject.cpp +++ b/Objects/private/primitives/methodobject.cpp @@ -38,20 +38,18 @@ tp::alni MethodObject::save_size(MethodObject* self) { return sizeof(tp::alni); } -void MethodObject::save(MethodObject* self, Archiver& file_self) { +void MethodObject::save(MethodObject* self, ArchiverOut& file_self) { auto script_section = obj::ScriptSection::globalHandle(); - // script_table_file_address tp::alni script_table_file_address = script_section->get_script_file_adress(self->mScript); - file_self.write(&script_table_file_address); + file_self << script_table_file_address; } -void MethodObject::load(Archiver& file_self, obj::MethodObject* self) { +void MethodObject::load(ArchiverIn& file_self, obj::MethodObject* self) { auto script_section = obj::ScriptSection::globalHandle(); - // script_table_file_address tp::alni script_table_file_address; - file_self.read(&script_table_file_address); + file_self >> script_table_file_address; self->mScript = script_section->get_scritp_from_file_adress(script_table_file_address); } diff --git a/Objects/private/primitives/stringobject.cpp b/Objects/private/primitives/stringobject.cpp index 678a956..3ef9dd7 100644 --- a/Objects/private/primitives/stringobject.cpp +++ b/Objects/private/primitives/stringobject.cpp @@ -54,13 +54,13 @@ static alni save_size(StringObject* self) { return {}; } -static void save(StringObject* self, Archiver& file_self) { - self->val.save(&file_self); +static void save(StringObject* self, ArchiverOut& file_self) { + file_self << self->val; } -static void load(Archiver& file_self, StringObject* self) { +static void load(ArchiverIn& file_self, StringObject* self) { new (&self->val) tp::String(); - self->val.load(&file_self); + file_self >> self->val; } alni allocated_size(StringObject* self) { diff --git a/Objects/private/primitives/typeobject.cpp b/Objects/private/primitives/typeobject.cpp index 3ce305c..7e5288f 100644 --- a/Objects/private/primitives/typeobject.cpp +++ b/Objects/private/primitives/typeobject.cpp @@ -16,17 +16,17 @@ TypeObject* TypeObject::create(const ObjectType* type) { static alni save_size(TypeObject* self) { tp::String const nameid(self->mTypeRef->name); - return nameid.save_size(); + return nameid.size() + sizeof(nameid.size()); } -static void save(TypeObject* self, Archiver& file_self) { +static void save(TypeObject* self, ArchiverOut& file_self) { tp::String const nameid(self->mTypeRef->name); - nameid.save(&file_self); + file_self << nameid; } -static void load(Archiver& file_self, TypeObject* self) { +static void load(ArchiverIn& file_self, TypeObject* self) { tp::String nameid; - nameid.load(&file_self); + file_self >> nameid; auto idx = NDO->types.presents(nameid); diff --git a/Objects/public/compiler/expression.h b/Objects/public/compiler/expression.h index c297b99..3e71c73 100644 --- a/Objects/public/compiler/expression.h +++ b/Objects/public/compiler/expression.h @@ -33,7 +33,7 @@ namespace obj { Expression(Type type); ExpressionChild* ExprChild(tp::String id); - ExpressionCall* ExprCall(tp::init_list args); + ExpressionCall* ExprCall(tp::InitialierList args); }; struct ExpressionNew : public Expression { @@ -61,7 +61,7 @@ namespace obj { struct ExpressionCall : public Expression { Expression* mParent = NULL; tp::Buffer mArgs; - ExpressionCall(Expression* mParent, tp::init_list args); + ExpressionCall(Expression* mParent, tp::InitialierList args); }; struct ExpressionAriphm : public Expression { diff --git a/Objects/public/compiler/instruction.h b/Objects/public/compiler/instruction.h index d0047a8..26f142d 100644 --- a/Objects/public/compiler/instruction.h +++ b/Objects/public/compiler/instruction.h @@ -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::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::Node* inst, InstType jump_type); + Instruction(Instruction* inst, InstType jump_type); }; }; }; \ No newline at end of file diff --git a/Objects/public/compiler/statement.h b/Objects/public/compiler/statement.h index 0e53a3c..c708820 100644 --- a/Objects/public/compiler/statement.h +++ b/Objects/public/compiler/statement.h @@ -31,7 +31,7 @@ namespace obj { tp::Buffer mStatements; bool mPushToScopeStack = false; - StatementScope(tp::init_list statements, bool aPushToScopeStack); + StatementScope(tp::InitialierList statements, bool aPushToScopeStack); }; struct StatementFuncDef : public Statement { @@ -39,7 +39,7 @@ namespace obj { tp::String mFunctionId; tp::Buffer mStatements; - StatementFuncDef(tp::String function_id, tp::init_list args, tp::init_list statements); + StatementFuncDef(tp::String function_id, tp::InitialierList args, tp::InitialierList statements); }; struct StatementLocalDef : public Statement { @@ -101,14 +101,14 @@ namespace obj { }; // Helpers - StatementFuncDef* StmDefFunc(tp::String id, tp::init_list args, tp::init_list stms); + StatementFuncDef* StmDefFunc(tp::String id, tp::InitialierList args, tp::InitialierList 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 statements, bool aPushToScopeStack); + StatementScope* StmScope(tp::InitialierList statements, bool aPushToScopeStack); StatementWhile* StmWhile(Expression* condition, StatementScope* scope); StatementIgnore* StmIgnore(Expression* expr); StatementClassDef* StmClassDef(tp::String id, StatementScope* scope); diff --git a/Objects/public/core/object.h b/Objects/public/core/object.h index 9feeef6..8782bdf 100644 --- a/Objects/public/core/object.h +++ b/Objects/public/core/object.h @@ -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 + class Archiver : public tp::ArchiverTemplate { + 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 - 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 - 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; + using ArchiverOut = Archiver; + 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); diff --git a/Objects/public/core/scriptsection.h b/Objects/public/core/scriptsection.h index 56efcf7..724b15b 100644 --- a/Objects/public/core/scriptsection.h +++ b/Objects/public/core/scriptsection.h @@ -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); }; }; \ No newline at end of file diff --git a/Objects/public/core/typegroups.h b/Objects/public/core/typegroups.h index 1dcb138..ac546a8 100644 --- a/Objects/public/core/typegroups.h +++ b/Objects/public/core/typegroups.h @@ -21,7 +21,7 @@ namespace obj { TypeGroups(bool is_group); - void addType(ObjectType* type, tp::init_list path, tp::alni cur_arg = 0); + void addType(ObjectType* type, tp::InitialierList path, tp::alni cur_arg = 0); void setType(ObjectType* type); bool isGroup(); Dict* getChilds(); diff --git a/Objects/public/core/typemethods.h b/Objects/public/core/typemethods.h index d485aa4..06a95d5 100644 --- a/Objects/public/core/typemethods.h +++ b/Objects/public/core/typemethods.h @@ -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; diff --git a/Objects/public/interpreter/interpreter.h b/Objects/public/interpreter/interpreter.h index eeab2cd..c6f67b2 100644 --- a/Objects/public/interpreter/interpreter.h +++ b/Objects/public/interpreter/interpreter.h @@ -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 globals2 = {}); + void exec(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList 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 globals2 = {}); + void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList globals2 = {}); }; }; \ No newline at end of file diff --git a/Objects/public/interpreter/opcodes.h b/Objects/public/interpreter/opcodes.h index 54fe22e..e77092b 100644 --- a/Objects/public/interpreter/opcodes.h +++ b/Objects/public/interpreter/opcodes.h @@ -121,7 +121,7 @@ namespace obj { tp::halni len = 0; OperandsInfo(); - OperandsInfo(tp::init_list list); + OperandsInfo(tp::InitialierList list); }; struct ParamsInfo { @@ -135,7 +135,7 @@ namespace obj { tp::halni len = 0; ParamsInfo(); - ParamsInfo(tp::init_list list); + ParamsInfo(tp::InitialierList list); }; struct OpInfo { diff --git a/Objects/public/parser/parser.h b/Objects/public/parser/parser.h index 7e53411..dba98fb 100644 --- a/Objects/public/parser/parser.h +++ b/Objects/public/parser/parser.h @@ -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 expressions = { + BCgen::Expression* parseExpr(tp::InitialierList 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 stm_types = { + BCgen::Statement* parseStm(tp::InitialierList stm_types = { StmType::DefFunc, StmType::DefLocal, StmType::Return, diff --git a/Objects/public/primitives/classobject.h b/Objects/public/primitives/classobject.h index 2778972..e3d6d31 100644 --- a/Objects/public/primitives/classobject.h +++ b/Objects/public/primitives/classobject.h @@ -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 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; diff --git a/Objects/public/primitives/dictobject.h b/Objects/public/primitives/dictobject.h index 6445196..6806436 100644 --- a/Objects/public/primitives/dictobject.h +++ b/Objects/public/primitives/dictobject.h @@ -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 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::Idx presents(tp::String); - Object* getSlotVal(tp::alni); + Object* getSlotVal(tp::Map::Idx); const tp::Map& getItems() const; diff --git a/Objects/public/primitives/enumobject.h b/Objects/public/primitives/enumobject.h index 13aebef..6e12823 100644 --- a/Objects/public/primitives/enumobject.h +++ b/Objects/public/primitives/enumobject.h @@ -17,7 +17,7 @@ namespace obj { static void destructor(EnumObject* self); static void copy(EnumObject* self, const EnumObject* in); - void init(tp::init_list list); + void init(tp::InitialierList 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 list); + static EnumObject* create(tp::InitialierList list); }; }; \ No newline at end of file diff --git a/Objects/public/primitives/interpreterobject.h b/Objects/public/primitives/interpreterobject.h index 5710924..9f5f235 100644 --- a/Objects/public/primitives/interpreterobject.h +++ b/Objects/public/primitives/interpreterobject.h @@ -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 globals = {}); + void exec(obj::ClassObject* self = NULL, tp::InitialierList globals = {}); void debug(); bool running(); }; diff --git a/Objects/public/primitives/linkobject.h b/Objects/public/primitives/linkobject.h index 52b7129..b614773 100644 --- a/Objects/public/primitives/linkobject.h +++ b/Objects/public/primitives/linkobject.h @@ -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 childs_retrival(LinkObject* self); diff --git a/Objects/public/primitives/listobject.h b/Objects/public/primitives/listobject.h index bd17841..3546f70 100644 --- a/Objects/public/primitives/listobject.h +++ b/Objects/public/primitives/listobject.h @@ -19,8 +19,8 @@ namespace obj { static tp::alni allocated_size_recursive(ListObject* self); static tp::alni allocated_size(ListObject* self); static tp::Buffer 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& getItems() const; diff --git a/Objects/public/primitives/methodobject.h b/Objects/public/primitives/methodobject.h index e4aedf3..907225a 100644 --- a/Objects/public/primitives/methodobject.h +++ b/Objects/public/primitives/methodobject.h @@ -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(); diff --git a/Objects/public/primitives/primitives.h b/Objects/public/primitives/primitives.h index e659765..81802d2 100644 --- a/Objects/public/primitives/primitives.h +++ b/Objects/public/primitives/primitives.h @@ -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(); -}; \ No newline at end of file +#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" \ No newline at end of file diff --git a/Objects/tests/Tests.cpp b/Objects/tests/Tests.cpp new file mode 100644 index 0000000..52e3859 --- /dev/null +++ b/Objects/tests/Tests.cpp @@ -0,0 +1,9 @@ + +#include "NewPlacement.hpp" +#include "Testing.hpp" + +#include "primitives/primitives.h" + +int main() { + return 0; +} \ No newline at end of file diff --git a/Strings/public/Strings.hpp b/Strings/public/Strings.hpp index b146d41..b999f8d 100644 --- a/Strings/public/Strings.hpp +++ b/Strings/public/Strings.hpp @@ -166,6 +166,21 @@ namespace tp { } } + template + void archiveWrite(tArchiver& ar) const { + auto size = this->size(); + ar << size; + ar.writeBytes(read(), size); + } + + template + void archiveRead(tArchiver& ar) { + Index size; + ar >> size; + resize(size); + ar.readBytes(write(), size); + } + public: // Syntax sugars explicit StringTemplate(alni val) {