RIP tp::Strings

This commit is contained in:
IlyaShurupov 2024-03-22 14:44:26 +03:00
parent aa53a4addb
commit 893a07e924
90 changed files with 419 additions and 1475 deletions

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