3 Commits

Author SHA1 Message Date
fca18e63a6 Commit before replacing GC* with std::shared_ptr<GC> 2026-04-30 10:07:14 -05:00
63b00ebbcb Use alpine for Docker 2026-04-16 22:24:18 -05:00
7badbeb217 Use alpine for Docker 2026-04-16 22:18:53 -05:00
12 changed files with 511 additions and 675 deletions

View File

@@ -1,57 +1,42 @@
version: 43 version: 43
jobs: jobs:
- name: Build for x86_64 - name: Build for x86_64
steps: steps:
- type: CheckoutStep - type: CheckoutStep
name: Checkout name: Checkout
cloneCredential: cloneCredential:
type: DefaultCredential type: DefaultCredential
withLfs: true withLfs: true
withSubmodules: false withSubmodules: false
condition: SUCCESSFUL condition: SUCCESSFUL
optional: false optional: false
- type: CommandStep - type: BuildImageStep
name: Execute build name: Build Docker Image
runInContainer: true dockerfile: Dockerfile
image: onedev.site.tesses.net/tesses-framework/tesses-framework:latest output:
interpreter: type: RegistryOutput
type: DefaultInterpreter tags: onedev.site.tesses.net/crosslang/crosslang:latest onedev.site.tesses.net/crosslang/crosslang:@commit_hash@
commands: | registryLogins:
mkdir build - registryUrl: "@server_url@"
cd build userName: "@job_token@"
cmake -S .. -B . -DCROSSLANG_FETCHCONTENT=OFF passwordSecret: dockersecret
make -j12 platforms: linux/amd64
make install DESTDIR=../out condition: SUCCESSFUL
useTTY: true optional: false
condition: SUCCESSFUL triggers:
optional: false - type: DependencyFinishedTrigger
- type: BuildImageStep projects: tesses-framework
name: Build Docker Image - type: BranchUpdateTrigger
dockerfile: Dockerfile.run branches: master
output: userMatch: anyone
type: RegistryOutput projects: crosslang
tags: onedev.site.tesses.net/crosslang/crosslang:latest onedev.site.tesses.net/crosslang/crosslang:@commit_hash@ projectDependencies:
registryLogins: - projectPath: tesses-framework
- registryUrl: '@server_url@' buildProvider:
userName: '@job_token@' type: LastFinishedBuild
passwordSecret: dockersecret jobName: Build for x86_64
platforms: linux/amd64 artifacts: "*"
condition: SUCCESSFUL retryCondition: never
optional: false maxRetries: 3
triggers: retryDelay: 30
- type: DependencyFinishedTrigger timeout: 14400
projects: tesses-framework
- type: BranchUpdateTrigger
branches: master
userMatch: anyone
projects: crosslang
projectDependencies:
- projectPath: tesses-framework
buildProvider:
type: LastFinishedBuild
jobName: Build for x86_64
artifacts: '*'
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 14400

View File

