1 Commits

Author SHA1 Message Date
fca18e63a6 Commit before replacing GC* with std::shared_ptr<GC> 2026-04-30 10:07:14 -05:00
9 changed files with 454 additions and 610 deletions

View File

@@ -1456,7 +1456,7 @@ class GC {
~GCList();
friend class GC;
};
@@ -2028,19 +2028,11 @@ class GC {
GCList* ls;
TObjectVFS(GC* gc, TObject obj);
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode);
Tesses::Framework::Filesystem::FIFOCreationResult CreateFIFO(Tesses::Framework::Filesystem::VFSPath path);
void CreateDirectory(Tesses::Framework::Filesystem::VFSPath path);
void DeleteDirectory(Tesses::Framework::Filesystem::VFSPath path);
bool RegularFileExists(Tesses::Framework::Filesystem::VFSPath path);
bool SymlinkExists(Tesses::Framework::Filesystem::VFSPath path);
bool CharacterDeviceExists(Tesses::Framework::Filesystem::VFSPath path);
bool BlockDeviceExists(Tesses::Framework::Filesystem::VFSPath path);
bool SocketFileExists(Tesses::Framework::Filesystem::VFSPath path);
bool FIFOFileExists(Tesses::Framework::Filesystem::VFSPath path);
bool FileExists(Tesses::Framework::Filesystem::VFSPath path);
bool SpecialFileExists(Tesses::Framework::Filesystem::VFSPath path);
void CreateSymlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath symlinkFile);
void CreateHardlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath newName);
bool DirectoryExists(Tesses::Framework::Filesystem::VFSPath path);
void DeleteFile(Tesses::Framework::Filesystem::VFSPath path);
void Lock(Tesses::Framework::Filesystem::VFSPath path);
void Unlock(Tesses::Framework::Filesystem::VFSPath path);
@@ -2052,10 +2044,13 @@ class GC {
Tesses::Framework::Filesystem::VFSPath ReadLink(Tesses::Framework::Filesystem::VFSPath path);
std::string VFSPathToSystem(Tesses::Framework::Filesystem::VFSPath path);
Tesses::Framework::Filesystem::VFSPath SystemToVFSPath(std::string path);
void GetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime& lastWrite, Tesses::Framework::Date::DateTime& lastAccess);
void SetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime lastWrite, Tesses::Framework::Date::DateTime lastAccess);
void Chmod(Tesses::Framework::Filesystem::VFSPath path, uint32_t mode);
void Chown(Tesses::Framework::Filesystem::VFSPath path, uint32_t uid, uint32_t gid);
bool StatVFS(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatVFSData& data);
bool Stat(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatData& data);
void Close();
~TObjectVFS();
};

View File

@@ -6,12 +6,12 @@
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
static GC gc;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));

View File

@@ -6,12 +6,13 @@
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
static GC gc;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));

View File

