RIP tp::Strings
This commit is contained in:
parent
aa53a4addb
commit
893a07e924
90 changed files with 419 additions and 1475 deletions
|
|
@ -13,7 +13,6 @@ include(CMakeOptions.txt)
|
||||||
add_subdirectory(Modules)
|
add_subdirectory(Modules)
|
||||||
add_subdirectory(Containers)
|
add_subdirectory(Containers)
|
||||||
add_subdirectory(Math)
|
add_subdirectory(Math)
|
||||||
add_subdirectory(Strings)
|
|
||||||
# add_subdirectory(Language)
|
# add_subdirectory(Language)
|
||||||
add_subdirectory(Externals)
|
add_subdirectory(Externals)
|
||||||
add_subdirectory(Connection)
|
add_subdirectory(Connection)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/)
|
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Strings)
|
target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS})
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS})
|
||||||
|
|
||||||
file(COPY "library" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}")
|
file(COPY "library" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}")
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ using namespace tp;
|
||||||
#define AS_BOOL trackProperty.second.evaluate_as_boolean()
|
#define AS_BOOL trackProperty.second.evaluate_as_boolean()
|
||||||
#define PROP(name) trackProperty.first == #name
|
#define PROP(name) trackProperty.first == #name
|
||||||
|
|
||||||
tp::String getHome() {
|
std::string getHome() {
|
||||||
const char* envVarName = "LIB_VIEW_HOME";
|
const char* envVarName = "LIB_VIEW_HOME";
|
||||||
char* envVarValue = std::getenv(envVarName);
|
char* envVarValue = std::getenv(envVarName);
|
||||||
if (envVarValue != nullptr) {
|
if (envVarValue != nullptr) {
|
||||||
tp::String out;
|
std::string out;
|
||||||
out = (int1*) (std::string(envVarValue) + "/").c_str();
|
out = (int1*) (std::string(envVarValue) + "/").c_str();
|
||||||
return out;
|
return out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -25,11 +25,11 @@ tp::String getHome() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tp::String getSongLocalPath(SongId id) { return getHome() + "tracks/" + tp::String((tp::alni) id); }
|
std::string getSongLocalPath(SongId id) { return getHome() + "tracks/" + std::to_string((tp::alni) id); }
|
||||||
|
|
||||||
SONG_FORMAT getSongFormat(const String& localPath) {
|
SONG_FORMAT getSongFormat(const std::string& localPath) {
|
||||||
std::filesystem::path wavFormat((localPath + ".wav").read());
|
std::filesystem::path wavFormat((localPath + ".wav").c_str());
|
||||||
std::filesystem::path flacFormat((localPath + ".flac").read());
|
std::filesystem::path flacFormat((localPath + ".flac").c_str());
|
||||||
if (std::filesystem::exists(flacFormat)) return SONG_FORMAT::FLAC;
|
if (std::filesystem::exists(flacFormat)) return SONG_FORMAT::FLAC;
|
||||||
if (std::filesystem::exists(wavFormat)) return SONG_FORMAT::WAV;
|
if (std::filesystem::exists(wavFormat)) return SONG_FORMAT::WAV;
|
||||||
return SONG_FORMAT::NONE;
|
return SONG_FORMAT::NONE;
|
||||||
|
|
@ -42,11 +42,11 @@ void Library::checkExisting() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Library::loadJson(const String& path) {
|
bool Library::loadJson(const std::string& path) {
|
||||||
LocalConnection libraryFile;
|
LocalConnection libraryFile;
|
||||||
Buffer<int1> libraryFileMem;
|
Buffer<int1> libraryFileMem;
|
||||||
|
|
||||||
if (!libraryFile.connect(LocalConnection::Location(path.read()), LocalConnection::Type(true))) return false;
|
if (!libraryFile.connect(LocalConnection::Location(path.c_str()), LocalConnection::Type(true))) return false;
|
||||||
|
|
||||||
libraryFileMem.reserve(libraryFile.size());
|
libraryFileMem.reserve(libraryFile.size());
|
||||||
libraryFile.readBytes(libraryFileMem.getBuff(), libraryFile.size());
|
libraryFile.readBytes(libraryFileMem.getBuff(), libraryFile.size());
|
||||||
|
|
@ -56,8 +56,8 @@ bool Library::loadJson(const String& path) {
|
||||||
std::string err = picojson::parse(jsonNode, json);
|
std::string err = picojson::parse(jsonNode, json);
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
printf("Given path - %s\n", path.read());
|
printf("Given path - %s\n", path.c_str());
|
||||||
printf("Home for library is - '%s'. Set it in the env as LIB_VIEW_HOME \n", getHome().read());
|
printf("Home for library is - '%s'. Set it in the env as LIB_VIEW_HOME \n", getHome().c_str());
|
||||||
printf("Error parsing json library file - check your paths and files\n %s \n", err.c_str());
|
printf("Error parsing json library file - check your paths and files\n %s \n", err.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ class Context {
|
||||||
public:
|
public:
|
||||||
Context() = default;
|
Context() = default;
|
||||||
|
|
||||||
bool preloadInfo(const tp::String& path, MusicStream* owner) {
|
bool preloadInfo(const std::string& path, MusicStream* owner) {
|
||||||
mOwner = owner;
|
mOwner = owner;
|
||||||
|
|
||||||
pFlac = drflac_open_file((path + ".flac").read(), NULL);
|
pFlac = drflac_open_file((path + ".flac").c_str(), NULL);
|
||||||
|
|
||||||
if (pFlac == NULL) {
|
if (pFlac == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ namespace tp {
|
||||||
const RectF textAreaName = { textArea.x, textArea.y, textArea.z, textArea.w * 0.5f };
|
const RectF textAreaName = { textArea.x, textArea.y, textArea.z, textArea.w * 0.5f };
|
||||||
const RectF textAreaAuthor = { textArea.x, textArea.y + textArea.w * 0.5f, textArea.z, textArea.w * 0.5f };
|
const RectF textAreaAuthor = { textArea.x, textArea.y + textArea.w * 0.5f, textArea.z, textArea.w * 0.5f };
|
||||||
|
|
||||||
canvas.text(mTrack->mName.read(), textAreaName, 15.f, Canvas::LC, 4.f, { 0.9f, 0.9f, 0.9f, 1.f });
|
canvas.text(mTrack->mName.c_str(), textAreaName, 15.f, Canvas::LC, 4.f, { 0.9f, 0.9f, 0.9f, 1.f });
|
||||||
canvas.text(mTrack->mArtist.read(), textAreaAuthor, 12.f, Canvas::LC, 4.f, { 0.8f, 0.8f, 0.8f, 1.f });
|
canvas.text(mTrack->mArtist.c_str(), textAreaAuthor, 12.f, Canvas::LC, 4.f, { 0.8f, 0.8f, 0.8f, 1.f });
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -70,7 +70,7 @@ namespace tp {
|
||||||
template <typename Events, typename Canvas>
|
template <typename Events, typename Canvas>
|
||||||
class TrackInfoWidget : public Widget<Events, Canvas> {
|
class TrackInfoWidget : public Widget<Events, Canvas> {
|
||||||
struct SortType {
|
struct SortType {
|
||||||
String text;
|
std::string text;
|
||||||
bool dec = false;
|
bool dec = false;
|
||||||
bool inc = false;
|
bool inc = false;
|
||||||
};
|
};
|
||||||
|
|
@ -140,15 +140,15 @@ namespace tp {
|
||||||
|
|
||||||
ImGui::Text("Song Info:");
|
ImGui::Text("Song Info:");
|
||||||
if (mTrack) {
|
if (mTrack) {
|
||||||
ImGui::Text("Name : %s", mTrack->mName.read());
|
ImGui::Text("Name : %s", mTrack->mName.c_str());
|
||||||
ImGui::Text("Author : %s", mTrack->mArtist.read());
|
ImGui::Text("Author : %s", mTrack->mArtist.c_str());
|
||||||
ImGui::Text("Love : %s", mTrack->mLoved ? "true" : "false");
|
ImGui::Text("Love : %s", mTrack->mLoved ? "true" : "false");
|
||||||
ImGui::Text("Id : %lli", mTrack->mId);
|
ImGui::Text("Id : %lli", mTrack->mId);
|
||||||
ImGui::Text("Total Time : %lli", mTrack->mTotalTime);
|
ImGui::Text("Total Time : %lli", mTrack->mTotalTime);
|
||||||
ImGui::Text("Play Count : %lli", mTrack->mPlayCount);
|
ImGui::Text("Play Count : %lli", mTrack->mPlayCount);
|
||||||
ImGui::Text("Skip Count : %lli", mTrack->mSkipCount);
|
ImGui::Text("Skip Count : %lli", mTrack->mSkipCount);
|
||||||
ImGui::Text("Date Added : %s", mTrack->mDateAdded.read());
|
ImGui::Text("Date Added : %s", mTrack->mDateAdded.c_str());
|
||||||
ImGui::Text("Album : %s", mTrack->mAlbum.read());
|
ImGui::Text("Album : %s", mTrack->mAlbum.c_str());
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Not Selected");
|
ImGui::Text("Not Selected");
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +168,7 @@ namespace tp {
|
||||||
sortFilter.Draw("Sorting Type");
|
sortFilter.Draw("Sorting Type");
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); ++i) {
|
for (int i = 0; i < items.size(); ++i) {
|
||||||
if (!sortFilter.PassFilter(items[i].text.read())) continue;
|
if (!sortFilter.PassFilter(items[i].text.c_str())) continue;
|
||||||
|
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
|
|
||||||
|
|
@ -182,7 +182,7 @@ namespace tp {
|
||||||
|
|
||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("%s", items[i].text.read());
|
ImGui::Text("%s", items[i].text.c_str());
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,7 +258,8 @@ namespace tp {
|
||||||
mSongList.mContents.clear();
|
mSongList.mContents.clear();
|
||||||
|
|
||||||
for (auto track : mTracks) {
|
for (auto track : mTracks) {
|
||||||
if (!mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mName.read()) && !mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mArtist.read())) {
|
if (!mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mName.c_str()) &&
|
||||||
|
!mCurrentTrackInfo.songFilter.PassFilter(track->mTrack->mArtist.c_str())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
typedef tp::ualni SongId;
|
typedef tp::ualni SongId;
|
||||||
enum class SONG_FORMAT { WAV, FLAC, NONE };
|
enum class SONG_FORMAT { WAV, FLAC, NONE };
|
||||||
|
|
||||||
tp::String getHome();
|
std::string getHome();
|
||||||
tp::String getSongLocalPath(SongId id);
|
std::string getSongLocalPath(SongId id);
|
||||||
SONG_FORMAT getSongFormat(const tp::String& path);
|
SONG_FORMAT getSongFormat(const std::string& path);
|
||||||
|
|
||||||
class Track {
|
class Track {
|
||||||
public:
|
public:
|
||||||
|
|
@ -16,23 +15,23 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SongId mId = 0;
|
SongId mId = 0;
|
||||||
tp::String mName = "undef";
|
std::string mName = "undef";
|
||||||
tp::String mArtist = "undef";
|
std::string mArtist = "undef";
|
||||||
tp::String mAlbumArtist = "undef";
|
std::string mAlbumArtist = "undef";
|
||||||
tp::String mComposer = "undef";
|
std::string mComposer = "undef";
|
||||||
tp::String mAlbum = "undef";
|
std::string mAlbum = "undef";
|
||||||
tp::String mGenre = "undef";
|
std::string mGenre = "undef";
|
||||||
tp::ualni mSize = 0;
|
tp::ualni mSize = 0;
|
||||||
tp::ualni mTotalTime = 0;
|
tp::ualni mTotalTime = 0;
|
||||||
tp::ualni mYear = 0;
|
tp::ualni mYear = 0;
|
||||||
tp::String mDateModified = "undef";
|
std::string mDateModified = "undef";
|
||||||
tp::String mDateAdded = "undef";
|
std::string mDateAdded = "undef";
|
||||||
tp::ualni mPlayCount = 0;
|
tp::ualni mPlayCount = 0;
|
||||||
tp::String mPlayDate = "undef";
|
std::string mPlayDate = "undef";
|
||||||
tp::String mPlayDateUTC = "undef";
|
std::string mPlayDateUTC = "undef";
|
||||||
tp::ualni mSkipCount = 0;
|
tp::ualni mSkipCount = 0;
|
||||||
tp::String mSkipDate = "undef";
|
std::string mSkipDate = "undef";
|
||||||
tp::String mReleaseDate = "undef";
|
std::string mReleaseDate = "undef";
|
||||||
tp::ualni mAlbumRating = 0;
|
tp::ualni mAlbumRating = 0;
|
||||||
bool mAlbumRatingComputed = false;
|
bool mAlbumRatingComputed = false;
|
||||||
bool mLoved = false;
|
bool mLoved = false;
|
||||||
|
|
@ -46,7 +45,7 @@ public:
|
||||||
Library() = default;
|
Library() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool loadJson(const tp::String& path);
|
bool loadJson(const std::string& path);
|
||||||
void checkExisting();
|
void checkExisting();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -45,4 +45,5 @@ namespace tp {
|
||||||
ualni hash(halni bytes) { return hash(alni(bytes)); }
|
ualni hash(halni bytes) { return hash(alni(bytes)); }
|
||||||
ualni hash(uhalni bytes) { return hash(alni(bytes)); }
|
ualni hash(uhalni bytes) { return hash(alni(bytes)); }
|
||||||
ualni hash(ualni bytes) { return hash(alni(bytes)); }
|
ualni hash(ualni bytes) { return hash(alni(bytes)); }
|
||||||
|
ualni hash(const std::string& in) { return hash(in.c_str()); }
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +51,8 @@ namespace tp {
|
||||||
// check if type has explicit write method. if not write as bytes
|
// check if type has explicit write method. if not write as bytes
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void operator<<(const Type& val) {
|
void operator<<(const Type& val) {
|
||||||
|
static_assert(!std::is_same<Type, std::string>::value);
|
||||||
|
|
||||||
static_assert(!tRead);
|
static_assert(!tRead);
|
||||||
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
||||||
if constexpr (HasFunc::template Write<Type>::value) {
|
if constexpr (HasFunc::template Write<Type>::value) {
|
||||||
|
|
@ -63,6 +65,8 @@ namespace tp {
|
||||||
// check if type has explicit read method. if not read as bytes
|
// check if type has explicit read method. if not read as bytes
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void operator>>(Type& val) {
|
void operator>>(Type& val) {
|
||||||
|
static_assert(!std::is_same<Type, std::string>::value);
|
||||||
|
|
||||||
static_assert(tRead);
|
static_assert(tRead);
|
||||||
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
||||||
if constexpr (HasFunc::template Read<Type>::value) {
|
if constexpr (HasFunc::template Read<Type>::value) {
|
||||||
|
|
@ -75,6 +79,8 @@ namespace tp {
|
||||||
// check if type has explicit archive method. if not read/write as bytes
|
// check if type has explicit archive method. if not read/write as bytes
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void operator%(Type& val) {
|
void operator%(Type& val) {
|
||||||
|
static_assert(!std::is_same<Type, std::string>::value);
|
||||||
|
|
||||||
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
||||||
if constexpr (HasFunc::template Archive<Type>::value) {
|
if constexpr (HasFunc::template Archive<Type>::value) {
|
||||||
val.archive(*this);
|
val.archive(*this);
|
||||||
|
|
@ -89,6 +95,8 @@ namespace tp {
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void operator%(const Type& val) {
|
void operator%(const Type& val) {
|
||||||
|
static_assert(!std::is_same<Type, std::string>::value);
|
||||||
|
|
||||||
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
static_assert(HasFunc::template AssertCombinations<Type>::assert());
|
||||||
if constexpr (HasFunc::template Archive<Type>::value) {
|
if constexpr (HasFunc::template Archive<Type>::value) {
|
||||||
((Type&) val).archive(*this);
|
((Type&) val).archive(*this);
|
||||||
|
|
@ -132,29 +140,4 @@ namespace tp {
|
||||||
ualni mAddress = 0;
|
ualni mAddress = 0;
|
||||||
ualni mFirstNotWritten = 0;
|
ualni mFirstNotWritten = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StringArchiver {
|
|
||||||
std::string* val;
|
|
||||||
|
|
||||||
StringArchiver(std::string& val) { this->val = &val; }
|
|
||||||
|
|
||||||
template <typename tArchiver>
|
|
||||||
void archiveRead(tArchiver& ar) {
|
|
||||||
ualni len;
|
|
||||||
ar >> len;
|
|
||||||
val->resize(len);
|
|
||||||
for (ualni i = 0; i < len; i++) {
|
|
||||||
ar >> (*val)[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename tArchiver>
|
|
||||||
void archiveWrite(tArchiver& ar) const {
|
|
||||||
ualni len = val->size();
|
|
||||||
ar << len;
|
|
||||||
for (ualni i = 0; i < len; i++) {
|
|
||||||
ar << (*val)[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace tp {
|
namespace tp {
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
|
|
@ -49,6 +50,7 @@ namespace tp {
|
||||||
ualni hash(uhalni bytes);
|
ualni hash(uhalni bytes);
|
||||||
ualni hash(ualni bytes);
|
ualni hash(ualni bytes);
|
||||||
ualni hash(alnf bytes);
|
ualni hash(alnf bytes);
|
||||||
|
ualni hash(const std::string& in);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T clamp(T v, T l, T u) {
|
T clamp(T v, T l, T u) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE})
|
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)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC USERDATA_DESTROY_FAILED_TREE_ROOTS)
|
||||||
|
|
||||||
### -------------------------- Applications -------------------------- ###
|
### -------------------------- Applications -------------------------- ###
|
||||||
|
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -121,14 +121,14 @@ obj::Object* imgui_object_create_menu(obj::TypeGroups* type_group = NULL) {
|
||||||
for (auto childo : *type_group->getChilds()) {
|
for (auto childo : *type_group->getChilds()) {
|
||||||
|
|
||||||
if (childo->val->isGroup()) {
|
if (childo->val->isGroup()) {
|
||||||
if (ImGui::BeginMenu((childo->key).read())) {
|
if (ImGui::BeginMenu((childo->key).c_str())) {
|
||||||
newo = imgui_object_create_menu(childo->val);
|
newo = imgui_object_create_menu(childo->val);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button((childo->key).read(), { 100, 0 })) {
|
if (ImGui::Button((childo->key).c_str(), { 100, 0 })) {
|
||||||
if (childo->key == "null") {
|
if (childo->key == "null") {
|
||||||
newo = NDO_NULL;
|
newo = NDO_NULL;
|
||||||
} else {
|
} 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"); }
|
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;
|
mActive = child;
|
||||||
mViewStack.pushBack({ mActive, name });
|
mViewStack.pushBack({ mActive, name });
|
||||||
obj::NDO->refinc(child);
|
obj::NDO->refinc(child);
|
||||||
|
|
@ -198,8 +198,8 @@ void obj::ObjectsGUI::preview(obj::Object* obj) {
|
||||||
NDO_CASTV(obj::StringObject, obj, stringo);
|
NDO_CASTV(obj::StringObject, obj, stringo);
|
||||||
static char val[2048] = { " " };
|
static char val[2048] = { " " };
|
||||||
if (stringo->val != val) {
|
if (stringo->val != val) {
|
||||||
assert(tp::String::Logic::calcLength(stringo->val.read()) < 2048);
|
assert(stringo->val.size() < 2048);
|
||||||
tp::memCopy(val, stringo->val.read(), stringo->val.size() + 1);
|
tp::memCopy(val, stringo->val.c_str(), stringo->val.size() + 1);
|
||||||
}
|
}
|
||||||
ImGui::InputText("", val, 2048);
|
ImGui::InputText("", val, 2048);
|
||||||
if (stringo->val != val) {
|
if (stringo->val != val) {
|
||||||
|
|
@ -301,7 +301,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
|
||||||
}
|
}
|
||||||
|
|
||||||
// INFO
|
// 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) {
|
if (hd) {
|
||||||
Text(info.desc);
|
Text(info.desc);
|
||||||
if (info.operands.len) {
|
if (info.operands.len) {
|
||||||
|
|
@ -365,20 +365,20 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
|
||||||
Begin("ScopeStack");
|
Begin("ScopeStack");
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < interp.mScopeStack.mIdx; i++) {
|
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];
|
auto& scope = interp.mScopeStack.mBuff[i];
|
||||||
|
|
||||||
if (TreeNode("Locals")) {
|
if (TreeNode("Locals")) {
|
||||||
for (auto local : scope.mLocals) {
|
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();
|
||||||
TreePop();
|
TreePop();
|
||||||
End();
|
End();
|
||||||
return { local->val, local->key };
|
return { local->val, local->key };
|
||||||
}
|
}
|
||||||
|
|
||||||
PushID(local->key.read());
|
PushID(local->key.c_str());
|
||||||
SameLine();
|
SameLine();
|
||||||
preview(local->val);
|
preview(local->val);
|
||||||
PopID();
|
PopID();
|
||||||
|
|
@ -389,7 +389,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
|
||||||
if (TreeNode("Temps")) {
|
if (TreeNode("Temps")) {
|
||||||
tp::alni idx = 0;
|
tp::alni idx = 0;
|
||||||
for (auto tmp : scope.mTemps) {
|
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();
|
||||||
TreePop();
|
TreePop();
|
||||||
End();
|
End();
|
||||||
|
|
@ -429,7 +429,7 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::interpreterView(obj::Interpreter
|
||||||
if (Button(const_obj.data()->type->name)) {
|
if (Button(const_obj.data()->type->name)) {
|
||||||
End();
|
End();
|
||||||
PopID();
|
PopID();
|
||||||
return { const_obj.data(), tp::String(idx) };
|
return { const_obj.data(), std::to_string(idx) };
|
||||||
}
|
}
|
||||||
SameLine();
|
SameLine();
|
||||||
preview(const_obj.data());
|
preview(const_obj.data());
|
||||||
|
|
@ -531,11 +531,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) {
|
||||||
if (mClipboard) {
|
if (mClipboard) {
|
||||||
if (ImGui::Selectable("Paste")) {
|
if (ImGui::Selectable("Paste")) {
|
||||||
tp::alni idx = 1;
|
tp::alni idx = 1;
|
||||||
tp::String name_base = tp::String("clipboard ") + tp::String(mClipboard->type->name) + tp::String(" ");
|
auto name_base = std::string("clipboard ") + std::string(mClipboard->type->name) + " ";
|
||||||
tp::String name_out = name_base;
|
auto name_out = name_base;
|
||||||
|
|
||||||
while (dict->presents(name_out)) {
|
while (dict->presents(name_out)) {
|
||||||
name_out = name_base + tp::String(idx);
|
name_out = name_base + std::to_string(idx);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -549,11 +549,11 @@ void obj::ObjectsGUI::dictViewDrawCreate(obj::DictObject* dict) {
|
||||||
|
|
||||||
if (newo) {
|
if (newo) {
|
||||||
tp::alni idx = 1;
|
tp::alni idx = 1;
|
||||||
tp::String name_base = tp::String("new ") + tp::String(newo->type->name) + tp::String(" ");
|
auto name_base = std::string("new ") + std::string(newo->type->name) + " ";
|
||||||
tp::String name_out = name_base;
|
auto name_out = name_base;
|
||||||
|
|
||||||
while (dict->presents(name_out)) {
|
while (dict->presents(name_out)) {
|
||||||
name_out = name_base + tp::String(idx);
|
name_out = name_base + std::to_string(idx);
|
||||||
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) {
|
void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, const std::string& key, obj::Object* obj, bool& popup) {
|
||||||
if (ImGui::BeginPopupContextItem(key.read(), ImGuiPopupFlags_MouseButtonRight)) {
|
if (ImGui::BeginPopupContextItem(key.c_str(), ImGuiPopupFlags_MouseButtonRight)) {
|
||||||
popup = true;
|
popup = true;
|
||||||
|
|
||||||
ImGui::Text("%s at %x", obj->type->name, obj);
|
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 {
|
} else {
|
||||||
|
|
||||||
if (mLastNameEditObject != obj) {
|
if (mLastNameEditObject != obj) {
|
||||||
tp::memCopy(mNameEdit, key.read(), key.size() + 1);
|
tp::memCopy(mNameEdit, key.c_str(), key.size() + 1);
|
||||||
mLastNameEditObject = obj;
|
mLastNameEditObject = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -589,7 +589,7 @@ void obj::ObjectsGUI::dictViewEdit(obj::DictObject* dict, tp::String key, obj::O
|
||||||
} else {
|
} else {
|
||||||
obj::NDO->refinc(obj);
|
obj::NDO->refinc(obj);
|
||||||
dict->remove(key);
|
dict->remove(key);
|
||||||
auto id = tp::String(mNameEdit);
|
auto id = std::string(mNameEdit);
|
||||||
dict->put(id, obj);
|
dict->put(id, obj);
|
||||||
obj::NDO->destroy(obj);
|
obj::NDO->destroy(obj);
|
||||||
}
|
}
|
||||||
|
|
@ -626,16 +626,16 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::dictView(obj::DictObject* obj) {
|
||||||
ImGui::TableNextRow(0, 30);
|
ImGui::TableNextRow(0, 30);
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
|
||||||
if (ImGui::Selectable(childo->key.read())) {
|
if (ImGui::Selectable(childo->key.c_str())) {
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
ImGui::EndChild();
|
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);
|
dictViewEdit(obj, childo->key, childo->val, popup);
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
ImGui::TableSetColumnIndex(1);
|
||||||
ImGui::PushID((int) childo->key.read()[0]);
|
ImGui::PushID((int) childo->key.c_str()[0]);
|
||||||
preview(childo->val);
|
preview(childo->val);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
@ -670,13 +670,13 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::listView(obj::ListObject* obj) {
|
||||||
ImGui::TableNextRow(0, 36);
|
ImGui::TableNextRow(0, 36);
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
if (ImGui::Selectable(tp::String(idx).read())) {
|
if (ImGui::Selectable(std::to_string(idx).c_str())) {
|
||||||
out = ViewStackNode(childo.data(), { tp::String(childo->type->name) + tp::String("at") + tp::String(idx) });
|
out = ViewStackNode(childo.data(), { std::string(childo->type->name) + "at" + std::to_string(idx) });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if (ImGui::BeginPopupContextItem(tp::String(idx).read(), ImGuiPopupFlags_MouseButtonRight)) {
|
if (ImGui::BeginPopupContextItem(std::to_string(idx).c_str(), ImGuiPopupFlags_MouseButtonRight)) {
|
||||||
popup = true;
|
popup = true;
|
||||||
|
|
||||||
ImGui::Text("%s at %x", childo->type->name, childo.data());
|
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;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawStrView(tp::String& in) {
|
void drawStrView(std::string& in) {
|
||||||
static char val[2048] = { " " };
|
static char val[2048] = { " " };
|
||||||
|
|
||||||
if (in != val) {
|
if (in != val) {
|
||||||
assert(tp::String::Logic::calcLength(in.read()) < 2048);
|
assert(in.size() < 2048);
|
||||||
tp::memCopy(val, in.read(), in.size() + 1);
|
tp::memCopy(val, in.c_str(), in.size() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::BeginChild("str_edit");
|
ImGui::BeginChild("str_edit");
|
||||||
|
|
@ -800,11 +800,11 @@ obj::ObjectsGUI::ViewStackNode obj::ObjectsGUI::classView(obj::ClassObject* self
|
||||||
ImGui::TableNextRow(0, 30);
|
ImGui::TableNextRow(0, 30);
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
|
||||||
if (ImGui::Selectable(childo->key.read())) {
|
if (ImGui::Selectable(childo->key.c_str())) {
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
ImGui::EndChild();
|
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);
|
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)) {
|
if (n_methods && ImGui::TreeNodeBehavior(window->GetID("Methods"), tree_flags, "Methods", 0)) {
|
||||||
for (auto childo : dict->getItems()) {
|
for (auto childo : dict->getItems()) {
|
||||||
if (childo->val->type == &obj::MethodObject::TypeData) {
|
if (childo->val->type == &obj::MethodObject::TypeData) {
|
||||||
if (ImGui::Selectable(childo->key.read())) {
|
if (ImGui::Selectable(childo->key.c_str())) {
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
ImGui::EndChild();
|
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);
|
dictViewEdit(dict, childo->key, childo->val, popup);
|
||||||
}
|
}
|
||||||
|
|
@ -896,10 +896,10 @@ void obj::ObjectsGUI::explorer() {
|
||||||
ImGui::PushID((int) idx);
|
ImGui::PushID((int) idx);
|
||||||
bool go_back = false;
|
bool go_back = false;
|
||||||
if (childo == rev_path.last()) {
|
if (childo == rev_path.last()) {
|
||||||
go_back = ImGui::Button(childo->data->id.read());
|
go_back = ImGui::Button(childo->data->id.c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
} else {
|
} else {
|
||||||
go_back = ImGui::Button((childo->data->id).read());
|
go_back = ImGui::Button((childo->data->id).c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "compiler/function.h"
|
#include "compiler/function.h"
|
||||||
|
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
|
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
|
|
@ -18,9 +18,9 @@ namespace obj {
|
||||||
|
|
||||||
struct ViewStackNode {
|
struct ViewStackNode {
|
||||||
obj::Object* obj;
|
obj::Object* obj;
|
||||||
tp::String id;
|
std::string id;
|
||||||
ViewStackNode() { obj = NULL; }
|
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; }
|
operator bool() { return obj; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace obj {
|
||||||
ObjectsGUI();
|
ObjectsGUI();
|
||||||
~ObjectsGUI();
|
~ObjectsGUI();
|
||||||
|
|
||||||
void cd(obj::Object* child, tp::String name);
|
void cd(obj::Object* child, const std::string& name);
|
||||||
void cdup();
|
void cdup();
|
||||||
|
|
||||||
void clearEvents();
|
void clearEvents();
|
||||||
|
|
@ -67,7 +67,7 @@ namespace obj {
|
||||||
ViewStackNode methodView(obj::MethodObject* in);
|
ViewStackNode methodView(obj::MethodObject* in);
|
||||||
ViewStackNode colorView(obj::ColorObject* in);
|
ViewStackNode colorView(obj::ColorObject* in);
|
||||||
ViewStackNode interpreterView(obj::InterpreterObject* 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);
|
void dictViewDrawCreate(obj::DictObject* dict);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
@ -60,7 +60,7 @@ ConstObject* ConstObjectsPool::get(tp::alni val) {
|
||||||
return const_obj;
|
return const_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstObject* ConstObjectsPool::get(tp::String val) {
|
ConstObject* ConstObjectsPool::get(const std::string& val) {
|
||||||
auto idx = mStrings.presents(val);
|
auto idx = mStrings.presents(val);
|
||||||
ConstObject* const_obj = NULL;
|
ConstObject* const_obj = NULL;
|
||||||
if (idx) {
|
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(NDO_CAST(MethodObject, method) && "Object is not a method object");
|
||||||
ASSERT(!mMethods.presents(method_id) && "Method Redefinition");
|
ASSERT(!mMethods.presents(method_id) && "Method Redefinition");
|
||||||
auto out = registerObject(method);
|
auto out = registerObject(method);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using namespace BCgen;
|
||||||
Expression::Expression(Type type) :
|
Expression::Expression(Type type) :
|
||||||
mType(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); }
|
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),
|
Expression(Type::NEW),
|
||||||
mNewType(type) {}
|
mNewType(type) {}
|
||||||
|
|
||||||
ExpressionNew::~ExpressionNew() = default;
|
ExpressionNew::~ExpressionNew() = default;
|
||||||
|
|
||||||
ExpressionLocal::ExpressionLocal(const tp::String& id) :
|
ExpressionLocal::ExpressionLocal(const std::string& id) :
|
||||||
Expression(Type::LOCAL),
|
Expression(Type::LOCAL),
|
||||||
mLocalId(id) {}
|
mLocalId(id) {}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ ExpressionLocal::~ExpressionLocal() = default;
|
||||||
ExpressionSelf::ExpressionSelf() :
|
ExpressionSelf::ExpressionSelf() :
|
||||||
Expression(Type::SELF) {}
|
Expression(Type::SELF) {}
|
||||||
|
|
||||||
ExpressionChild::ExpressionChild(Expression* mParent, const tp::String& id) :
|
ExpressionChild::ExpressionChild(Expression* mParent, const std::string& id) :
|
||||||
Expression(Type::CHILD),
|
Expression(Type::CHILD),
|
||||||
mParent(mParent),
|
mParent(mParent),
|
||||||
mLocalId(id) {}
|
mLocalId(id) {}
|
||||||
|
|
@ -79,13 +79,13 @@ ExpressionArithmetics::~ExpressionArithmetics() {
|
||||||
delete mRight;
|
delete mRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionFunc::ExpressionFunc(const tp::String& id) :
|
ExpressionFunc::ExpressionFunc(const std::string& id) :
|
||||||
Expression(Type::FUNC),
|
Expression(Type::FUNC),
|
||||||
mFuncId(id) {}
|
mFuncId(id) {}
|
||||||
|
|
||||||
ExpressionFunc::~ExpressionFunc() = default;
|
ExpressionFunc::~ExpressionFunc() = default;
|
||||||
|
|
||||||
ExpressionConst::ExpressionConst(const tp::String& val) :
|
ExpressionConst::ExpressionConst(const std::string& val) :
|
||||||
Expression(Type::CONST_EXPR),
|
Expression(Type::CONST_EXPR),
|
||||||
mConstType(STR),
|
mConstType(STR),
|
||||||
str(val) {}
|
str(val) {}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
#include "primitives/methodobject.h"
|
#include "primitives/methodobject.h"
|
||||||
#include "primitives/primitives.h"
|
#include "primitives/primitives.h"
|
||||||
|
|
||||||
#include "Logging.hpp"
|
|
||||||
|
|
||||||
#include "parser/parser.h"
|
#include "parser/parser.h"
|
||||||
|
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
@ -27,7 +25,7 @@ void obj::BCgen::Genereate(ByteCode& out, StatementScope* body) {
|
||||||
root.generateByteCode(out);
|
root.generateByteCode(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstObject* FunctionDefinition::defineLocal(tp::String id) {
|
ConstObject* FunctionDefinition::defineLocal(const std::string& id) {
|
||||||
auto idx = mLocals.presents(id);
|
auto idx = mLocals.presents(id);
|
||||||
// RelAssert(!idx && "Local Redefinition");
|
// RelAssert(!idx && "Local Redefinition");
|
||||||
auto const_str_id = mConstants.get(id);
|
auto const_str_id = mConstants.get(id);
|
||||||
|
|
@ -35,7 +33,7 @@ ConstObject* FunctionDefinition::defineLocal(tp::String id) {
|
||||||
return const_str_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;
|
mFunctionId = function_id;
|
||||||
inst(Instruction(OpCode::SAVE_ARGS, args.size(), 1));
|
inst(Instruction(OpCode::SAVE_ARGS, args.size(), 1));
|
||||||
for (auto id : args) {
|
for (auto id : args) {
|
||||||
|
|
@ -190,7 +188,7 @@ void FunctionDefinition::EvalStatement(Statement* stm) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
tp::String type;
|
std::string type;
|
||||||
switch (stm_local_def->mConstExpr->mConstType) {
|
switch (stm_local_def->mConstExpr->mConstType) {
|
||||||
case ExpressionConst::BOOL:
|
case ExpressionConst::BOOL:
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
using namespace BCgen;
|
using namespace BCgen;
|
||||||
|
|
||||||
StatementFuncDef::StatementFuncDef(const tp::String& function_id) :
|
StatementFuncDef::StatementFuncDef(const std::string& function_id) :
|
||||||
Statement(Type::DEF_FUNC) {
|
Statement(Type::DEF_FUNC) {
|
||||||
mFunctionId = function_id;
|
mFunctionId = function_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementFuncDef::~StatementFuncDef() { delete mStatements; }
|
StatementFuncDef::~StatementFuncDef() { delete mStatements; }
|
||||||
|
|
||||||
StatementLocalDef::StatementLocalDef(const tp::String& id, Expression* value) :
|
StatementLocalDef::StatementLocalDef(const std::string& id, Expression* value) :
|
||||||
mLocalId(id),
|
mLocalId(id),
|
||||||
Statement(Type::DEF_LOCAL) {
|
Statement(Type::DEF_LOCAL) {
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ StatementIgnore::StatementIgnore(Expression* expr) :
|
||||||
|
|
||||||
StatementIgnore::~StatementIgnore() { delete mExpr; }
|
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) {
|
Statement(Type::CLASS_DEF) {
|
||||||
mClassId = class_id;
|
mClassId = class_id;
|
||||||
mScope = scope;
|
mScope = scope;
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,6 @@ static void deinit(const tp::ModuleManifest*) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static tp::ModuleManifest* sModuleDependencies[] = {
|
static tp::ModuleManifest* sModuleDependencies[] = {
|
||||||
// &tp::gModuleCompressor,
|
|
||||||
&tp::gModuleStrings,
|
|
||||||
nullptr
|
nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,29 @@
|
||||||
|
|
||||||
namespace obj {
|
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);
|
Object* ObjectMemAllocate(const ObjectType* type);
|
||||||
void ObjectMemDeallocate(Object* in);
|
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_copy(Object* self, const Object* in, const ObjectType* type);
|
||||||
void hierarchy_construct(Object* self, const ObjectType* type);
|
void hierarchy_construct(Object* self, const ObjectType* type);
|
||||||
|
|
@ -36,7 +55,7 @@ namespace obj {
|
||||||
type->type_methods.init();
|
type->type_methods.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* objects_api::create(const tp::String& name) {
|
Object* objects_api::create(const std::string& name) {
|
||||||
MODULE_SANITY_CHECK(gModuleObjects);
|
MODULE_SANITY_CHECK(gModuleObjects);
|
||||||
|
|
||||||
const ObjectType* type = types.get(name);
|
const ObjectType* type = types.get(name);
|
||||||
|
|
@ -44,7 +63,7 @@ namespace obj {
|
||||||
Object* obj_instance = ObjectMemAllocate(type);
|
Object* obj_instance = ObjectMemAllocate(type);
|
||||||
|
|
||||||
if (!obj_instance) {
|
if (!obj_instance) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hierarchy_construct(obj_instance, obj_instance->type);
|
hierarchy_construct(obj_instance, obj_instance->type);
|
||||||
|
|
@ -69,7 +88,7 @@ namespace obj {
|
||||||
|
|
||||||
Object* objects_api::copy(Object* self, const Object* in) {
|
Object* objects_api::copy(Object* self, const Object* in) {
|
||||||
if (self->type != in->type) {
|
if (self->type != in->type) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hierarchy_copy(self, in, self->type);
|
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) {
|
if (self->type->convesions && self->type->convesions->from_string) {
|
||||||
self->type->convesions->from_string(self, val);
|
self->type->convesions->from_string(self, val);
|
||||||
return;
|
return;
|
||||||
|
|
@ -134,7 +153,7 @@ namespace obj {
|
||||||
return true;
|
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);
|
DEBUG_ASSERT(self->type->convesions && self->type->convesions->to_string);
|
||||||
return self->type->convesions->to_string(self);
|
return self->type->convesions->to_string(self);
|
||||||
}
|
}
|
||||||
|
|
@ -217,6 +236,6 @@ namespace obj {
|
||||||
}
|
}
|
||||||
typeiter = typeiter->base;
|
typeiter = typeiter->base;
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ namespace obj {
|
||||||
|
|
||||||
ObjectsFileHeader(bool default_val = true) {
|
ObjectsFileHeader(bool default_val = true) {
|
||||||
if (default_val) {
|
if (default_val) {
|
||||||
tp::memCopy(&name, "objects", tp::String::Logic::calcLength("objects") + 1);
|
tp::memCopy(&name, "objects", 8);
|
||||||
tp::memCopy(&version, "0", tp::String::Logic::calcLength("0") + 1);
|
tp::memCopy(&version, "0", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -26,10 +26,10 @@ namespace obj {
|
||||||
Object* ObjectMemAllocate(const ObjectType* type) {
|
Object* ObjectMemAllocate(const ObjectType* type) {
|
||||||
ObjectMemHead* memh = (ObjectMemHead*) malloc(type->size + sizeof(ObjectMemHead));
|
ObjectMemHead* memh = (ObjectMemHead*) malloc(type->size + sizeof(ObjectMemHead));
|
||||||
if (!memh) {
|
if (!memh) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
memh->down = NULL;
|
memh->down = nullptr;
|
||||||
memh->flags = 0;
|
memh->flags = 0;
|
||||||
|
|
||||||
memh->refc = (tp::alni) 1;
|
memh->refc = (tp::alni) 1;
|
||||||
|
|
@ -235,10 +235,11 @@ namespace obj {
|
||||||
// save file object header
|
// save file object header
|
||||||
ObjectFileHead ofh = { 0, getrefc(in) };
|
ObjectFileHead ofh = { 0, getrefc(in) };
|
||||||
ndf << ofh;
|
ndf << ofh;
|
||||||
ndf << tp::String(in->type->name);
|
|
||||||
|
save_string(ndf, in->type->name);
|
||||||
|
|
||||||
// allocate for object file header
|
// 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
|
// calc max size needed for saving all hierarchy of types
|
||||||
tp::alni file_alloc_size = objsize_file_util(in, in->type);
|
tp::alni file_alloc_size = objsize_file_util(in, in->type);
|
||||||
|
|
@ -281,14 +282,14 @@ namespace obj {
|
||||||
ObjectFileHead ofh;
|
ObjectFileHead ofh;
|
||||||
ndf >> ofh;
|
ndf >> ofh;
|
||||||
|
|
||||||
tp::String type_name;
|
std::string type_name;
|
||||||
ndf >> type_name;
|
load_string(ndf, type_name);
|
||||||
|
|
||||||
const ObjectType* object_type = NDO->types.get(type_name);
|
const ObjectType* object_type = NDO->types.get(type_name);
|
||||||
Object* out = ObjectMemAllocate(object_type);
|
Object* out = ObjectMemAllocate(object_type);
|
||||||
|
|
||||||
if (!out) {
|
if (!out) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
setrefc(out, 0);
|
setrefc(out, 0);
|
||||||
|
|
@ -312,8 +313,8 @@ namespace obj {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool objects_api::save(Object* in, tp::String path, bool compressed) {
|
bool objects_api::save(Object* in, const std::string& path, bool compressed) {
|
||||||
ArchiverOut ndf(path.read());
|
ArchiverOut ndf(path.c_str());
|
||||||
|
|
||||||
if (!ndf.isOpened()) {
|
if (!ndf.isOpened()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -365,22 +366,22 @@ namespace obj {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* objects_api::load(tp::String path) {
|
Object* objects_api::load(const std::string& path) {
|
||||||
/*
|
/*
|
||||||
auto temp_file_name = path + ".unz";
|
auto temp_file_name = path + ".unz";
|
||||||
bool unz_res = tp::decompressF2F(path.cstr(), temp_file_name.cstr());
|
bool unz_res = tp::decompressF2F(path.cstr(), temp_file_name.cstr());
|
||||||
|
|
||||||
if (!unz_res) {
|
if (!unz_res) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD);
|
File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ArchiverIn ndf(path.read());
|
ArchiverIn ndf(path.c_str());
|
||||||
|
|
||||||
if (!ndf.isOpened()) {
|
if (!ndf.isOpened()) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for compatibility
|
// check for compatibility
|
||||||
|
|
@ -390,7 +391,7 @@ namespace obj {
|
||||||
ndf >> loaded_header;
|
ndf >> loaded_header;
|
||||||
|
|
||||||
if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) {
|
if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndf.setAddress(0);
|
ndf.setAddress(0);
|
||||||
|
|
@ -423,7 +424,7 @@ namespace obj {
|
||||||
/*
|
/*
|
||||||
ndf.close();
|
ndf.close();
|
||||||
|
|
||||||
if (unz_res == NULL) {
|
if (unz_res == nullptr) {
|
||||||
File::remove(temp_file_name.cstr());
|
File::remove(temp_file_name.cstr());
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
||||||
ScriptSection* gScriptSection = NULL;
|
ScriptSection* gScriptSection = nullptr;
|
||||||
|
|
||||||
struct script_data_head {
|
struct script_data_head {
|
||||||
tp::alni refc = 0;
|
tp::alni refc = 0;
|
||||||
|
|
@ -19,7 +19,7 @@ Script* ScriptSection::createScript() {
|
||||||
auto out = (Script*) (sdhead + 1);
|
auto out = (Script*) (sdhead + 1);
|
||||||
|
|
||||||
if (!sdhead) {
|
if (!sdhead) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdhead->refc = 1;
|
sdhead->refc = 1;
|
||||||
|
|
@ -215,7 +215,7 @@ Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) {
|
||||||
return iter.data();
|
return iter.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptSection::~ScriptSection() {
|
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,
|
.pre_save = (obj::pre_save_callback*) ScriptSection::save_script_table_to_file,
|
||||||
.size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size,
|
.size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size,
|
||||||
.pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file,
|
.pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file,
|
||||||
.post_save = NULL,
|
.post_save = nullptr,
|
||||||
.post_load = NULL,
|
.post_load = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
void ScriptSection::initialize() {
|
void ScriptSection::initialize() {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ obj::TypeGroups::TypeGroups(bool is_group) :
|
||||||
if (is_group) {
|
if (is_group) {
|
||||||
new (&childs) Dict();
|
new (&childs) Dict();
|
||||||
} else {
|
} else {
|
||||||
type = NULL;
|
type = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList<const char*>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeGroups* group = NULL;
|
TypeGroups* group = nullptr;
|
||||||
tp::alni index = 0;
|
tp::alni index = 0;
|
||||||
|
|
||||||
for (auto dir : path) {
|
for (auto dir : path) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
||||||
.nameid = "type",
|
.nameid = "type",
|
||||||
.descr = "retrieves typeobject",
|
.descr = "retrieves typeobject",
|
||||||
.exec = [](const TypeMethod* tm) { tm->ret.obj = TypeObject::create(tm->self->type); },
|
.exec = [](const TypeMethod* tm) { tm->ret.obj = TypeObject::create(tm->self->type); },
|
||||||
.ret = { "typeobject", NULL },
|
.ret = { "typeobject", nullptr },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.nameid = "to_str",
|
.nameid = "to_str",
|
||||||
|
|
@ -25,7 +25,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
||||||
tm->ret.obj = StringObject::create(NDO->toString(tm->self));
|
tm->ret.obj = StringObject::create(NDO->toString(tm->self));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.ret = { "string object", NULL },
|
.ret = { "string object", nullptr },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.nameid = "to_float",
|
.nameid = "to_float",
|
||||||
|
|
@ -36,11 +36,11 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
||||||
tm->ret.obj = FloatObject::create(NDO->toFloat(tm->self));
|
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++) {
|
for (tp::int2 idx = 0; idx < mNMethods; idx++) {
|
||||||
if (id == methods[idx]->nameid) {
|
if (id == methods[idx]->nameid) {
|
||||||
return idx;
|
return idx;
|
||||||
|
|
@ -58,7 +58,7 @@ tp::int2 TypeMethods::presents(tp::String id) const {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, tp::String id) {
|
TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, const std::string& id) {
|
||||||
|
|
||||||
tp::int2 depth = 0;
|
tp::int2 depth = 0;
|
||||||
tp::int2 idx = 0;
|
tp::int2 idx = 0;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "primitives/primitives.h"
|
#include "primitives/primitives.h"
|
||||||
|
|
||||||
#include "Logging.hpp"
|
|
||||||
|
|
||||||
#include "Timing.hpp"
|
#include "Timing.hpp"
|
||||||
|
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
|
|
@ -224,9 +222,9 @@ void Interpreter::stepBytecodeIn() {
|
||||||
auto obj = mOperandsStack.getOperand();
|
auto obj = mOperandsStack.getOperand();
|
||||||
if (obj->type->convesions && obj->type->convesions->to_string) {
|
if (obj->type->convesions && obj->type->convesions->to_string) {
|
||||||
auto str = NDO->toString(obj);
|
auto str = NDO->toString(obj);
|
||||||
gLogger->write(str, true);
|
printf("%s\n", str.c_str());
|
||||||
} else {
|
} else {
|
||||||
gLogger->write(String(obj->type->name), true);
|
printf("Object with type '%s' has no string representation.\n", obj->type->name);
|
||||||
}
|
}
|
||||||
break;
|
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) {
|
if (idx) {
|
||||||
return scope.mLocals.getSlotVal(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");
|
DEBUG_ASSERT(mIdx != 0 && "No scope given");
|
||||||
Scope::ObjDict& locals = mBuff[mIdx - 1].mLocals;
|
Scope::ObjDict& locals = mBuff[mIdx - 1].mLocals;
|
||||||
auto idx = locals.presents(id);
|
auto idx = locals.presents(id);
|
||||||
|
|
@ -73,9 +73,9 @@ void ScopeStack::addLocal(obj::Object* local, tp::String id) {
|
||||||
locals.put(id, local);
|
locals.put(id, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj::Object* ScopeStack::getLocal(tp::String& str) {
|
obj::Object* ScopeStack::getLocal(const std::string& str) {
|
||||||
mIterIdx = mIdx - 1;
|
mIterIdx = mIdx - 1;
|
||||||
return getLocalUtil(mBuff[mIdx - 1], &str);
|
return getLocalUtil(mBuff[mIdx - 1], str);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope* ScopeStack::getCurrentScope() { return &mBuff[mIdx - 1]; }
|
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) {
|
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) {
|
static UserData expr_function(const UserData* start, const Node*, size_t) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
struct UserNode {
|
struct UserNode {
|
||||||
obj::BCgen::Expression* expression = nullptr;
|
obj::BCgen::Expression* expression = nullptr;
|
||||||
obj::BCgen::Statement* statement = nullptr;
|
obj::BCgen::Statement* statement = nullptr;
|
||||||
tp::Buffer<tp::String>* arguments = nullptr;
|
tp::Buffer<std::string>* arguments = nullptr;
|
||||||
|
|
||||||
UserNode(obj::BCgen::Statement* stm) :
|
UserNode(obj::BCgen::Statement* stm) :
|
||||||
statement(stm) {}
|
statement(stm) {}
|
||||||
|
|
@ -20,7 +20,7 @@ struct UserNode {
|
||||||
UserNode(obj::BCgen::Expression* expr) :
|
UserNode(obj::BCgen::Expression* expr) :
|
||||||
expression(expr) {}
|
expression(expr) {}
|
||||||
|
|
||||||
UserNode(tp::Buffer<tp::String>* argList) :
|
UserNode(tp::Buffer<std::string>* argList) :
|
||||||
arguments(argList) {}
|
arguments(argList) {}
|
||||||
|
|
||||||
UserNode() = default;
|
UserNode() = default;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public:
|
||||||
virtual void lalr_vprintf(const char* format, va_list args) override { printf(format, args); }
|
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;
|
CustomErrorPolicy errorPolicy;
|
||||||
|
|
||||||
|
|
@ -30,8 +30,8 @@ Parser::Result Parser::parse(const tp::String& stream) {
|
||||||
|
|
||||||
bind(parser);
|
bind(parser);
|
||||||
|
|
||||||
std::string streamStd(stream.read());
|
std::string streamStd(stream.c_str());
|
||||||
streamStd += "\n"; // for windows os to make happy
|
streamStd += "\n"; // for windows os to be happy
|
||||||
|
|
||||||
ASSERT(parser.valid());
|
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_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; }
|
alni BoolObject::to_int(BoolObject* self) { return self->val; }
|
||||||
|
|
||||||
|
|
@ -42,9 +44,9 @@ struct ObjectTypeConversions BoolObjectTypeConversions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct obj::ObjectType obj::BoolObject::TypeData = {
|
struct obj::ObjectType obj::BoolObject::TypeData = {
|
||||||
.base = NULL,
|
.base = nullptr,
|
||||||
.constructor = (object_constructor) BoolObject::constructor,
|
.constructor = (object_constructor) BoolObject::constructor,
|
||||||
.destructor = NULL,
|
.destructor = nullptr,
|
||||||
.copy = (object_copy) BoolObject::copy,
|
.copy = (object_copy) BoolObject::copy,
|
||||||
.size = sizeof(BoolObject),
|
.size = sizeof(BoolObject),
|
||||||
.name = "bool",
|
.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::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);
|
auto newo = NDO->create(type);
|
||||||
members->put(id, newo);
|
members->put(id, newo);
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +55,7 @@ alni allocated_size_recursive(ClassObject* self) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ObjectType ClassObject::TypeData = { .base = NULL,
|
struct ObjectType ClassObject::TypeData = { .base = nullptr,
|
||||||
.constructor = (object_constructor) ClassObject::constructor,
|
.constructor = (object_constructor) ClassObject::constructor,
|
||||||
.destructor = (object_destructor) ClassObject::destructor,
|
.destructor = (object_destructor) ClassObject::destructor,
|
||||||
.copy = (object_copy) ClassObject::copy,
|
.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)); }
|
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;
|
// 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));
|
// 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
|
// TODO : implement
|
||||||
|
|
@ -33,10 +33,10 @@ static void load(ArchiverIn& file_self, ColorObject* self) { file_self >> self->
|
||||||
struct ObjectTypeConversions ColorObjectTypeConversions = {
|
struct ObjectTypeConversions ColorObjectTypeConversions = {
|
||||||
.from_int = (object_from_int) ColorObject::from_int,
|
.from_int = (object_from_int) ColorObject::from_int,
|
||||||
.from_float = (object_from_float) ColorObject::from_float,
|
.from_float = (object_from_float) ColorObject::from_float,
|
||||||
.from_string = NULL,
|
.from_string = nullptr,
|
||||||
.to_string = (object_to_string) ColorObject::to_string,
|
.to_string = (object_to_string) ColorObject::to_string,
|
||||||
.to_int = NULL,
|
.to_int = nullptr,
|
||||||
.to_float = NULL,
|
.to_float = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
void sub(ColorObject* self, ColorObject* in) { self->mCol = in->mCol - self->mCol; }
|
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 = {
|
struct ObjectTypeAriphmetics ColorObject::TypeAriphm = {
|
||||||
.add = (object_add) add,
|
.add = (object_add) add,
|
||||||
.sub = (object_sub) sub,
|
.sub = (object_sub) sub,
|
||||||
.mul = (object_mul) NULL,
|
.mul = (object_mul) nullptr,
|
||||||
.div = (object_div) NULL,
|
.div = (object_div) nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct obj::ObjectType obj::ColorObject::TypeData = {
|
struct obj::ObjectType obj::ColorObject::TypeData = {
|
||||||
.base = NULL,
|
.base = nullptr,
|
||||||
.constructor = ColorObject::constructor,
|
.constructor = ColorObject::constructor,
|
||||||
.destructor = NULL,
|
.destructor = nullptr,
|
||||||
.copy = (object_copy) ColorObject::copy,
|
.copy = (object_copy) ColorObject::copy,
|
||||||
.size = sizeof(ColorObject),
|
.size = sizeof(ColorObject),
|
||||||
.name = "RGBA",
|
.name = "RGBA",
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ using namespace tp;
|
||||||
void DictObject::constructor(Object* self) {
|
void DictObject::constructor(Object* self) {
|
||||||
NDO_CASTV(DictObject, self, dict);
|
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) {
|
void DictObject::copy(Object* in, const Object* target) {
|
||||||
|
|
@ -41,7 +41,7 @@ alni DictObject::save_size(DictObject* self) {
|
||||||
|
|
||||||
for (auto item : self->items) {
|
for (auto item : self->items) {
|
||||||
// string length
|
// string length
|
||||||
save_size += tp::SaveSizeCounter::calc(item->key);
|
save_size += save_string_size(item->key);
|
||||||
|
|
||||||
// object file adress
|
// object file adress
|
||||||
save_size += sizeof(alni);
|
save_size += sizeof(alni);
|
||||||
|
|
@ -63,12 +63,12 @@ void DictObject::save(DictObject* self, ArchiverOut& file_self) {
|
||||||
file_self << ndo_object_adress;
|
file_self << ndo_object_adress;
|
||||||
|
|
||||||
// item key
|
// item key
|
||||||
file_self << item->key;
|
save_string(file_self, item->key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DictObject::load(ArchiverIn& file_self, DictObject* self) {
|
void DictObject::load(ArchiverIn& file_self, DictObject* self) {
|
||||||
new (&self->items) tp::Map<tp::String, Object*>();
|
new (&self->items) tp::Map<std::string, Object*>();
|
||||||
|
|
||||||
alni len;
|
alni len;
|
||||||
file_self >> 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);
|
Object* val = NDO->load(file_self, ndo_object_adress);
|
||||||
|
|
||||||
// read key value
|
// read key value
|
||||||
String key;
|
std::string key;
|
||||||
file_self >> key;
|
load_string(file_self, key);
|
||||||
|
|
||||||
// add to dictinary
|
// add to dictinary
|
||||||
self->put(key, val);
|
self->put(key, val);
|
||||||
|
|
@ -118,13 +118,13 @@ alni DictObject::allocated_size_recursive(DictObject* self) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DictObject::put(tp::String str, Object* obj) {
|
void DictObject::put(const std::string& str, Object* obj) {
|
||||||
DEBUG_ASSERT(obj);
|
DEBUG_ASSERT(obj);
|
||||||
NDO->refinc(obj);
|
NDO->refinc(obj);
|
||||||
items.put(str, obj);
|
items.put(str, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DictObject::remove(tp::String str) {
|
void DictObject::remove(const std::string& str) {
|
||||||
auto idx = items.presents(str);
|
auto idx = items.presents(str);
|
||||||
if (idx) {
|
if (idx) {
|
||||||
NDO->destroy(items.getSlotVal(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",
|
static auto tm_get = TypeMethod{ .nameid = "get",
|
||||||
.descr = "gets the object",
|
.descr = "gets the object",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "primitives/enumobject.h"
|
#include "primitives/enumobject.h"
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
|
|
@ -37,7 +38,7 @@ void obj::EnumObject::init(tp::InitialierList<const char*> list) {
|
||||||
alni* entry = entries;
|
alni* entry = entries;
|
||||||
for (auto elem : list) {
|
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;
|
if (len > ENV_ALNI_SIZE_B - 1) len = ENV_ALNI_SIZE_B - 1;
|
||||||
|
|
||||||
tp::memCopy(entry, elem, len);
|
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) {
|
if (self->entries) {
|
||||||
alni* entry = self->entries;
|
alni* entry = self->entries;
|
||||||
for (uhalni i = 0; i < self->nentries; i++) {
|
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;
|
self->active = i;
|
||||||
}
|
}
|
||||||
entry += 1;
|
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) {
|
if (!self->entries) {
|
||||||
return tp::String();
|
return {};
|
||||||
}
|
}
|
||||||
auto val = (const char*) (&self->entries[self->active]);
|
auto val = (const char*) (&self->entries[self->active]);
|
||||||
return String(val);
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
alni EnumObject::to_int(EnumObject* self) {
|
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_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); }
|
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_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); }
|
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); }
|
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);
|
auto out = (MethodObject*) NDO->create(MethodObject::TypeData.name);
|
||||||
out->mScript->mReadable->val = script;
|
out->mScript->mReadable->val = script;
|
||||||
out->compile();
|
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"); }
|
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; }
|
alni to_int(NullObject* self) { return 0; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@
|
||||||
using namespace obj;
|
using namespace obj;
|
||||||
using namespace tp;
|
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; }
|
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;
|
NDO_CASTV(StringObject, NDO->create("str"), out)->val = in;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
@ -24,23 +24,27 @@ void StringObject::from_float(StringObject* self, alnf in) {
|
||||||
// self->val = 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;
|
// 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) {
|
static void load(ArchiverIn& file_self, StringObject* self) {
|
||||||
new (&self->val) tp::String();
|
new (&self->val) std::string();
|
||||||
file_self >> self->val;
|
load_string(file_self, self->val);
|
||||||
}
|
}
|
||||||
|
|
||||||
alni allocated_size(StringObject* self) {
|
alni allocated_size(StringObject* self) {
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,16 @@ TypeObject* TypeObject::create(const ObjectType* type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static alni save_size(TypeObject* self) {
|
static alni save_size(TypeObject* self) {
|
||||||
tp::String const nameid(self->mTypeRef->name);
|
return save_string_size(self->mTypeRef->name);
|
||||||
return nameid.size() + sizeof(nameid.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void save(TypeObject* self, ArchiverOut& file_self) {
|
static void save(TypeObject* self, ArchiverOut& file_self) {
|
||||||
tp::String const nameid(self->mTypeRef->name);
|
save_string(file_self, self->mTypeRef->name);
|
||||||
file_self << nameid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load(ArchiverIn& file_self, TypeObject* self) {
|
static void load(ArchiverIn& file_self, TypeObject* self) {
|
||||||
tp::String nameid;
|
std::string nameid;
|
||||||
file_self >> nameid;
|
load_string(file_self, nameid);
|
||||||
|
|
||||||
auto idx = NDO->types.presents(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 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);
|
auto idx = NDO->types.presents(in);
|
||||||
|
|
||||||
if (idx) {
|
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; }
|
bool comparator(TypeObject* left, TypeObject* right) { return left->mTypeRef == right->mTypeRef; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace obj {
|
||||||
|
|
||||||
class ConstObject {
|
class ConstObject {
|
||||||
public:
|
public:
|
||||||
obj::Object* mObj = NULL;
|
obj::Object* mObj = nullptr;
|
||||||
tp::alni mConstIdx = 0;
|
tp::alni mConstIdx = 0;
|
||||||
|
|
||||||
ConstObject();
|
ConstObject();
|
||||||
|
|
@ -19,8 +19,8 @@ namespace obj {
|
||||||
|
|
||||||
class ConstObjectsPool {
|
class ConstObjectsPool {
|
||||||
public:
|
public:
|
||||||
tp::Map<tp::String, ConstObject*> mMethods;
|
tp::Map<std::string, ConstObject*> mMethods;
|
||||||
tp::Map<tp::String, ConstObject*> mStrings;
|
tp::Map<std::string, ConstObject*> mStrings;
|
||||||
tp::Map<tp::alni, ConstObject*> mIntegers;
|
tp::Map<tp::alni, ConstObject*> mIntegers;
|
||||||
tp::Map<tp::alnf, ConstObject*> mFloats;
|
tp::Map<tp::alnf, ConstObject*> mFloats;
|
||||||
ConstObject mBoolTrue;
|
ConstObject mBoolTrue;
|
||||||
|
|
@ -30,11 +30,11 @@ namespace obj {
|
||||||
tp::alni mTotalObjects = 0;
|
tp::alni mTotalObjects = 0;
|
||||||
|
|
||||||
ConstObject* get(tp::alni val);
|
ConstObject* get(tp::alni val);
|
||||||
ConstObject* get(tp::String val);
|
ConstObject* get(const std::string& val);
|
||||||
ConstObject* get(tp::alnf val);
|
ConstObject* get(tp::alnf val);
|
||||||
ConstObject* get(bool 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);
|
ConstObject* registerObject(obj::Object* obj);
|
||||||
void save(tp::Buffer<ConstData>& out);
|
void save(tp::Buffer<ConstData>& out);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
|
|
||||||
#include "interpreter/opcodes.h"
|
#include "interpreter/opcodes.h"
|
||||||
|
|
@ -28,7 +28,7 @@ namespace obj::BCgen {
|
||||||
explicit Expression(Type type);
|
explicit Expression(Type type);
|
||||||
virtual ~Expression() = default;
|
virtual ~Expression() = default;
|
||||||
|
|
||||||
struct ExpressionChild* ExprChild(const tp::String& id);
|
struct ExpressionChild* ExprChild(const std::string& id);
|
||||||
struct ExpressionCall* ExprCall(class ExpressionList* args);
|
struct ExpressionCall* ExprCall(class ExpressionList* args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -39,28 +39,28 @@ namespace obj::BCgen {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionNew : public Expression {
|
struct ExpressionNew : public Expression {
|
||||||
tp::String mNewType;
|
std::string mNewType;
|
||||||
explicit ExpressionNew(const tp::String& type);
|
explicit ExpressionNew(const std::string& type);
|
||||||
~ExpressionNew() override;
|
~ExpressionNew() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionLocal : public Expression {
|
struct ExpressionLocal : public Expression {
|
||||||
tp::String mLocalId;
|
std::string mLocalId;
|
||||||
explicit ExpressionLocal(const tp::String& id);
|
explicit ExpressionLocal(const std::string& id);
|
||||||
~ExpressionLocal() override;
|
~ExpressionLocal() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionFunc : public Expression {
|
struct ExpressionFunc : public Expression {
|
||||||
tp::String mFuncId;
|
std::string mFuncId;
|
||||||
explicit ExpressionFunc(const tp::String& id);
|
explicit ExpressionFunc(const std::string& id);
|
||||||
~ExpressionFunc() override;
|
~ExpressionFunc() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionChild : public Expression {
|
struct ExpressionChild : public Expression {
|
||||||
Expression* mParent = nullptr;
|
Expression* mParent = nullptr;
|
||||||
tp::String mLocalId;
|
std::string mLocalId;
|
||||||
bool mMethod = false;
|
bool mMethod = false;
|
||||||
ExpressionChild(Expression* mParent, const tp::String& id);
|
ExpressionChild(Expression* mParent, const std::string& id);
|
||||||
~ExpressionChild() override;
|
~ExpressionChild() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -102,12 +102,12 @@ namespace obj::BCgen {
|
||||||
|
|
||||||
struct ExpressionConst : public Expression {
|
struct ExpressionConst : public Expression {
|
||||||
enum ConstType { STR, INT, BOOL, FLT } mConstType;
|
enum ConstType { STR, INT, BOOL, FLT } mConstType;
|
||||||
tp::String str;
|
std::string str;
|
||||||
tp::alni integer = 0;
|
tp::alni integer = 0;
|
||||||
tp::alnf floating = 0;
|
tp::alnf floating = 0;
|
||||||
bool boolean = false;
|
bool boolean = false;
|
||||||
|
|
||||||
explicit ExpressionConst(const tp::String& val);
|
explicit ExpressionConst(const std::string& val);
|
||||||
explicit ExpressionConst(const char* val);
|
explicit ExpressionConst(const char* val);
|
||||||
explicit ExpressionConst(tp::alni val);
|
explicit ExpressionConst(tp::alni val);
|
||||||
explicit ExpressionConst(tp::int4 val);
|
explicit ExpressionConst(tp::int4 val);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
#include "List.hpp"
|
#include "List.hpp"
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
|
|
||||||
|
|
@ -16,17 +16,17 @@ namespace obj {
|
||||||
|
|
||||||
struct FunctionDefinition {
|
struct FunctionDefinition {
|
||||||
|
|
||||||
FunctionDefinition* mPrnt = NULL;
|
FunctionDefinition* mPrnt = nullptr;
|
||||||
|
|
||||||
// signature
|
// signature
|
||||||
tp::String mFunctionId;
|
std::string mFunctionId;
|
||||||
tp::List<ConstObject*> mArgsOrder;
|
tp::List<ConstObject*> mArgsOrder;
|
||||||
|
|
||||||
ConstObjectsPool mConstants;
|
ConstObjectsPool mConstants;
|
||||||
tp::Map<tp::String, ConstObject*> mLocals;
|
tp::Map<std::string, ConstObject*> mLocals;
|
||||||
tp::List<Instruction> mInstructions;
|
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() {}
|
FunctionDefinition() {}
|
||||||
|
|
||||||
void generateByteCode(ByteCode& out);
|
void generateByteCode(ByteCode& out);
|
||||||
|
|
@ -36,7 +36,7 @@ namespace obj {
|
||||||
void EvalExpr(Expression* expr);
|
void EvalExpr(Expression* expr);
|
||||||
void EvalStatement(Statement* expr);
|
void EvalStatement(Statement* expr);
|
||||||
|
|
||||||
ConstObject* defineLocal(tp::String id);
|
ConstObject* defineLocal(const std::string& id);
|
||||||
};
|
};
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,11 @@ namespace obj {
|
||||||
tp::alni mParam = 0;
|
tp::alni mParam = 0;
|
||||||
tp::alni mParamBytes = 1;
|
tp::alni mParamBytes = 1;
|
||||||
|
|
||||||
ConstObject* mConstData = NULL;
|
ConstObject* mConstData = nullptr;
|
||||||
ConstObject* mConstData2 = NULL;
|
ConstObject* mConstData2 = nullptr;
|
||||||
|
|
||||||
tp::alni mInstIdx = 0;
|
tp::alni mInstIdx = 0;
|
||||||
Instruction* mInstTarget = NULL;
|
Instruction* mInstTarget = nullptr;
|
||||||
|
|
||||||
Instruction();
|
Instruction();
|
||||||
Instruction(ConstObject* constData);
|
Instruction(ConstObject* constData);
|
||||||
|
|
|
||||||
|
|
@ -36,21 +36,21 @@ namespace obj::BCgen {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StatementFuncDef : public Statement {
|
struct StatementFuncDef : public Statement {
|
||||||
tp::Buffer<tp::String> mArgs;
|
tp::Buffer<std::string> mArgs;
|
||||||
tp::String mFunctionId;
|
std::string mFunctionId;
|
||||||
StatementScope* mStatements = nullptr;
|
StatementScope* mStatements = nullptr;
|
||||||
|
|
||||||
explicit StatementFuncDef(const tp::String& function_id);
|
explicit StatementFuncDef(const std::string& function_id);
|
||||||
~StatementFuncDef() override;
|
~StatementFuncDef() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StatementLocalDef : public Statement {
|
struct StatementLocalDef : public Statement {
|
||||||
tp::String mLocalId;
|
std::string mLocalId;
|
||||||
Expression* mNewExpr = nullptr;
|
Expression* mNewExpr = nullptr;
|
||||||
ExpressionConst* mConstExpr = nullptr;
|
ExpressionConst* mConstExpr = nullptr;
|
||||||
bool mIsConstExpr = false;
|
bool mIsConstExpr = false;
|
||||||
|
|
||||||
StatementLocalDef(const tp::String& id, Expression* value);
|
StatementLocalDef(const std::string& id, Expression* value);
|
||||||
~StatementLocalDef() override;
|
~StatementLocalDef() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -102,10 +102,10 @@ namespace obj::BCgen {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StatementClassDef : public Statement {
|
struct StatementClassDef : public Statement {
|
||||||
tp::String mClassId;
|
std::string mClassId;
|
||||||
StatementScope* mScope = nullptr;
|
StatementScope* mScope = nullptr;
|
||||||
|
|
||||||
StatementClassDef(const tp::String& class_id, StatementScope* scope);
|
StatementClassDef(const std::string& class_id, StatementScope* scope);
|
||||||
~StatementClassDef() override;
|
~StatementClassDef() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
#include "List.hpp"
|
#include "List.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Strings.hpp"
|
|
||||||
#include "LocalConnection.hpp"
|
#include "LocalConnection.hpp"
|
||||||
|
|
||||||
#include "core/typegroups.h"
|
#include "core/typegroups.h"
|
||||||
|
|
@ -14,6 +13,8 @@
|
||||||
#include "Archiver.hpp"
|
#include "Archiver.hpp"
|
||||||
#include "SizeCounter.hpp"
|
#include "SizeCounter.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
//#include "interpreter/interpreter.h"
|
//#include "interpreter/interpreter.h"
|
||||||
|
|
||||||
/* Steps to create custom Object:
|
/* Steps to create custom Object:
|
||||||
|
|
@ -38,6 +39,7 @@ implement construct, destruct and copy methods */
|
||||||
|
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
|
|
||||||
template<bool tRead>
|
template<bool tRead>
|
||||||
class Archiver : public tp::ArchiverTemplate<tRead> {
|
class Archiver : public tp::ArchiverTemplate<tRead> {
|
||||||
tp::LocalConnection mConnection;
|
tp::LocalConnection mConnection;
|
||||||
|
|
@ -84,6 +86,10 @@ namespace obj {
|
||||||
using ArchiverIn = Archiver<true>;
|
using ArchiverIn = Archiver<true>;
|
||||||
using ArchiverOut = Archiver<false>;
|
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 tp::ModuleManifest gModuleObjects;
|
||||||
|
|
||||||
extern struct objects_api* NDO;
|
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_int)(Object* self, tp::alni in);
|
||||||
typedef void (*object_from_float)(Object* self, tp::alnf in);
|
typedef void (*object_from_float)(Object* self, tp::alnf in);
|
||||||
typedef void (*object_from_string)(Object* self, tp::String in);
|
typedef void (*object_from_string)(Object* self, const std::string& in);
|
||||||
typedef tp::String(*object_to_string)(Object* self);
|
typedef std::string(*object_to_string)(Object* self);
|
||||||
typedef tp::alni(*object_to_int)(Object* self);
|
typedef tp::alni(*object_to_int)(Object* self);
|
||||||
typedef tp::alnf(*object_to_float)(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
|
typedef tp::alni (*object_allocated_size_recursive)(Object*); // default value = object_allocated_size
|
||||||
|
|
||||||
struct ObjectType {
|
struct ObjectType {
|
||||||
const ObjectType* base = NULL;
|
const ObjectType* base = nullptr;
|
||||||
object_constructor constructor = NULL;
|
object_constructor constructor = nullptr;
|
||||||
object_destructor destructor = NULL;
|
object_destructor destructor = nullptr;
|
||||||
object_copy copy = NULL;
|
object_copy copy = nullptr;
|
||||||
tp::alni size = 0;
|
tp::alni size = 0;
|
||||||
const char* name;
|
const char* name;
|
||||||
const ObjectTypeConversions* convesions = NULL;
|
const ObjectTypeConversions* convesions = nullptr;
|
||||||
const ObjectTypeAriphmetics* ariphmetics = NULL;
|
const ObjectTypeAriphmetics* ariphmetics = nullptr;
|
||||||
object_save_size save_size = NULL;
|
object_save_size save_size = nullptr;
|
||||||
object_save save = NULL;
|
object_save save = nullptr;
|
||||||
object_load load = NULL;
|
object_load load = nullptr;
|
||||||
object_compare comparison = NULL;
|
object_compare comparison = nullptr;
|
||||||
void* vtable = NULL;
|
void* vtable = nullptr;
|
||||||
const char* description = NULL;
|
const char* description = nullptr;
|
||||||
object_debug_all_childs_retrival childs_retrival = NULL;
|
object_debug_all_childs_retrival childs_retrival = nullptr;
|
||||||
object_allocated_size allocated_size = NULL;
|
object_allocated_size allocated_size = nullptr;
|
||||||
object_allocated_size_recursive allocated_size_recursive = NULL;
|
object_allocated_size_recursive allocated_size_recursive = nullptr;
|
||||||
TypeMethods type_methods;
|
TypeMethods type_methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -182,26 +188,26 @@ namespace obj {
|
||||||
|
|
||||||
struct objects_api {
|
struct objects_api {
|
||||||
|
|
||||||
tp::Map<tp::String, const ObjectType*> types;
|
tp::Map<std::string, const ObjectType*> types;
|
||||||
obj::TypeGroups type_groups;
|
obj::TypeGroups type_groups;
|
||||||
Interpreter* interp = NULL;
|
Interpreter* interp = nullptr;
|
||||||
|
|
||||||
objects_api();
|
objects_api();
|
||||||
~objects_api();
|
~objects_api();
|
||||||
|
|
||||||
void define(ObjectType* type);
|
void define(ObjectType* type);
|
||||||
Object* create(const tp::String& name);
|
Object* create(const std::string& name);
|
||||||
Object* copy(Object* self, const Object* in);
|
Object* copy(Object* self, const Object* in);
|
||||||
bool compare(Object* first, Object* second);
|
bool compare(Object* first, Object* second);
|
||||||
Object* instatiate(Object*);
|
Object* instatiate(Object*);
|
||||||
void set(Object* self, tp::alni val);
|
void set(Object* self, tp::alni val);
|
||||||
void set(Object* self, tp::alnf 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::alni toInt(Object* self);
|
||||||
tp::alnf toFloat(Object* self);
|
tp::alnf toFloat(Object* self);
|
||||||
bool toBool(Object* self);
|
bool toBool(Object* self);
|
||||||
tp::String toString(Object* self);
|
std::string toString(Object* self);
|
||||||
|
|
||||||
void clear_object_flags();
|
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_util(Object* self, const ObjectType* type, bool different_object = true);
|
||||||
tp::alni objsize_ram_recursive(Object* self);
|
tp::alni objsize_ram_recursive(Object* self);
|
||||||
|
|
||||||
bool save(Object*, tp::String path, bool compressed = true);
|
bool save(Object*, const std::string& path, bool compressed = true);
|
||||||
Object* load(tp::String path);
|
Object* load(const std::string& path);
|
||||||
tp::alni save(ArchiverOut&, Object*);
|
tp::alni save(ArchiverOut&, Object*);
|
||||||
Object* load(ArchiverIn&, tp::alni file_adress);
|
Object* load(ArchiverIn&, tp::alni file_adress);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
|
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
|
|
@ -13,13 +13,13 @@ namespace obj {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef tp::Map<tp::String, obj::TypeGroups*> Dict;
|
typedef tp::Map<std::string, obj::TypeGroups*> Dict;
|
||||||
|
|
||||||
TypeGroups();
|
TypeGroups();
|
||||||
|
|
||||||
friend struct obj::objects_api;
|
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 addType(ObjectType* type, tp::InitialierList<const char*> path, tp::alni cur_arg = 0);
|
||||||
void setType(ObjectType* type);
|
void setType(ObjectType* type);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
|
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
|
|
@ -13,19 +13,19 @@ namespace obj {
|
||||||
struct TypeMethod {
|
struct TypeMethod {
|
||||||
enum { MAX_ARGS = 8 };
|
enum { MAX_ARGS = 8 };
|
||||||
struct Arg {
|
struct Arg {
|
||||||
const char* descr = NULL;
|
const char* descr = nullptr;
|
||||||
mutable Object* obj = NULL;
|
mutable Object* obj = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* nameid = NULL;
|
const char* nameid = nullptr;
|
||||||
const char* descr = NULL;
|
const char* descr = nullptr;
|
||||||
|
|
||||||
mutable Object* self = NULL;
|
mutable Object* self = nullptr;
|
||||||
Arg args[MAX_ARGS];
|
Arg args[MAX_ARGS];
|
||||||
|
|
||||||
tp::int1 mNargs = 0;
|
tp::int1 mNargs = 0;
|
||||||
|
|
||||||
void (*exec)(const TypeMethod* tm) = NULL;
|
void (*exec)(const TypeMethod* tm) = nullptr;
|
||||||
|
|
||||||
mutable Arg ret;
|
mutable Arg ret;
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace obj {
|
||||||
operator bool() { return key != -1; }
|
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);
|
static const TypeMethod* getMethod(const ObjectType*, LookupKey);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
@ -56,7 +56,7 @@ namespace obj {
|
||||||
tp::halni nMethods() const;
|
tp::halni nMethods() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
tp::int2 presents(tp::String) const;
|
tp::int2 presents(const std::string&) const;
|
||||||
const TypeMethod* getMethod(tp::int2) const;
|
const TypeMethod* getMethod(tp::int2) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "primitives/stringobject.h"
|
#include "primitives/stringobject.h"
|
||||||
|
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Strings.hpp"
|
#include <string>
|
||||||
|
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@ namespace obj {
|
||||||
|
|
||||||
struct CallFrame {
|
struct CallFrame {
|
||||||
enum { CALL_DEPTH = 1024 };
|
enum { CALL_DEPTH = 1024 };
|
||||||
obj::Object* mSelf = NULL;
|
obj::Object* mSelf = nullptr;
|
||||||
obj::MethodObject* mMethod = NULL;
|
obj::MethodObject* mMethod = nullptr;
|
||||||
tp::ualni mIp = 0;
|
tp::ualni mIp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void enter(const CallFrame& frame);
|
void enter(const CallFrame& frame);
|
||||||
void leave();
|
void leave();
|
||||||
ByteCode* getBytecode();
|
ByteCode* getBytecode();
|
||||||
tp::halni len() const;
|
[[nodiscard]] tp::halni len() const;
|
||||||
|
|
||||||
tp::ConstSizeBuffer<CallFrame, CallFrame::CALL_DEPTH> mStack;
|
tp::ConstSizeBuffer<CallFrame, CallFrame::CALL_DEPTH> mStack;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ namespace obj {
|
||||||
ScopeStack mScopeStack;
|
ScopeStack mScopeStack;
|
||||||
CallStack mCallStack;
|
CallStack mCallStack;
|
||||||
|
|
||||||
obj::Object* mLastParent = NULL;
|
obj::Object* mLastParent = nullptr;
|
||||||
bool mIsTypeMethod = false;
|
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 stepBytecode();
|
||||||
void stepBytecodeIn();
|
void stepBytecodeIn();
|
||||||
|
|
@ -24,6 +24,6 @@ namespace obj {
|
||||||
|
|
||||||
bool finished();
|
bool finished();
|
||||||
|
|
||||||
void execAll(obj::MethodObject* method, obj::ClassObject* self = NULL, obj::DictObject* globals = NULL, tp::InitialierList<GlobalDef> globals2 = {});
|
void execAll(obj::MethodObject* method, obj::ClassObject* self = nullptr, obj::DictObject* globals = nullptr, tp::InitialierList<GlobalDef> globals2 = {});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
struct Scope {
|
struct Scope {
|
||||||
typedef tp::Map<tp::String, obj::Object*> ObjDict;
|
typedef tp::Map<std::string, obj::Object*> ObjDict;
|
||||||
typedef tp::List<obj::Object*> ObjList;
|
typedef tp::List<obj::Object*> ObjList;
|
||||||
|
|
||||||
ObjDict mLocals;
|
ObjDict mLocals;
|
||||||
|
|
@ -31,16 +31,16 @@ namespace obj {
|
||||||
ScopeStack();
|
ScopeStack();
|
||||||
void enterScope(bool aChildReachable);
|
void enterScope(bool aChildReachable);
|
||||||
void leaveScope();
|
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 addTemp(obj::Object* tmp);
|
||||||
void popTemp();
|
void popTemp();
|
||||||
void addTempReturn(obj::Object* ret);
|
void addTempReturn(obj::Object* ret);
|
||||||
obj::Object* getLocal(tp::String& str);
|
obj::Object* getLocal(const std::string& str);
|
||||||
Scope* getCurrentScope();
|
Scope* getCurrentScope();
|
||||||
~ScopeStack();
|
~ScopeStack();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
obj::Object* getLocalUtil(Scope& scope, tp::String* id);
|
obj::Object* getLocalUtil(Scope& scope, const std::string& id);
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -12,11 +12,11 @@ namespace obj {
|
||||||
struct Result {
|
struct Result {
|
||||||
obj::BCgen::StatementScope* scope = nullptr;
|
obj::BCgen::StatementScope* scope = nullptr;
|
||||||
bool isError = false;
|
bool isError = false;
|
||||||
tp::String description;
|
std::string description;
|
||||||
tp::halni line = 0;
|
tp::halni line = 0;
|
||||||
tp::halni column = 0;
|
tp::halni column = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Result parse(const tp::String& stream);
|
Result parse(const std::string& stream);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ namespace obj {
|
||||||
|
|
||||||
static void from_int(BoolObject* self, tp::alni in);
|
static void from_int(BoolObject* self, tp::alni in);
|
||||||
static void from_float(BoolObject* self, tp::alnf in);
|
static void from_float(BoolObject* self, tp::alnf in);
|
||||||
static void from_string(BoolObject* self, tp::String in);
|
static void from_string(BoolObject* self, const std::string& in);
|
||||||
static tp::String to_string(BoolObject* self);
|
static std::string to_string(BoolObject* self);
|
||||||
static tp::alni to_int(BoolObject* self);
|
static tp::alni to_int(BoolObject* self);
|
||||||
static tp::alnf to_float(BoolObject* self);
|
static tp::alnf to_float(BoolObject* self);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ namespace obj {
|
||||||
|
|
||||||
DictObject* members;
|
DictObject* members;
|
||||||
|
|
||||||
void addMember(Object* obj, tp::String id);
|
void addMember(Object* obj, const std::string& id);
|
||||||
void createMember(tp::String type, tp::String id);
|
void createMember(const std::string& type, const std::string& id);
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type* createMember(tp::String id) {
|
Type* createMember(const std::string& id) {
|
||||||
auto out = NDO->create(Type::TypeData.name);
|
auto out = NDO->create(Type::TypeData.name);
|
||||||
addMember(out, id);
|
addMember(out, id);
|
||||||
NDO->destroy(out);
|
NDO->destroy(out);
|
||||||
|
|
@ -28,7 +28,7 @@ namespace obj {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type* getMember(const tp::String& id) {
|
Type* getMember(const std::string& id) {
|
||||||
auto idx = members->presents(id);
|
auto idx = members->presents(id);
|
||||||
if (bool(idx)) {
|
if (bool(idx)) {
|
||||||
return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData));
|
return ((Type*)obj::ndo_cast(members->getSlotVal(idx), &Type::TypeData));
|
||||||
|
|
@ -37,7 +37,7 @@ namespace obj {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
Type* getMemberAssert(const tp::String& id) {
|
Type* getMemberAssert(const std::string& id) {
|
||||||
auto out = getMember<Type>(id);
|
auto out = getMember<Type>(id);
|
||||||
assert(out && "invalid member access");
|
assert(out && "invalid member access");
|
||||||
return out;
|
return out;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace obj {
|
||||||
|
|
||||||
static void from_int(ColorObject* self, tp::alni in);
|
static void from_int(ColorObject* self, tp::alni in);
|
||||||
static void from_float(ColorObject* self, tp::alnf 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);
|
static ColorObject* create(tp::RGBA in);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@ namespace obj {
|
||||||
static tp::alni allocated_size(DictObject* self);
|
static tp::alni allocated_size(DictObject* self);
|
||||||
static tp::alni allocated_size_recursive(DictObject* self);
|
static tp::alni allocated_size_recursive(DictObject* self);
|
||||||
|
|
||||||
void put(tp::String, Object*);
|
void put(const std::string&, Object*);
|
||||||
void remove(tp::String);
|
void remove(const std::string&);
|
||||||
Object* get(tp::String);
|
Object* get(const std::string&);
|
||||||
tp::Map<tp::String, Object*>::Idx presents(tp::String);
|
tp::Map<std::string, Object*>::Idx presents(const std::string&);
|
||||||
Object* getSlotVal(tp::Map<tp::String, Object*>::Idx);
|
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:
|
private:
|
||||||
tp::Map<tp::String, Object*> items;
|
tp::Map<std::string, Object*> items;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -23,8 +23,8 @@ namespace obj {
|
||||||
|
|
||||||
static void from_int(EnumObject* self, tp::alni in);
|
static void from_int(EnumObject* self, tp::alni in);
|
||||||
static void from_float(EnumObject* self, tp::alnf in);
|
static void from_float(EnumObject* self, tp::alnf in);
|
||||||
static void from_string(EnumObject* self, tp::String in);
|
static void from_string(EnumObject* self, const std::string& in);
|
||||||
static tp::String to_string(EnumObject* self);
|
static std::string to_string(EnumObject* self);
|
||||||
static tp::alni to_int(EnumObject* self);
|
static tp::alni to_int(EnumObject* self);
|
||||||
static tp::alnf to_float(EnumObject* self);
|
static tp::alnf to_float(EnumObject* self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ namespace obj {
|
||||||
|
|
||||||
static void from_int(FloatObject* self, tp::alni in);
|
static void from_int(FloatObject* self, tp::alni in);
|
||||||
static void from_float(FloatObject* self, tp::alnf in);
|
static void from_float(FloatObject* self, tp::alnf in);
|
||||||
static void from_string(FloatObject* self, tp::String in);
|
static void from_string(FloatObject* self, const std::string& in);
|
||||||
static tp::String to_string(FloatObject* self);
|
static std::string to_string(FloatObject* self);
|
||||||
static tp::alni to_int(FloatObject* self);
|
static tp::alni to_int(FloatObject* self);
|
||||||
static tp::alnf to_float(FloatObject* self);
|
static tp::alnf to_float(FloatObject* self);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace obj {
|
||||||
static void constructor(InterpreterObject* self);
|
static void constructor(InterpreterObject* self);
|
||||||
static void load(ArchiverIn& file_self, 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();
|
void debug();
|
||||||
bool running();
|
bool running();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ namespace obj {
|
||||||
|
|
||||||
static void from_int(Object* self, tp::alni in);
|
static void from_int(Object* self, tp::alni in);
|
||||||
static void from_float(Object* self, tp::alnf in);
|
static void from_float(Object* self, tp::alnf in);
|
||||||
static void from_string(Object* self, tp::String in);
|
static void from_string(Object* self, const std::string& in);
|
||||||
static tp::String to_string(Object* self);
|
static std::string to_string(Object* self);
|
||||||
static tp::alni to_int(Object* self);
|
static tp::alni to_int(Object* self);
|
||||||
static tp::alnf to_float(Object* self);
|
static tp::alnf to_float(Object* self);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace obj {
|
||||||
static void save(ListObject* self, ArchiverOut& file_self);
|
static void save(ListObject* self, ArchiverOut& file_self);
|
||||||
static tp::alni save_size(ListObject* self);
|
static tp::alni save_size(ListObject* self);
|
||||||
|
|
||||||
const tp::List<Object*>& getItems() const;
|
[[nodiscard]] const tp::List<Object*>& getItems() const;
|
||||||
|
|
||||||
void pushBack(Object* obj);
|
void pushBack(Object* obj);
|
||||||
void pushFront(Object* obj);
|
void pushFront(Object* obj);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@ namespace obj {
|
||||||
|
|
||||||
void compile();
|
void compile();
|
||||||
|
|
||||||
static MethodObject* create(tp::String script);
|
static MethodObject* create(const std::string& script);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -6,18 +6,18 @@
|
||||||
namespace obj {
|
namespace obj {
|
||||||
|
|
||||||
struct StringObject : Object {
|
struct StringObject : Object {
|
||||||
tp::String val;
|
std::string val;
|
||||||
|
|
||||||
static ObjectType TypeData;
|
static ObjectType TypeData;
|
||||||
static void constructor(Object* self);
|
static void constructor(Object* self);
|
||||||
static void destructor(StringObject* self);
|
static void destructor(StringObject* self);
|
||||||
static void copy(Object* self, const Object* in);
|
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_int(StringObject* self, tp::alni in);
|
||||||
static void from_float(StringObject* self, tp::alnf in);
|
static void from_float(StringObject* self, tp::alnf in);
|
||||||
static void from_string(StringObject* self, tp::String in);
|
static void from_string(StringObject* self, const std::string& in);
|
||||||
static tp::String to_string(StringObject* self);
|
static std::string to_string(StringObject* self);
|
||||||
static tp::alni to_int(StringObject* self);
|
static tp::alni to_int(StringObject* self);
|
||||||
static tp::alnf to_float(StringObject* self);
|
static tp::alnf to_float(StringObject* self);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@ SUITE(Core) {
|
||||||
|
|
||||||
integer->val = 10;
|
integer->val = 10;
|
||||||
|
|
||||||
printf("%s\n", NDO->toString(integer).read());
|
printf("%s\n", NDO->toString(integer).c_str());
|
||||||
|
|
||||||
NDO->save(integer, "tmp.o");
|
NDO->save(integer, "tmp.o");
|
||||||
auto savedInt = NDO->load("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->compare(integer, savedInt));
|
||||||
CHECK(NDO_CAST(IntObject, savedInt));
|
CHECK(NDO_CAST(IntObject, savedInt));
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ SUITE(Parser) {
|
||||||
{
|
{
|
||||||
Parser parser;
|
Parser parser;
|
||||||
|
|
||||||
String stream = "";
|
std::string stream = "";
|
||||||
auto res = parser.parse(stream);
|
auto res = parser.parse(stream);
|
||||||
|
|
||||||
CHECK(!res.isError);
|
CHECK(!res.isError);
|
||||||
|
|
@ -24,7 +24,7 @@ SUITE(Parser) {
|
||||||
{
|
{
|
||||||
Parser parser;
|
Parser parser;
|
||||||
|
|
||||||
String stream = "var i = true;";
|
std::string stream = "var i = true;";
|
||||||
auto res = parser.parse(stream);
|
auto res = parser.parse(stream);
|
||||||
|
|
||||||
CHECK(!res.isError);
|
CHECK(!res.isError);
|
||||||
|
|
@ -35,7 +35,7 @@ SUITE(Parser) {
|
||||||
{
|
{
|
||||||
Parser 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);
|
auto res = parser.parse(stream);
|
||||||
|
|
||||||
CHECK(!res.isError);
|
CHECK(!res.isError);
|
||||||
|
|
@ -51,7 +51,7 @@ SUITE(Parser) {
|
||||||
|
|
||||||
{
|
{
|
||||||
Parser 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);
|
auto res = parser.parse(stream);
|
||||||
|
|
||||||
CHECK(res.isError);
|
CHECK(res.isError);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,5 @@ tp::ModuleManifest* objDeps[] = { &obj::gModuleObjects, nullptr };
|
||||||
tp::ModuleManifest objTestModule("ObjectsTests", nullptr, nullptr, objDeps);
|
tp::ModuleManifest objTestModule("ObjectsTests", nullptr, nullptr, objDeps);
|
||||||
|
|
||||||
#include <UnitTest++/UnitTest++.h>
|
#include <UnitTest++/UnitTest++.h>
|
||||||
#include <UnitTest++/TestReporterStdout.h>
|
|
||||||
|
|
||||||
int main(int /*argc*/, char** /*argv*/) { return UnitTest::RunAllTests(); }
|
int main(int /*argc*/, char** /*argv*/) { return UnitTest::RunAllTests(); }
|
||||||
|
|
@ -11,7 +11,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp")
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/)
|
target_include_directories(${PROJECT_NAME} PUBLIC ./public/ ${BINDINGS_INCLUDE} ./ext/)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Math Strings)
|
target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets Math)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS})
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS})
|
||||||
|
|
||||||
### -------------------------- Applications -------------------------- ###
|
### -------------------------- Applications -------------------------- ###
|
||||||
|
|
|
||||||
|
|
@ -33,15 +33,5 @@ void runApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
tp::ModuleManifest* deps[] = { &tp::gModuleStrings, nullptr };
|
|
||||||
tp::ModuleManifest binModule("LibViewEntry", nullptr, nullptr, deps);
|
|
||||||
|
|
||||||
if (!binModule.initialize()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp();
|
runApp();
|
||||||
|
|
||||||
binModule.deinitialize();
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
#include "Strings.hpp"
|
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "LocalConnection.hpp"
|
#include "LocalConnection.hpp"
|
||||||
#include "Shader.hpp"
|
#include "Shader.hpp"
|
||||||
|
|
@ -96,7 +95,7 @@ void RenderShader::load(const char* pvert, const char* pgeom, const char* pfrag,
|
||||||
|
|
||||||
if (paths) {
|
if (paths) {
|
||||||
|
|
||||||
String content;
|
std::string content;
|
||||||
|
|
||||||
auto loadFile = [&](const char* path) {
|
auto loadFile = [&](const char* path) {
|
||||||
LocalConnection file;
|
LocalConnection file;
|
||||||
|
|
@ -105,26 +104,30 @@ void RenderShader::load(const char* pvert, const char* pgeom, const char* pfrag,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
content.resize(file.size());
|
const auto size = file.size();
|
||||||
file.readBytes(content.write(), content.size());
|
auto tmp = new char[size + 1];
|
||||||
|
tmp[size] = 0;
|
||||||
|
file.readBytes(tmp, size);
|
||||||
|
content = tmp;
|
||||||
|
delete[] tmp;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("Compiling shader : %s\n", pvert);
|
printf("Compiling shader : %s\n", pvert);
|
||||||
if (loadFile(pvert)) {
|
if (loadFile(pvert)) {
|
||||||
compile_shader(content.read(), VertexShaderID);
|
compile_shader(content.c_str(), VertexShaderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GeometryShaderID) {
|
if (GeometryShaderID) {
|
||||||
printf("Compiling shader : %s\n", pgeom);
|
printf("Compiling shader : %s\n", pgeom);
|
||||||
if (loadFile(pgeom)) {
|
if (loadFile(pgeom)) {
|
||||||
compile_shader(content.read(), GeometryShaderID);
|
compile_shader(content.c_str(), GeometryShaderID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Compiling shader : %s\n", pfrag);
|
printf("Compiling shader : %s\n", pfrag);
|
||||||
if (loadFile(pfrag)) {
|
if (loadFile(pfrag)) {
|
||||||
compile_shader(content.read(), FragmentShaderID);
|
compile_shader(content.c_str(), FragmentShaderID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
|
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
#include "Shader.hpp"
|
#include "Shader.hpp"
|
||||||
|
|
||||||
#include "GraphicsApi.hpp"
|
#include "GraphicsApi.hpp"
|
||||||
|
|
@ -71,7 +69,7 @@ void RenderTexture::draw(const GLuint& out) {
|
||||||
|
|
||||||
struct texture_drawer_data {
|
struct texture_drawer_data {
|
||||||
|
|
||||||
Map<String, GLuint> textures;
|
Map<std::string, GLuint> textures;
|
||||||
|
|
||||||
GLuint quad_VertexArrayID;
|
GLuint quad_VertexArrayID;
|
||||||
GLuint quad_vertexbuffer;
|
GLuint quad_vertexbuffer;
|
||||||
|
|
@ -147,7 +145,7 @@ void RenderTexture::draw_texture(uint4 out, uint4 in) {
|
||||||
texdd->shader.unbind();
|
texdd->shader.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint load_texture(const String& name) {
|
GLuint load_texture(const std::string& name) {
|
||||||
GLuint tex_2d = 0;
|
GLuint tex_2d = 0;
|
||||||
|
|
||||||
ASSERT(0 && "incomplete compilation - no SOIL support added");
|
ASSERT(0 && "incomplete compilation - no SOIL support added");
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
#include "Topology.hpp"
|
#include "Topology.hpp"
|
||||||
#include "Color.hpp"
|
#include "Color.hpp"
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
#include "GraphicsApi.hpp"
|
#include "GraphicsApi.hpp"
|
||||||
#include "FrameBuffer.hpp"
|
#include "FrameBuffer.hpp"
|
||||||
|
|
@ -88,7 +87,7 @@ namespace tp {
|
||||||
Layer() = default;
|
Layer() = default;
|
||||||
~Layer();
|
~Layer();
|
||||||
|
|
||||||
String name = "new layer";
|
std::string name = "new layer";
|
||||||
List<Stroke*> strokes; // TODO use vector
|
List<Stroke*> strokes; // TODO use vector
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
|
@ -108,13 +107,13 @@ namespace tp {
|
||||||
Camera mCamera;
|
Camera mCamera;
|
||||||
RGBA mBackgroundColor = { 0.22f, 0.22f, 0.25f, 1.f };
|
RGBA mBackgroundColor = { 0.22f, 0.22f, 0.25f, 1.f };
|
||||||
|
|
||||||
Map<String, Brush*> mBrushes;
|
Map<std::string, Brush*> mBrushes;
|
||||||
String mActiveBrush;
|
std::string mActiveBrush;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Brush {
|
class Brush {
|
||||||
public:
|
public:
|
||||||
String mType = "equal";
|
std::string mType = "equal";
|
||||||
Brush() = default;
|
Brush() = default;
|
||||||
virtual void sample(Project* proj, Vec2F crs, halnf pressure) {}
|
virtual void sample(Project* proj, Vec2F crs, halnf pressure) {}
|
||||||
virtual void draw(Renderer* render, const Camera* camera) {}
|
virtual void draw(Renderer* render, const Camera* camera) {}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
project(Strings)
|
|
||||||
|
|
||||||
### ---------------------- Static Library --------------------- ###
|
|
||||||
file(GLOB SOURCES "./private/*.cpp")
|
|
||||||
file(GLOB HEADERS "./public/*.hpp")
|
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Containers)
|
|
||||||
|
|
||||||
### -------------------------- Tests -------------------------- ###
|
|
||||||
enable_testing()
|
|
||||||
file(GLOB TEST_SOURCES "./tests/*.cpp")
|
|
||||||
add_executable(Test${PROJECT_NAME} ${TEST_SOURCES})
|
|
||||||
target_link_libraries(Test${PROJECT_NAME} ${PROJECT_NAME} UnitTest++)
|
|
||||||
add_test(NAME Test${PROJECT_NAME} COMMAND Test${PROJECT_NAME})
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#include "Logging.hpp"
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
namespace tp {
|
|
||||||
|
|
||||||
Logger* gLogger = nullptr;
|
|
||||||
|
|
||||||
ualni Logger::Report::getLineCount() const { return (ualni) (mLineOffsets.size() - 1); }
|
|
||||||
|
|
||||||
String Logger::Report::getString() const { return mData; }
|
|
||||||
|
|
||||||
void Logger::Report::calcLineCount() { mData.calcLineOffsets(mLineOffsets); }
|
|
||||||
|
|
||||||
Logger::Report::Report() { mData = " - "; }
|
|
||||||
|
|
||||||
Logger::Report::Report(const String& text) :
|
|
||||||
mData(text) {
|
|
||||||
calcLineCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::Report::Report(const String& text, Type type) :
|
|
||||||
mType(type),
|
|
||||||
mData(text) {
|
|
||||||
calcLineCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::write(const String& in, bool post, Report::Type type) {
|
|
||||||
mBuff.pushBack(Report(in, type));
|
|
||||||
mLineCount += mBuff.last()->data.getLineCount();
|
|
||||||
if (!mCursor) mCursor = mBuff.last();
|
|
||||||
if (post) printf("%s", in.read());
|
|
||||||
}
|
|
||||||
|
|
||||||
String Logger::read() {
|
|
||||||
if (!mCursor) return {};
|
|
||||||
const Report& out = mCursor->data;
|
|
||||||
mCursor = mCursor->next;
|
|
||||||
return out.getString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::initializeGlobal() {
|
|
||||||
DEBUG_ASSERT(!gLogger)
|
|
||||||
gLogger = new Logger();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::deinitializeGlobal() {
|
|
||||||
DEBUG_ASSERT(gLogger)
|
|
||||||
delete gLogger;
|
|
||||||
gLogger = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
|
|
||||||
#include "Strings.hpp"
|
|
||||||
#include "Logging.hpp"
|
|
||||||
|
|
||||||
using namespace tp;
|
|
||||||
|
|
||||||
bool initialize(const ModuleManifest*) {
|
|
||||||
Logger::initializeGlobal();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deinitialize(const ModuleManifest*) { Logger::deinitializeGlobal(); }
|
|
||||||
|
|
||||||
static tp::ModuleManifest* sModuleDependencies[] = { nullptr };
|
|
||||||
|
|
||||||
ModuleManifest tp::gModuleStrings = ModuleManifest("Strings", initialize, deinitialize, sModuleDependencies);
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Buffer.hpp"
|
|
||||||
#include "List.hpp"
|
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
namespace tp {
|
|
||||||
|
|
||||||
class Logger {
|
|
||||||
public:
|
|
||||||
class Report {
|
|
||||||
String mData;
|
|
||||||
Buffer<String::Index> mLineOffsets;
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Type { INFO, ERR, WARN, SUC } mType = INFO;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Report();
|
|
||||||
explicit Report(const String& text);
|
|
||||||
Report(const String& text, Type type);
|
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] ualni getLineCount() const;
|
|
||||||
[[nodiscard]] String getString() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void calcLineCount();
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
List<Report>::Node* mCursor = nullptr;
|
|
||||||
List<Report> mBuff;
|
|
||||||
ualni mLineCount = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void write(const String& in, bool post = true, Report::Type type = Report::Type::INFO);
|
|
||||||
|
|
||||||
[[nodiscard]] String read();
|
|
||||||
[[nodiscard]] const List<Report>& getBuff() const { return mBuff; }
|
|
||||||
[[nodiscard]] ualni getLineCount() const { return mLineCount; }
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void initializeGlobal();
|
|
||||||
static void deinitializeGlobal();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Logger* gLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define LOG(val) tp::str::gLogger->write((val), 1)
|
|
||||||
|
|
||||||
#ifdef ENV_BUILD_DEBUG
|
|
||||||
#define DEBUG_LOG(val) tp::str::gLogger->write((val), 1)
|
|
||||||
#else
|
|
||||||
#define DEBUG_LOG(val) (0)
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Buffer.hpp"
|
|
||||||
#include "Utils.hpp"
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
namespace tp {
|
|
||||||
|
|
||||||
template <typename tChar = uint1>
|
|
||||||
class StringLogic {
|
|
||||||
public:
|
|
||||||
typedef halni Index;
|
|
||||||
typedef Index LineId;
|
|
||||||
typedef Index ColumnId;
|
|
||||||
|
|
||||||
static inline bool isNewLineChar(tChar in) { return (in == '\n') || (in == '\r'); }
|
|
||||||
static inline bool isEndChar(tChar in) { return in == '\0'; }
|
|
||||||
static constexpr tChar getEndChar() { return '\0'; }
|
|
||||||
|
|
||||||
static Index calcLength(const tChar* in) {
|
|
||||||
const tChar* iter = in;
|
|
||||||
while (*iter != '\0')
|
|
||||||
iter++;
|
|
||||||
return iter - in;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insertLogic(tChar* result, Index resultLen, const tChar* cur, const tChar* tar, Index at, Index len) {
|
|
||||||
auto curLen = calcLength(cur);
|
|
||||||
auto allLen = curLen + len;
|
|
||||||
ASSERT(allLen <= resultLen);
|
|
||||||
|
|
||||||
DEBUG_ASSERT(curLen >= 0)
|
|
||||||
DEBUG_ASSERT(len >= 0)
|
|
||||||
DEBUG_ASSERT(at < curLen + 1 && at >= 0)
|
|
||||||
|
|
||||||
for (Index idx = 0; idx < at; idx++) {
|
|
||||||
result[idx] = cur[idx];
|
|
||||||
}
|
|
||||||
for (Index idx = 0; idx < len; idx++) {
|
|
||||||
result[idx + at] = tar[idx];
|
|
||||||
}
|
|
||||||
for (Index idx = at + len; idx < allLen; idx++) {
|
|
||||||
result[idx] = cur[idx - len];
|
|
||||||
}
|
|
||||||
result[allLen] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// including end not including start
|
|
||||||
static void removeLogic(tChar* result, Index resultLen, const tChar* cur, Index start, Index end) {
|
|
||||||
auto curLen = calcLength(cur);
|
|
||||||
auto rangeLen = end - start;
|
|
||||||
auto newLen = curLen - rangeLen;
|
|
||||||
|
|
||||||
ASSERT(newLen <= resultLen);
|
|
||||||
|
|
||||||
result[newLen] = '\0';
|
|
||||||
for (Index idx = 0; idx < start; idx++) {
|
|
||||||
result[idx] = cur[idx];
|
|
||||||
}
|
|
||||||
for (Index idx = end; idx < curLen; idx++) {
|
|
||||||
result[idx - rangeLen] = cur[idx];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isEqualLogic(const tChar* left, const tChar* right) {
|
|
||||||
Index idx = 0;
|
|
||||||
LOOP:
|
|
||||||
if (left[idx] == '\0' || right[idx] == '\0') {
|
|
||||||
if (left[idx] == '\0' && right[idx] == '\0') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (left[idx] != right[idx]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
idx++;
|
|
||||||
goto LOOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns 0 : nl1 + 1 : nl2 + 1 : nl3 + 1 : ... : size
|
|
||||||
static void calcLineOffsets(const tChar* aBuff, Index aLength, Buffer<Index>& aOut) {
|
|
||||||
Index lines = 0;
|
|
||||||
for (auto idx : Range(aLength)) {
|
|
||||||
if (isNewLineChar(aBuff[idx])) {
|
|
||||||
lines++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
aOut.reserve(lines + 2); // plus start and end offsets
|
|
||||||
lines = 0;
|
|
||||||
for (auto idx : Range(aLength)) {
|
|
||||||
if (isNewLineChar(aBuff[idx])) {
|
|
||||||
aOut[lines + 1] = Index(idx + 1);
|
|
||||||
lines++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
aOut[0] = 0;
|
|
||||||
aOut[lines + 1] = aLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertStringToValue(const tChar* input, alni& output) {
|
|
||||||
char* endPtr;
|
|
||||||
output = std::strtoll(input, &endPtr, 10);
|
|
||||||
return (endPtr == input + calcLength(input));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertStringToValue(const tChar* input, alnf& output) {
|
|
||||||
char* endPtr;
|
|
||||||
output = std::strtod(input, &endPtr);
|
|
||||||
return (endPtr == input + calcLength(input));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertStringToValue(const tChar* input, bool& output) {
|
|
||||||
output = !(isEqualLogic(input, "False") || isEqualLogic(input, "false") || isEqualLogic(input, "0"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertValueToString(alni input, tChar* output, Index bufferSize) {
|
|
||||||
int result = std::snprintf(output, bufferSize, "%lld", input);
|
|
||||||
return result >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertValueToString(alnf input, tChar* output, Index bufferSize) {
|
|
||||||
int result = std::snprintf(output, bufferSize, "%f", input);
|
|
||||||
return result >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool convertValueToString(bool input, tChar* output, Index bufferSize) {
|
|
||||||
const char* str = (input ? "true" : "false");
|
|
||||||
Index length = calcLength(str);
|
|
||||||
if (length >= bufferSize) return false;
|
|
||||||
memCopy(output, str, length + 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,273 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "StringLogic.hpp"
|
|
||||||
|
|
||||||
namespace tp {
|
|
||||||
|
|
||||||
// Static data
|
|
||||||
extern ModuleManifest gModuleStrings;
|
|
||||||
|
|
||||||
template <typename tChar>
|
|
||||||
class StringTemplate;
|
|
||||||
|
|
||||||
// Hidden slave class
|
|
||||||
template <typename tChar = int1>
|
|
||||||
class StringData {
|
|
||||||
friend StringTemplate<tChar>;
|
|
||||||
typedef StringLogic<tChar> Logic;
|
|
||||||
typedef typename StringLogic<tChar>::Index Index;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint2 mIsConst; // source is non-modifiable
|
|
||||||
uint2 mEditedIdx; // editor id
|
|
||||||
uint4 mReferenceCount; // number of users of this
|
|
||||||
tChar* mBuff; // actual string data
|
|
||||||
|
|
||||||
StringData() {
|
|
||||||
mBuff = (tChar*) "*";
|
|
||||||
mReferenceCount = 1;
|
|
||||||
mIsConst = true;
|
|
||||||
mEditedIdx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringData(const tChar* aBuff, bool aIsConst) {
|
|
||||||
MODULE_SANITY_CHECK(gModuleStrings)
|
|
||||||
DEBUG_ASSERT(aBuff)
|
|
||||||
mBuff = (tChar*) aBuff;
|
|
||||||
mReferenceCount = 0;
|
|
||||||
mIsConst = aIsConst;
|
|
||||||
mEditedIdx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit StringData(tChar* aBuff) {
|
|
||||||
MODULE_SANITY_CHECK(gModuleStrings)
|
|
||||||
DEBUG_ASSERT(aBuff)
|
|
||||||
auto const len = Logic::calcLength(aBuff);
|
|
||||||
mReferenceCount = 0;
|
|
||||||
mIsConst = false;
|
|
||||||
mEditedIdx = 0;
|
|
||||||
mBuff = new tChar[len + 1];
|
|
||||||
mBuff[len] = Logic::getEndChar();
|
|
||||||
memCopy(mBuff, aBuff, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] tChar* getBuffer() { return mBuff; }
|
|
||||||
|
|
||||||
~StringData() {
|
|
||||||
if (!mIsConst) delete[] mBuff;
|
|
||||||
}
|
|
||||||
|
|
||||||
void resize(Index size) {
|
|
||||||
DEBUG_ASSERT(mReferenceCount == 1 && !mIsConst)
|
|
||||||
delete[] mBuff;
|
|
||||||
mBuff = new tChar[size + 1];
|
|
||||||
// set non-zero value so that size() function wont return size that may be less that actual
|
|
||||||
memSetVal(mBuff, size, 1);
|
|
||||||
mBuff[size] = Logic::getEndChar();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename tChar = int1>
|
|
||||||
class StringTemplate {
|
|
||||||
public:
|
|
||||||
typedef StringLogic<tChar> Logic;
|
|
||||||
typedef StringData<tChar> Data;
|
|
||||||
typedef typename Logic::Index Index;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
STRINGS_POOL_SIZE = 1024,
|
|
||||||
MAX_INT_STRING_LENGTH = 10,
|
|
||||||
MAX_BOOL_STRING_LENGTH = 10,
|
|
||||||
MAX_FLOAT_STRING_LENGTH = 10,
|
|
||||||
};
|
|
||||||
|
|
||||||
static Data sNullString;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Data* mData;
|
|
||||||
|
|
||||||
public: // Main Interface
|
|
||||||
// Creates null string reference
|
|
||||||
StringTemplate() {
|
|
||||||
mData = &sNullString;
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// References existing string data
|
|
||||||
StringTemplate(const StringTemplate& in) {
|
|
||||||
mData = in.mData;
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* alloc() { return malloc(sizeof(StringData<tChar>)); }
|
|
||||||
|
|
||||||
// Creates new string data from raw data pointer.
|
|
||||||
// Does not own string buffer - string buffer will not be freed. Initializes as const memory.
|
|
||||||
StringTemplate(const tChar* raw) {
|
|
||||||
mData = new (alloc()) StringData(raw, true);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copies raw data and claims ownership over it
|
|
||||||
StringTemplate(tChar* raw) {
|
|
||||||
mData = new (alloc()) StringData(raw);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
~StringTemplate() { decReference(mData); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void incReference(Data* dp) { dp->mReferenceCount++; }
|
|
||||||
|
|
||||||
void decReference(Data* dp) {
|
|
||||||
DEBUG_ASSERT(dp->mReferenceCount > 0)
|
|
||||||
dp->mReferenceCount--;
|
|
||||||
if (!dp->mReferenceCount) {
|
|
||||||
mData->~StringData();
|
|
||||||
free(mData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public: // Access
|
|
||||||
// used to read data
|
|
||||||
[[nodiscard]] const tChar* read() const { return mData->mBuff; }
|
|
||||||
|
|
||||||
// used to write data
|
|
||||||
// output will be null if in TextEditing mode
|
|
||||||
[[nodiscard]] tChar* write() {
|
|
||||||
makeModifiable();
|
|
||||||
return mData->getBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// output will be null if in TextEditing mode
|
|
||||||
tChar* resize(Index size) {
|
|
||||||
makeModifiable();
|
|
||||||
mData->resize(size);
|
|
||||||
return write();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void makeModifiable() {
|
|
||||||
// We have no rights to modify if someone references that memory too
|
|
||||||
// So we need to create new copy of StringData
|
|
||||||
if (mData->mReferenceCount > 1) {
|
|
||||||
mData = new (alloc()) StringData(mData->mBuff);
|
|
||||||
incReference(mData);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also if initial raw data was marked as const - create copy of raw data
|
|
||||||
// Note - raw data will be lost at this point if no other record of such is stored
|
|
||||||
if (mData->mIsConst) {
|
|
||||||
mData = new (alloc()) StringData(mData->mBuff);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class tArchiver>
|
|
||||||
void archiveWrite(tArchiver& ar) const {
|
|
||||||
auto size = this->size();
|
|
||||||
ar << size;
|
|
||||||
ar.writeBytes(read(), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class tArchiver>
|
|
||||||
void archiveRead(tArchiver& ar) {
|
|
||||||
Index size;
|
|
||||||
ar >> size;
|
|
||||||
resize(size);
|
|
||||||
ar.readBytes(write(), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public: // Syntax sugars
|
|
||||||
explicit StringTemplate(alni val) {
|
|
||||||
tChar raw[MAX_INT_STRING_LENGTH];
|
|
||||||
Logic::convertValueToString(val, raw, MAX_INT_STRING_LENGTH);
|
|
||||||
mData = new (alloc()) StringData(raw);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit StringTemplate(alnf val) {
|
|
||||||
tChar raw[MAX_INT_STRING_LENGTH];
|
|
||||||
Logic::convertValueToString(val, raw, MAX_FLOAT_STRING_LENGTH);
|
|
||||||
mData = new (alloc()) StringData(raw);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit StringTemplate(bool val) {
|
|
||||||
tChar raw[MAX_INT_STRING_LENGTH];
|
|
||||||
Logic::convertValueToString(val, raw, MAX_BOOL_STRING_LENGTH);
|
|
||||||
mData = new (alloc()) StringData(raw);
|
|
||||||
incReference(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator alni() {
|
|
||||||
alni out;
|
|
||||||
Logic::convertStringToValue(read(), out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator alnf() {
|
|
||||||
alnf out;
|
|
||||||
Logic::convertStringToValue(read(), out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator bool() {
|
|
||||||
bool out;
|
|
||||||
Logic::convertStringToValue(read(), out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Index size() const { return Logic::calcLength(read()); }
|
|
||||||
|
|
||||||
void calcLineOffsets(Buffer<Index>& aOut) const { Logic::calcLineOffsets(read(), size(), aOut); }
|
|
||||||
|
|
||||||
StringTemplate& operator=(tChar* in) {
|
|
||||||
this->~StringTemplate();
|
|
||||||
new (this) StringTemplate(in);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringTemplate& operator=(const tChar* in) {
|
|
||||||
this->~StringTemplate();
|
|
||||||
new (this) StringTemplate(in);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringTemplate& operator=(const StringTemplate& in) {
|
|
||||||
if (&in == this) return *this;
|
|
||||||
this->~StringTemplate();
|
|
||||||
new (this) StringTemplate(in);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const StringTemplate& in) const {
|
|
||||||
if (&in == this) return true;
|
|
||||||
if (in.mData == mData) return true;
|
|
||||||
return Logic::isEqualLogic(in.read(), read());
|
|
||||||
}
|
|
||||||
|
|
||||||
StringTemplate operator+(const StringTemplate& in) const {
|
|
||||||
StringTemplate out;
|
|
||||||
auto const newSize = in.size() + size();
|
|
||||||
out.resize(newSize);
|
|
||||||
Logic::insertLogic(out.write(), newSize, read(), in.read(), size(), in.size());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public: // Debugging
|
|
||||||
[[nodiscard]] ualni getReferenceCount() const { return mData->mReferenceCount; }
|
|
||||||
[[nodiscard]] bool getIsConstFlag() const { return mData->mIsConst; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename tChar>
|
|
||||||
StringData<tChar> StringTemplate<tChar>::sNullString;
|
|
||||||
|
|
||||||
using String = StringTemplate<int1>;
|
|
||||||
|
|
||||||
template <typename tChar>
|
|
||||||
ualni hash(StringTemplate<tChar> in) {
|
|
||||||
return hash(in.read());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,244 +0,0 @@
|
||||||
|
|
||||||
#include "UnitTest++/UnitTest++.h"
|
|
||||||
|
|
||||||
#include "Strings.hpp"
|
|
||||||
#include "StringLogic.hpp"
|
|
||||||
|
|
||||||
SUITE(Strings) {
|
|
||||||
using namespace tp;
|
|
||||||
|
|
||||||
typedef StringLogic<char> Logic;
|
|
||||||
|
|
||||||
struct TestStruct {
|
|
||||||
String str = "test data";
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(CoreLogic) {
|
|
||||||
String str;
|
|
||||||
CHECK(str.getIsConstFlag());
|
|
||||||
CHECK(str.getReferenceCount() == 2);
|
|
||||||
|
|
||||||
String str2;
|
|
||||||
CHECK(str.getIsConstFlag());
|
|
||||||
CHECK(str.getReferenceCount() == 3);
|
|
||||||
|
|
||||||
auto tmp = new TestStruct();
|
|
||||||
CHECK(tmp->str.getIsConstFlag());
|
|
||||||
CHECK(tmp->str.getReferenceCount() == 1);
|
|
||||||
|
|
||||||
str = tmp->str;
|
|
||||||
|
|
||||||
CHECK(str.getIsConstFlag());
|
|
||||||
CHECK(str.getReferenceCount() == 2);
|
|
||||||
|
|
||||||
delete tmp;
|
|
||||||
|
|
||||||
CHECK(str.getIsConstFlag());
|
|
||||||
CHECK(str.getReferenceCount() == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Addition) {
|
|
||||||
String str1 = "abc";
|
|
||||||
String str2 = "def";
|
|
||||||
{ str1 + str2; }
|
|
||||||
{
|
|
||||||
CHECK(str1 + str2 == "abcdef");
|
|
||||||
CHECK(str1 + "aaaccc" == "abcaaaccc");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(isNewLineChar) {
|
|
||||||
CHECK(Logic::isNewLineChar('\n'));
|
|
||||||
CHECK(Logic::isNewLineChar('\r'));
|
|
||||||
CHECK(!Logic::isNewLineChar('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(isEndChar) {
|
|
||||||
CHECK(Logic::isEndChar('\0'));
|
|
||||||
CHECK(!Logic::isEndChar('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(calcLength) {
|
|
||||||
const char* str1 = "Hello";
|
|
||||||
const char* str2 = "Wor\nld2";
|
|
||||||
CHECK(Logic::calcLength(str1) == 5);
|
|
||||||
CHECK(Logic::calcLength(str2) == 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(insertLogic_emptyTarget) {
|
|
||||||
char inserted[40] = { "" };
|
|
||||||
const char* cur = "Hello";
|
|
||||||
const char* tar = "";
|
|
||||||
const char* result = "Hello";
|
|
||||||
Logic::insertLogic(inserted, 40, cur, tar, 5, 0);
|
|
||||||
CHECK(Logic::isEqualLogic(inserted, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(insertLogic_emptyCurrent) {
|
|
||||||
char inserted[40] = { "" };
|
|
||||||
const char* cur = "";
|
|
||||||
const char* tar = "World";
|
|
||||||
const char* result = "World";
|
|
||||||
Logic::insertLogic(inserted, 40, cur, tar, 0, 5);
|
|
||||||
CHECK(Logic::isEqualLogic(inserted, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(insertLogic_curLengthLessThanPos) {
|
|
||||||
char inserted[40] = { "" };
|
|
||||||
const char* cur = "Hello";
|
|
||||||
const char* tar = "World";
|
|
||||||
const char* result = "HelloWorld";
|
|
||||||
Logic::insertLogic(inserted, 40, cur, tar, 5, 5);
|
|
||||||
CHECK(Logic::isEqualLogic(inserted, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(removeLogic_emptyCurrent) {
|
|
||||||
char removed[40] = { "" };
|
|
||||||
const char* cur = "";
|
|
||||||
const char* result = "";
|
|
||||||
Logic::removeLogic(removed, 40, cur, 0, 0);
|
|
||||||
CHECK(Logic::isEqualLogic(removed, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(removeLogic_removeUntilEnd) {
|
|
||||||
char removed[40] = { "" };
|
|
||||||
const char* cur = "HelloWorld";
|
|
||||||
const char* result = "World";
|
|
||||||
Logic::removeLogic(removed, 40, cur, 0, 5);
|
|
||||||
CHECK(Logic::isEqualLogic(removed, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(removeLogic_removeMiddleCharacters) {
|
|
||||||
char removed[40] = { "" };
|
|
||||||
const char* cur = "HelloWorld";
|
|
||||||
const char* result = "Helrld";
|
|
||||||
Logic::removeLogic(removed, 40, cur, 3, 7);
|
|
||||||
CHECK(Logic::isEqualLogic(removed, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(insertLogicGood) {
|
|
||||||
char inserted[40] = { "" };
|
|
||||||
const char* cur = "Hello";
|
|
||||||
const char* tar = "World";
|
|
||||||
const char* result = "HelloWorld";
|
|
||||||
Logic::insertLogic(inserted, 40, cur, tar, 5, 5);
|
|
||||||
CHECK(Logic::isEqualLogic(inserted, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(removeLogicGood) {
|
|
||||||
char removed[40] = { "" };
|
|
||||||
const char* cur = "HelloWorld";
|
|
||||||
const char* result = "Helld";
|
|
||||||
Logic::removeLogic(removed, 40, cur, 3, 8);
|
|
||||||
CHECK(Logic::isEqualLogic(removed, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertStringToValue_alni) {
|
|
||||||
const char* str1 = "123";
|
|
||||||
const char* str2 = "456xyz";
|
|
||||||
const char* str3 = "789";
|
|
||||||
alni output;
|
|
||||||
CHECK(Logic::convertStringToValue(str1, output) && output == 123);
|
|
||||||
CHECK(!Logic::convertStringToValue(str2, output));
|
|
||||||
CHECK(Logic::convertStringToValue(str3, output) && output == 789);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertStringToValue_alnf) {
|
|
||||||
const char* str1 = "12.34";
|
|
||||||
const char* str2 = "56.78xyz";
|
|
||||||
const char* str3 = "90.12";
|
|
||||||
alnf output;
|
|
||||||
CHECK(Logic::convertStringToValue(str1, output) && output == 12.34);
|
|
||||||
CHECK(!Logic::convertStringToValue(str2, output));
|
|
||||||
CHECK(Logic::convertStringToValue(str3, output) && output == 90.12);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertStringToValue_bool) {
|
|
||||||
const char* str1 = "true";
|
|
||||||
const char* str2 = "false";
|
|
||||||
const char* str3 = "1";
|
|
||||||
const char* str4 = "0";
|
|
||||||
bool output;
|
|
||||||
CHECK(Logic::convertStringToValue(str1, output) && output == true);
|
|
||||||
CHECK(Logic::convertStringToValue(str2, output) && output == false);
|
|
||||||
CHECK(Logic::convertStringToValue(str3, output) && output == true);
|
|
||||||
CHECK(Logic::convertStringToValue(str4, output) && output == false);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertValueToString_alni) {
|
|
||||||
alni input1 = 123;
|
|
||||||
alni input2 = -456;
|
|
||||||
char output[10];
|
|
||||||
CHECK(Logic::convertValueToString(input1, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "123"));
|
|
||||||
|
|
||||||
CHECK(Logic::convertValueToString(input2, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "-456"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertValueToString_alnf) {
|
|
||||||
alnf input1 = 12.34;
|
|
||||||
alnf input2 = -56.78;
|
|
||||||
char output[10];
|
|
||||||
|
|
||||||
CHECK(Logic::convertValueToString(input1, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "12.340000"));
|
|
||||||
|
|
||||||
CHECK(Logic::convertValueToString(input2, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "-56.78000"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(convertValueToString_bool) {
|
|
||||||
bool input1 = true;
|
|
||||||
bool input2 = false;
|
|
||||||
char output[10];
|
|
||||||
|
|
||||||
CHECK(Logic::convertValueToString(input1, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "true"));
|
|
||||||
|
|
||||||
CHECK(Logic::convertValueToString(input2, output, 10));
|
|
||||||
CHECK(Logic::isEqualLogic(output, "false"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(isEqualLogic) {
|
|
||||||
const char* str1 = "Hello";
|
|
||||||
const char* str2 = "Hello";
|
|
||||||
const char* str3 = "World";
|
|
||||||
const char* str4 = "Hello2";
|
|
||||||
CHECK(Logic::isEqualLogic(str1, str2));
|
|
||||||
CHECK(!Logic::isEqualLogic(str1, str4));
|
|
||||||
CHECK(!Logic::isEqualLogic(str1, str3));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(calcLineOffsets) {
|
|
||||||
const char* str = "\n\nHello\nWorld\n\n ";
|
|
||||||
Buffer<Logic::Index> offsets;
|
|
||||||
Logic::calcLineOffsets(str, Logic::calcLength(str), offsets);
|
|
||||||
|
|
||||||
CHECK(offsets.size() == 7);
|
|
||||||
|
|
||||||
CHECK(offsets[0] == 0);
|
|
||||||
CHECK(offsets[1] == 1);
|
|
||||||
CHECK(offsets[2] == 2);
|
|
||||||
CHECK(offsets[3] == 8);
|
|
||||||
CHECK(offsets[4] == 14);
|
|
||||||
CHECK(offsets[5] == 15);
|
|
||||||
CHECK(offsets[6] == 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
tp::ModuleManifest* deps[] = { &tp::gModuleStrings, nullptr };
|
|
||||||
tp::ModuleManifest testModule("StringsTest", nullptr, nullptr, deps);
|
|
||||||
|
|
||||||
if (!testModule.initialize()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto res = UnitTest::RunAllTests();
|
|
||||||
|
|
||||||
testModule.deinitialize();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@ file(GLOB HEADERS "./public/*.hpp")
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Math Graphics Imgui Strings)
|
target_link_libraries(${PROJECT_NAME} PUBLIC Math Graphics Imgui)
|
||||||
|
|
||||||
### -------------------------- Tests -------------------------- ###
|
### -------------------------- Tests -------------------------- ###
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,11 @@ namespace tp {
|
||||||
const auto size = this->getValue("Size");
|
const auto size = this->getValue("Size");
|
||||||
const auto colUser = this->getColor("ColUser");
|
const auto colUser = this->getColor("ColUser");
|
||||||
|
|
||||||
canvas.text(mUser.read(), this->mArea, size, Canvas::CC, padding, colUser);
|
canvas.text(mUser.c_str(), this->mArea, size, Canvas::CC, padding, colUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String mUser = "UserName";
|
std::string mUser = "UserName";
|
||||||
bool mIsHover = false;
|
bool mIsHover = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -83,13 +83,13 @@ namespace tp {
|
||||||
content.y = userName.y + userName.w;
|
content.y = userName.y + userName.w;
|
||||||
content.w = this->mArea.w - userName.w;
|
content.w = this->mArea.w - userName.w;
|
||||||
|
|
||||||
canvas.text(mContent.read(), content, size, Canvas::LC, padding, col);
|
canvas.text(mContent.c_str(), content, size, Canvas::LC, padding, col);
|
||||||
canvas.text(mUser.read(), userName, sizeUser, Canvas::LC, padding, colUser);
|
canvas.text(mUser.c_str(), userName, sizeUser, Canvas::LC, padding, colUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String mContent = "Message Content";
|
std::string mContent = "Message Content";
|
||||||
String mUser = "UserName";
|
std::string mUser = "UserName";
|
||||||
bool mIsHover = false;
|
bool mIsHover = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace tp {
|
||||||
this->addValue("Rounding", "Rounding");
|
this->addValue("Rounding", "Rounding");
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonWidget(const String& label, const tp::RectF& aArea) {
|
ButtonWidget(const std::string& label, const tp::RectF& aArea) {
|
||||||
this->mArea = aArea;
|
this->mArea = aArea;
|
||||||
this->mLabel.mLabel = label;
|
this->mLabel.mLabel = label;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace tp {
|
||||||
if (!this->mVisible) return;
|
if (!this->mVisible) return;
|
||||||
|
|
||||||
canvas.text(
|
canvas.text(
|
||||||
mLabel.read(),
|
mLabel.c_str(),
|
||||||
this->mArea,
|
this->mArea,
|
||||||
this->getValue("Size"),
|
this->getValue("Size"),
|
||||||
Canvas::CC,
|
Canvas::CC,
|
||||||
|
|
@ -33,6 +33,6 @@ namespace tp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String mLabel = "Label";
|
std::string mLabel = "Label";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WidgetBase.hpp"
|
#include "WidgetBase.hpp"
|
||||||
|
#include "Buffer.hpp"
|
||||||
|
|
||||||
namespace tp {
|
namespace tp {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace tp {
|
||||||
|
|
||||||
// ImGui::PushID((int) alni(this));
|
// ImGui::PushID((int) alni(this));
|
||||||
ImGui::Begin(
|
ImGui::Begin(
|
||||||
mId.read(),
|
mId.c_str(),
|
||||||
0,
|
0,
|
||||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground |
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground |
|
||||||
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoResize
|
||||||
|
|
@ -55,7 +55,7 @@ namespace tp {
|
||||||
nChanged = true;
|
nChanged = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ImGui::InputTextEx("input", mId.read(), mBuff, mMaxBufferSize, { this->mArea.z, this->mArea.w }, 0)) {
|
if (ImGui::InputTextEx("input", mId.c_str(), mBuff, mMaxBufferSize, { this->mArea.z, this->mArea.w }, 0)) {
|
||||||
mValue = mBuff;
|
mValue = mBuff;
|
||||||
nChanged = true;
|
nChanged = true;
|
||||||
}
|
}
|
||||||
|
|
@ -68,8 +68,8 @@ namespace tp {
|
||||||
enum { mMaxBufferSize = 512 };
|
enum { mMaxBufferSize = 512 };
|
||||||
char mBuff[mMaxBufferSize] = "";
|
char mBuff[mMaxBufferSize] = "";
|
||||||
bool nChanged = false;
|
bool nChanged = false;
|
||||||
String mValue;
|
std::string mValue;
|
||||||
String mId = "id";
|
std::string mId = "id";
|
||||||
bool mMultiline = false;
|
bool mMultiline = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ namespace tp {
|
||||||
this->mArea = { 0, 0, 100, 100 };
|
this->mArea = { 0, 0, 100, 100 };
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const RGBA& getColor(const String& name) const {
|
[[nodiscard]] const RGBA& getColor(const std::string& name) const {
|
||||||
const auto& node = cfg->values.get(name);
|
const auto& node = cfg->values.get(name);
|
||||||
if (node.type == WidgetConfig::Node::REF) {
|
if (node.type == WidgetConfig::Node::REF) {
|
||||||
return globalCfg->configs.get(node.refGroup).values.get(node.refName).color;
|
return globalCfg->configs.get(node.refGroup).values.get(node.refName).color;
|
||||||
|
|
@ -19,7 +19,7 @@ namespace tp {
|
||||||
return cfg->values.get(name).color;
|
return cfg->values.get(name).color;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] halnf getValue(const String& name) const {
|
[[nodiscard]] halnf getValue(const std::string& name) const {
|
||||||
const auto& node = cfg->values.get(name);
|
const auto& node = cfg->values.get(name);
|
||||||
if (node.type == WidgetConfig::Node::REF) {
|
if (node.type == WidgetConfig::Node::REF) {
|
||||||
return globalCfg->configs.get(node.refGroup).values.get(node.refName).value;
|
return globalCfg->configs.get(node.refGroup).values.get(node.refName).value;
|
||||||
|
|
@ -27,17 +27,17 @@ namespace tp {
|
||||||
return cfg->values.get(name).value;
|
return cfg->values.get(name).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addColor(const String& name, const RGBA& val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
void addColor(const std::string& name, const RGBA& val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
||||||
void addValue(const String& name, halnf val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
void addValue(const std::string& name, halnf val) { cfg->values.put(name, WidgetConfig::Node(val)); }
|
||||||
|
|
||||||
void addColor(const String& name, const String& presetName) {
|
void addColor(const std::string& name, const std::string& presetName) {
|
||||||
cfg->values.put(name, WidgetConfig::Node(presetName));
|
cfg->values.put(name, WidgetConfig::Node(presetName));
|
||||||
}
|
}
|
||||||
void addValue(const String& name, const String& presetName) {
|
void addValue(const std::string& name, const std::string& presetName) {
|
||||||
cfg->values.put(name, WidgetConfig::Node(presetName));
|
cfg->values.put(name, WidgetConfig::Node(presetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void createConfig(const String& name) {
|
void createConfig(const std::string& name) {
|
||||||
globalCfg->configs.put(name, {});
|
globalCfg->configs.put(name, {});
|
||||||
cfg = &globalCfg->configs.get(name);
|
cfg = &globalCfg->configs.get(name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#include "Animations.hpp"
|
#include "Animations.hpp"
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
#include "Rect.hpp"
|
#include "Rect.hpp"
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
#include "InputCodes.hpp"
|
#include "InputCodes.hpp"
|
||||||
|
|
||||||
|
|
@ -18,8 +17,8 @@ namespace tp {
|
||||||
|
|
||||||
Type type = NONE;
|
Type type = NONE;
|
||||||
|
|
||||||
String refGroup;
|
std::string refGroup;
|
||||||
String refName;
|
std::string refName;
|
||||||
|
|
||||||
Node() = default;
|
Node() = default;
|
||||||
|
|
||||||
|
|
@ -33,14 +32,14 @@ namespace tp {
|
||||||
color = val;
|
color = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Node(const String& val) {
|
explicit Node(const std::string& val) {
|
||||||
refGroup = "Presets";
|
refGroup = "Presets";
|
||||||
refName = val;
|
refName = val;
|
||||||
type = REF;
|
type = REF;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Map<String, Node> values;
|
Map<std::string, Node> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GlobalGUIConfig {
|
struct GlobalGUIConfig {
|
||||||
|
|
@ -54,16 +53,16 @@ namespace tp {
|
||||||
presets.values.put("Padding", WidgetConfig::Node(5.f));
|
presets.values.put("Padding", WidgetConfig::Node(5.f));
|
||||||
presets.values.put("HandleSize", WidgetConfig::Node(5.f));
|
presets.values.put("HandleSize", WidgetConfig::Node(5.f));
|
||||||
|
|
||||||
presets.values.put("Background", WidgetConfig::Node({ 0.03f, 0.03f, 0.03f, 1.f }));
|
presets.values.put("Background", WidgetConfig::Node(RGBA{ 0.03f, 0.03f, 0.03f, 1.f }));
|
||||||
presets.values.put("Base", WidgetConfig::Node({ 0.07f, 0.07f, 0.07f, 1.f }));
|
presets.values.put("Base", WidgetConfig::Node(RGBA{ 0.07f, 0.07f, 0.07f, 1.f }));
|
||||||
presets.values.put("Accent", WidgetConfig::Node({ 0.13f, 0.13f, 0.13f, 1.f }));
|
presets.values.put("Accent", WidgetConfig::Node(RGBA{ 0.13f, 0.13f, 0.13f, 1.f }));
|
||||||
presets.values.put("Interaction", WidgetConfig::Node({ 0.33f, 0.33f, 0.3f, 1.f }));
|
presets.values.put("Interaction", WidgetConfig::Node(RGBA{ 0.33f, 0.33f, 0.3f, 1.f }));
|
||||||
presets.values.put("Action", WidgetConfig::Node({ 0.44f, 0.44f, 0.4f, 1.f }));
|
presets.values.put("Action", WidgetConfig::Node(RGBA{ 0.44f, 0.44f, 0.4f, 1.f }));
|
||||||
presets.values.put("Front", WidgetConfig::Node({ 1.f, 1.f, 1.f, 1.f }));
|
presets.values.put("Front", WidgetConfig::Node(RGBA{ 1.f, 1.f, 1.f, 1.f }));
|
||||||
presets.values.put("FrontDim", WidgetConfig::Node({ 0.7f, 0.7f, 0.7f, 1.f }));
|
presets.values.put("FrontDim", WidgetConfig::Node(RGBA{ 0.7f, 0.7f, 0.7f, 1.f }));
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, WidgetConfig> configs;
|
Map<std::string, WidgetConfig> configs;
|
||||||
|
|
||||||
~GlobalGUIConfig() {
|
~GlobalGUIConfig() {
|
||||||
configs.removeAll();
|
configs.removeAll();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue