From c831174e186f50deae0807a15bc70ba04212c59f Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Mon, 14 Apr 2025 14:03:05 -0500 Subject: [PATCH] Add markedtobject --- CMakeLists.txt | 1 + include/CrossLang.hpp | 16 +++++++++++++ src/crosslang.cpp | 3 +-- src/markedtobject.cpp | 40 +++++++++++++++++++++++++++++++++ src/runtime_methods/console.cpp | 2 +- src/runtime_methods/crypto.cpp | 1 + src/runtime_methods/env.cpp | 22 +++++++++--------- src/runtime_methods/process.cpp | 2 +- src/runtime_methods/time.cpp | 12 +++++++++- src/sqlite/sqlite3.c | 4 ++-- src/sqlite/vfs.c | 2 +- src/vm/gc.cpp | 4 ++-- 12 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 src/markedtobject.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 284ec39..44b9b09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ src/vm/gclist.cpp src/vm/vm.cpp src/bitconverter.cpp src/archive.cpp +src/markedtobject.cpp ) if(CROSSLANG_ENABLE_PLATFORM_FOLDERS) diff --git a/include/CrossLang.hpp b/include/CrossLang.hpp index 0081e7b..6e330a9 100644 --- a/include/CrossLang.hpp +++ b/include/CrossLang.hpp @@ -1571,4 +1571,20 @@ class GC { void LoadPlugin(GC* gc, TRootEnvironment* env, Tesses::Framework::Filesystem::VFSPath sharedObjectPath); std::string Json_Encode(TObject o,bool indent=false); TObject Json_Decode(GCList ls,std::string str); + //DO NOT USE DIRECTLY + class SharedPtrTObject { + GCList* ls; + TObject o; + public: + SharedPtrTObject(GC* gc, TObject o); + TObject& GetObject(); + GC* GetGC(); + ~SharedPtrTObject(); + }; + using MarkedTObject = std::shared_ptr; + + MarkedTObject CreateMarkedTObject(GC* gc, TObject o); + MarkedTObject CreateMarkedTObject(GC& gc, TObject o); + MarkedTObject CreateMarkedTObject(GCList* gc, TObject o); + MarkedTObject CreateMarkedTObject(GCList& gc, TObject o); }; diff --git a/src/crosslang.cpp b/src/crosslang.cpp index bbce355..1d1a308 100644 --- a/src/crosslang.cpp +++ b/src/crosslang.cpp @@ -53,8 +53,7 @@ int main(int argc, char** argv) - Tesses::Framework::Filesystem::VFSPath dir = sago::getConfigHome(); - dir = dir / "Tesses" / "CrossLang"; + Tesses::Framework::Filesystem::VFSPath dir = GetCrossLangConfigDir(); Tesses::Framework::Filesystem::VFSPath filename = dir / "Shell" / "Shell.crvm"; diff --git a/src/markedtobject.cpp b/src/markedtobject.cpp new file mode 100644 index 0000000..7defd25 --- /dev/null +++ b/src/markedtobject.cpp @@ -0,0 +1,40 @@ +#include + +namespace Tesses::CrossLang +{ + SharedPtrTObject::SharedPtrTObject(GC* gc, TObject o) + { + this->ls = new GCList(gc); + this->ls->Add(o); + this->o = o; + } + TObject& SharedPtrTObject::GetObject() + { + return this->o; + } + SharedPtrTObject::~SharedPtrTObject() + { + if(this->ls) + delete this->ls; + } + GC* SharedPtrTObject::GetGC() + { + return this->ls->GetGC(); + } + MarkedTObject CreateMarkedTObject(GC* gc, TObject o) + { + return std::make_shared(gc,o); + } + MarkedTObject CreateMarkedTObject(GC& gc, TObject o) + { + return CreateMarkedTObject(&gc,o); + } + MarkedTObject CreateMarkedTObject(GCList* gc, TObject o) + { + return CreateMarkedTObject(gc->GetGC(),o); + } + MarkedTObject CreateMarkedTObject(GCList& gc, TObject o) + { + return CreateMarkedTObject(gc.GetGC(),o); + } +} \ No newline at end of file diff --git a/src/runtime_methods/console.cpp b/src/runtime_methods/console.cpp index 2c43b7b..5e42cd4 100644 --- a/src/runtime_methods/console.cpp +++ b/src/runtime_methods/console.cpp @@ -2,7 +2,7 @@ #include "CrossLang.hpp" #include -#if defined(GEKKO) +#if defined(GEKKO) || defined(__SWITCH__) #undef CROSSLANG_ENABLE_TERMIOS #endif diff --git a/src/runtime_methods/crypto.cpp b/src/runtime_methods/crypto.cpp index 00bade1..4ff1af6 100644 --- a/src/runtime_methods/crypto.cpp +++ b/src/runtime_methods/crypto.cpp @@ -1,4 +1,5 @@ #include "CrossLang.hpp" + #include #if defined(TESSESFRAMEWORK_ENABLE_MBED) #include diff --git a/src/runtime_methods/env.cpp b/src/runtime_methods/env.cpp index 7eaa138..20bb1f6 100644 --- a/src/runtime_methods/env.cpp +++ b/src/runtime_methods/env.cpp @@ -13,7 +13,16 @@ namespace Tesses::CrossLang #else static char EnvPathSeperator=':'; #endif - + static std::string GetHomeFolder() + { + #if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS) + return sago::getHomeDir(); + #elif defined(__EMSCRIPTEN__) + return "/home/web_user"; + #else + return "/CrossLangProfile"; + #endif + } Tesses::Framework::Filesystem::VFSPath GetCrossLangConfigDir() { Tesses::Framework::Filesystem::VFSPath p; @@ -58,16 +67,7 @@ namespace Tesses::CrossLang #endif } - static std::string GetHomeFolder() - { - #if defined(CROSSLANG_ENABLE_PLATFORM_FOLDERS) - return sago::getHomeDir(); - #elif defined(__EMSCRIPTEN__) - return "/home/web_user"; - #else - return "/CrossLangProfile"; - #endif - } + static TObject Env_getCrossLangConfig(GCList& ls, std::vector args) { return GetCrossLangConfigDir(); diff --git a/src/runtime_methods/process.cpp b/src/runtime_methods/process.cpp index 7f87ac3..7969c72 100644 --- a/src/runtime_methods/process.cpp +++ b/src/runtime_methods/process.cpp @@ -1,6 +1,6 @@ #include "CrossLang.hpp" -#if defined(GEKKO) +#if defined(GEKKO) || defined(__SWITCH__) #undef CROSSLANG_ENABLE_PROCESS #endif diff --git a/src/runtime_methods/time.cpp b/src/runtime_methods/time.cpp index 93a9a35..1345122 100644 --- a/src/runtime_methods/time.cpp +++ b/src/runtime_methods/time.cpp @@ -8,8 +8,13 @@ namespace Tesses::CrossLang { static int64_t ToLocalTime(int64_t local) { + #if defined(__SWITCH__) + local -= _timezone; + if(_daylight) + #else local -= timezone; if(daylight) + #endif { auto epoch = date::sys_days{date::January/1/1970}; epoch += date::days(local/86400); @@ -163,10 +168,15 @@ namespace Tesses::CrossLang dict->DeclareFunction(gc, "Sleep","Sleep for a specified amount of milliseconds (multiply seconds by 1000 to get milliseconds)", {"ms"},Time_Sleep); gc->BarrierBegin(); + #if defined(__SWITCH__) + dict->SetValue("Zone", (int64_t)-(_timezone)); + dict->SetValue("SupportsDaylightSavings",(int64_t)_daylight); + #else dict->SetValue("Zone", (int64_t)-(timezone)); dict->SetValue("SupportsDaylightSavings",(int64_t)daylight); + #endif env->DeclareVariable("Time", dict); gc->BarrierEnd(); } -} \ No newline at end of file +} diff --git a/src/sqlite/sqlite3.c b/src/sqlite/sqlite3.c index ea26adf..472629f 100644 --- a/src/sqlite/sqlite3.c +++ b/src/sqlite/sqlite3.c @@ -20,8 +20,8 @@ ** The content in this amalgamation comes from Fossil check-in ** c9c2ab54ba1f5f46360f1b4f35d849cd3f08. */ - -#if defined(GEKKO) + +#if defined(GEKKO) || defined(__SWITCH__) //-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_WAL -DSQLITE_THREADSAFE=0 #define SQLITE_OMIT_LOAD_EXTENSION #define SQLITE_OMIT_WAL diff --git a/src/sqlite/vfs.c b/src/sqlite/vfs.c index afd4664..0cd753f 100644 --- a/src/sqlite/vfs.c +++ b/src/sqlite/vfs.c @@ -115,7 +115,7 @@ /*removed tests from https://www.sqlite.org/src/doc/trunk/src/test_demovfs.c*/ -#if defined(GEKKO) +#if defined(GEKKO) || defined(__SWITCH__) #include "sqlite3.h" diff --git a/src/vm/gc.cpp b/src/vm/gc.cpp index 3ead883..9a1148f 100644 --- a/src/vm/gc.cpp +++ b/src/vm/gc.cpp @@ -8,7 +8,7 @@ extern "C" { #include "../sqlite/sqlite3.h" } -#if defined(GEKKO) +#if defined(GEKKO) || defined(__SWITCH__) extern "C" { sqlite3_vfs *sqlite3_demovfs(); } @@ -31,7 +31,7 @@ namespace Tesses::CrossLang tzset(); #if defined(CROSSLANG_ENABLE_SQLITE) sqlite3_initialize(); - #if defined(GEKKO) + #if defined(GEKKO) || defined(__SWITCH__) sqlite3_vfs_register(sqlite3_demovfs(),1); #endif #endif