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

@ -11,7 +11,7 @@ ExpressionChild* Expression::ExprChild(tp::String 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);
}
@ -51,7 +51,7 @@ ExpressionBoolean::ExpressionBoolean(Expression* invert)
: 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;
}

View file

@ -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<Instruction>::Node* jump_inst, tp::List<Instruction>::Node* to) {
tp::alni calcOffset(tp::List<Instruction>::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;
}

View file

@ -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<Instruction>::Node* inst, InstType jump_type): mInstTarget(inst) {
Instruction::Instruction(Instruction* inst, InstType jump_type): mInstTarget(inst) {
mInstType = jump_type;
}

View file

@ -5,7 +5,7 @@ using namespace obj;
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;
mArgs = args;
mStatements = statements;
@ -36,7 +36,7 @@ StatementPrint::StatementPrint(Expression* target) : mTarget(target) {
mType = Type::PRINT;
}
StatementScope::StatementScope(tp::init_list<Statement*> statements, bool aPushToScopeStack) {
StatementScope::StatementScope(tp::InitialierList<Statement*> 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<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);
}
@ -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<Statement*> statements, bool aPushToScopeStack = false) {
StatementScope* obj::BCgen::StmScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack = false) {
return new StatementScope(statements, aPushToScopeStack);
}

View file

@ -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);
tp::ModuleManifest obj::gModuleObjects = tp::ModuleManifest("Objects", init, deinit, sModuleDependencies);

View file

@ -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();
}
};

View file

@ -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<ObjectFileHead>(&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(&current_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++) {

View file

@ -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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<tp::alni>(&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<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) {

View file

@ -31,7 +31,7 @@ void obj::TypeGroups::setType(ObjectType* 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);
tp::alni dir_len = (tp::alni) path.size();

View file

@ -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;

View file

@ -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<GlobalDef> globals2) {
void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList<GlobalDef> 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<GlobalDef> globals2) {
void Interpreter::execAll(obj::MethodObject* method, obj::ClassObject* self, obj::DictObject* globals, tp::InitialierList<GlobalDef> globals2) {
if (!method->mScript->mBytecode.mInstructions.size()) {
return;
}

View file

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

View file

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

View file

@ -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<ExprType> expessions = {
tp::InitialierList<ExprType> expessions = {
ExprType::Compound,
ExprType::NEW,
ExprType::LOCAL,
@ -333,7 +334,7 @@ PRECEDENCE:
Expression* Parser::parseExprBOOLEAN() {
tp::init_list<ExprType> expessions = {
tp::InitialierList<ExprType> expessions = {
ExprType::Compound,
ExprType::NEW,
ExprType::LOCAL,
@ -412,7 +413,7 @@ PRECEDENCE:
Expression* Parser::parseExprBOOLEAN_NOT() {
CHECK(tokRead() == Token::BOOL_NOT, {});
tp::init_list<ExprType> exprs = {
tp::InitialierList<ExprType> exprs = {
ExprType::Compound,
ExprType::BOOLEAN,
ExprType::Ariphm,
@ -473,7 +474,7 @@ Expression* Parser::parseExprChain(Expression* prnt) {
return prnt;
}
Expression* Parser::parseExpr(tp::init_list<ExprType> expressions) {
Expression* Parser::parseExpr(tp::InitialierList<ExprType> 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<StmType> stm_types) {
Statement* Parser::parseStm(tp::InitialierList<StmType> stm_types) {
Statement* out = NULL;
List<Error*> 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;

View file

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

View file

@ -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<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;
file_self.read<alni>(&ndo_object_adress);
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);
}
static void save(ColorObject* self, Archiver& file_self) {
file_self.write<tp::RGBA>(&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<tp::RGBA>(&self->mCol);
static void load(ArchiverIn& file_self, ColorObject* self) {
file_self >> self->mCol;
}
struct ObjectTypeConversions ColorObjectTypeConversions = {

View file

@ -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<alni>(&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<alni>(&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<tp::String, Object*>();
alni len;
file_self.read<alni>(&len);
file_self >> len;
for (alni i = 0; i < len; i++) {
// read val
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);
// 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<Object*> 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<tp::String, Object*>::Idx DictObject::presents(tp::String 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);
}

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);
}
void obj::EnumObject::init(tp::init_list<const char*> list) {
void obj::EnumObject::init(tp::InitialierList<const char*> 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<uhalni>(&empty_code);
file_self << empty_code;
return;
}
file_self.write<uhalni>(&self->active);
file_self.write<uhalni>(&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<uhalni>(&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<uhalni>(&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<const char*> list) {
EnumObject* obj::EnumObject::create(tp::InitialierList<const char*> list) {
auto enum_object = (EnumObject*)obj::NDO->create("enum");
enum_object->init(list);
return enum_object;

View file

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

View file

@ -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<Interpreter::GlobalDef> globals) {
void InterpreterObject::exec(obj::ClassObject* self, tp::InitialierList<Interpreter::GlobalDef> globals) {
if (running()) {
return;

View file

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

View file

@ -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<alni>(&link_object_save_adress);
file_self << link_object_save_adress;
}
else {
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;
file_self.read<alni>(&saved_object_adress);
file_self >> saved_object_adress;
if (saved_object_adress == -1) {
self->link = NULL;

View file

@ -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<alni>(&len);
file_self << len;
for (auto item : self->items) {
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*>();
alni len;
file_self.read<alni>(&len);
file_self >> len;
for (alni i = 0; i < len; i++) {
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));
}
}
@ -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) {

View file

@ -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<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();
// 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);
}

View file

@ -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) {

View file

@ -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);