@@ -1,8 +1,17 @@
FROM onedev.site.tesses.net/tesses-framework/tesses-framework:latest FROM alpine:latest AS build
RUN apt update -y && \
apt install -y --no-install-recommends \ RUN apk update
libjansson-dev wget && \ RUN apk add --no-cache cmake g++ make git
apt clean -y && \
rm -rf /var/lib/apt/lists/* COPY ./ /src
RUN mkdir /src && cd /src && git clone https://onedev.site.tesses.net/crosslang . && cd /src && mkdir build && cd build && cmake -S .. -B . && make -j4 && make install && cd / && rm -r /src
WORKDIR /
RUN cd /src && mkdir build && cd build && cmake -S .. -B . -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_APPS=ON -DCMAKE_BUILD_TYPE=Release ; make -j`nproc` && make install DESTDIR=/out
FROM alpine:latest
RUN apk update
RUN apk add --no-cache libstdc++
COPY --from=build /out/usr /usr
ENV CROSSLANG_CONTAINER=1
ENTRYPOINT ["/usr/local/bin/crossint"]

View File

@@ -1,2 +0,0 @@
FROM onedev.site.tesses.net/tesses-framework/tesses-framework:latest
COPY out /

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -7,7 +7,7 @@ using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
//crosslang crossint //crosslang crossint
//crosslang //crosslang
//crosslang ... //crosslang ...
std::string programName = "crosslang"; std::string programName = "crosslang";
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
path.RemoveExtension(); path.RemoveExtension();
programName = path.GetFileName(); programName = path.GetFileName();
} }
std::vector<std::string> args(argc); std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++)
args[i] = argv[i]; args[i] = argv[i];
@@ -28,14 +28,17 @@ int main(int argc, char** argv)
{ {
GC gc; GC gc;
gc.Start(); gc.Start();
int64_t myi64=0;
{
GCList ls(gc); GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls)); TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env); TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args); auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64)) GetObject(res,myi64);
return (int)myi64;
return 0; }
return (int)myi64;
} }
else if(programName == "crossc") else if(programName == "crossc")
{ {
@@ -73,31 +76,37 @@ int main(int argc, char** argv)
{ {
GC gc; GC gc;
gc.Start(); gc.Start();
int64_t myi64=0;
{
GCList ls(gc); GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls)); TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env); TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args); auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64; GetObject(res,myi64);
if(GetObject(res,myi64)) }
return (int)myi64; return (int)myi64;
return 0;
} }
else if(args.size() > 1) else if(args.size() > 1)
{ {
if(args[1] == "crossint") if(args[1] == "crossint")
{ {
int64_t myi64=0;
args.erase(args.begin()); args.erase(args.begin());
GC gc; GC gc;
gc.Start(); gc.Start();
{
GCList ls(gc); GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls)); TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env); TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args); auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64)) GetObject(res,myi64);
return (int)myi64; }
return 0; return (int)myi64;
} }
else if(args[1] == "crossc") else if(args[1] == "crossc")
{ {
@@ -136,29 +145,36 @@ int main(int argc, char** argv)
} }
else if(args[1] == "crossvm") else if(args[1] == "crossvm")
{ {
int64_t myi64=0;
args.erase(args.begin()); args.erase(args.begin());
GC gc; GC gc;
gc.Start(); gc.Start();
{
GCList ls(gc); GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls)); TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env); TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args); auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64; GetObject(res,myi64);
if(GetObject(res,myi64)) }
return (int)myi64;
return 0; return (int)myi64;
} }
} }
{
int64_t myi64=0;
GC gc; GC gc;
gc.Start(); gc.Start();
GCList ls(gc); {
auto res= Programs::CrossLangShell(ls, args); GCList ls(gc);
int64_t myi64; auto res= Programs::CrossLangShell(ls, args);
if(GetObject(res,myi64))
return (int)myi64; GetObject(res,myi64);
return 0;
return 0;
}
} return (int)myi64;
}
}

View File

@@ -641,10 +641,7 @@ namespace Tesses::CrossLang
} }
return nullptr; 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) static TObject New_Filesystem(GCList& ls, std::vector<TObject> args)
{ {
@@ -1329,9 +1326,7 @@ namespace Tesses::CrossLang
newTypes->DeclareFunction(gc, "Filesystem","Create filesystem", {"fs"},New_Filesystem); newTypes->DeclareFunction(gc, "Filesystem","Create filesystem", {"fs"},New_Filesystem);
newTypes->DeclareFunction(gc, "TempFS","Create a temp directory",{"",""}, New_TempFS); newTypes->DeclareFunction(gc, "TempFS","Create a temp directory",{"",""}, New_TempFS);
newTypes->DeclareFunction(gc, "Stream","Create stream", {"strm"},New_Stream); 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{ newTypes->DeclareFunction(gc,"Version","Create a version object",{"$major","$minor","$patch","$build","$stage"},[](GCList& ls, std::vector<TObject> args)->TObject{
int64_t major=1; int64_t major=1;

View File

@@ -7,130 +7,23 @@ namespace Tesses::CrossLang {
this->ls = new GCList(gc); this->ls = new GCList(gc);
this->ls->Add(obj); this->ls->Add(obj);
this->obj = obj; this->obj = obj;
TDictionary* dict;
if(GetObjectHeap(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;
});
}
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();
});
}
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();
}
} }
Tesses::Framework::Filesystem::FIFOCreationResult TObjectVFS::CreateFIFO(Tesses::Framework::Filesystem::VFSPath path)
{
TDictionary* dict;
if(GetObjectHeap(this->obj, dict))
{
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;
}
return Tesses::Framework::Filesystem::FIFOCreationResult::UnknownError;
}
std::shared_ptr<Tesses::Framework::Streams::Stream> TObjectVFS::OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode) std::shared_ptr<Tesses::Framework::Streams::Stream> TObjectVFS::OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode)
{ {
TDictionary* dict; TDictionary* dict;
@@ -189,136 +82,7 @@ namespace Tesses::CrossLang {
} }
} }
bool TObjectVFS::RegularFileExists(Tesses::Framework::Filesystem::VFSPath path) void TObjectVFS::CreateSymlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath symlinkFile)
{
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; TDictionary* dict;
@@ -340,22 +104,7 @@ namespace Tesses::CrossLang {
} }
} }
bool TObjectVFS::DirectoryExists(Tesses::Framework::Filesystem::VFSPath path) void TObjectVFS::DeleteFile(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; TDictionary* dict;
@@ -484,31 +233,6 @@ namespace Tesses::CrossLang {
} }
return Tesses::Framework::Filesystem::VFSPath(); 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) 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) bool TObjectVFS::StatVFS(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatVFSData& data)
{ {
TDictionary* dict; TDictionary* dict;

View File

@@ -1997,6 +1997,38 @@ namespace Tesses::CrossLang {
cse.back()->Push(gc, nullptr); cse.back()->Push(gc, nullptr);
return false; 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") if(key == "StatVFS")
{ {
Tesses::Framework::Filesystem::VFSPath path; Tesses::Framework::Filesystem::VFSPath path;

View File

@@ -13,28 +13,23 @@ using namespace Tesses::Framework::Threading;
using namespace std::chrono; using namespace std::chrono;
namespace Tesses::CrossLang namespace Tesses::CrossLang
{ {
bool GC::IsRunning() bool GC::IsRunning()
{ {
bool run = this->running; bool run = this->running;
return run; return run;
} }
GC::GC() 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) TDictionary* CreateThread(GCList& ls, TCallable* callable,bool detached)
{ {
TDictionary* dict = TDictionary::Create(ls); TDictionary* dict = TDictionary::Create(ls);
ThreadHandle* th = new ThreadHandle(); ThreadHandle* th = new ThreadHandle();
th->gc = ls.GetGC(); th->gc = ls.GetGC();
th->callable = callable; th->callable = callable;
@@ -43,16 +38,16 @@ namespace Tesses::CrossLang
th->detached=detached; th->detached=detached;
ls.Add(th); ls.Add(th);
ls.GetGC()->Watch(th); ls.GetGC()->Watch(th);
ls.GetGC()->BarrierBegin(); ls.GetGC()->BarrierBegin();
dict->SetValue("_internal", th); dict->SetValue("_internal", th);
dict->DeclareFunction(ls.GetGC(),"Join","Join thread",{},[th](GCList& _ls, std::vector<TObject> _args)-> TObject{ dict->DeclareFunction(ls.GetGC(),"Join","Join thread",{},[th](GCList& _ls, std::vector<TObject> _args)-> TObject{
th->thrd->Join(); th->thrd->Join();
delete th->thrd; delete th->thrd;
if(th->hasReturned) if(th->hasReturned)
{ {
_ls.GetGC()->BarrierBegin(); _ls.GetGC()->BarrierBegin();
@@ -69,12 +64,12 @@ namespace Tesses::CrossLang
_ls.GetGC()->BarrierEnd(); _ls.GetGC()->BarrierEnd();
return Undefined(); return Undefined();
}); });
dict->DeclareFunction(ls.GetGC(),"getFinished","Get whether thread has finished",{},[th](GCList& _ls, std::vector<TObject> _args)-> TObject{ dict->DeclareFunction(ls.GetGC(),"getFinished","Get whether thread has finished",{},[th](GCList& _ls, std::vector<TObject> _args)-> TObject{
return (bool)(th->hasReturned==true); return (bool)(th->hasReturned==true);
}); });
ls.GetGC()->BarrierEnd(); ls.GetGC()->BarrierEnd();
th->thrd =new Thread([th]()->void { th->thrd =new Thread([th]()->void {
GC* gc=th->gc; GC* gc=th->gc;
GCList ls(gc); GCList ls(gc);
@@ -83,7 +78,7 @@ namespace Tesses::CrossLang
TObject cb = th->callable->Call(ls,{}); TObject cb = th->callable->Call(ls,{});
gc->BarrierBegin(); gc->BarrierBegin();
th->returnValue=cb; th->returnValue=cb;
gc->BarrierEnd(); gc->BarrierEnd();
th->hasReturned=true; th->hasReturned=true;
}); });
while(!th->hasInit); while(!th->hasInit);
@@ -91,14 +86,20 @@ namespace Tesses::CrossLang
} }
void GC::Start() 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->mtx=new Mutex();
this->running = true; this->running = true;
this->thrd = new Thread([this]()->void { this->thrd = new Thread([this]()->void {
std::chrono::time_point<std::chrono::system_clock> last_frame, this_frame; std::chrono::time_point<std::chrono::system_clock> last_frame, this_frame;
this_frame = system_clock::now(); this_frame = system_clock::now();
last_frame = this_frame; last_frame = this_frame;
while(this->IsRunning()) while(this->IsRunning())
{ {
this_frame = system_clock::now(); this_frame = system_clock::now();
@@ -108,7 +109,7 @@ namespace Tesses::CrossLang
last_frame = this_frame; last_frame = this_frame;
this->Collect(); this->Collect();
} }
@@ -129,14 +130,14 @@ namespace Tesses::CrossLang
void GC::BarrierBegin() void GC::BarrierBegin()
{ {
this->mtx->Lock(); this->mtx->Lock();
} }
void GC::BarrierEnd() void GC::BarrierEnd()
{ {
this->mtx->Unlock(); this->mtx->Unlock();
} }
void GC::Watch(TObject obj) void GC::Watch(TObject obj)
{ {
@@ -144,7 +145,7 @@ namespace Tesses::CrossLang
{ {
auto _item=std::get<THeapObjectHolder>(obj).obj; auto _item=std::get<THeapObjectHolder>(obj).obj;
this->BarrierBegin(); this->BarrierBegin();
for(auto item : this->objects) for(auto item : this->objects)
{ {
if(item == _item) { if(item == _item) {
@@ -187,7 +188,7 @@ namespace Tesses::CrossLang
{ {
auto _item=std::get<THeapObjectHolder>(obj).obj; auto _item=std::get<THeapObjectHolder>(obj).obj;
this->BarrierBegin(); this->BarrierBegin();
for(auto item : this->roots) for(auto item : this->roots)
{ {
if(item == _item) { if(item == _item) {
@@ -203,6 +204,7 @@ namespace Tesses::CrossLang
{ {
return this->tpool->GetValue(); return this->tpool->GetValue();
} }
void GC::UnsetRoot(TObject obj) void GC::UnsetRoot(TObject obj)
{ {
if(std::holds_alternative<THeapObjectHolder>(obj)) if(std::holds_alternative<THeapObjectHolder>(obj))
@@ -224,14 +226,19 @@ namespace Tesses::CrossLang
GC::~GC() GC::~GC()
{ {
GC::BarrierBegin(); GC::BarrierBegin();
this->roots.clear(); this->roots.clear();
GC::BarrierEnd(); GC::BarrierEnd();
this->running=false; this->running=false;
this->thrd->Join(); this->thrd->Join();
delete this->thrd; delete this->thrd;
for(auto item : objects) delete item; for(auto item : objects) delete item;
delete this->mtx;
delete this->tpool; delete this->tpool;
delete this->mtx;
} }
void GC::RegisterEverythingCallback(std::function<void(GC* gc, TRootEnvironment* env)> cb) void GC::RegisterEverythingCallback(std::function<void(GC* gc, TRootEnvironment* env)> cb)
@@ -265,6 +272,6 @@ namespace Tesses::CrossLang
} }
} }
this->BarrierEnd(); this->BarrierEnd();
} }
}; };

View File

@@ -44,7 +44,7 @@ namespace Tesses::CrossLang
{ {
auto _item=std::get<THeapObjectHolder>(obj).obj; auto _item=std::get<THeapObjectHolder>(obj).obj;
this->gc->BarrierBegin(); this->gc->BarrierBegin();
for(auto item : this->items) for(auto item : this->items)
{ {
if(item == _item) { if(item == _item) {
@@ -70,4 +70,4 @@ namespace Tesses::CrossLang
this->gc->UnsetRoot(this); this->gc->UnsetRoot(this);
gc->BarrierEnd(); gc->BarrierEnd();
} }
} }