RIP tp::Strings
This commit is contained in:
parent
fa2d0aaa92
commit
1756ca026d
90 changed files with 419 additions and 1475 deletions
|
|
@ -60,7 +60,7 @@ ConstObject* ConstObjectsPool::get(tp::alni val) {
|
|||
return const_obj;
|
||||
}
|
||||
|
||||
ConstObject* ConstObjectsPool::get(tp::String val) {
|
||||
ConstObject* ConstObjectsPool::get(const std::string& val) {
|
||||
auto idx = mStrings.presents(val);
|
||||
ConstObject* const_obj = NULL;
|
||||
if (idx) {
|
||||
|
|
@ -100,7 +100,7 @@ ConstObject* ConstObjectsPool::get(bool val) {
|
|||
}
|
||||
}
|
||||
|
||||
ConstObject* ConstObjectsPool::addMethod(tp::String method_id, obj::Object* method) {
|
||||
ConstObject* ConstObjectsPool::addMethod(const std::string& method_id, obj::Object* method) {
|
||||
ASSERT(NDO_CAST(MethodObject, method) && "Object is not a method object");
|
||||
ASSERT(!mMethods.presents(method_id) && "Method Redefinition");
|
||||
auto out = registerObject(method);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using namespace BCgen;
|
|||
Expression::Expression(Type type) :
|
||||
mType(type) {}
|
||||
|
||||
ExpressionChild* Expression::ExprChild(const tp::String& id) { return new ExpressionChild(this, id); }
|
||||
ExpressionChild* Expression::ExprChild(const std::string& id) { return new ExpressionChild(this, id); }
|
||||
|
||||
ExpressionCall* Expression::ExprCall(ExpressionList* args) { return new ExpressionCall(this, args); }
|
||||
|
||||
|
|
@ -46,13 +46,13 @@ ExpressionList::~ExpressionList() {
|
|||
}
|
||||
}
|
||||
|
||||
ExpressionNew::ExpressionNew(const tp::String& type) :
|
||||
ExpressionNew::ExpressionNew(const std::string& type) :
|
||||
Expression(Type::NEW),
|
||||
mNewType(type) {}
|
||||
|
||||
ExpressionNew::~ExpressionNew() = default;
|
||||
|
||||
ExpressionLocal::ExpressionLocal(const tp::String& id) :
|
||||
ExpressionLocal::ExpressionLocal(const std::string& id) :
|
||||
Expression(Type::LOCAL),
|
||||
mLocalId(id) {}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ ExpressionLocal::~ExpressionLocal() = default;
|
|||
ExpressionSelf::ExpressionSelf() :
|
||||
Expression(Type::SELF) {}
|
||||
|
||||
ExpressionChild::ExpressionChild(Expression* mParent, const tp::String& id) :
|
||||
ExpressionChild::ExpressionChild(Expression* mParent, const std::string& id) :
|
||||
Expression(Type::CHILD),
|
||||
mParent(mParent),
|
||||
mLocalId(id) {}
|
||||
|
|
@ -79,13 +79,13 @@ ExpressionArithmetics::~ExpressionArithmetics() {
|
|||
delete mRight;
|
||||
}
|
||||
|
||||
ExpressionFunc::ExpressionFunc(const tp::String& id) :
|
||||
ExpressionFunc::ExpressionFunc(const std::string& id) :
|
||||
Expression(Type::FUNC),
|
||||
mFuncId(id) {}
|
||||
|
||||
ExpressionFunc::~ExpressionFunc() = default;
|
||||
|
||||
ExpressionConst::ExpressionConst(const tp::String& val) :
|
||||
ExpressionConst::ExpressionConst(const std::string& val) :
|
||||
Expression(Type::CONST_EXPR),
|
||||
mConstType(STR),
|
||||
str(val) {}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include "primitives/methodobject.h"
|
||||
#include "primitives/primitives.h"
|
||||
|
||||
#include "Logging.hpp"
|
||||
|
||||
#include "parser/parser.h"
|
||||
|
||||
using namespace obj;
|
||||
|
|
@ -27,7 +25,7 @@ void obj::BCgen::Genereate(ByteCode& out, StatementScope* body) {
|
|||
root.generateByteCode(out);
|
||||
}
|
||||
|
||||
ConstObject* FunctionDefinition::defineLocal(tp::String id) {
|
||||
ConstObject* FunctionDefinition::defineLocal(const std::string& id) {
|
||||
auto idx = mLocals.presents(id);
|
||||
// RelAssert(!idx && "Local Redefinition");
|
||||
auto const_str_id = mConstants.get(id);
|
||||
|
|
@ -35,7 +33,7 @@ ConstObject* FunctionDefinition::defineLocal(tp::String id) {
|
|||
return const_str_id;
|
||||
}
|
||||
|
||||
FunctionDefinition::FunctionDefinition(tp::String function_id, tp::Buffer<tp::String> args, FunctionDefinition* prnt) {
|
||||
FunctionDefinition::FunctionDefinition(const std::string& function_id, tp::Buffer<std::string> args, FunctionDefinition* prnt) {
|
||||
mFunctionId = function_id;
|
||||
inst(Instruction(OpCode::SAVE_ARGS, args.size(), 1));
|
||||
for (auto id : args) {
|
||||
|
|
@ -190,7 +188,7 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
|
|||
|
||||
} else {
|
||||
|
||||
tp::String type;
|
||||
std::string type;
|
||||
switch (stm_local_def->mConstExpr->mConstType) {
|
||||
case ExpressionConst::BOOL:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
using namespace obj;
|
||||
using namespace BCgen;
|
||||
|
||||
StatementFuncDef::StatementFuncDef(const tp::String& function_id) :
|
||||
StatementFuncDef::StatementFuncDef(const std::string& function_id) :
|
||||
Statement(Type::DEF_FUNC) {
|
||||
mFunctionId = function_id;
|
||||
}
|
||||
|
||||
StatementFuncDef::~StatementFuncDef() { delete mStatements; }
|
||||
|
||||
StatementLocalDef::StatementLocalDef(const tp::String& id, Expression* value) :
|
||||
StatementLocalDef::StatementLocalDef(const std::string& id, Expression* value) :
|
||||
mLocalId(id),
|
||||
Statement(Type::DEF_LOCAL) {
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ StatementIgnore::StatementIgnore(Expression* expr) :
|
|||
|
||||
StatementIgnore::~StatementIgnore() { delete mExpr; }
|
||||
|
||||
StatementClassDef::StatementClassDef(const tp::String& class_id, StatementScope* scope) :
|
||||
StatementClassDef::StatementClassDef(const std::string& class_id, StatementScope* scope) :
|
||||
Statement(Type::CLASS_DEF) {
|
||||
mClassId = class_id;
|
||||
mScope = scope;
|
||||
|
|
|
|||
|
|
@ -76,8 +76,6 @@ static void deinit(const tp::ModuleManifest*) {
|
|||
}
|
||||
|
||||
static tp::ModuleManifest* sModuleDependencies[] = {
|
||||
// &tp::gModuleCompressor,
|
||||
&tp::gModuleStrings,
|
||||
nullptr
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,29 @@
|
|||
|
||||
namespace obj {
|
||||
|
||||
void save_string(ArchiverOut& file, const std::string& string) {
|
||||
file << string.size();
|
||||
file.writeBytes(string.c_str(), string.size());
|
||||
}
|
||||
|
||||
tp::ualni save_string_size(const std::string& string) {
|
||||
return string.size() + sizeof(string.size());
|
||||
}
|
||||
|
||||
void load_string(ArchiverIn& file, std::string& out) {
|
||||
typeof(out.size()) size;
|
||||
file >> size;
|
||||
auto buff = new char[size + 1];
|
||||
file.readBytes(buff, size);
|
||||
buff[size] = 0;
|
||||
out = buff;
|
||||
delete[] buff;
|
||||
}
|
||||
|
||||
Object* ObjectMemAllocate(const ObjectType* type);
|
||||
void ObjectMemDeallocate(Object* in);
|
||||
|
||||
objects_api* NDO = NULL;
|
||||
objects_api* NDO = nullptr;
|
||||
|
||||
void hierarchy_copy(Object* self, const Object* in, const ObjectType* type);
|
||||
void hierarchy_construct(Object* self, const ObjectType* type);
|
||||
|
|
@ -36,7 +55,7 @@ namespace obj {
|
|||
type->type_methods.init();
|
||||
}
|
||||
|
||||
Object* objects_api::create(const tp::String& name) {
|
||||
Object* objects_api::create(const std::string& name) {
|
||||
MODULE_SANITY_CHECK(gModuleObjects);
|
||||
|
||||
const ObjectType* type = types.get(name);
|
||||
|
|
@ -44,7 +63,7 @@ namespace obj {
|
|||
Object* obj_instance = ObjectMemAllocate(type);
|
||||
|
||||
if (!obj_instance) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hierarchy_construct(obj_instance, obj_instance->type);
|
||||
|
|
@ -69,7 +88,7 @@ namespace obj {
|
|||
|
||||
Object* objects_api::copy(Object* self, const Object* in) {
|
||||
if (self->type != in->type) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hierarchy_copy(self, in, self->type);
|
||||
|
|
@ -110,7 +129,7 @@ namespace obj {
|
|||
}
|
||||
}
|
||||
|
||||
void objects_api::set(Object* self, tp::String val) {
|
||||
void objects_api::set(Object* self, const std::string& val) {
|
||||
if (self->type->convesions && self->type->convesions->from_string) {
|
||||
self->type->convesions->from_string(self, val);
|
||||
return;
|
||||
|
|
@ -134,7 +153,7 @@ namespace obj {
|
|||
return true;
|
||||
}
|
||||
|
||||
tp::String objects_api::toString(Object* self) {
|
||||
std::string objects_api::toString(Object* self) {
|
||||
DEBUG_ASSERT(self->type->convesions && self->type->convesions->to_string);
|
||||
return self->type->convesions->to_string(self);
|
||||
}
|
||||
|
|
@ -217,6 +236,6 @@ namespace obj {
|
|||
}
|
||||
typeiter = typeiter->base;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ namespace obj {
|
|||
|
||||
ObjectsFileHeader(bool default_val = true) {
|
||||
if (default_val) {
|
||||
tp::memCopy(&name, "objects", tp::String::Logic::calcLength("objects") + 1);
|
||||
tp::memCopy(&version, "0", tp::String::Logic::calcLength("0") + 1);
|
||||
tp::memCopy(&name, "objects", 8);
|
||||
tp::memCopy(&version, "0", 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -26,10 +26,10 @@ namespace obj {
|
|||
Object* ObjectMemAllocate(const ObjectType* type) {
|
||||
ObjectMemHead* memh = (ObjectMemHead*) malloc(type->size + sizeof(ObjectMemHead));
|
||||
if (!memh) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
memh->down = NULL;
|
||||
memh->down = nullptr;
|
||||
memh->flags = 0;
|
||||
|
||||
memh->refc = (tp::alni) 1;
|
||||
|
|
@ -235,10 +235,11 @@ namespace obj {
|
|||
// save file object header
|
||||
ObjectFileHead ofh = { 0, getrefc(in) };
|
||||
ndf << ofh;
|
||||
ndf << tp::String(in->type->name);
|
||||
|
||||
save_string(ndf, in->type->name);
|
||||
|
||||
// allocate for object file header
|
||||
ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + tp::SaveSizeCounter::calc(tp::String(in->type->name)));
|
||||
ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + save_string_size(in->type->name));
|
||||
|
||||
// calc max size needed for saving all hierarchy of types
|
||||
tp::alni file_alloc_size = objsize_file_util(in, in->type);
|
||||
|
|
@ -281,14 +282,14 @@ namespace obj {
|
|||
ObjectFileHead ofh;
|
||||
ndf >> ofh;
|
||||
|
||||
tp::String type_name;
|
||||
ndf >> type_name;
|
||||
std::string type_name;
|
||||
load_string(ndf, type_name);
|
||||
|
||||
const ObjectType* object_type = NDO->types.get(type_name);
|
||||
Object* out = ObjectMemAllocate(object_type);
|
||||
|
||||
if (!out) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
setrefc(out, 0);
|
||||
|
|
@ -312,8 +313,8 @@ namespace obj {
|
|||
return out;
|
||||
}
|
||||
|
||||
bool objects_api::save(Object* in, tp::String path, bool compressed) {
|
||||
ArchiverOut ndf(path.read());
|
||||
bool objects_api::save(Object* in, const std::string& path, bool compressed) {
|
||||
ArchiverOut ndf(path.c_str());
|
||||
|
||||
if (!ndf.isOpened()) {
|
||||
return false;
|
||||
|
|
@ -365,22 +366,22 @@ namespace obj {
|
|||
return true;
|
||||
}
|
||||
|
||||
Object* objects_api::load(tp::String path) {
|
||||
Object* objects_api::load(const std::string& path) {
|
||||
/*
|
||||
auto temp_file_name = path + ".unz";
|
||||
bool unz_res = tp::decompressF2F(path.cstr(), temp_file_name.cstr());
|
||||
|
||||
if (!unz_res) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD);
|
||||
*/
|
||||
|
||||
ArchiverIn ndf(path.read());
|
||||
ArchiverIn ndf(path.c_str());
|
||||
|
||||
if (!ndf.isOpened()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// check for compatibility
|
||||
|
|
@ -390,7 +391,7 @@ namespace obj {
|
|||
ndf >> loaded_header;
|
||||
|
||||
if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ndf.setAddress(0);
|
||||
|
|
@ -423,7 +424,7 @@ namespace obj {
|
|||
/*
|
||||
ndf.close();
|
||||
|
||||
if (unz_res == NULL) {
|
||||
if (unz_res == nullptr) {
|
||||
File::remove(temp_file_name.cstr());
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using namespace obj;
|
||||
|
||||
ScriptSection* gScriptSection = NULL;
|
||||
ScriptSection* gScriptSection = nullptr;
|
||||
|
||||
struct script_data_head {
|
||||
tp::alni refc = 0;
|
||||
|
|
@ -19,7 +19,7 @@ Script* ScriptSection::createScript() {
|
|||
auto out = (Script*) (sdhead + 1);
|
||||
|
||||
if (!sdhead) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sdhead->refc = 1;
|
||||
|
|
@ -215,7 +215,7 @@ Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) {
|
|||
return iter.data();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScriptSection::~ScriptSection() {
|
||||
|
|
@ -229,8 +229,8 @@ obj::save_load_callbacks ScriptSection::slcb_script_section = {
|
|||
.pre_save = (obj::pre_save_callback*) ScriptSection::save_script_table_to_file,
|
||||
.size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size,
|
||||
.pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file,
|
||||
.post_save = NULL,
|
||||
.post_load = NULL,
|
||||
.post_save = nullptr,
|
||||
.post_load = nullptr,
|
||||
};
|
||||
|
||||
void ScriptSection::initialize() {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ obj::TypeGroups::TypeGroups(bool is_group) :
|
|||
if (is_group) {
|
||||
new (&childs) Dict();
|
||||
} else {
|
||||
type = NULL;
|
||||
type = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList<const char*>
|
|||
return;
|
||||
}
|
||||
|
||||
TypeGroups* group = NULL;
|
||||
TypeGroups* group = nullptr;
|
||||
tp::alni index = 0;
|
||||
|
||||
for (auto dir : path) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
.nameid = "type",
|
||||
.descr = "retrieves typeobject",
|
||||
.exec = [](const TypeMethod* tm) { tm->ret.obj = TypeObject::create(tm->self->type); },
|
||||
.ret = { "typeobject", NULL },
|
||||
.ret = { "typeobject", nullptr },
|
||||
},
|
||||
{
|
||||
.nameid = "to_str",
|
||||
|
|
@ -25,7 +25,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
tm->ret.obj = StringObject::create(NDO->toString(tm->self));
|
||||
}
|
||||
},
|
||||
.ret = { "string object", NULL },
|
||||
.ret = { "string object", nullptr },
|
||||
},
|
||||
{
|
||||
.nameid = "to_float",
|
||||
|
|
@ -36,11 +36,11 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
tm->ret.obj = FloatObject::create(NDO->toFloat(tm->self));
|
||||
}
|
||||
},
|
||||
.ret = { "string object", NULL },
|
||||
.ret = { "string object", nullptr },
|
||||
},
|
||||
};
|
||||
|
||||
tp::int2 TypeMethods::presents(tp::String id) const {
|
||||
tp::int2 TypeMethods::presents(const std::string& id) const {
|
||||
for (tp::int2 idx = 0; idx < mNMethods; idx++) {
|
||||
if (id == methods[idx]->nameid) {
|
||||
return idx;
|
||||
|
|
@ -58,7 +58,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, const std::string& id) {
|
||||
|
||||
tp::int2 depth = 0;
|
||||
tp::int2 idx = 0;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include "primitives/primitives.h"
|
||||
|
||||
#include "Logging.hpp"
|
||||
|
||||
#include "Timing.hpp"
|
||||
|
||||
using namespace obj;
|
||||
|
|
@ -224,9 +222,9 @@ void Interpreter::stepBytecodeIn() {
|
|||
auto obj = mOperandsStack.getOperand();
|
||||
if (obj->type->convesions && obj->type->convesions->to_string) {
|
||||
auto str = NDO->toString(obj);
|
||||
gLogger->write(str, true);
|
||||
printf("%s\n", str.c_str());
|
||||
} else {
|
||||
gLogger->write(String(obj->type->name), true);
|
||||
printf("Object with type '%s' has no string representation.\n", obj->type->name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ Scope::~Scope() {
|
|||
}
|
||||
}
|
||||
|
||||
obj::Object* ScopeStack::getLocalUtil(Scope& scope, tp::String* id) {
|
||||
obj::Object* ScopeStack::getLocalUtil(Scope& scope, const std::string& id) {
|
||||
|
||||
auto idx = scope.mLocals.presents(*id);
|
||||
auto idx = scope.mLocals.presents(id);
|
||||
|
||||
if (idx) {
|
||||
return scope.mLocals.getSlotVal(idx);
|
||||
|
|
@ -62,7 +62,7 @@ void ScopeStack::addTempReturn(obj::Object* ret) {
|
|||
}
|
||||
}
|
||||
|
||||
void ScopeStack::addLocal(obj::Object* local, tp::String id) {
|
||||
void ScopeStack::addLocal(obj::Object* local, const std::string& id) {
|
||||
DEBUG_ASSERT(mIdx != 0 && "No scope given");
|
||||
Scope::ObjDict& locals = mBuff[mIdx - 1].mLocals;
|
||||
auto idx = locals.presents(id);
|
||||
|
|
@ -73,9 +73,9 @@ void ScopeStack::addLocal(obj::Object* local, tp::String id) {
|
|||
locals.put(id, local);
|
||||
}
|
||||
|
||||
obj::Object* ScopeStack::getLocal(tp::String& str) {
|
||||
obj::Object* ScopeStack::getLocal(const std::string& str) {
|
||||
mIterIdx = mIdx - 1;
|
||||
return getLocalUtil(mBuff[mIdx - 1], &str);
|
||||
return getLocalUtil(mBuff[mIdx - 1], str);
|
||||
}
|
||||
|
||||
Scope* ScopeStack::getCurrentScope() { return &mBuff[mIdx - 1]; }
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ static UserData id_list_append(const UserData* start, const Node* nodes, size_t)
|
|||
}
|
||||
|
||||
static UserData id_list_create(const UserData*, const Node* nodes, size_t) {
|
||||
return new tp::Buffer<tp::String>({ (char*) nodes[0].lexeme().c_str() });
|
||||
return new tp::Buffer<std::string>({ (char*) nodes[0].lexeme().c_str() });
|
||||
}
|
||||
|
||||
static UserData expr_function(const UserData* start, const Node*, size_t) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
struct UserNode {
|
||||
obj::BCgen::Expression* expression = nullptr;
|
||||
obj::BCgen::Statement* statement = nullptr;
|
||||
tp::Buffer<tp::String>* arguments = nullptr;
|
||||
tp::Buffer<std::string>* arguments = nullptr;
|
||||
|
||||
UserNode(obj::BCgen::Statement* stm) :
|
||||
statement(stm) {}
|
||||
|
|
@ -20,7 +20,7 @@ struct UserNode {
|
|||
UserNode(obj::BCgen::Expression* expr) :
|
||||
expression(expr) {}
|
||||
|
||||
UserNode(tp::Buffer<tp::String>* argList) :
|
||||
UserNode(tp::Buffer<std::string>* argList) :
|
||||
arguments(argList) {}
|
||||
|
||||
UserNode() = default;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public:
|
|||
virtual void lalr_vprintf(const char* format, va_list args) override { printf(format, args); }
|
||||
};
|
||||
|
||||
Parser::Result Parser::parse(const tp::String& stream) {
|
||||
Parser::Result Parser::parse(const std::string& stream) {
|
||||
|
||||
CustomErrorPolicy errorPolicy;
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ Parser::Result Parser::parse(const tp::String& stream) {
|
|||
|
||||
bind(parser);
|
||||
|
||||
std::string streamStd(stream.read());
|
||||
streamStd += "\n"; // for windows os to make happy
|
||||
std::string streamStd(stream.c_str());
|
||||
streamStd += "\n"; // for windows os to be happy
|
||||
|
||||
ASSERT(parser.valid());
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ void BoolObject::from_int(BoolObject* self, alni in) { self->val = in; }
|
|||
|
||||
void BoolObject::from_float(BoolObject* self, alnf in) { self->val = alni(bool(in)); }
|
||||
|
||||
void BoolObject::from_string(BoolObject* self, String in) { self->val = alni(bool(in)); }
|
||||
void BoolObject::from_string(BoolObject* self, const std::string& in) {
|
||||
self->val = in == "true" || in == "True";
|
||||
}
|
||||
|
||||
String BoolObject::to_string(BoolObject* self) { return String(bool(self->val)); }
|
||||
std::string BoolObject::to_string(BoolObject* self) { return std::to_string(bool(self->val)); }
|
||||
|
||||
alni BoolObject::to_int(BoolObject* self) { return self->val; }
|
||||
|
||||
|
|
@ -42,9 +44,9 @@ struct ObjectTypeConversions BoolObjectTypeConversions = {
|
|||
};
|
||||
|
||||
struct obj::ObjectType obj::BoolObject::TypeData = {
|
||||
.base = NULL,
|
||||
.base = nullptr,
|
||||
.constructor = (object_constructor) BoolObject::constructor,
|
||||
.destructor = NULL,
|
||||
.destructor = nullptr,
|
||||
.copy = (object_copy) BoolObject::copy,
|
||||
.size = sizeof(BoolObject),
|
||||
.name = "bool",
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ void ClassObject::copy(ClassObject* self, const ClassObject* blueprint) { NDO->c
|
|||
|
||||
void ClassObject::destructor(ClassObject* self) { NDO->destroy(self->members); }
|
||||
|
||||
void ClassObject::addMember(Object* obj, tp::String id) { members->put(id, obj); }
|
||||
void ClassObject::addMember(Object* obj, const std::string& id) { members->put(id, obj); }
|
||||
|
||||
void ClassObject::createMember(tp::String type, tp::String id) {
|
||||
void ClassObject::createMember(const std::string& type, const std::string& id) {
|
||||
auto newo = NDO->create(type);
|
||||
members->put(id, newo);
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ alni allocated_size_recursive(ClassObject* self) {
|
|||
return out;
|
||||
}
|
||||
|
||||
struct ObjectType ClassObject::TypeData = { .base = NULL,
|
||||
struct ObjectType ClassObject::TypeData = { .base = nullptr,
|
||||
.constructor = (object_constructor) ClassObject::constructor,
|
||||
.destructor = (object_destructor) ClassObject::destructor,
|
||||
.copy = (object_copy) ClassObject::copy,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ void ColorObject::from_int(ColorObject* self, alni in) { self->mCol = tp::RGBA((
|
|||
|
||||
void ColorObject::from_float(ColorObject* self, alnf in) { NDO_CAST(ColorObject, self)->mCol = tp::RGBA(tp::clamp((tp::halnf) in, 0.f, 1.f)); }
|
||||
|
||||
String ColorObject::to_string(ColorObject* self) {
|
||||
std::string ColorObject::to_string(ColorObject* self) {
|
||||
// auto &col = NDO_CAST(ColorObject, self)->mCol;
|
||||
// return tp::sfmt("%i:%i:%i:%i", (tp::alni) (col.r * 255), (tp::alni)(col.g * 255), (tp::alni)(col.b * 255), (tp::alni)(col.a * 255));
|
||||
// TODO : implement
|
||||
|
|
@ -33,10 +33,10 @@ static void load(ArchiverIn& file_self, ColorObject* self) { file_self >> self->
|
|||
struct ObjectTypeConversions ColorObjectTypeConversions = {
|
||||
.from_int = (object_from_int) ColorObject::from_int,
|
||||
.from_float = (object_from_float) ColorObject::from_float,
|
||||
.from_string = NULL,
|
||||
.from_string = nullptr,
|
||||
.to_string = (object_to_string) ColorObject::to_string,
|
||||
.to_int = NULL,
|
||||
.to_float = NULL,
|
||||
.to_int = nullptr,
|
||||
.to_float = nullptr,
|
||||
};
|
||||
|
||||
void sub(ColorObject* self, ColorObject* in) { self->mCol = in->mCol - self->mCol; }
|
||||
|
|
@ -46,14 +46,14 @@ void add(ColorObject* self, ColorObject* in) { self->mCol = in->mCol + self->mCo
|
|||
struct ObjectTypeAriphmetics ColorObject::TypeAriphm = {
|
||||
.add = (object_add) add,
|
||||
.sub = (object_sub) sub,
|
||||
.mul = (object_mul) NULL,
|
||||
.div = (object_div) NULL,
|
||||
.mul = (object_mul) nullptr,
|
||||
.div = (object_div) nullptr,
|
||||
};
|
||||
|
||||
struct obj::ObjectType obj::ColorObject::TypeData = {
|
||||
.base = NULL,
|
||||
.base = nullptr,
|
||||
.constructor = ColorObject::constructor,
|
||||
.destructor = NULL,
|
||||
.destructor = nullptr,
|
||||
.copy = (object_copy) ColorObject::copy,
|
||||
.size = sizeof(ColorObject),
|
||||
.name = "RGBA",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using namespace tp;
|
|||
void DictObject::constructor(Object* self) {
|
||||
NDO_CASTV(DictObject, self, dict);
|
||||
|
||||
new (&dict->items) Map<String, Object*>();
|
||||
new (&dict->items) Map<std::string, Object*>();
|
||||
}
|
||||
|
||||
void DictObject::copy(Object* in, const Object* target) {
|
||||
|
|
@ -41,7 +41,7 @@ alni DictObject::save_size(DictObject* self) {
|
|||
|
||||
for (auto item : self->items) {
|
||||
// string length
|
||||
save_size += tp::SaveSizeCounter::calc(item->key);
|
||||
save_size += save_string_size(item->key);
|
||||
|
||||
// object file adress
|
||||
save_size += sizeof(alni);
|
||||
|
|
@ -63,12 +63,12 @@ void DictObject::save(DictObject* self, ArchiverOut& file_self) {
|
|||
file_self << ndo_object_adress;
|
||||
|
||||
// item key
|
||||
file_self << item->key;
|
||||
save_string(file_self, item->key);
|
||||
}
|
||||
}
|
||||
|
||||
void DictObject::load(ArchiverIn& file_self, DictObject* self) {
|
||||
new (&self->items) tp::Map<tp::String, Object*>();
|
||||
new (&self->items) tp::Map<std::string, Object*>();
|
||||
|
||||
alni len;
|
||||
file_self >> len;
|
||||
|
|
@ -81,8 +81,8 @@ void DictObject::load(ArchiverIn& file_self, DictObject* self) {
|
|||
Object* val = NDO->load(file_self, ndo_object_adress);
|
||||
|
||||
// read key value
|
||||
String key;
|
||||
file_self >> key;
|
||||
std::string key;
|
||||
load_string(file_self, key);
|
||||
|
||||
// add to dictinary
|
||||
self->put(key, val);
|
||||
|
|
@ -118,13 +118,13 @@ alni DictObject::allocated_size_recursive(DictObject* self) {
|
|||
return out;
|
||||
}
|
||||
|
||||
void DictObject::put(tp::String str, Object* obj) {
|
||||
void DictObject::put(const std::string& str, Object* obj) {
|
||||
DEBUG_ASSERT(obj);
|
||||
NDO->refinc(obj);
|
||||
items.put(str, obj);
|
||||
}
|
||||
|
||||
void DictObject::remove(tp::String str) {
|
||||
void DictObject::remove(const std::string& str) {
|
||||
auto idx = items.presents(str);
|
||||
if (idx) {
|
||||
NDO->destroy(items.getSlotVal(idx));
|
||||
|
|
@ -132,13 +132,13 @@ void DictObject::remove(tp::String str) {
|
|||
}
|
||||
}
|
||||
|
||||
Object* DictObject::get(tp::String str) { return items.get(str); }
|
||||
Object* DictObject::get(const std::string& str) { return items.get(str); }
|
||||
|
||||
tp::Map<tp::String, Object*>::Idx DictObject::presents(tp::String str) { return items.presents(str); }
|
||||
tp::Map<std::string, Object*>::Idx DictObject::presents(const std::string& str) { return items.presents(str); }
|
||||
|
||||
Object* DictObject::getSlotVal(tp::Map<tp::String, Object*>::Idx idx) { return items.getSlotVal(idx); }
|
||||
Object* DictObject::getSlotVal(tp::Map<std::string, Object*>::Idx idx) { return items.getSlotVal(idx); }
|
||||
|
||||
const tp::Map<tp::String, Object*>& DictObject::getItems() const { return items; }
|
||||
const tp::Map<std::string, Object*>& DictObject::getItems() const { return items; }
|
||||
|
||||
static auto tm_get = TypeMethod{ .nameid = "get",
|
||||
.descr = "gets the object",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "primitives/enumobject.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace obj;
|
||||
using namespace tp;
|
||||
|
|
@ -37,7 +38,7 @@ void obj::EnumObject::init(tp::InitialierList<const char*> list) {
|
|||
alni* entry = entries;
|
||||
for (auto elem : list) {
|
||||
|
||||
alni len = tp::String::Logic::calcLength(elem);
|
||||
alni len = std::strlen(elem);
|
||||
if (len > ENV_ALNI_SIZE_B - 1) len = ENV_ALNI_SIZE_B - 1;
|
||||
|
||||
tp::memCopy(entry, elem, len);
|
||||
|
|
@ -69,11 +70,11 @@ void EnumObject::from_float(EnumObject* self, alnf in) {
|
|||
}
|
||||
}
|
||||
|
||||
void EnumObject::from_string(EnumObject* self, String in) {
|
||||
void EnumObject::from_string(EnumObject* self, const std::string& in) {
|
||||
if (self->entries) {
|
||||
alni* entry = self->entries;
|
||||
for (uhalni i = 0; i < self->nentries; i++) {
|
||||
if (tp::String::Logic::isEqualLogic((const char*) entry, in.read())) {
|
||||
if (in == ((const char*) entry)) {
|
||||
self->active = i;
|
||||
}
|
||||
entry += 1;
|
||||
|
|
@ -81,12 +82,12 @@ void EnumObject::from_string(EnumObject* self, String in) {
|
|||
}
|
||||
}
|
||||
|
||||
String EnumObject::to_string(EnumObject* self) {
|
||||
std::string EnumObject::to_string(EnumObject* self) {
|
||||
if (!self->entries) {
|
||||
return tp::String();
|
||||
return {};
|
||||
}
|
||||
auto val = (const char*) (&self->entries[self->active]);
|
||||
return String(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
alni EnumObject::to_int(EnumObject* self) {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@ void FloatObject::from_int(FloatObject* self, alni in) { self->val = alnf(in); }
|
|||
|
||||
void FloatObject::from_float(FloatObject* self, alnf in) { self->val = in; }
|
||||
|
||||
void FloatObject::from_string(FloatObject* self, String in) { self->val = alnf(in); }
|
||||
void FloatObject::from_string(FloatObject* self, const std::string& in) {
|
||||
self->val = std::stof(in);
|
||||
}
|
||||
|
||||
String FloatObject::to_string(FloatObject* self) { return String(self->val); }
|
||||
std::string FloatObject::to_string(FloatObject* self) { return std::to_string(self->val); }
|
||||
|
||||
alni FloatObject::to_int(FloatObject* self) { return alni(self->val); }
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,11 @@ void IntObject::from_int(Object* self, alni in) { NDO_CAST(IntObject, self)->val
|
|||
|
||||
void IntObject::from_float(Object* self, alnf in) { NDO_CAST(IntObject, self)->val = (alni) in; }
|
||||
|
||||
void IntObject::from_string(Object* self, String in) { NDO_CAST(IntObject, self)->val = alni(in); }
|
||||
void IntObject::from_string(Object* self, const std::string& in) {
|
||||
NDO_CAST(IntObject, self)->val = std::stol(in);
|
||||
}
|
||||
|
||||
String IntObject::to_string(Object* self) { return String(NDO_CAST(IntObject, self)->val); }
|
||||
std::string IntObject::to_string(Object* self) { return std::to_string(NDO_CAST(IntObject, self)->val); }
|
||||
|
||||
alni IntObject::to_int(Object* self) { return alni(NDO_CAST(IntObject, self)->val); }
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void MethodObject::UnInitialize() { obj::ScriptSection::uninitialize(); }
|
|||
|
||||
void MethodObject::compile() { BCgen::Compile(this); }
|
||||
|
||||
MethodObject* MethodObject::create(tp::String script) {
|
||||
MethodObject* MethodObject::create(const std::string& script) {
|
||||
auto out = (MethodObject*) NDO->create(MethodObject::TypeData.name);
|
||||
out->mScript->mReadable->val = script;
|
||||
out->compile();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ void NullObject::uninit() {
|
|||
|
||||
void NullObject::destructor(Object* self) { DEBUG_ASSERT(uninit_flag && "Only one the instance of NullObject exists and thus it can't be destroyed"); }
|
||||
|
||||
String to_string(NullObject* self) { return "NULL"; }
|
||||
std::string to_string(NullObject* self) { return "NULL"; }
|
||||
|
||||
alni to_int(NullObject* self) { return 0; }
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
using namespace obj;
|
||||
using namespace tp;
|
||||
|
||||
void StringObject::constructor(Object* self) { new (&NDO_CAST(StringObject, self)->val) String(); }
|
||||
void StringObject::constructor(Object* self) { new (&NDO_CAST(StringObject, self)->val) std::string(); }
|
||||
|
||||
void StringObject::destructor(StringObject* self) { self->val.~String(); }
|
||||
void StringObject::destructor(StringObject* self) { self->val.~basic_string(); }
|
||||
|
||||
void StringObject::copy(Object* self, const Object* in) { NDO_CAST(StringObject, self)->val = NDO_CAST(StringObject, in)->val; }
|
||||
|
||||
StringObject* StringObject::create(String in) {
|
||||
StringObject* StringObject::create(const std::string& in) {
|
||||
NDO_CASTV(StringObject, NDO->create("str"), out)->val = in;
|
||||
return out;
|
||||
}
|
||||
|
|
@ -24,23 +24,27 @@ void StringObject::from_float(StringObject* self, alnf in) {
|
|||
// self->val = in;
|
||||
}
|
||||
|
||||
void StringObject::from_string(StringObject* self, String in) {
|
||||
void StringObject::from_string(StringObject* self, const std::string& in) {
|
||||
// self->val = in;
|
||||
}
|
||||
|
||||
String StringObject::to_string(StringObject* self) { return self->val; }
|
||||
std::string StringObject::to_string(StringObject* self) { return self->val; }
|
||||
|
||||
alni StringObject::to_int(StringObject* self) { return alni(self->val); }
|
||||
alni StringObject::to_int(StringObject* self) { return std::stoi(self->val); }
|
||||
|
||||
alnf StringObject::to_float(StringObject* self) { return alnf(self->val); }
|
||||
alnf StringObject::to_float(StringObject* self) { return std::stof(self->val); }
|
||||
|
||||
static alni save_size(StringObject* self) { return tp::SaveSizeCounter::calc(self->val); }
|
||||
static alni save_size(StringObject* self) {
|
||||
return save_string_size(self->val);
|
||||
}
|
||||
|
||||
static void save(StringObject* self, ArchiverOut& file_self) { file_self << self->val; }
|
||||
static void save(StringObject* self, ArchiverOut& file_self) {
|
||||
save_string(file_self, self->val);
|
||||
}
|
||||
|
||||
static void load(ArchiverIn& file_self, StringObject* self) {
|
||||
new (&self->val) tp::String();
|
||||
file_self >> self->val;
|
||||
new (&self->val) std::string();
|
||||
load_string(file_self, self->val);
|
||||
}
|
||||
|
||||
alni allocated_size(StringObject* self) {
|
||||
|
|
|
|||
|
|
@ -12,18 +12,16 @@ TypeObject* TypeObject::create(const ObjectType* type) {
|
|||
}
|
||||
|
||||
static alni save_size(TypeObject* self) {
|
||||
tp::String const nameid(self->mTypeRef->name);
|
||||
return nameid.size() + sizeof(nameid.size());
|
||||
return save_string_size(self->mTypeRef->name);
|
||||
}
|
||||
|
||||
static void save(TypeObject* self, ArchiverOut& file_self) {
|
||||
tp::String const nameid(self->mTypeRef->name);
|
||||
file_self << nameid;
|
||||
save_string(file_self, self->mTypeRef->name);
|
||||
}
|
||||
|
||||
static void load(ArchiverIn& file_self, TypeObject* self) {
|
||||
tp::String nameid;
|
||||
file_self >> nameid;
|
||||
std::string nameid;
|
||||
load_string(file_self, nameid);
|
||||
|
||||
auto idx = NDO->types.presents(nameid);
|
||||
|
||||
|
|
@ -36,7 +34,7 @@ static void load(ArchiverIn& file_self, TypeObject* self) {
|
|||
|
||||
static alni allocated_size(TypeObject* self) { return sizeof(alni); }
|
||||
|
||||
static void from_string(TypeObject* self, tp::String in) {
|
||||
static void from_string(TypeObject* self, const std::string& in) {
|
||||
auto idx = NDO->types.presents(in);
|
||||
|
||||
if (idx) {
|
||||
|
|
@ -46,7 +44,7 @@ static void from_string(TypeObject* self, tp::String in) {
|
|||
}
|
||||
}
|
||||
|
||||
static String to_string(TypeObject* self) { return self->mTypeRef->name; }
|
||||
static std::string to_string(TypeObject* self) { return self->mTypeRef->name; }
|
||||
|
||||
bool comparator(TypeObject* left, TypeObject* right) { return left->mTypeRef == right->mTypeRef; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue