RIP tp::Strings

This commit is contained in:
IlyaShurupov 2024-03-22 14:44:26 +03:00 committed by Ilya Shurupov
parent fa2d0aaa92
commit 1756ca026d
90 changed files with 419 additions and 1475 deletions

View file

@ -7,7 +7,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE})
target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Connection LALR Strings)
target_link_libraries(${PROJECT_NAME} PUBLIC Math Connection LALR)
target_compile_definitions(${PROJECT_NAME} PUBLIC USERDATA_DESTROY_FAILED_TREE_ROOTS)
### -------------------------- Applications -------------------------- ###

View file

@ -1,48 +0,0 @@
#include "Compiler/Compiler.h"
#include "MethodObject/MethodObject.h"
#include "log.h"
#include "primitives/primitives.h"
using namespace osc;
using namespace tp;
using namespace obj;
int main(int argc, char* argv[]) {
tp::alloc_init();
string::Initialize();
Logger::init();
objects_init();
primitives_define_types();
MethodObject::Initialize();
{
Compiler compiler;
tp::string script;
RelAssert(argc == 2 && "Invalid Arguments");
script.loadFile(argv[1]);
compiler.compile(script);
GLog->write("oscc : compilation finished", 1);
}
try {
MethodObject::UnInitialize();
objects_finalize();
primitives_uninitialize();
Logger::deinit();
string::UnInitialize();
tp::alloc_uninit();
} catch (...) {
tp::terminate();
}
}

View file

