Objects Compiled

This commit is contained in:
IlushaShurupov 2023-07-30 18:30:36 +03:00 committed by Ilya Shurupov
parent 31e420b311
commit edf0548046
52 changed files with 384 additions and 370 deletions

View file

@ -10,6 +10,8 @@ project(Types)
add_compile_definitions(MEM_DEBUG) add_compile_definitions(MEM_DEBUG)
set(EXTERNALS ../Externals)
add_subdirectory(Modules) add_subdirectory(Modules)
add_subdirectory(Utils) add_subdirectory(Utils)
add_subdirectory(Containers) add_subdirectory(Containers)
@ -18,11 +20,7 @@ add_subdirectory(Allocators)
add_subdirectory(Strings) add_subdirectory(Strings)
add_subdirectory(Tokenizer) add_subdirectory(Tokenizer)
add_subdirectory(CommandLine) add_subdirectory(CommandLine)
set(EXTERNALS ../Externals)
add_subdirectory(Externals) add_subdirectory(Externals)
add_subdirectory(Connection) add_subdirectory(Connection)
add_subdirectory(Graphics) add_subdirectory(Graphics)
add_subdirectory(Objects)
#add_subdirectory(Objects)

View file

@ -115,27 +115,6 @@ namespace tp {
incrementAddresses(size); incrementAddresses(size);
} }
template<typename tType>
static void test() {
const tType val;
tType res;
res.change();
ArchiverExample<tMaxMemory, false> write;
ArchiverExample<tMaxMemory, true> 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: public:
int1 mBuff[tMaxMemory]{}; int1 mBuff[tMaxMemory]{};

View file

@ -15,11 +15,11 @@ target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Tokenizer CommandLine Connection) target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Tokenizer CommandLine Connection)
### -------------------------- Applications -------------------------- ### ### -------------------------- Applications -------------------------- ###
add_executable(osc ./applications/Compiler.cpp) #add_executable(osc ./applications/Compiler.cpp)
add_executable(osi ./applications/Interpreter.cpp) #add_executable(osi ./applications/Interpreter.cpp)
target_link_libraries(osc ${PROJECT_NAME}) #target_link_libraries(osc ${PROJECT_NAME})
target_link_libraries(osi ${PROJECT_NAME}) #target_link_libraries(osi ${PROJECT_NAME})
### -------------------------- Tests -------------------------- ### ### -------------------------- Tests -------------------------- ###
enable_testing() enable_testing()

View file

@ -1,15 +1,12 @@
#include "MethodObject/methodobject.h" #include "primitives/methodobject.h"
#include "primitives/primitives.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 tp;
using namespace obj; using namespace obj;
@ -23,9 +20,9 @@ void TestCompile(ByteCode& bytecode) {
StmDefLocal("i1", ExprConst(1)), StmDefLocal("i1", ExprConst(1)),
StmDefLocal("i2", ExprConst(2)), StmDefLocal("i2", ExprConst(2)),
StmDefFunc("add", {"first", "second"}, { //StmDefFunc("add", {"first", "second"}, {
StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second"))) // StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second")))
}), //}),
StmPrint(ExprLocal("i1")), StmPrint(ExprLocal("i1")),
StmPrint(ExprConst(" + ")), StmPrint(ExprConst(" + ")),

View file

@ -11,7 +11,7 @@ ExpressionChild* Expression::ExprChild(tp::String id) {
return new ExpressionChild(this, id); return new ExpressionChild(this, id);
} }
ExpressionCall* Expression::ExprCall(tp::init_list<Expression*> args) { ExpressionCall* Expression::ExprCall(tp::InitialierList<Expression*> args) {
return new ExpressionCall(this, args); return new ExpressionCall(this, args);
} }
@ -51,7 +51,7 @@ ExpressionBoolean::ExpressionBoolean(Expression* invert)
: Expression(Type::BOOLEAN), mLeft(invert), mBoolType(BoolType::NOT){ : Expression(Type::BOOLEAN), mLeft(invert), mBoolType(BoolType::NOT){
} }
ExpressionCall::ExpressionCall(Expression * mParent, tp::init_list<Expression*> args) : Expression(Type::CALL), mParent(mParent) { ExpressionCall::ExpressionCall(Expression * mParent, tp::InitialierList<Expression*> args) : Expression(Type::CALL), mParent(mParent) {
mArgs = args; mArgs = args;
} }

View file

@ -73,8 +73,8 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
auto jump_inst = inst(Instruction(NULL, Instruction::InstType::JUMP)); auto jump_inst = inst(Instruction(NULL, Instruction::InstType::JUMP));
auto end_mark = inst(Instruction()); auto end_mark = inst(Instruction());
jump_if_inst->data.mInstTarget = end_mark; jump_if_inst->data.mInstTarget = &end_mark->data;
jump_inst->data.mInstTarget = check_mark; jump_inst->data.mInstTarget = &check_mark->data;
break; break;
} }
@ -98,8 +98,8 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
auto end_mark = inst(Instruction()); auto end_mark = inst(Instruction());
jump_if_inst->data.mInstTarget = else_mark; jump_if_inst->data.mInstTarget = &else_mark->data;
jump_inst->data.mInstTarget = end_mark; jump_inst->data.mInstTarget = &end_mark->data;
break; break;
} }
@ -396,11 +396,11 @@ void writeParam(ByteCode& out, tp::alni& idx, tp::int1* data, tp::alni size) {
} }
} }
tp::alni calcOffset(tp::List<Instruction>::Node* jump_inst, tp::List<Instruction>::Node* to) { tp::alni calcOffset(tp::List<Instruction>::Node* jump_inst, Instruction* to) {
tp::alni offset = 0; 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; auto iter_node = reversed ? jump_inst : jump_inst->next;
while (iter_node != to) { while (&iter_node->data != to) {
offset += instSize(iter_node->data); offset += instSize(iter_node->data);
iter_node = reversed ? iter_node->prev : iter_node->next; iter_node = reversed ? iter_node->prev : iter_node->next;
} }

View file

@ -1,4 +1,5 @@
#include "NewPlacement.hpp"
#include "compiler/instruction.h" #include "compiler/instruction.h"
using namespace obj; 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) { : mOp(op), mParam(param), mArgType(ArgType::PARAM), mParamBytes(nBytes), mInstType(InstType::EXEC) {
} }
Instruction::Instruction(tp::List<Instruction>::Node* inst, InstType jump_type): mInstTarget(inst) { Instruction::Instruction(Instruction* inst, InstType jump_type): mInstTarget(inst) {
mInstType = jump_type; mInstType = jump_type;
} }

View file

@ -5,7 +5,7 @@ using namespace obj;
using namespace BCgen; using namespace BCgen;
StatementFuncDef::StatementFuncDef(tp::String function_id, tp::init_list<tp::String> args, tp::init_list<Statement*> statements) { StatementFuncDef::StatementFuncDef(tp::String function_id, tp::InitialierList<tp::String> args, tp::InitialierList<Statement*> statements) {
mType = Type::DEF_FUNC; mType = Type::DEF_FUNC;
mArgs = args; mArgs = args;
mStatements = statements; mStatements = statements;
@ -36,7 +36,7 @@ StatementPrint::StatementPrint(Expression* target) : mTarget(target) {
mType = Type::PRINT; mType = Type::PRINT;
} }
StatementScope::StatementScope(tp::init_list<Statement*> statements, bool aPushToScopeStack) { StatementScope::StatementScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack) {
mType = Type::SCOPE; mType = Type::SCOPE;
mStatements = statements; mStatements = statements;
mPushToScopeStack = aPushToScopeStack; mPushToScopeStack = aPushToScopeStack;
@ -67,7 +67,7 @@ StatementClassDef::StatementClassDef(tp::String class_id, StatementScope* scope)
} }
// helpers // helpers
StatementFuncDef* obj::BCgen::StmDefFunc(tp::String id, tp::init_list<tp::String> args, tp::init_list<Statement*> stms) { StatementFuncDef* obj::BCgen::StmDefFunc(tp::String id, tp::InitialierList<tp::String> args, tp::InitialierList<Statement*> stms) {
return new StatementFuncDef(id, args, 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); return new StatementIf(condition, on_true, on_false);
} }
StatementScope* obj::BCgen::StmScope(tp::init_list<Statement*> statements, bool aPushToScopeStack = false) { StatementScope* obj::BCgen::StmScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack = false) {
return new StatementScope(statements, aPushToScopeStack); return new StatementScope(statements, aPushToScopeStack);
} }