@@ -28,14 +28,17 @@ int main(int argc, char** argv)
{
GC gc;
gc.Start();
int64_t myi64=0;
{
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
GetObject(res,myi64);
}
return (int)myi64;
return 0;
}
else if(programName == "crossc")
{
@@ -73,31 +76,37 @@ int main(int argc, char** argv)
{
GC gc;
gc.Start();
int64_t myi64=0;
{
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
GetObject(res,myi64);
}
return (int)myi64;
return 0;
}
else if(args.size() > 1)
{
if(args[1] == "crossint")
{
int64_t myi64=0;
args.erase(args.begin());
GC gc;
gc.Start();
{
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
GetObject(res,myi64);
}
return (int)myi64;
return 0;
}
else if(args[1] == "crossc")
{
@@ -136,29 +145,36 @@ int main(int argc, char** argv)
}
else if(args[1] == "crossvm")
{
int64_t myi64=0;
args.erase(args.begin());
GC gc;
gc.Start();
{
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
GetObject(res,myi64);
}
return (int)myi64;
return 0;
}
}
{
int64_t myi64=0;
GC gc;
gc.Start();
{
GCList ls(gc);
auto res= Programs::CrossLangShell(ls, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
return 0;
GetObject(res,myi64);
}
return (int)myi64;
}
}

View File

@@ -641,10 +641,7 @@ namespace Tesses::CrossLang
}
return nullptr;
}
static TObject New_MemoryFilesystem(GCList& ls, std::vector<TObject> args)
{
return std::make_shared<Tesses::Framework::Filesystem::MemoryFilesystem>();
}
static TObject New_Filesystem(GCList& ls, std::vector<TObject> args)
{
@@ -1330,8 +1327,6 @@ namespace Tesses::CrossLang
newTypes->DeclareFunction(gc, "TempFS","Create a temp directory",{"",""}, New_TempFS);
newTypes->DeclareFunction(gc, "Stream","Create stream", {"strm"},New_Stream);
newTypes->DeclareFunction(gc, "MemoryFilesystem","Create in memory filesystem", {},New_MemoryFilesystem);
newTypes->DeclareFunction(gc,"Version","Create a version object",{"$major","$minor","$patch","$build","$stage"},[](GCList& ls, std::vector<TObject> args)->TObject{
int64_t major=1;

View File

@@ -7,130 +7,23 @@ namespace Tesses::CrossLang {
this->ls = new GCList(gc);
this->ls->Add(obj);
this->obj = obj;
}
Tesses::Framework::Filesystem::FIFOCreationResult TObjectVFS::CreateFIFO(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(obj,dict))
if(GetObjectHeap(this->obj, dict))
{
gc->BarrierBegin();
if(!dict->HasValue("OpenFile"))
{
dict->DeclareFunction(gc,"OpenFile","Open a file",{"path","mode"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return nullptr;
});
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "CreateFIFO",{path});
int64_t n=0;
if(GetObject(res, n)) return (Tesses::Framework::Filesystem::FIFOCreationResult)n;
}
if(!dict->HasValue("EnumeratePaths"))
{
dict->DeclareFunction(gc,"EnumeratePaths","Enumerate paths",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return TVFSPathEnumerator::Create(ls,Tesses::Framework::Filesystem::VFSPathEnumerator());
});
}
if(!dict->HasValue("ReadLink"))
{
dict->DeclareFunction(gc,"ReadLink","Read a symlink",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return Tesses::Framework::Filesystem::VFSPath();
});
return Tesses::Framework::Filesystem::FIFOCreationResult::UnknownError;
}
if(!dict->HasValue("VFSPathToSystem"))
{
dict->DeclareFunction(gc,"VFSPathToSystem","Convert path to system",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
Tesses::Framework::Filesystem::VFSPath path;
if(GetArgumentAsPath(args,0,path))
{
return path.ToString();
}
return "/";
});
}
if(!dict->HasValue("SystemToVFSPath"))
{
dict->DeclareFunction(gc,"SystemToVFSPath","Convert system to path",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
std::string p;
if(GetArgument(args,0,p))
{
return Tesses::Framework::Filesystem::VFSPath(p);
}
return Tesses::Framework::Filesystem::VFSPath();
});
}
if(!dict->HasValue("GetDate"))
{
dict->DeclareFunction(gc,"GetDate","Get date from file",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
auto dict = TDictionary::Create(ls);
ls.GetGC()->BarrierBegin();
dict->SetValue("LastWrite", (int64_t)time(NULL));
dict->SetValue("LastAccess", (int64_t)time(NULL));
ls.GetGC()->BarrierEnd();
return dict;
});
}
if(!dict->HasValue("RegularFileExists"))
{
dict->DeclareFunction(gc,"RegularFileExists","Regular file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("SymlinkExists"))
{
dict->DeclareFunction(gc,"SymlinkExists","Symlink exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("CharacterDeviceExists"))
{
dict->DeclareFunction(gc,"CharacterDeviceExists","Character file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("BlockDeviceExists"))
{
dict->DeclareFunction(gc,"BlockDeviceExists","Block file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("SocketFileExists"))
{
dict->DeclareFunction(gc,"SocketFileExists","Socket file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("FIFOFileExists"))
{
dict->DeclareFunction(gc,"FIFOFileExists","FIFO file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("FileExists"))
{
dict->DeclareFunction(gc,"FileExists","File exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("SpecialFileExists"))
{
dict->DeclareFunction(gc,"SpecialFileExists","Special file exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
if(!dict->HasValue("DirectoryExists"))
{
dict->DeclareFunction(gc,"DirectoryExists","Directory exists",{"path"}, [](GCList& ls, std::vector<TObject> args)->TObject {
return false;
});
}
gc->BarrierEnd();
}
}
std::shared_ptr<Tesses::Framework::Streams::Stream> TObjectVFS::OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode)
{
TDictionary* dict;
@@ -189,135 +82,6 @@ namespace Tesses::CrossLang {
}
}
bool TObjectVFS::RegularFileExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "RegularFileExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::SymlinkExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "SymlinkExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::CharacterDeviceExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "CharacterDeviceExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::BlockDeviceExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "BlockDeviceExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::SocketFileExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "SocketFileExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::FIFOFileExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "FIFOFileExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::FileExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "FileExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
bool TObjectVFS::SpecialFileExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "SpecialFileExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
void TObjectVFS::CreateSymlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath symlinkFile)
{
TDictionary* dict;
@@ -340,21 +104,6 @@ namespace Tesses::CrossLang {
}
}
bool TObjectVFS::DirectoryExists(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "DirectoryExists",{path});
bool out;
if(GetObject(res,out))
{
return out;
}
}
return false;
}
void TObjectVFS::DeleteFile(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
@@ -484,31 +233,6 @@ namespace Tesses::CrossLang {
}
return Tesses::Framework::Filesystem::VFSPath();
}
void TObjectVFS::GetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime& lastWrite, Tesses::Framework::Date::DateTime& lastAccess)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "GetDate",{path});
if(GetObjectHeap(res,dict))
{
this->ls->GetGC()->BarrierBegin();
res = dict->GetValue("LastWrite");
std::shared_ptr<Tesses::Framework::Date::DateTime> d;
if(GetObject(res,d))
lastWrite =*d;
res = dict->GetValue("LastAccess");
if(GetObject(res,d))
lastWrite = *d;
this->ls->GetGC()->BarrierEnd();
}
}
}
void TObjectVFS::SetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime lastWrite, Tesses::Framework::Date::DateTime lastAccess)
{
@@ -532,6 +256,80 @@ namespace Tesses::CrossLang {
}
}
void TObjectVFS::Chown(Tesses::Framework::Filesystem::VFSPath path, uint32_t uid, uint32_t gid)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
dict->CallMethod(ls, "Chown",{path,(int64_t)uid, (int64_t)gid});
}
}
bool TObjectVFS::Stat(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatData& data)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
GCList ls(this->ls->GetGC());
auto res = dict->CallMethod(ls, "Stat",{path});
int64_t _num;
TDictionary* _dict;
TObject _o;
if(GetObjectHeap(res,_dict))
{
this->ls->GetGC()->BarrierBegin();
_o = dict->GetValue("BlockSize");
if(GetObject(_o,_num)) data.BlockSize = (uint64_t)_num;
_o = dict->GetValue("BlockCount");
if(GetObject(_o,_num)) data.BlockCount = (uint64_t)_num;
_o = dict->GetValue("Device");
if(GetObject(_o,_num)) data.Device = (uint64_t)_num;
_o = dict->GetValue("DeviceId");
if(GetObject(_o,_num)) data.DeviceId = (uint64_t)_num;
_o = dict->GetValue("GroupId");
if(GetObject(_o,_num)) data.GroupId = (uint32_t)_num;
_o = dict->GetValue("HardLinks");
if(GetObject(_o,_num)) data.HardLinks = (uint64_t)_num;
std::shared_ptr<Tesses::Framework::Date::DateTime> dt;
_o = dict->GetValue("LastAccess");
if(GetObject(_o,dt)) data.LastAccess = dt ? *dt : Tesses::Framework::Date::DateTime(0);
_o = dict->GetValue("LastModified");
if(GetObject(_o,dt)) data.LastModified = dt ? *dt : Tesses::Framework::Date::DateTime(0);
_o = dict->GetValue("LastStatus");
if(GetObject(_o,dt)) data.LastStatus = dt ? *dt : Tesses::Framework::Date::DateTime(0);
_o = dict->GetValue("Mode");
if(GetObject(_o,_num)) data.Mode = (uint32_t)_num;
_o = dict->GetValue("Size");
if(GetObject(_o,_num)) data.Size = (uint64_t)_num;
_o = dict->GetValue("UserId");
if(GetObject(_o,_num)) data.UserId = (uint32_t)_num;
this->ls->GetGC()->BarrierEnd();
return true;
}
}
return false;
}
bool TObjectVFS::StatVFS(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatVFSData& data)
{
TDictionary* dict;

View File

@@ -1997,6 +1997,38 @@ namespace Tesses::CrossLang {
cse.back()->Push(gc, nullptr);
return false;
}
if(key == "Stat")
{
Tesses::Framework::Filesystem::VFSPath path;
if(GetArgumentAsPath(args,0,path))
{
Tesses::Framework::Filesystem::StatData data;
if(vfs->Stat(path,data))
{
cse.back()->Push(gc, TDictionary::Create(ls,{
TDItem("BlockCount", (int64_t)data.BlockCount),
TDItem("BlockSize", (int64_t)data.BlockSize),
TDItem("Device", (int64_t)data.Device),
TDItem("DeviceId", (int64_t)data.DeviceId),
TDItem("GroupId", (int64_t)data.GroupId),
TDItem("HardLinks", (int64_t)data.HardLinks),
TDItem("Inode", (int64_t)data.Inode),
TDItem("LastAccess", std::make_shared<Tesses::Framework::Date::DateTime>(data.LastAccess)),
TDItem("LastModified", std::make_shared<Tesses::Framework::Date::DateTime>(data.LastModified)),
TDItem("LastStatus", std::make_shared<Tesses::Framework::Date::DateTime>(data.LastStatus)),
TDItem("Mode", (int64_t)data.Mode),
TDItem("Size", (int64_t)data.Size),
TDItem("UserId", (int64_t)data.UserId)
}));
return false;
}
}
cse.back()->Push(gc, nullptr);
return false;
}
if(key == "StatVFS")
{
Tesses::Framework::Filesystem::VFSPath path;

View File

@@ -24,11 +24,6 @@ namespace Tesses::CrossLang
GC::GC()
{
this->tpool=new Tesses::Framework::Lazy<Tesses::Framework::Threading::ThreadPool*>([]()->Tesses::Framework::Threading::ThreadPool*{
auto threads = Tesses::Framework::Threading::ThreadPool::GetNumberOfCores();
if(threads < 4) threads=4;
return new Tesses::Framework::Threading::ThreadPool(threads);
},[](Tesses::Framework::Threading::ThreadPool* p)->void{delete p;});
}
TDictionary* CreateThread(GCList& ls, TCallable* callable,bool detached)
{
@@ -91,6 +86,12 @@ namespace Tesses::CrossLang
}
void GC::Start()
{
this->tpool=new Tesses::Framework::Lazy<Tesses::Framework::Threading::ThreadPool*>([]()->Tesses::Framework::Threading::ThreadPool*{
auto threads = Tesses::Framework::Threading::ThreadPool::GetNumberOfCores();
if(threads < 4) threads=4;
return new Tesses::Framework::Threading::ThreadPool(threads);
},[](Tesses::Framework::Threading::ThreadPool* p)->void{delete p;});
this->mtx=new Mutex();
this->running = true;
this->thrd = new Thread([this]()->void {
@@ -203,6 +204,7 @@ namespace Tesses::CrossLang
{
return this->tpool->GetValue();
}
void GC::UnsetRoot(TObject obj)
{
if(std::holds_alternative<THeapObjectHolder>(obj))
@@ -224,14 +226,19 @@ namespace Tesses::CrossLang
GC::~GC()
{
GC::BarrierBegin();
this->roots.clear();
GC::BarrierEnd();
this->running=false;
this->thrd->Join();
delete this->thrd;
for(auto item : objects) delete item;
delete this->mtx;
delete this->tpool;
delete this->mtx;
}
void GC::RegisterEverythingCallback(std::function<void(GC* gc, TRootEnvironment* env)> cb)