@ -121,14 +121,14 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = NULL) {
for (auto childo : *type_group->getChilds()) {
if (childo->val->isGroup()) {
if (ImGui::BeginMenu((childo->key).read())) {
if (ImGui::BeginMenu((childo->key).c_str())) {
newo = imgui_object_create_menu(childo->val);
ImGui::EndMenu();
}
continue;
}
if (ImGui::Button((childo->key).read(), { 100, 0 })) {
if (ImGui::Button((childo->key).c_str(), { 100, 0 })) {
if (childo->key == "null") {
newo = NDO_NULL;
} else {
@ -142,7 +142,7 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = NULL) {
obj::ObjectsGUI::ObjectsGUI() { assert(obj::NDO && "Objects library is not initialized"); }
void obj::ObjectsGUI::cd(obj::Object* child, tp::String name) {
void obj::ObjectsGUI::cd(obj::Object* child, const std::string& name) {
mActive = child;
mViewStack.pushBack({ mActive, name });
obj::NDO->refinc(child);
@ -198,8 +198,8 @@ void obj::ObjectsGUI::preview(obj::Object* obj) {
NDO_CASTV(obj::StringObject, obj, stringo);
static char val[2048] = { " " };
if (stringo->val != val) {
assert(tp::String::Logic::calcLength(stringo->val.read()) < 2048);
tp::memCopy(val, stringo->val.read(), stringo->val.size() + 1);
assert(stringo->val.size() < 2048);
tp::memCopy(val, stringo->val.c_str(), stringo->val.size() + 1);
}
ImGui::InputText("", val, 2048);
if (stringo->val != val) {
@ -301,7 +301,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
}
// INFO
auto hd = HoverPopupBegin(tp::String((tp::alni) ip).read(), { 400, 250 });
auto hd = HoverPopupBegin(std::to_string((tp::alni) ip).c_str(), { 400, 250 });
if (hd) {
Text(info.desc);
if (info.operands.len) {
@ -365,20 +365,20 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
Begin("ScopeStack");
{
for (auto i = 0; i < interp.mScopeStack.mIdx; i++) {
if (TreeNode(tp::String((tp::alni) i).read())) {
if (TreeNode(std::to_string((tp::alni) i).c_str())) {
auto& scope = interp.mScopeStack.mBuff[i];
if (TreeNode("Locals")) {
for (auto local : scope.mLocals) {
if (Selectable(local->key.read(), false, 0, ImVec2(100, 0))) {
if (Selectable(local->key.c_str(), false, 0, ImVec2(100, 0))) {
TreePop();
TreePop();
End();
return { local->val, local->key };
}
PushID(local->key.read());
PushID(local->key.c_str());
SameLine();
preview(local->val);
PopID();
@ -389,7 +389,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
if (TreeNode("Temps")) {
tp::alni idx = 0;
for (auto tmp : scope.mTemps) {
if (Selectable(tp::String(idx).read(), false, 0, ImVec2(100, 0))) {
if (Selectable(std::to_string(idx).c_str(), false, 0, ImVec2(100, 0))) {
TreePop();
TreePop();
End();
@ -429,7 +429,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
if (Button(const_obj.data()->type->name)) {
End();
PopID();
return { const_obj.data(), tp::String(idx) };
return { const_obj.data(), std::to_string(idx) };
}
SameLine();
preview(const_obj.data());
@ -531,11 +531,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) {
if (mClipboard) {
if (ImGui::Selectable("Paste")) {
tp::alni idx = 1;
tp::String name_base = tp::String("clipboard ") + tp::String(mClipboard->type->name) + tp::String(" ");
tp::String name_out = name_base;
auto name_base = std::string("clipboard ") + std::string(mClipboard->type->name) + " ";
auto name_out = name_base;
while (dict->presents(name_out)) {
name_out = name_base + tp::String(idx);
name_out = name_base + std::to_string(idx);
idx++;
}
@ -549,11 +549,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) {
if (newo) {
tp::alni idx = 1;
tp::String name_base = tp::String("new ") + tp::String(newo->type->name) + tp::String(" ");
tp::String name_out = name_base;
auto name_base = std::string("new ") + std::string(newo->type->name) + " ";
auto name_out = name_base;
while (dict->presents(name_out)) {
name_out = name_base + tp::String(idx);
name_out = name_base + std::to_string(idx);
idx++;
}
@ -567,8 +567,8 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) {
}
}
void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::Object* obj, bool& popup) {
if (ImGui::BeginPopupContextItem(key.read(), ImGuiPopupFlags_MouseButtonRight)) {
void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, const std::string& key, obj::Object* obj, bool& popup) {
if (ImGui::BeginPopupContextItem(key.c_str(), ImGuiPopupFlags_MouseButtonRight)) {
popup = true;
ImGui::Text("%s at %x", obj->type->name, obj);
@ -578,7 +578,7 @@ void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::O
} else {
if (mLastNameEditObject != obj) {
tp::memCopy(mNameEdit, key.read(), key.size() + 1);
tp::memCopy(mNameEdit, key.c_str(), key.size() + 1);
mLastNameEditObject = obj;
}
@ -589,7 +589,7 @@ void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::O
} else {
obj::NDO->refinc(obj);
dict->remove(key);
auto id = tp::String(mNameEdit);
auto id = std::string(mNameEdit);
dict->put(id, obj);
obj::NDO->destroy(obj);
}
@ -626,16 +626,16 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::dictView(obj::DictObject* obj) {
ImGui::TableNextRow(0, 30);
ImGui::TableSetColumnIndex(0);
if (ImGui::Selectable(childo->key.read())) {
if (ImGui::Selectable(childo->key.c_str())) {
ImGui::EndTable();
ImGui::EndChild();
return { childo->val, { tp::String(childo->val->type->name) + tp::String(" ") + childo->key } };
return { childo->val, { std::string(childo->val->type->name) + " " + childo->key } };
}
dictViewEdit(obj, childo->key, childo->val, popup);
ImGui::TableSetColumnIndex(1);
ImGui::PushID((int) childo->key.read()[0]);
ImGui::PushID((int) childo->key.c_str()[0]);
preview(childo->val);
ImGui::PopID();
}
@ -670,13 +670,13 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::listView(obj::ListObject* obj) {
ImGui::TableNextRow(0, 36);
ImGui::TableSetColumnIndex(0);
if (ImGui::Selectable(tp::String(idx).read())) {
out = ViewStackNode(childo.data(), { tp::String(childo->type->name) + tp::String("at") + tp::String(idx) });
if (ImGui::Selectable(std::to_string(idx).c_str())) {
out = ViewStackNode(childo.data(), { std::string(childo->type->name) + "at" + std::to_string(idx) });
break;
}
{
if (ImGui::BeginPopupContextItem(tp::String(idx).read(), ImGuiPopupFlags_MouseButtonRight)) {
if (ImGui::BeginPopupContextItem(std::to_string(idx).c_str(), ImGuiPopupFlags_MouseButtonRight)) {
popup = true;
ImGui::Text("%s at %x", childo->type->name, childo.data());
@ -742,12 +742,12 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::listView(obj::ListObject* obj) {
return out;
}
void drawStrView(tp::String& in) {
void drawStrView(std::string& in) {
static char val[2048] = { " " };
if (in != val) {
assert(tp::String::Logic::calcLength(in.read()) < 2048);
tp::memCopy(val, in.read(), in.size() + 1);
assert(in.size() < 2048);
tp::memCopy(val, in.c_str(), in.size() + 1);
}
ImGui::BeginChild("str_edit");
@ -800,11 +800,11 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self
ImGui::TableNextRow(0, 30);
ImGui::TableSetColumnIndex(0);
if (ImGui::Selectable(childo->key.read())) {
if (ImGui::Selectable(childo->key.c_str())) {
ImGui::EndTable();
ImGui::TreePop();
ImGui::EndChild();
return { childo->val, { tp::String(childo->val->type->name) + childo->key } };
return { childo->val, { std::string(childo->val->type->name) + childo->key } };
}
dictViewEdit(dict, childo->key, childo->val, popup);
@ -824,10 +824,10 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self
if (n_methods && ImGui::TreeNodeBehavior(window->GetID("Methods"), tree_flags, "Methods", 0)) {
for (auto childo : dict->getItems()) {
if (childo->val->type == &obj::MethodObject::TypeData) {
if (ImGui::Selectable(childo->key.read())) {
if (ImGui::Selectable(childo->key.c_str())) {
ImGui::TreePop();
ImGui::EndChild();
return { childo->val, { tp::String(childo->val->type->name) + childo->key } };
return { childo->val, { std::string(childo->val->type->name) + childo->key } };
}
dictViewEdit(dict, childo->key, childo->val, popup);
}
@ -896,10 +896,10 @@ void obj::ObjectsGUI::explorer() {
ImGui::PushID((int) idx);
bool go_back = false;
if (childo == rev_path.last()) {
go_back = ImGui::Button(childo->data->id.read());
go_back = ImGui::Button(childo->data->id.c_str());
ImGui::SameLine();
} else {
go_back = ImGui::Button((childo->data->id).read());
go_back = ImGui::Button((childo->data->id).c_str());
ImGui::SameLine();
}
ImGui::PopID();

View file

@ -6,7 +6,7 @@
#include "compiler/function.h"
#include "Strings.hpp"
#include <string>
namespace obj {
@ -18,9 +18,9 @@ namespace obj {
struct ViewStackNode {
obj::Object* obj;
tp::String id;
std::string id;
ViewStackNode() { obj = NULL; }
ViewStackNode(obj::Object* obj, tp::String id) : obj(obj), id(id) {}
ViewStackNode(obj::Object* obj, const std::string& id) : obj(obj), id(id) {}
operator bool() { return obj; }
};
@ -42,7 +42,7 @@ namespace obj {
ObjectsGUI();
~ObjectsGUI();
void cd(obj::Object* child, tp::String name);
void cd(obj::Object* child, const std::string& name);
void cdup();
void clearEvents();
@ -67,7 +67,7 @@ namespace obj {
ViewStackNode methodView(obj::MethodObject* in);
ViewStackNode colorView(obj::ColorObject* in);
ViewStackNode interpreterView(obj::InterpreterObject* in);
void dictViewEdit(obj::DictObject* dict, tp::String item_id, obj::Object* obj, bool& popup);
void dictViewEdit(obj::DictObject* dict, const std::string& item_id, obj::Object* obj, bool& popup);
void dictViewDrawCreate(obj::DictObject* dict);
};
};

View file

@ -1,58 +0,0 @@
#include "MethodObject/methodobject.h"
#include "primitives/primitives.h"
#include "Interpreter/Interpreter.h"
#include "log.h"
using namespace osc;
using namespace tp;
using namespace obj;
int main(int argc, char* argv[]) {
tp::alloc_init();
string::Initialize();
Logger::init();
objects_init();
primitives_define_types();
MethodObject::Initialize();
{
time_ms load_start = get_time();
RelAssert(argc == 2 && "Invalid Arguments");
auto obj = NDO->load(argv[1]);
RelAssert(obj && "Failed to Load the File");
RelAssert(obj->type == &MethodObject::TypeData && "Innvalid file content");
Interpreter interp;
NDO_CASTV(MethodObject, obj, method);
RelAssert(method->mScript && "Innvalid file content");
time_ms load_end = get_time();
GLog->write("\noscvm - execution started\n");
time_ms exec_start = get_time();
interp.exec(&method->mScript->mBytecode);
time_ms exec_end = get_time();
auto exec_time = (exec_end - exec_start);
auto load_time = (load_end - load_start);
GLog->write(sfmt("\noscvm - execution finished (Load : %f Exec : %f)", load_time, exec_time));
}
try {
MethodObject::UnInitialize();
objects_finalize();
primitives_uninitialize();
Logger::deinit();
string::UnInitialize();
tp::alloc_uninit();
} catch (...) {
tp::terminate();
}
}

View file

@ -1,89 +0,0 @@
#include "primitives/methodobject.h"
#include "primitives/primitives.h"
#include "interpreter/interpreter.h"
#include "compiler/function.h"
using namespace tp;
using namespace obj;
void TestCompile(ByteCode& bytecode) {
using namespace BCgen;
Genereate(
bytecode,
StmScope({
StmDefFunc(
"main",
{},
{
StmDefLocal("i1", ExprConst(1)),
StmDefLocal("i2", ExprConst(2)),
// StmDefFunc("add", {"first", "second"}, {
// StmReturn(ExprAdd(ExprLocal("first"), ExprLocal("second")))
//}),
StmPrint(ExprLocal("i1")),
StmPrint(ExprConst(" + ")),
StmPrint(ExprLocal("i2")),
StmPrint(ExprConst(" = ")),
StmPrint(ExprFunc("add")->ExprCall({ ExprLocal("i1"), ExprLocal("i2") })),
StmPrint(ExprConst("\n")),
}
),
StmPrint(ExprBoolNot(ExprConst(0))),
StmWhile(ExprConst(false), StmScope({ StmIgnore(ExprFunc("main")->ExprCall({})) })),
StmIf(
ExprConst(true),
StmScope({
// StmIgnore(ExprFunc("main")->ExprCall({})),
// StmPrint(ExprConst("true")),
}),
StmScope({
// StmPrint(ExprConst("false")),
})
) })
);
}
int main(int argc, char* argv[]) {
tp::alloc_init();
string::Initialize();
Logger::init();
objects_init();
primitives_define_types();
MethodObject::Initialize();
{
Interpreter interp;
ByteCode bytecode;
TestCompile(bytecode);
GLog->write(" >> Exec: start \n");
auto start = get_time();
interp.exec(&bytecode);
auto end = get_time();
GLog->write(sfmt("\n >> Exec time %i ms", end - start));
}
MethodObject::UnInitialize();
objects_finalize();
primitives_uninitialize();
Logger::deinit();
string::UnInitialize();
tp::alloc_uninit();
}

View file

@ -1,68 +0,0 @@
#include "primitives/primitives.h"
#include "compiler/function.h"
#include "interpreter/interpreter.h"
#include "CmdArgParser.h"
void compile(char argc, const char* argv[]) {
tp::CmdArgParser args = { { "script", tp::CmdArgParser::Arg::FILE_IN }, { "out", "out.mo" } };
if (!args.parse(argc, argv, true)) {
return;
}
auto& script_file = args.getFile("script");
auto outpath = args.getString("out");
tp::string script;
script.loadFile(&script_file);
auto method = obj::MethodObject::create(script);
obj::NDO->save(method, outpath);
}
void execute(char argc, const char* argv[]) {
tp::CmdArgParser args = { { "object_path", tp::CmdArgParser::Arg::STR }, { "debug", false } };
if (!args.parse(argc, argv, true)) {
return;
}
auto object_path = args.getString("object_path");
auto debug = args.getBool("debug");
auto obj = obj::NDO->load(object_path);
if (!obj) {
printf("Invalid Object File\n");
return;
}
NDO_CASTV(obj::MethodObject, obj, method);
if (!method) {
printf("Object Is Not A Method\n");
return;
}
obj::Interpreter interpreter;
interpreter.execAll(method);
}
int main(char argc, const char* argv[]) {
tp::ModuleManifest* ModuleDependencies[] = { &obj::gModuleObjects, NULL };
tp::ModuleManifest TestModule("Test", NULL, NULL, ModuleDependencies);
if (!TestModule.initialize()) {
return 1;
}
#ifdef OBC
compile(argc, argv);
#elif OBVM
execute(argc, argv);
#endif // OBC
TestModule.deinitialize();
}

View file

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

View file

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

View file

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

View file

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

View file

@ -76,8 +76,6 @@ static void deinit(const tp::ModuleManifest*) {
}
static tp::ModuleManifest* sModuleDependencies[] = {
// &tp::gModuleCompressor,
&tp::gModuleStrings,
nullptr
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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",

View file

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

View file

@ -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",

View file

@ -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",

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ namespace obj {
class ConstObject {
public:
obj::Object* mObj = NULL;
obj::Object* mObj = nullptr;
tp::alni mConstIdx = 0;
ConstObject();
@ -19,8 +19,8 @@ namespace obj {
class ConstObjectsPool {
public:
tp::Map<tp::String, ConstObject*> mMethods;
tp::Map<tp::String, ConstObject*> mStrings;
tp::Map<std::string, ConstObject*> mMethods;
tp::Map<std::string, ConstObject*> mStrings;
tp::Map<tp::alni, ConstObject*> mIntegers;
tp::Map<tp::alnf, ConstObject*> mFloats;
ConstObject mBoolTrue;
@ -30,11 +30,11 @@ namespace obj {
tp::alni mTotalObjects = 0;
ConstObject* get(tp::alni val);
ConstObject* get(tp::String val);
ConstObject* get(const std::string& val);
ConstObject* get(tp::alnf val);
ConstObject* get(bool val);
ConstObject* addMethod(tp::String method_id, obj::Object* method);
ConstObject* addMethod(const std::string& method_id, obj::Object* method);
ConstObject* registerObject(obj::Object* obj);
void save(tp::Buffer<ConstData>& out);

View file

@ -1,7 +1,7 @@
#pragma once
#include "Strings.hpp"
#include <string>
#include "Buffer.hpp"
#include "interpreter/opcodes.h"
@ -28,7 +28,7 @@ namespace obj::BCgen {
explicit Expression(Type type);
virtual ~Expression() = default;
struct ExpressionChild* ExprChild(const tp::String& id);
struct ExpressionChild* ExprChild(const std::string& id);
struct ExpressionCall* ExprCall(class ExpressionList* args);
};
@ -39,28 +39,28 @@ namespace obj::BCgen {
};
struct ExpressionNew : public Expression {
tp::String mNewType;
explicit ExpressionNew(const tp::String& type);
std::string mNewType;
explicit ExpressionNew(const std::string& type);
~ExpressionNew() override;
};
struct ExpressionLocal : public Expression {
tp::String mLocalId;
explicit ExpressionLocal(const tp::String& id);
std::string mLocalId;
explicit ExpressionLocal(const std::string& id);
~ExpressionLocal() override;
};
struct ExpressionFunc : public Expression {
tp::String mFuncId;
explicit ExpressionFunc(const tp::String& id);
std::string mFuncId;
explicit ExpressionFunc(const std::string& id);
~ExpressionFunc() override;
};
struct ExpressionChild : public Expression {
Expression* mParent = nullptr;
tp::String mLocalId;
std::string mLocalId;
bool mMethod = false;
ExpressionChild(Expression* mParent, const tp::String& id);
ExpressionChild(Expression* mParent, const std::string& id);
~ExpressionChild() override;
};
@ -102,12 +102,12 @@ namespace obj::BCgen {
struct ExpressionConst : public Expression {
enum ConstType { STR, INT, BOOL, FLT } mConstType;
tp::String str;
std::string str;
tp::alni integer = 0;
tp::alnf floating = 0;
bool boolean = false;
explicit ExpressionConst(const tp::String& val);
explicit ExpressionConst(const std::string& val);
explicit ExpressionConst(const char* val);
explicit ExpressionConst(tp::alni val);
explicit ExpressionConst(tp::int4 val);

View file

@ -1,7 +1,7 @@
#pragma once
#include "Strings.hpp"
#include <string>
#include "List.hpp"
#include "Map.hpp"
@ -16,17 +16,17 @@ namespace obj {
struct FunctionDefinition {
FunctionDefinition* mPrnt = NULL;
FunctionDefinition* mPrnt = nullptr;
// signature
tp::String mFunctionId;
std::string mFunctionId;
tp::List<ConstObject*> mArgsOrder;
ConstObjectsPool mConstants;
tp::Map<tp::String, ConstObject*> mLocals;
tp::Map<std::string, ConstObject*> mLocals;
tp::List<Instruction> mInstructions;
FunctionDefinition(tp::String function_id, tp::Buffer<tp::String> args, FunctionDefinition* prnt);
FunctionDefinition(const std::string& function_id, tp::Buffer<std::string> args, FunctionDefinition* prnt);
FunctionDefinition() {}
void generateByteCode(ByteCode& out);
@ -36,7 +36,7 @@ namespace obj {
void EvalExpr(Expression* expr);
void EvalStatement(Statement* expr);
ConstObject* defineLocal(tp::String id);
ConstObject* defineLocal(const std::string& id);
};
void init();

View file

@ -35,11 +35,11 @@ namespace obj {
tp::alni mParam = 0;
tp::alni mParamBytes = 1;
ConstObject* mConstData = NULL;
ConstObject* mConstData2 = NULL;
ConstObject* mConstData = nullptr;
ConstObject* mConstData2 = nullptr;
tp::alni mInstIdx = 0;
Instruction* mInstTarget = NULL;
Instruction* mInstTarget = nullptr;
Instruction();
Instruction(ConstObject* constData);

View file

@ -36,21 +36,21 @@ namespace obj::BCgen {
};
struct StatementFuncDef : public Statement {
tp::Buffer<tp::String> mArgs;
tp::String mFunctionId;
tp::Buffer<std::string> mArgs;
std::string mFunctionId;
StatementScope* mStatements = nullptr;
explicit StatementFuncDef(const tp::String& function_id);
explicit StatementFuncDef(const std::string& function_id);
~StatementFuncDef() override;
};
struct StatementLocalDef : public Statement {
tp::String mLocalId;
std::string mLocalId;
Expression* mNewExpr = nullptr;
ExpressionConst* mConstExpr = nullptr;
bool mIsConstExpr = false;
StatementLocalDef(const tp::String& id, Expression* value);
StatementLocalDef(const std::string& id, Expression* value);
~StatementLocalDef() override;
};
@ -102,10 +102,10 @@ namespace obj::BCgen {
};
struct StatementClassDef : public Statement {
tp::String mClassId;
std::string mClassId;
StatementScope* mScope = nullptr;
StatementClassDef(const tp::String& class_id, StatementScope* scope);
StatementClassDef(const std::string& class_id, StatementScope* scope);
~StatementClassDef() override;
};
}

View file

@ -5,7 +5,6 @@
#include "Map.hpp"
#include "List.hpp"
#include "Buffer.hpp"
#include "Strings.hpp"
#include "LocalConnection.hpp"
#include "core/typegroups.h"
@ -14,6 +13,8 @@
#include "Archiver.hpp"
#include "SizeCounter.hpp"
#include <string>
//#include "interpreter/interpreter.h"
/* Steps to create custom Object:
@ -38,6 +39,7 @@ implement construct, destruct and copy methods */
namespace obj {
template<bool tRead>
class Archiver : public tp::ArchiverTemplate<tRead> {
tp::LocalConnection mConnection;
@ -84,6 +86,10 @@ namespace obj {
using ArchiverIn = Archiver<true>;
using ArchiverOut = Archiver<false>;
void save_string(ArchiverOut& file, const std::string& string);
tp::ualni save_string_size(const std::string& string);
void load_string(ArchiverIn& file, std::string& out);
extern tp::ModuleManifest gModuleObjects;
extern struct objects_api* NDO;
@ -101,8 +107,8 @@ namespace obj {
typedef void (*object_from_int)(Object* self, tp::alni in);
typedef void (*object_from_float)(Object* self, tp::alnf in);
typedef void (*object_from_string)(Object* self, tp::String in);
typedef tp::String(*object_to_string)(Object* self);
typedef void (*object_from_string)(Object* self, const std::string& in);
typedef std::string(*object_to_string)(Object* self);
typedef tp::alni(*object_to_int)(Object* self);
typedef tp::alnf(*object_to_float)(Object* self);
@ -142,23 +148,23 @@ namespace obj {
typedef tp::alni (*object_allocated_size_recursive)(Object*); // default value = object_allocated_size
struct ObjectType {
const ObjectType* base = NULL;
object_constructor constructor = NULL;
object_destructor destructor = NULL;
object_copy copy = NULL;
const ObjectType* base = nullptr;
object_constructor constructor = nullptr;
object_destructor destructor = nullptr;
object_copy copy = nullptr;
tp::alni size = 0;
const char* name;
const ObjectTypeConversions* convesions = NULL;
const ObjectTypeAriphmetics* ariphmetics = NULL;
object_save_size save_size = NULL;
object_save save = NULL;
object_load load = NULL;
object_compare comparison = NULL;
void* vtable = NULL;
const char* description = NULL;
object_debug_all_childs_retrival childs_retrival = NULL;
object_allocated_size allocated_size = NULL;
object_allocated_size_recursive allocated_size_recursive = NULL;
const ObjectTypeConversions* convesions = nullptr;
const ObjectTypeAriphmetics* ariphmetics = nullptr;
object_save_size save_size = nullptr;
object_save save = nullptr;
object_load load = nullptr;
object_compare comparison = nullptr;
void* vtable = nullptr;
const char* description = nullptr;
object_debug_all_childs_retrival childs_retrival = nullptr;
object_allocated_size allocated_size = nullptr;
object_allocated_size_recursive allocated_size_recursive = nullptr;
TypeMethods type_methods;
};
@ -182,26 +188,26 @@ namespace obj {
struct objects_api {
tp::Map<tp::String, const ObjectType*> types;
tp::Map<std::string, const ObjectType*> types;
obj::TypeGroups type_groups;
Interpreter* interp = NULL;
Interpreter* interp = nullptr;
objects_api();
~objects_api();
void define(ObjectType* type);
Object* create(const tp::String& name);
Object* create(const std::string& name);
Object* copy(Object* self, const Object* in);
bool compare(Object* first, Object* second);
Object* instatiate(Object*);
void set(Object* self, tp::alni val);
void set(Object* self, tp::alnf val);
void set(Object* self, tp::String val);
void set(Object* self, const std::string& val);
tp::alni toInt(Object* self);
tp::alnf toFloat(Object* self);
bool toBool(Object* self);
tp::String toString(Object* self);
std::string toString(Object* self);
void clear_object_flags();
@ -225,8 +231,8 @@ namespace obj {
tp::alni objsize_ram_recursive_util(Object* self, const ObjectType* type, bool different_object = true);
tp::alni objsize_ram_recursive(Object* self);
bool save(Object*, tp::String path, bool compressed = true);
Object* load(tp::String path);
bool save(Object*, const std::string& path, bool compressed = true);
Object* load(const std::string& path);
tp::alni save(ArchiverOut&, Object*);
Object* load(ArchiverIn&, tp::alni file_adress);
};

View file

@ -2,7 +2,7 @@
#pragma once
#include "Map.hpp"
#include "Strings.hpp"
#include <string>
namespace obj {
@ -13,13 +13,13 @@ namespace obj {
public:
typedef tp::Map<tp::String, obj::TypeGroups*> Dict;
typedef tp::Map<std::string, obj::TypeGroups*> Dict;
TypeGroups();
friend struct obj::objects_api;
TypeGroups(bool is_group);
explicit TypeGroups(bool is_group);
void addType(ObjectType* type, tp::InitialierList<const char*> path, tp::alni cur_arg = 0);
void setType(ObjectType* type);

View file

@ -2,7 +2,7 @@
#pragma once
#include "Buffer.hpp"
#include "Strings.hpp"
#include <string>
namespace obj {
@ -13,19 +13,19 @@ namespace obj {
struct TypeMethod {
enum { MAX_ARGS = 8 };
struct Arg {
const char* descr = NULL;
mutable Object* obj = NULL;
const char* descr = nullptr;
mutable Object* obj = nullptr;
};
const char* nameid = NULL;
const char* descr = NULL;
const char* nameid = nullptr;
const char* descr = nullptr;
mutable Object* self = NULL;
mutable Object* self = nullptr;
Arg args[MAX_ARGS];
tp::int1 mNargs = 0;
void (*exec)(const TypeMethod* tm) = NULL;
void (*exec)(const TypeMethod* tm) = nullptr;
mutable Arg ret;
@ -48,7 +48,7 @@ namespace obj {
operator bool() { return key != -1; }
};
static LookupKey presents(const ObjectType*, tp::String);
static LookupKey presents(const ObjectType*, const std::string&);
static const TypeMethod* getMethod(const ObjectType*, LookupKey);
void init();
@ -56,7 +56,7 @@ namespace obj {
tp::halni nMethods() const;
private:
tp::int2 presents(tp::String) const;
tp::int2 presents(const std::string&) const;
const TypeMethod* getMethod(tp::int2) const;
};

View file

@ -7,7 +7,7 @@
#include "primitives/stringobject.h"
#include "Buffer.hpp"
#include "Strings.hpp"
#include <string>
namespace obj {

View file

@ -17,15 +17,15 @@ namespace obj {
struct CallFrame {
enum { CALL_DEPTH = 1024 };
obj::Object* mSelf = NULL;
obj::MethodObject* mMethod = NULL;
obj::Object* mSelf = nullptr;
obj::MethodObject* mMethod = nullptr;
tp::ualni mIp = 0;
};
void enter(const CallFrame& frame);
void leave();
ByteCode* getBytecode();
tp::halni len() const;
[[nodiscard]] tp::halni len() const;
tp::ConstSizeBuffer<CallFrame, CallFrame::CALL_DEPTH> mStack;
};

View file

@ -10,13 +10,13 @@ namespace obj {
ScopeStack mScopeStack;
CallStack mCallStack;
obj::Object* mLastParent = NULL;
obj::Object* mLastParent = nullptr;
bool mIsTypeMethod = false;
const TypeMethod* mTypeMethod = NULL;
const TypeMethod* mTypeMethod = nullptr;
typedef struct { obj::Object* obj; tp::String id; } GlobalDef;
typedef struct { obj::Object* obj; std::string id; } GlobalDef;
void exec(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList<GlobalDef> globals2 = {});
void exec(obj::MethodObject* method, obj::ClassObject* self = nullptr, obj::DictObject* globals = nullptr, tp::InitialierList<GlobalDef> globals2 = {});
void stepBytecode();
void stepBytecodeIn();
@ -24,6 +24,6 @@ namespace obj {
bool finished();
void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList<GlobalDef> globals2 = {});
void execAll(obj::MethodObject* method, obj::ClassObject* self = nullptr, obj::DictObject* globals = nullptr, tp::InitialierList<GlobalDef> globals2 = {});
};
};

View file

@ -6,7 +6,7 @@
namespace obj {
struct Scope {
typedef tp::Map<tp::String, obj::Object*> ObjDict;
typedef tp::Map<std::string, obj::Object*> ObjDict;
typedef tp::List<obj::Object*> ObjList;
ObjDict mLocals;
@ -31,16 +31,16 @@ namespace obj {
ScopeStack();
void enterScope(bool aChildReachable);
void leaveScope();
void addLocal(obj::Object* local, tp::String id);
void addLocal(obj::Object* local, const std::string& id);
void addTemp(obj::Object* tmp);
void popTemp();
void addTempReturn(obj::Object* ret);
obj::Object* getLocal(tp::String& str);
obj::Object* getLocal(const std::string& str);
Scope* getCurrentScope();
~ScopeStack();
private:
obj::Object* getLocalUtil(Scope& scope, tp::String* id);
obj::Object* getLocalUtil(Scope& scope, const std::string& id);
};
};

View file

@ -12,11 +12,11 @@ namespace obj {
struct Result {
obj::BCgen::StatementScope* scope = nullptr;
bool isError = false;
tp::String description;
std::string description;
tp::halni line = 0;
tp::halni column = 0;
};
Result parse(const tp::String& stream);
Result parse(const std::string& stream);
};
};

View file

@ -16,8 +16,8 @@ namespace obj {
static void from_int(BoolObject* self, tp::alni in);
static void from_float(BoolObject* self, tp::alnf in);
static void from_string(BoolObject* self, tp::String in);
static tp::String to_string(BoolObject* self);
static void from_string(BoolObject* self, const std::string& in);
static std::string to_string(BoolObject* self);
static tp::alni to_int(BoolObject* self);
static tp::alnf to_float(BoolObject* self);
};

View file

@ -16,11 +16,11 @@ namespace obj {
DictObject* members;
void addMember(Object* obj, tp::String id);
void createMember(tp::String type, tp::String id);
void addMember(Object* obj, const std::string& id);
void createMember(const std::string& type, const std::string& id);
template<typename Type>
Type* createMember(tp::String id) {
Type* createMember(const std::string& id) {
auto out = NDO->create(Type::TypeData.name);
addMember(out, id);
NDO->destroy(out);
@ -28,7 +28,7 @@ namespace obj {
}
template<typename Type>
Type* getMember(const tp::String& id) {
Type* getMember(const std::string& id) {
auto idx = members->presents(id);
if (bool(idx)) {
return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData));
@ -37,7 +37,7 @@ namespace obj {
}
template<typename Type>
Type* getMemberAssert(const tp::String& id) {
Type* getMemberAssert(const std::string& id) {
auto out = getMember<Type>(id);
assert(out && "invalid member access");
return out;

View file

@ -17,7 +17,7 @@ namespace obj {
static void from_int(ColorObject* self, tp::alni in);
static void from_float(ColorObject* self, tp::alnf in);
static tp::String to_string(ColorObject* self);
static std::string to_string(ColorObject* self);
static ColorObject* create(tp::RGBA in);
};

View file

@ -17,15 +17,15 @@ namespace obj {
static tp::alni allocated_size(DictObject* self);
static tp::alni allocated_size_recursive(DictObject* self);
void put(tp::String, Object*);
void remove(tp::String);
Object* get(tp::String);
tp::Map<tp::String, Object*>::Idx presents(tp::String);
Object* getSlotVal(tp::Map<tp::String, Object*>::Idx);
void put(const std::string&, Object*);
void remove(const std::string&);
Object* get(const std::string&);
tp::Map<std::string, Object*>::Idx presents(const std::string&);
Object* getSlotVal(tp::Map<std::string, Object*>::Idx);
const tp::Map<tp::String, Object*>& getItems() const;
[[nodiscard]] const tp::Map<std::string, Object*>& getItems() const;
private:
tp::Map<tp::String, Object*> items;
tp::Map<std::string, Object*> items;
};
};

View file

@ -23,8 +23,8 @@ namespace obj {
static void from_int(EnumObject* self, tp::alni in);
static void from_float(EnumObject* self, tp::alnf in);
static void from_string(EnumObject* self, tp::String in);
static tp::String to_string(EnumObject* self);
static void from_string(EnumObject* self, const std::string& in);
static std::string to_string(EnumObject* self);
static tp::alni to_int(EnumObject* self);
static tp::alnf to_float(EnumObject* self);

View file

@ -18,8 +18,8 @@ namespace obj {
static void from_int(FloatObject* self, tp::alni in);
static void from_float(FloatObject* self, tp::alnf in);
static void from_string(FloatObject* self, tp::String in);
static tp::String to_string(FloatObject* self);
static void from_string(FloatObject* self, const std::string& in);
static std::string to_string(FloatObject* self);
static tp::alni to_int(FloatObject* self);
static tp::alnf to_float(FloatObject* self);
};

View file

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

View file

@ -17,8 +17,8 @@ namespace obj {
static void from_int(Object* self, tp::alni in);
static void from_float(Object* self, tp::alnf in);
static void from_string(Object* self, tp::String in);
static tp::String to_string(Object* self);
static void from_string(Object* self, const std::string& in);
static std::string to_string(Object* self);
static tp::alni to_int(Object* self);
static tp::alnf to_float(Object* self);
};

View file

@ -23,7 +23,7 @@ namespace obj {
static void save(ListObject* self, ArchiverOut& file_self);
static tp::alni save_size(ListObject* self);
const tp::List<Object*>& getItems() const;
[[nodiscard]] const tp::List<Object*>& getItems() const;
void pushBack(Object* obj);
void pushFront(Object* obj);

View file

@ -23,6 +23,6 @@ namespace obj {
void compile();
static MethodObject* create(tp::String script);
static MethodObject* create(const std::string& script);
};
};

View file

@ -6,18 +6,18 @@
namespace obj {
struct StringObject : Object {
tp::String val;
std::string val;
static ObjectType TypeData;
static void constructor(Object* self);
static void destructor(StringObject* self);
static void copy(Object* self, const Object* in);
static StringObject* create(tp::String in);
static StringObject* create(const std::string& in);
static void from_int(StringObject* self, tp::alni in);
static void from_float(StringObject* self, tp::alnf in);
static void from_string(StringObject* self, tp::String in);
static tp::String to_string(StringObject* self);
static void from_string(StringObject* self, const std::string& in);
static std::string to_string(StringObject* self);
static tp::alni to_int(StringObject* self);
static tp::alnf to_float(StringObject* self);
};

View file

@ -17,12 +17,12 @@ SUITE(Core) {
integer->val = 10;
printf("%s\n", NDO->toString(integer).read());
printf("%s\n", NDO->toString(integer).c_str());
NDO->save(integer, "tmp.o");
auto savedInt = NDO->load("tmp.o");
printf("%s\n", NDO->toString(savedInt).read());
printf("%s\n", NDO->toString(savedInt).c_str());
CHECK(NDO->compare(integer, savedInt));
CHECK(NDO_CAST(IntObject, savedInt));

View file

@ -13,7 +13,7 @@ SUITE(Parser) {
{
Parser parser;
String stream = "";
std::string stream = "";
auto res = parser.parse(stream);
CHECK(!res.isError);
@ -24,7 +24,7 @@ SUITE(Parser) {
{
Parser parser;
String stream = "var i = true;";
std::string stream = "var i = true;";
auto res = parser.parse(stream);
CHECK(!res.isError);
@ -35,7 +35,7 @@ SUITE(Parser) {
{
Parser parser;
String stream = "var i = true; print (i + 1) * 10;";
std::string stream = "var i = true; print (i + 1) * 10;";
auto res = parser.parse(stream);
CHECK(!res.isError);
@ -51,7 +51,7 @@ SUITE(Parser) {
{
Parser parser;
String stream = "var i = true; print (i + 1) * 10; invalidCharacter ";
std::string stream = "var i = true; print (i + 1) * 10; invalidCharacter ";
auto res = parser.parse(stream);
CHECK(res.isError);

View file

@ -7,6 +7,5 @@ tp::ModuleManifest* objDeps[] = { &obj::gModuleObjects, nullptr };
tp::ModuleManifest objTestModule("ObjectsTests", nullptr, nullptr, objDeps);
#include <UnitTest++/UnitTest++.h>
#include <UnitTest++/TestReporterStdout.h>
int main(int /*argc*/, char** /*argv*/) { return UnitTest::RunAllTests(); }