View file

@ -1,29 +1,29 @@
#pragma once
#include "NewPlacement.hpp" #include "NewPlacement.hpp"
#include "primitives/primitives.h"
#include "Tokenizer.hpp" #include "Tokenizer.hpp"
void obj::primitives_uninitialize() { #include "compiler/function.h"
obj::NullObject::uninit();
obj::MethodObject::UnInitialize();
}
void obj::primitives_define_types() { #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"
using namespace obj; using namespace obj;
using namespace tp; using namespace tp;
static bool initialized = false;
if (initialized) {
return;
}
DEBUG_ASSERT(NDO && "Objects library is not initialized");
static void defineTypes() {
NDO->define(&DictObject::TypeData); NDO->define(&DictObject::TypeData);
NDO->define(&IntObject::TypeData); NDO->define(&IntObject::TypeData);
NDO->define(&LinkObject::TypeData); NDO->define(&LinkObject::TypeData);
@ -37,7 +37,9 @@ void obj::primitives_define_types() {
NDO->define(&ColorObject::TypeData); NDO->define(&ColorObject::TypeData);
NDO->define(&InterpreterObject::TypeData); NDO->define(&InterpreterObject::TypeData);
NDO->define(&TypeObject::TypeData); NDO->define(&TypeObject::TypeData);
}
static void defineGroups() {
NDO->type_groups.addType(&DictObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&DictObject::TypeData, {"Primitives"});
NDO->type_groups.addType(&IntObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&IntObject::TypeData, {"Primitives"});
NDO->type_groups.addType(&LinkObject::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(&ClassObject::TypeData, {"Primitives"});
NDO->type_groups.addType(&ColorObject::TypeData, {"Primitives"}); NDO->type_groups.addType(&ColorObject::TypeData, {"Primitives"});
NDO->type_groups.addType(&InterpreterObject::TypeData, { "scripting" }); NDO->type_groups.addType(&InterpreterObject::TypeData, { "scripting" });
obj::MethodObject::Initialize();
initialized = true;
} }
namespace obj {
objects_api* objects_init();
void objects_finalize();
};
static bool objInit() { static bool init(const tp::ModuleManifest*) {
obj::objects_init(); if (!NDO) NDO = new objects_api();
obj::primitives_define_types(); obj::BCgen::init();
MethodObject::Initialize();
defineTypes();
defineGroups();
return true; return true;
} }
static void objDeinit() { static void deinit(const tp::ModuleManifest*) {
obj::primitives_uninitialize();
obj::objects_finalize(); NullObject::uninit();
MethodObject::UnInitialize();
obj::BCgen::deinit();
delete NDO;
} }
static tp::ModuleManifest* sModuleDependencies[] = { static tp::ModuleManifest* sModuleDependencies[] = {
@ -80,4 +84,4 @@ static tp::ModuleManifest* sModuleDependencies[] = {
NULL NULL
}; };
tp::ModuleManifest obj::gModuleObjects = tp::ModuleManifest("Objects", objInit, objDeinit, sModuleDependencies); tp::ModuleManifest obj::gModuleObjects = tp::ModuleManifest("Objects", init, deinit, sModuleDependencies);

View file

@ -227,24 +227,4 @@ namespace obj {
} }
return NULL; 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();
}
}; };

View file

@ -1,5 +1,6 @@
#include "NewPlacement.hpp"
#include "core/object.h" #include "core/object.h"
#include "HeapAllocatorGlobal.hpp" #include "HeapAllocatorGlobal.hpp"
@ -30,7 +31,7 @@ namespace obj {
} }
memh->down = NULL; memh->down = NULL;
memh->flags = NULL; memh->flags = 0;
#ifdef OBJECT_REF_COUNT #ifdef OBJECT_REF_COUNT
memh->refc = (tp::alni) 1; memh->refc = (tp::alni) 1;
@ -185,7 +186,7 @@ namespace obj {
return objsize_file_recursive_util(self, self->type); 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) { if (type->base) {
object_recursive_save(ndf, self, 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 already saved return file_adress
if (NDO_MEMH_FROM_NDO(in)->flags != -1) { if (NDO_MEMH_FROM_NDO(in)->flags != -1) {
return NDO_MEMH_FROM_NDO(in)->flags; return NDO_MEMH_FROM_NDO(in)->flags;
} }
// save write adress for parent save function call // 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 // 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 // save file_adress in memhead
NDO_MEMH_FROM_NDO(in)->flags = save_adress; NDO_MEMH_FROM_NDO(in)->flags = save_adress;
// update write adress // update write adress
ndf.adress = save_adress; ndf.setAddress(save_adress);
// save file object header // save file object header
ObjectFileHead ofh = { 0, getrefc(in) }; ObjectFileHead ofh = { 0, getrefc(in) };
ndf.write(&ofh); ndf << ofh;
tp::String(in->type->name).save(&ndf); ndf << tp::String(in->type->name);
// allocate for object file header // 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 // calc max size needed for saving all hierarchy of types
tp::alni file_alloc_size = objsize_file_util(in, in->type); tp::alni file_alloc_size = objsize_file_util(in, in->type);
// offes first available adress // offes first available adress
ndf.avl_adress += file_alloc_size; ndf.setFreeAddress(ndf.getFreeAddress() + file_alloc_size);
object_recursive_save(ndf, in, in->type); object_recursive_save(ndf, in, in->type);
// restore adress for parent save function // restore adress for parent save function
ndf.adress = tmp_adress; ndf.setAddress(tmp_adress);
// return addres of saved object in file space // return addres of saved object in file space
return save_adress; 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) { if (type->base) {
object_recursive_load(ndf, out, 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 // check if already saved
if (((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress) { if (((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress) {
return ((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress; return ((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress;
} }
// save read adress // save read address
tp::alni parent_file_adress = ndf.adress; tp::alni parent_file_adress = ndf.getAddress();
// set read adress // set read address
ndf.adress = file_adress; ndf.setAddress(file_adress);
ObjectFileHead ofh; ObjectFileHead ofh;
ndf.read<ObjectFileHead>(&ofh); ndf >> ofh;
tp::String type_name; tp::String type_name;
type_name.load(&ndf); ndf >> type_name;
const ObjectType* object_type = NDO->types.get(type_name); const ObjectType* object_type = NDO->types.get(type_name);
Object* out = ObjectMemAllocate(object_type); Object* out = ObjectMemAllocate(object_type);
@ -277,40 +279,40 @@ namespace obj {
// save heap adress in "loaded_file" // save heap adress in "loaded_file"
((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress = out; ((ObjectFileHead*) (loaded_file + file_adress))->load_head_adress = out;
// loads recursivelly // loads recursively
object_recursive_load(ndf, out, object_type); object_recursive_load(ndf, out, object_type);
// restore read adress for parent call to continue // restore read address for parent call to continue
ndf.adress = parent_file_adress; ndf.setAddress(parent_file_adress);
// return heap memory adress // return heap memory adress
return out; return out;
} }
bool objects_api::save(Object* in, tp::String path, bool compressed) { 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; return false;
} }
clear_object_flags(); clear_object_flags();
// save vesion info // save version info
ObjectsFileHeader header; ObjectsFileHeader header;
ndf.write(&header); ndf << header;
ndf.avl_adress = ndf.adress; ndf.setFreeAddress(ndf.getAddress());
// pre allocate // pre allocate
for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
if (sl_callbacks[i]) { if (sl_callbacks[i]) {
DEBUG_ASSERT(sl_callbacks[i]->size); 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++) { for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
if (sl_callbacks[i] && sl_callbacks[i]->pre_save) { if (sl_callbacks[i] && sl_callbacks[i]->pre_save) {
sl_callbacks[i]->pre_save(sl_callbacks[i]->self, ndf); sl_callbacks[i]->pre_save(sl_callbacks[i]->self, ndf);
@ -319,15 +321,13 @@ namespace obj {
save(ndf, in); save(ndf, in);
// postsave // post-save
for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {
if (sl_callbacks[i] && sl_callbacks[i]->post_save) { if (sl_callbacks[i] && sl_callbacks[i]->post_save) {
sl_callbacks[i]->post_save(sl_callbacks[i]->self, ndf); sl_callbacks[i]->post_save(sl_callbacks[i]->self, ndf);
} }
} }
ndf.disconnect();
// TODO : add compression // TODO : add compression
/* /*
if (compressed) { if (compressed) {
@ -354,24 +354,28 @@ namespace obj {
File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD); 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; return NULL;
} }
// check for compability // check for compatibility
ObjectsFileHeader current_header; ObjectsFileHeader current_header;
ObjectsFileHeader loaded_header(false); ObjectsFileHeader loaded_header(false);
ndf.read(&loaded_header);
ndf >> loaded_header;
if (!tp::memEqual(&current_header, &loaded_header, sizeof(ObjectsFileHeader))) { if (!tp::memEqual(&current_header, &loaded_header, sizeof(ObjectsFileHeader))) {
return NULL; return NULL;
} }
ndf.adress = 0; ndf.setAddress(0);
loaded_file = (tp::int1*) malloc(ndf.size());
ndf.read_bytes(loaded_file, ndf.size()); loaded_file = (tp::int1*) malloc(ndf.getSize());
ndf.adress = sizeof(ObjectsFileHeader); ndf.readBytes(loaded_file, ndf.getSize());
ndf.setAddress(sizeof(ObjectsFileHeader));
// preload // preload
for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { 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 // post
for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) { for (tp::alni i = 0; i < SAVE_LOAD_MAX_CALLBACK_SLOTS; i++) {

View file

@ -74,14 +74,14 @@ tp::alni ScriptSection::get_script_file_adress(Script* in) {
return get_script_head_store_adress(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; tp::alni size = 0;
size += 5; // header size += 5; // header
size += sizeof(tp::alni); // scripts length size += sizeof(tp::alni); // scripts length
for (auto iter : self->mScripts) { 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); // scripts string obj ref
size += sizeof(tp::alni); // constants length size += sizeof(tp::alni); // constants length
@ -91,7 +91,8 @@ tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, Arch
} }
// instructions // instructions
size += iter->mBytecode.mInstructions.saveSize(); ASSERT(false)
// size += iter->mBytecode.mInstructions.saveSize();
} }
size += sizeof(tp::alni); // objects mem offset 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; 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 // header
file.write_bytes("/scr/", 5); file.writeBytes("/scr/", 5);
// scripts length // scripts length
tp::alni scripts_count = self->mScripts.length(); tp::alni scripts_count = self->mScripts.length();
file.write<tp::alni>(&scripts_count); file << scripts_count;
for (auto iter : self->mScripts) { for (auto iter : self->mScripts) {
// scripts string obj ref // scripts string obj ref
auto obj_addres = obj::NDO->save(file, iter->mReadable); auto obj_addres = obj::NDO->save(file, iter->mReadable);
file.write(&obj_addres); file << obj_addres;
// constants length // constants length
tp::alni consts_count = iter->mBytecode.mConstants.size(); tp::alni consts_count = iter->mBytecode.mConstants.size();
file.write<tp::alni>(&consts_count); file << consts_count;
for (auto const_obj : iter->mBytecode.mConstants) { for (auto const_obj : iter->mBytecode.mConstants) {
// constant object addres // constant object addres
auto obj_addres = obj::NDO->save(file, const_obj.data()); auto obj_addres = obj::NDO->save(file, const_obj.data());
file.write(&obj_addres); file << obj_addres;
} }
// mInstructions // mInstructions
iter->mBytecode.mInstructions.save(file); ASSERT(false)
file << iter->mBytecode.mInstructions;
} }
// header // header
file.write_bytes("/scr/", 5); file.writeBytes("/scr/", 5);
tp::alni objects_mem_offset = file.avl_adress; tp::alni objects_mem_offset = file.getFreeAddress();
file.write<tp::alni>(&objects_mem_offset); file << objects_mem_offset;
} }
void load_constants(ScriptSection* self, Archiver& file, tp::alni start_addr) { void load_constants(ScriptSection* self, ArchiverIn& file, tp::alni start_addr) {
auto addres = file.adress; auto addres = file.getAddress();
file.adress = start_addr; file.setAddress(start_addr);
file.adress += 5; // header file.setAddress( start_addr + 5); // header
tp::alni scripts_count; tp::alni scripts_count;
file.read<tp::alni>(&scripts_count); file >> scripts_count;
for (tp::alni i = 0; i < scripts_count; i++) { 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 // script text
tp::alni str_addr; tp::alni str_addr;
file.read<tp::alni>(&str_addr); file >> str_addr;
script->mReadable = NDO_CAST(obj::StringObject, obj::NDO->load(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) { for (auto const_obj : script->mBytecode.mConstants) {
tp::alni consts_addr; tp::alni consts_addr;
file.read<tp::alni>(&consts_addr); file >> consts_addr;
const_obj.data() = obj::NDO->load(file, consts_addr); const_obj.data() = obj::NDO->load(file, consts_addr);
} }
// instructions // 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) { for (auto iter : self->mScripts) {
set_script_head_store_adress(iter.data(), -1); set_script_head_store_adress(iter.data(), -1);
} }
auto section_start_addr = file.adress; auto section_start_addr = file.getAddress();
// header // header
file.adress += 5; file.setAddress(file.getAddress() + 5);
// scripts length // scripts length
tp::alni scripts_count; tp::alni scripts_count;
file.read<tp::alni>(&scripts_count); file >> scripts_count;
for (tp::alni i = 0; i < scripts_count; i++) { for (tp::alni i = 0; i < scripts_count; i++) {
auto new_script = self->createScript(); 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 // scripts text
file.adress += sizeof(tp::alni); file.setAddress(file.getAddress() + sizeof(tp::alni));
// constants length // constants length
tp::alni consts_count; tp::alni consts_count;
file.read<tp::alni>(&consts_count); file >> consts_count;
new_script->mBytecode.mConstants.reserve(consts_count); new_script->mBytecode.mConstants.reserve(consts_count);
for (tp::alni j = 0; j < consts_count; j++) { for (tp::alni j = 0; j < consts_count; j++) {
// constant object addres // constant object addres
tp::alni consts_addr; tp::alni consts_addr;
file.read<tp::alni>(&consts_addr); file >> consts_addr;
// skiping // skiping
//new_script->mBytecode.mConstants[j] = obj::NDO->load(file, consts_addr); //new_script->mBytecode.mConstants[j] = obj::NDO->load(file, consts_addr);
} }
// mInstructions // mInstructions
new_script->mBytecode.mInstructions.load(file); file >> new_script->mBytecode.mInstructions;
} }
load_constants(self, file, section_start_addr); load_constants(self, file, section_start_addr);
// header // header
file.adress += 5; file.setAddress(file.getAddress() + 5);
tp::alni objects_mem_offset; tp::alni objects_mem_offset;
file.read<tp::alni>(&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) { Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) {

View file

@ -31,7 +31,7 @@ void obj::TypeGroups::setType(ObjectType* type) {
this->type = type; this->type = type;
} }
void obj::TypeGroups::addType(ObjectType* type, tp::init_list<const char*> path, tp::alni cur_dir_idx) { void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList<const char*> path, tp::alni cur_dir_idx) {
DEBUG_ASSERT(is_group); DEBUG_ASSERT(is_group);
tp::alni dir_len = (tp::alni) path.size(); tp::alni dir_len = (tp::alni) path.size();

View file

@ -61,7 +61,7 @@ tp::int2 TypeMethods::presents(tp::String id) const {
return -1; 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 depth = 0;
tp::int2 idx = 0; tp::int2 idx = 0;

View file

@ -36,7 +36,7 @@ tp::uint2 param(ByteCode* bytecode) {
return loadConstDataIdx(bytecode); return loadConstDataIdx(bytecode);
} }
void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::init_list<GlobalDef> globals2) { void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList<GlobalDef> globals2) {
if (!method->mScript->mBytecode.mInstructions.size()) { if (!method->mScript->mBytecode.mInstructions.size()) {
return; return;
} }
@ -561,7 +561,7 @@ void Interpreter::stepBytecodeIn() {
} }
} }
void Interpreter::execAll(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::init_list<GlobalDef> globals2) { void Interpreter::execAll(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList<GlobalDef> globals2) {
if (!method->mScript->mBytecode.mInstructions.size()) { if (!method->mScript->mBytecode.mInstructions.size()) {
return; return;
} }

View file

@ -15,7 +15,7 @@ using namespace obj;
add(opcode, { #name, #desc, ops, params } ); add(opcode, { #name, #desc, ops, params } );
OpcodeInfos::OperandsInfo::OperandsInfo() {} OpcodeInfos::OperandsInfo::OperandsInfo() {}
OpcodeInfos::OperandsInfo::OperandsInfo(tp::init_list<Operand> list) { OpcodeInfos::OperandsInfo::OperandsInfo(tp::InitialierList<Operand> list) {
DEBUG_ASSERT(MAX_OPERANDS >= list.size()); DEBUG_ASSERT(MAX_OPERANDS >= list.size());
for (auto item : list) { for (auto item : list) {
buff[len] = item; buff[len] = item;
@ -24,7 +24,7 @@ OpcodeInfos::OperandsInfo::OperandsInfo(tp::init_list<Operand> list) {
} }
OpcodeInfos::ParamsInfo::ParamsInfo() {} OpcodeInfos::ParamsInfo::ParamsInfo() {}
OpcodeInfos::ParamsInfo::ParamsInfo(tp::init_list<Param> list) { OpcodeInfos::ParamsInfo::ParamsInfo(tp::InitialierList<Param> list) {
DEBUG_ASSERT(MAX_PARAMS >= list.size()); DEBUG_ASSERT(MAX_PARAMS >= list.size());
for (auto item : list) { for (auto item : list) {
buff[len] = item; buff[len] = item;

View file

@ -1,4 +1,6 @@
#include "NewPlacement.hpp"
#include "interpreter/operandsstack.h" #include "interpreter/operandsstack.h"
using namespace obj; using namespace obj;

View file

@ -91,9 +91,8 @@ Parser::Parser() {
tp::String to_string(const char* stream, tp::alni len) { tp::String to_string(const char* stream, tp::alni len) {
tp::String out; tp::String out;
out.reserve(len + 1); out.resize(len);
tp::memcp(out.get_writable(), stream, len); tp::memCopy(out.write(), stream, len);
out.get_writable()[len] = '\0';
return out; return out;
} }
@ -259,8 +258,10 @@ READ_ARG:
auto out = prnt->ExprCall({}); auto out = prnt->ExprCall({});
out->mArgs.reserve(args.length()); out->mArgs.reserve(args.length());
ualni idx = 0;
for (auto arg : args) { for (auto arg : args) {
out->mArgs[arg.idx()] = arg.data(); out->mArgs[idx] = arg.data();
idx++;
} }
return out; return out;
@ -268,7 +269,7 @@ READ_ARG:
Expression* Parser::parseExprAriphm() { Expression* Parser::parseExprAriphm() {
tp::init_list<ExprType> expessions = { tp::InitialierList<ExprType> expessions = {
ExprType::Compound, ExprType::Compound,
ExprType::NEW, ExprType::NEW,
ExprType::LOCAL, ExprType::LOCAL,
@ -333,7 +334,7 @@ PRECEDENCE:
Expression* Parser::parseExprBOOLEAN() { Expression* Parser::parseExprBOOLEAN() {
tp::init_list<ExprType> expessions = { tp::InitialierList<ExprType> expessions = {
ExprType::Compound, ExprType::Compound,
ExprType::NEW, ExprType::NEW,
ExprType::LOCAL, ExprType::LOCAL,
@ -412,7 +413,7 @@ PRECEDENCE:
Expression* Parser::parseExprBOOLEAN_NOT() { Expression* Parser::parseExprBOOLEAN_NOT() {
CHECK(tokRead() == Token::BOOL_NOT, {}); CHECK(tokRead() == Token::BOOL_NOT, {});
tp::init_list<ExprType> exprs = { tp::InitialierList<ExprType> exprs = {
ExprType::Compound, ExprType::Compound,
ExprType::BOOLEAN, ExprType::BOOLEAN,
ExprType::Ariphm, ExprType::Ariphm,
@ -473,7 +474,7 @@ Expression* Parser::parseExprChain(Expression* prnt) {
return prnt; return prnt;
} }
Expression* Parser::parseExpr(tp::init_list<ExprType> expressions) { Expression* Parser::parseExpr(tp::InitialierList<ExprType> expressions) {
Expression* out = NULL; Expression* out = NULL;
@ -604,8 +605,11 @@ READ_ARG:
auto func_def = StmDefFunc(name.token, {}, {}); auto func_def = StmDefFunc(name.token, {}, {});
func_def->mArgs.reserve(args.length()); func_def->mArgs.reserve(args.length());
ualni idx = 0;
for (auto iter : args) { for (auto iter : args) {
func_def->mArgs[iter.idx()] = iter.data(); func_def->mArgs[idx] = iter.data();
idx++;
} }
StatementScope* scope = parseScope(true); StatementScope* scope = parseScope(true);
@ -614,8 +618,11 @@ READ_ARG:
}); });
func_def->mStatements.reserve(scope->mStatements.size()); func_def->mStatements.reserve(scope->mStatements.size());
idx = 0;
for (auto stm : scope->mStatements) { for (auto stm : scope->mStatements) {
func_def->mStatements[stm.idx()] = stm.data(); func_def->mStatements[idx] = stm.data();
idx++;
} }
delete scope; delete scope;
@ -753,7 +760,7 @@ Statement* Parser::parseStmClassDef() {
return StmClassDef(id.token, scope); return StmClassDef(id.token, scope);
} }
Statement* Parser::parseStm(tp::init_list<StmType> stm_types) { Statement* Parser::parseStm(tp::InitialierList<StmType> stm_types) {
Statement* out = NULL; Statement* out = NULL;
List<Error*> errors; List<Error*> errors;
@ -865,8 +872,11 @@ READ_STM:
} }
out->mStatements.reserve(stms.length()); out->mStatements.reserve(stms.length());
ualni idx = 0;
for (auto stm : stms) { for (auto stm : stms) {
out->mStatements[stm.idx()] = stm.data(); out->mStatements[idx] = stm.data();
idx++;
} }
return out; return out;
@ -896,8 +906,11 @@ Parser::Resault Parser::parse(const tp::String& oscript) {
} while (tokInputLeft()); } while (tokInputLeft());
mRes.scope->mStatements.reserve(stms.length()); mRes.scope->mStatements.reserve(stms.length());
ualni idx = 0;
for (auto stm : stms) { for (auto stm : stms) {
mRes.scope->mStatements[stm.idx()] = stm.data(); mRes.scope->mStatements[idx] = stm.data();
idx++;
} }
return mRes; return mRes;

View file

@ -47,12 +47,12 @@ static alni save_size(BoolObject* self) {
return sizeof(alni); return sizeof(alni);
} }
static void save(BoolObject* self, Archiver& file_self) { static void save(BoolObject* self, ArchiverOut& file_self) {
file_self.write<alni>(&self->val); file_self << self->val;
} }
static void load(Archiver& file_self, BoolObject* self) { static void load(ArchiverIn& file_self, BoolObject* self) {
file_self.read<alni>(&self->val); file_self >> self->val;
} }
struct ObjectTypeConversions BoolObjectTypeConversions = { struct ObjectTypeConversions BoolObjectTypeConversions = {

View file

@ -37,15 +37,15 @@ alni ClassObject::save_size(ClassObject* self) {
return sizeof(alni); // dict object adress return sizeof(alni); // dict object adress
} }
void ClassObject::save(ClassObject* self, Archiver& file_self) { void ClassObject::save(ClassObject* self, ArchiverOut& file_self) {
// save dictobject // save dictobject
alni ndo_object_adress = NDO->save(file_self, self->members); alni ndo_object_adress = NDO->save(file_self, self->members);
file_self.write<alni>(&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; alni ndo_object_adress;
file_self.read<alni>(&ndo_object_adress); file_self >> ndo_object_adress;
self->members = NDO_CAST(DictObject, NDO->load(file_self, ndo_object_adress)); self->members = NDO_CAST(DictObject, NDO->load(file_self, ndo_object_adress));
} }

View file

@ -37,12 +37,12 @@ static alni save_size(ColorObject* self) {
return sizeof(tp::RGBA); return sizeof(tp::RGBA);
} }
static void save(ColorObject* self, Archiver& file_self) { static void save(ColorObject* self, ArchiverOut& file_self) {
file_self.write<tp::RGBA>(&self->mCol); file_self << self->mCol;
} }
static void load(Archiver& file_self, ColorObject* self) { static void load(ArchiverIn& file_self, ColorObject* self) {
file_self.read<tp::RGBA>(&self->mCol); file_self >> self->mCol;
} }
struct ObjectTypeConversions ColorObjectTypeConversions = { struct ObjectTypeConversions ColorObjectTypeConversions = {

View file

@ -52,39 +52,39 @@ alni DictObject::save_size(DictObject* self) {
return save_size; return save_size;
} }
void DictObject::save(DictObject* self, Archiver& file_self) { void DictObject::save(DictObject* self, ArchiverOut& file_self) {
// write size // write size
alni len = self->items.size(); alni len = self->items.size();
file_self.write<alni>(&len); file_self << len;
// save hashmap pairs // save hashmap pairs
for (auto item : self->items) { for (auto item : self->items) {
// item val // item val
alni ndo_object_adress = NDO->save(file_self, item->val); alni ndo_object_adress = NDO->save(file_self, item->val);
file_self.write<alni>(&ndo_object_adress); file_self << ndo_object_adress;
// item key // 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<tp::String, Object*>(); new (&self->items) tp::Map<tp::String, Object*>();
alni len; alni len;
file_self.read<alni>(&len); file_self >> len;
for (alni i = 0; i < len; i++) { for (alni i = 0; i < len; i++) {
// read val // read val
alni ndo_object_adress; alni ndo_object_adress;
file_self.read<alni>(&ndo_object_adress); file_self >> ndo_object_adress;
Object* val = NDO->load(file_self, ndo_object_adress); Object* val = NDO->load(file_self, ndo_object_adress);
// read key value // read key value
String key; String key;
key.load(&file_self); file_self >> key;
// add to dictinary // add to dictinary
self->items.put(key, val); self->items.put(key, val);
@ -103,11 +103,12 @@ tp::Buffer<Object*> DictObject::childs_retrival(DictObject* self) {
} }
alni DictObject::allocated_size(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) { for (auto item : self->items) {
out += item->key.sizeAllocatedMem(); // out += item->key.sizeAllocatedMem();
} }
return out; // return out;
return 0; return 0;
} }
@ -141,7 +142,7 @@ tp::Map<tp::String, Object*>::Idx DictObject::presents(tp::String str) {
return items.presents(str); return items.presents(str);
} }
Object* DictObject::getSlotVal(tp::alni idx) { Object* DictObject::getSlotVal(tp::Map<tp::String, Object*>::Idx idx) {
return items.getSlotVal(idx); return items.getSlotVal(idx);
} }

View file

@ -28,7 +28,7 @@ void EnumObject::copy(EnumObject* self, const EnumObject* in) {
tp::memCopy(self->entries, in->entries, self->nentries * ENV_ALNI_SIZE_B); tp::memCopy(self->entries, in->entries, self->nentries * ENV_ALNI_SIZE_B);
} }
void obj::EnumObject::init(tp::init_list<const char*> list) { void obj::EnumObject::init(tp::InitialierList<const char*> list) {
if (entries) free(entries); if (entries) free(entries);
@ -116,34 +116,34 @@ static alni save_size(EnumObject* self) {
return sizeof(uhalni) + sizeof(uhalni) + sizeof(alni) * self->nentries; 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) { if (!self->entries) {
uhalni empty_code = -1; uhalni empty_code = -1;
file_self.write<uhalni>(&empty_code); file_self << empty_code;
return; return;
} }
file_self.write<uhalni>(&self->active); file_self << self->active;
file_self.write<uhalni>(&self->nentries); file_self << self->nentries;
file_self.write_bytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); file_self.writeBytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B);
} }
static void load(Archiver& file_self, EnumObject* self) { static void load(ArchiverIn& file_self, EnumObject* self) {
file_self.read<uhalni>(&self->active); file_self >> self->active;
if (self->active == -1) { if (self->active == -1) {
self->nentries = 0; self->nentries = 0;
self->entries = NULL; self->entries = NULL;
return; return;
} }
file_self.read<uhalni>(&self->nentries); file_self >> self->nentries;
self->entries = (alni*) malloc(self->nentries * ENV_ALNI_SIZE_B); 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) { bool obj::EnumObject::compare(EnumObject* first, EnumObject* second) {
return first->entries != NULL && second->entries != NULL && first->active == second->active; return first->entries != NULL && second->entries != NULL && first->active == second->active;
} }
EnumObject* obj::EnumObject::create(tp::init_list<const char*> list) { EnumObject* obj::EnumObject::create(tp::InitialierList<const char*> list) {
auto enum_object = (EnumObject*)obj::NDO->create("enum"); auto enum_object = (EnumObject*)obj::NDO->create("enum");
enum_object->init(list); enum_object->init(list);
return enum_object; return enum_object;

View file

@ -47,12 +47,12 @@ static alni save_size(FloatObject* self) {
return sizeof(alnf); return sizeof(alnf);
} }
static void save(FloatObject* self, Archiver& file_self) { static void save(FloatObject* self, ArchiverOut& file_self) {
file_self.write<alnf>(&self->val); file_self << self->val;
} }
static void load(Archiver& file_self, FloatObject* self) { static void load(ArchiverIn& file_self, FloatObject* self) {
file_self.read<alnf>(&self->val); file_self >> self->val;
} }
struct ObjectTypeConversions FloatObjectTypeConversions = { struct ObjectTypeConversions FloatObjectTypeConversions = {

View file

@ -19,13 +19,13 @@ void InterpreterObject::destructor(InterpreterObject* self) {
self->mInterpreter.~Interpreter(); self->mInterpreter.~Interpreter();
} }
void InterpreterObject::load(Archiver& file_self, InterpreterObject* self) { void InterpreterObject::load(ArchiverIn& file_self, InterpreterObject* self) {
new (&self->mInterpreter) Interpreter(); new (&self->mInterpreter) Interpreter();
} }
bool InterpreterObject::running() { return !mInterpreter.finished(); } bool InterpreterObject::running() { return !mInterpreter.finished(); }
void InterpreterObject::exec(obj::ClassObject* self, tp::init_list<Interpreter::GlobalDef> globals) { void InterpreterObject::exec(obj::ClassObject* self, tp::InitialierList<Interpreter::GlobalDef> globals) {
if (running()) { if (running()) {
return; return;

View file

@ -49,12 +49,12 @@ static alni save_size(IntObject* self) {
return sizeof(alni); return sizeof(alni);
} }
static void save(IntObject* self, Archiver& file_self) { static void save(IntObject* self, ArchiverOut& file_self) {
file_self.write<alni>(&self->val); file_self << self->val;
} }
static void load(Archiver& file_self, IntObject* self) { static void load(ArchiverIn& file_self, IntObject* self) {
file_self.read<alni>(&self->val); file_self >> self->val;
} }
struct ObjectTypeConversions IntObjectTypeConversions = { struct ObjectTypeConversions IntObjectTypeConversions = {

View file

@ -28,21 +28,21 @@ alni LinkObject::save_size(LinkObject* self) {
return sizeof(alni); return sizeof(alni);
} }
void LinkObject::save(LinkObject* self, Archiver& file_self) { void LinkObject::save(LinkObject* self, ArchiverOut& file_self) {
if (self->link != NULL) { if (self->link != NULL) {
alni link_object_save_adress = NDO->save(file_self, self->link); alni link_object_save_adress = NDO->save(file_self, self->link);
file_self.write<alni>(&link_object_save_adress); file_self << link_object_save_adress;
} }
else { else {
alni null = -1; alni null = -1;
file_self.write<alni>(&null); file_self << null;
} }
} }
void LinkObject::load(Archiver& file_self, LinkObject* self) { void LinkObject::load(ArchiverIn& file_self, LinkObject* self) {
alni saved_object_adress; alni saved_object_adress;
file_self.read<alni>(&saved_object_adress); file_self >> saved_object_adress;
if (saved_object_adress == -1) { if (saved_object_adress == -1) {
self->link = NULL; self->link = NULL;

View file

@ -38,25 +38,25 @@ alni ListObject::save_size(ListObject* self) {
return (len + 1) * sizeof(alni); 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(); alni len = self->items.length();
file_self.write<alni>(&len); file_self << len;
for (auto item : self->items) { for (auto item : self->items) {
alni ndo_object_adress = NDO->save(file_self, item.data()); alni ndo_object_adress = NDO->save(file_self, item.data());
file_self.write<alni>(&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<Object*>(); new (&self->items) tp::List<Object*>();
alni len; alni len;
file_self.read<alni>(&len); file_self >> len;
for (alni i = 0; i < len; i++) { for (alni i = 0; i < len; i++) {
alni ndo_object_adress; alni ndo_object_adress;
file_self.read<alni>(&ndo_object_adress); file_self >> ndo_object_adress;
self->items.pushBack(NDO->load(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 ListObject::allocated_size_recursive(ListObject* self) {
alni out = self->items.sizeAllocatedMem(); ASSERT(false)
//alni out = self->items.sizeAllocatedMem();
for (auto item : self->items) { 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) { void ListObject::pushBack(Object* obj) {

View file

@ -38,20 +38,18 @@ tp::alni MethodObject::save_size(MethodObject* self) {
return sizeof(tp::alni); 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(); auto script_section = obj::ScriptSection::globalHandle();
// script_table_file_address // script_table_file_address
tp::alni script_table_file_address = script_section->get_script_file_adress(self->mScript); tp::alni script_table_file_address = script_section->get_script_file_adress(self->mScript);
file_self.write<tp::alni>(&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(); auto script_section = obj::ScriptSection::globalHandle();
// script_table_file_address // script_table_file_address
tp::alni script_table_file_address; tp::alni script_table_file_address;
file_self.read<tp::alni>(&script_table_file_address); file_self >> script_table_file_address;
self->mScript = script_section->get_scritp_from_file_adress(script_table_file_address); self->mScript = script_section->get_scritp_from_file_adress(script_table_file_address);
} }

View file

@ -54,13 +54,13 @@ static alni save_size(StringObject* self) {
return {}; return {};
} }
static void save(StringObject* self, Archiver& file_self) { static void save(StringObject* self, ArchiverOut& file_self) {
self->val.save(&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(); new (&self->val) tp::String();
self->val.load(&file_self); file_self >> self->val;
} }
alni allocated_size(StringObject* self) { alni allocated_size(StringObject* self) {

View file

@ -16,17 +16,17 @@ TypeObject* TypeObject::create(const ObjectType* type) {
static alni save_size(TypeObject* self) { static alni save_size(TypeObject* self) {
tp::String const nameid(self->mTypeRef->name); 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); 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; tp::String nameid;
nameid.load(&file_self); file_self >> nameid;
auto idx = NDO->types.presents(nameid); auto idx = NDO->types.presents(nameid);

View file

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

View file

@ -16,13 +16,13 @@ namespace obj {
OpCode mOp = OpCode::NONE; OpCode mOp = OpCode::NONE;
enum class ArgType { enum class ArgType : tp::ualni {
NO_ARG, NO_ARG,
PARAM, PARAM,
CONST, CONST,
} mArgType = ArgType::NO_ARG; } mArgType = ArgType::NO_ARG;
enum class InstType { enum class InstType : tp::ualni {
NONE, NONE,
JUMP, JUMP,
JUMP_IF, JUMP_IF,
@ -38,7 +38,7 @@ namespace obj {
ConstObject* mConstData2 = NULL; ConstObject* mConstData2 = NULL;
tp::alni mInstIdx = 0; tp::alni mInstIdx = 0;
tp::List<Instruction>::Node* mInstTarget = NULL; Instruction* mInstTarget = NULL;
Instruction(); Instruction();
Instruction(ConstObject* constData); Instruction(ConstObject* constData);
@ -46,7 +46,7 @@ namespace obj {
Instruction(OpCode op, ConstObject* constData); Instruction(OpCode op, ConstObject* constData);
Instruction(OpCode op, ConstObject* constData, ConstObject* constData2); Instruction(OpCode op, ConstObject* constData, ConstObject* constData2);
Instruction(OpCode op, tp::alni param, tp::alni nBytes); 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; tp::Buffer<Statement*> mStatements;
bool mPushToScopeStack = false; bool mPushToScopeStack = false;
StatementScope(tp::init_list<Statement*> statements, bool aPushToScopeStack); StatementScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack);
}; };
struct StatementFuncDef : public Statement { struct StatementFuncDef : public Statement {
@ -39,7 +39,7 @@ namespace obj {
tp::String mFunctionId; tp::String mFunctionId;
tp::Buffer<Statement*> mStatements; 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 { struct StatementLocalDef : public Statement {
@ -101,14 +101,14 @@ namespace obj {
}; };
// Helpers // 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); StatementLocalDef* StmDefLocal(tp::String id, Expression* value);
StatementCopy* StmCopy(Expression* left, Expression* right); StatementCopy* StmCopy(Expression* left, Expression* right);
StatementPrint* StmPrint(Expression* target); StatementPrint* StmPrint(Expression* target);
StatementReturn* StmReturn(Expression* obj); StatementReturn* StmReturn(Expression* obj);
StatementReturn* StmReturn(); StatementReturn* StmReturn();
StatementIf* StmIf(Expression* condition, StatementScope* on_true, StatementScope* on_false); 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); StatementWhile* StmWhile(Expression* condition, StatementScope* scope);
StatementIgnore* StmIgnore(Expression* expr); StatementIgnore* StmIgnore(Expression* expr);
StatementClassDef* StmClassDef(tp::String id, StatementScope* scope); StatementClassDef* StmClassDef(tp::String id, StatementScope* scope);

View file

@ -11,6 +11,8 @@
#include "core/typegroups.h" #include "core/typegroups.h"
#include "core/typemethods.h" #include "core/typemethods.h"
#include "Archiver.hpp"
//#include "interpreter/interpreter.h" //#include "interpreter/interpreter.h"
/* Steps to create custom Object: /* Steps to create custom Object:
@ -36,36 +38,48 @@ implement construct, destruct and copy methods */
namespace obj { 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: public:
enum Type { SAVE, LOAD };
Archiver() = default; Archiver() = default;
Archiver(const char*, Type) {}; explicit Archiver(const char* location) {};
bool opened; void writeBytes(const tp::int1* val, tp::ualni size) override {
mConnection.writeBytes(val, size);
tp::ualni adress{}; incrementAddresses(size);
// 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 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> tp::ualni getAddress() { return mAddress; }
void read(Type* in, tp::alni adress = -1) {
read_bytes((tp::int1*) in, sizeof(Type), adress); 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 tp::ModuleManifest gModuleObjects;
extern struct objects_api* NDO; extern struct objects_api* NDO;
@ -116,8 +130,8 @@ namespace obj {
typedef void (*object_copy)(Object* self, const Object* target); typedef void (*object_copy)(Object* self, const Object* target);
typedef tp::alni(*object_save_size)(Object* self); typedef tp::alni(*object_save_size)(Object* self);
typedef void (*object_save)(Object*, Archiver&); typedef void (*object_save)(Object*, ArchiverOut&);
typedef void (*object_load)(Archiver&, Object*); typedef void (*object_load)(ArchiverIn&, Object*);
typedef bool (*object_compare)(Object*, Object*); typedef bool (*object_compare)(Object*, Object*);
@ -130,7 +144,7 @@ namespace obj {
object_constructor constructor = NULL; object_constructor constructor = NULL;
object_destructor destructor = NULL; object_destructor destructor = NULL;
object_copy copy = NULL; object_copy copy = NULL;
tp::alni size = NULL; tp::alni size = 0;
const char* name; const char* name;
const ObjectTypeConversions* convesions = NULL; const ObjectTypeConversions* convesions = NULL;
const ObjectTypeAriphmetics* ariphmetics = NULL; const ObjectTypeAriphmetics* ariphmetics = NULL;
@ -148,11 +162,11 @@ namespace obj {
#define SAVE_LOAD_MAX_CALLBACK_SLOTS 100 #define SAVE_LOAD_MAX_CALLBACK_SLOTS 100
typedef void (pre_save_callback)(void* self, Archiver&); typedef void (pre_save_callback)(void* self, ArchiverOut&);
typedef void (pre_load_callback)(void* self, Archiver&); typedef void (pre_load_callback)(void* self, ArchiverIn&);
typedef void (post_save_callback)(void* self, Archiver&); typedef void (post_save_callback)(void* self, ArchiverOut&);
typedef void (post_load_callback)(void* self, Archiver&); typedef void (post_load_callback)(void* self, ArchiverIn&);
typedef tp::alni (slcb_size_callback)(void* self, Archiver&); typedef tp::alni (slcb_size_callback)(void* self, ArchiverOut&);
struct save_load_callbacks { struct save_load_callbacks {
void* self; void* self;
@ -213,8 +227,8 @@ namespace obj {
bool save(Object*, tp::String path, bool compressed = true); bool save(Object*, tp::String path, bool compressed = true);
Object* load(tp::String path); Object* load(tp::String path);
tp::alni save(Archiver&, Object*); tp::alni save(ArchiverOut&, Object*);
Object* load(Archiver&, tp::alni file_adress); Object* load(ArchiverIn&, tp::alni file_adress);
}; };
Object* ndo_cast(const Object* in, const ObjectType* to_type); Object* ndo_cast(const Object* in, const ObjectType* to_type);

View file

@ -29,8 +29,8 @@ namespace obj {
void delete_script(Script* script); void delete_script(Script* script);
void reference_script(Script* script); void reference_script(Script* script);
static void save_script_table_to_file(ScriptSection* self, Archiver& file); static void save_script_table_to_file(ScriptSection* self, ArchiverOut& file);
static void load_script_table_from_file(ScriptSection* self, Archiver& file); static void load_script_table_from_file(ScriptSection* self, ArchiverIn& file);
static tp::alni save_script_table_to_file_size(ScriptSection* self, Archiver& 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); 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); void setType(ObjectType* type);
bool isGroup(); bool isGroup();
Dict* getChilds(); Dict* getChilds();

View file

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

View file

@ -16,7 +16,7 @@ namespace obj {
typedef struct { obj::Object* obj; tp::String id; } GlobalDef; 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 stepBytecode();
void stepBytecodeIn(); void stepBytecodeIn();
@ -24,6 +24,6 @@ namespace obj {
bool finished(); 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; tp::halni len = 0;
OperandsInfo(); OperandsInfo();
OperandsInfo(tp::init_list<Operand> list); OperandsInfo(tp::InitialierList<Operand> list);
}; };
struct ParamsInfo { struct ParamsInfo {
@ -135,7 +135,7 @@ namespace obj {
tp::halni len = 0; tp::halni len = 0;
ParamsInfo(); ParamsInfo();
ParamsInfo(tp::init_list<Param> list); ParamsInfo(tp::InitialierList<Param> list);
}; };
struct OpInfo { struct OpInfo {

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ namespace obj {
static void destructor(EnumObject* self); static void destructor(EnumObject* self);
static void copy(EnumObject* self, const EnumObject* in); 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* getActiveName();
const char* getItemName(tp::uhalni idx); const char* getItemName(tp::uhalni idx);
@ -29,6 +29,6 @@ namespace obj {
static tp::alnf to_float(EnumObject* self); static tp::alnf to_float(EnumObject* self);
static bool compare(EnumObject* first, EnumObject* second); 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 destructor(InterpreterObject* self);
static void constructor(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(); void debug();
bool running(); bool running();
}; };

View file

@ -13,8 +13,8 @@ namespace obj {
static LinkObject* create(Object* in); static LinkObject* create(Object* in);
static tp::alni save_size(LinkObject* self); static tp::alni save_size(LinkObject* self);
static void save(LinkObject* self, Archiver& file_self); static void save(LinkObject* self, ArchiverOut& file_self);
static void load(Archiver& file_self, LinkObject* self); static void load(ArchiverIn& file_self, LinkObject* self);
static tp::alni allocated_size(LinkObject* self); static tp::alni allocated_size(LinkObject* self);
static tp::alni allocated_size_recursive(LinkObject* self); static tp::alni allocated_size_recursive(LinkObject* self);
static tp::Buffer<Object*> childs_retrival(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_recursive(ListObject* self);
static tp::alni allocated_size(ListObject* self); static tp::alni allocated_size(ListObject* self);
static tp::Buffer<Object*> childs_retrival(ListObject* self); static tp::Buffer<Object*> childs_retrival(ListObject* self);
static void load(Archiver& file_self, ListObject* self); static void load(ArchiverIn& file_self, ListObject* self);
static void save(ListObject* self, Archiver& file_self); static void save(ListObject* self, ArchiverOut& file_self);
static tp::alni save_size(ListObject* self); static tp::alni save_size(ListObject* self);
const tp::List<Object*>& getItems() const; const tp::List<Object*>& getItems() const;

View file

@ -15,8 +15,8 @@ namespace obj {
static void copy(MethodObject* self, MethodObject* in); static void copy(MethodObject* self, MethodObject* in);
static void destructor(MethodObject* self); static void destructor(MethodObject* self);
static tp::alni save_size(MethodObject* self); static tp::alni save_size(MethodObject* self);
static void save(MethodObject* self,Archiver& file_self); static void save(MethodObject* self, ArchiverOut& file_self);
static void load(Archiver& file_self, obj::MethodObject* self); static void load(ArchiverIn& file_self, obj::MethodObject* self);
static void Initialize(); static void Initialize();
static void UnInitialize(); static void UnInitialize();

View file

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

9
Objects/tests/Tests.cpp Normal file
View file

@ -0,0 +1,9 @@
#include "NewPlacement.hpp"
#include "Testing.hpp"
#include "primitives/primitives.h"
int main() {
return 0;
}

View file

@ -166,6 +166,21 @@ namespace tp {
} }
} }
template<class tArchiver>
void archiveWrite(tArchiver& ar) const {
auto size = this->size();
ar << size;
ar.writeBytes(read(), size);
}
template<class tArchiver>
void archiveRead(tArchiver& ar) {
Index size;
ar >> size;
resize(size);
ar.readBytes(write(), size);
}
public: // Syntax sugars public: // Syntax sugars
explicit StringTemplate(alni val) { explicit StringTemplate(alni val) {