Compare commits
6 Commits
37fd44fd78
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| d26e357448 | |||
| 2608e94192 | |||
| 0f0e47003c | |||
| 7008a6ae61 | |||
| 28eff630c6 | |||
| f23a3880d4 |
@@ -21,7 +21,7 @@ jobs:
|
||||
- run: pacman-key --config /opt/cross/ppc/pacman.conf --add /root/repository.key
|
||||
- run: printf "[tesses50.git.tesses.org]\nSigLevel = Optional TrustAll\nServer = https://git.tesses.org/api/packages/tesses50/arch/core/\$arch\n" >> /etc/pacman.conf
|
||||
- run: printf "[tesses50.git.tesses.org]\nSigLevel = Optional TrustAll\nServer = https://git.tesses.org/api/packages/tesses50/arch/core/\$arch\n" >> /opt/cross/ppc/pacman.conf
|
||||
- run: pacman --noconfirm -Sy mbedtls curl tessesframework zip zig ninja
|
||||
- run: pacman --noconfirm -Sy mbedtls tessesframework zip zig ninja
|
||||
- run: pacman --config /opt/cross/ppc/pacman.conf --noconfirm -Sy mbedtls tessesframework
|
||||
- run: cp Packaging/Linux/PKGBUILD /home/build/PKGBUILD
|
||||
- run: cp Packaging/Linux/build-arch.sh /home/build/build-arch.sh
|
||||
|
||||
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@@ -8,10 +8,10 @@
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/builds/linux/crosslang",
|
||||
"args": ["token"],
|
||||
"program": "${workspaceFolder}/builds/l/crossint",
|
||||
"args": ["queryable.tcross"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"cwd": "${workspaceFolder}/builds/l",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Maintainer: Mike Nolan <tesses@tesses.net>
|
||||
pkgname=crosslang # '-bzr', '-git', '-hg' or '-svn'
|
||||
pkgver=0.0.4
|
||||
pkgver=0.0.5
|
||||
pkgrel=1
|
||||
pkgdesc=""
|
||||
arch=('x86_64' 'powerpc')
|
||||
|
||||
@@ -7,7 +7,7 @@ echo " url \"https://git.tesses.org/tesses50/crosslang/archive/$VERSION.tar.gz\
|
||||
echo " sha256 \"$HASH\"" >> "Formula/crosslang.rb"
|
||||
echo " license \"GPLv3\"" >> "Formula/crosslang.rb"
|
||||
echo " depends_on \"cmake\" => :build" >> "Formula/crosslang.rb"
|
||||
echo " depends_on \"tessesframework\"" >> "Formula/crosslang.rb"
|
||||
echo " depends_on \"tesses50/tesses-tap/tessesframework\"" >> "Formula/crosslang.rb"
|
||||
echo " def install" >> "Formula/crosslang.rb"
|
||||
echo " system \"cmake\", \"-S\", \".\", \"-B\", \"build\", \"-DCROSSLANG_FETCHCONTENT=OFF\", *std_cmake_args" >> "Formula/crosslang.rb"
|
||||
echo " system \"cmake\", \"--build\", \"build\"" >> "Formula/crosslang.rb"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.5
|
||||
Fix crosslang Stat, StatVFS for custom crosslang filesystems and add queryable
|
||||
|
||||
## 0.0.4
|
||||
Rework for git.tesses.org, GC* is std::shared_ptr maybe will fix crash during exit
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ src/types/streamheapobject.cpp
|
||||
src/types/class.cpp
|
||||
src/types/classenvironment.cpp
|
||||
src/types/random.cpp
|
||||
src/types/relativefs.cpp
|
||||
src/types/queryable.cpp
|
||||
src/vm/filereader.cpp
|
||||
src/vm/gc.cpp
|
||||
src/vm/gclist.cpp
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
set(CROSSLANG_MAJOR_VERSION 0)
|
||||
set(CROSSLANG_MINOR_VERSION 0)
|
||||
set(CROSSLANG_PATCH_VERSION 4)
|
||||
set(CROSSLANG_PATCH_VERSION 5)
|
||||
|
||||
@@ -41,51 +41,6 @@ namespace Tesses::CrossLang {
|
||||
constexpr std::string_view VMName = "CrossLangVM";
|
||||
constexpr std::string_view VMHowToGet = "https://crosslang.tesseslanguage.com/";
|
||||
|
||||
class RelativeFilesystem : public Tesses::Framework::Filesystem::VFS
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
|
||||
public:
|
||||
RelativeFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath working);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DeleteDirectory(Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
|
||||
void DeleteFile(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void CreateSymlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath symlinkFile);
|
||||
Tesses::Framework::Filesystem::VFSPathEnumerator EnumeratePaths(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void CreateHardlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath newName);
|
||||
|
||||
void MoveFile(Tesses::Framework::Filesystem::VFSPath src, Tesses::Framework::Filesystem::VFSPath dest);
|
||||
|
||||
void MoveDirectory(Tesses::Framework::Filesystem::VFSPath src, Tesses::Framework::Filesystem::VFSPath dest);
|
||||
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 SetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime lastWrite, Tesses::Framework::Date::DateTime lastAccess);
|
||||
bool Stat(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatData& stat);
|
||||
bool StatVFS(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatVFSData& vfsData);
|
||||
|
||||
void Chmod(Tesses::Framework::Filesystem::VFSPath path, uint32_t mode);
|
||||
void Chown(Tesses::Framework::Filesystem::VFSPath path, uint32_t uid, uint32_t gid);
|
||||
|
||||
void Lock(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void Unlock(Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
Tesses::Framework::Filesystem::FIFOCreationResult CreateFIFO(Tesses::Framework::Filesystem::VFSPath path, uint32_t mod);
|
||||
Tesses::Framework::Filesystem::VFSPath GetWorking();
|
||||
void SetWorking(Tesses::Framework::Filesystem::VFSPath working);
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> GetVFS();
|
||||
protected:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::FSWatcher> CreateWatcher(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Escape a crosslang string (for generating source code)
|
||||
@@ -1075,6 +1030,11 @@ constexpr std::string_view ForStatement = "forStatement";
|
||||
*
|
||||
*/
|
||||
constexpr std::string_view WhileStatement = "whileStatement";
|
||||
/**
|
||||
* @brief using statement using(EXPR)
|
||||
*
|
||||
*/
|
||||
constexpr std::string_view UsingStatement = "usingStatement";
|
||||
/**
|
||||
* @brief Do statement do(COND)
|
||||
*
|
||||
@@ -1822,7 +1782,7 @@ class GC : public std::enable_shared_from_this<GC> {
|
||||
public:
|
||||
EnvironmentPermissions();
|
||||
Tesses::Framework::Filesystem::VFSPath sqliteOffsetPath;
|
||||
std::shared_ptr<RelativeFilesystem> localfs;
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::RelativeFilesystem> localfs;
|
||||
bool canRegisterEverything;
|
||||
bool canRegisterConsole;
|
||||
bool canRegisterIO;
|
||||
@@ -1886,10 +1846,10 @@ class GC : public std::enable_shared_from_this<GC> {
|
||||
static void RegisterHelpers(std::shared_ptr<GC> gc, TRootEnvironment* env);
|
||||
static void RegisterUuid(std::shared_ptr<GC> gc, TRootEnvironment* env);
|
||||
public:
|
||||
static void RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env, std::shared_ptr<RelativeFilesystem> localfs);
|
||||
static void RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env, std::shared_ptr<Tesses::Framework::Filesystem::RelativeFilesystem> localfs);
|
||||
static void RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env);
|
||||
static void RegisterConsole(std::shared_ptr<GC> gc,TRootEnvironment* env);
|
||||
static void RegisterIO(std::shared_ptr<GC> gc,TRootEnvironment* env, std::shared_ptr<RelativeFilesystem> local);
|
||||
static void RegisterIO(std::shared_ptr<GC> gc,TRootEnvironment* env, std::shared_ptr<Tesses::Framework::Filesystem::RelativeFilesystem> local);
|
||||
static void RegisterIO(std::shared_ptr<GC> gc,TRootEnvironment* env, bool enableLocalFS=true);
|
||||
static void RegisterNet(std::shared_ptr<GC> gc, TRootEnvironment* env);
|
||||
static void RegisterSqlite(std::shared_ptr<GC> gc,TRootEnvironment* env);
|
||||
@@ -2662,4 +2622,47 @@ class GC : public std::enable_shared_from_this<GC> {
|
||||
void CrossLangDump(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
void CrossLangCompiler(std::vector<std::string>& argv);
|
||||
}
|
||||
|
||||
enum class TQueryableMode {
|
||||
Passthrough,
|
||||
Skip,
|
||||
SkipWhile,
|
||||
Take,
|
||||
TakeWhile,
|
||||
Select,
|
||||
Where
|
||||
};
|
||||
|
||||
class TQueryable : public THeapObject {
|
||||
|
||||
|
||||
TObject parent;
|
||||
TQueryableMode mode;
|
||||
std::vector<TObject> args;
|
||||
TQueryable(TObject parent);
|
||||
TQueryable(TObject parent, TQueryableMode mode, std::vector<TObject> args);
|
||||
|
||||
public:
|
||||
|
||||
static TQueryable* Create(GCList& ls, TObject parent);
|
||||
static TQueryable* Create(GCList& ls, TObject parent, TQueryableMode mode, std::vector<TObject> args);
|
||||
|
||||
TQueryable* Skip(GCList& ls,int64_t no);
|
||||
TQueryable* SkipWhile(GCList& ls, TCallable* call);
|
||||
TQueryable* Take(GCList& ls, int64_t no);
|
||||
TQueryable* TakeWhile(GCList& ls, TCallable* call);
|
||||
TQueryable* Select(GCList& ls, TCallable* call);
|
||||
TQueryable* Where(GCList& ls, TCallable* call);
|
||||
void ForEach(std::shared_ptr<GC> gc, TCallable* call);
|
||||
int64_t Count(std::shared_ptr<GC> gc, TCallable* call);
|
||||
int64_t Count(std::shared_ptr<GC> gc);
|
||||
bool Contains(std::shared_ptr<GC>, TObject value);
|
||||
bool Any(std::shared_ptr<GC> gc, TCallable* call);
|
||||
bool All(std::shared_ptr<GC> gc, TCallable* call);
|
||||
|
||||
TList* ToList(GCList& ls);
|
||||
TEnumerator* GetEnumerator(GCList& ls);
|
||||
|
||||
void Mark();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
|
||||
Version: @PROJECT_VERSION@
|
||||
|
||||
@PKGCONFIG_DEPS@
|
||||
Requires: tessesframework
|
||||
|
||||
Cflags: -I"${includedir}"
|
||||
Libs: -L"${libdir}" -lcrosslang_shared
|
||||
@@ -8,6 +8,7 @@ URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
|
||||
Version: @PROJECT_VERSION@
|
||||
|
||||
@PKGCONFIG_DEPS@
|
||||
Requires: tessesframework_static
|
||||
|
||||
Cflags: -I"${includedir}"
|
||||
Libs: -L"${libdir}" -lcrosslang_static
|
||||
@@ -1383,6 +1383,104 @@ namespace Tesses::CrossLang
|
||||
instructions.push_back(new LabelInstruction(ifIdEnd));
|
||||
|
||||
}
|
||||
else if(adv.nodeName == UsingStatement && adv.nodes.size() == 2)
|
||||
{
|
||||
//using(EXPRESSION) {}
|
||||
//using(EXPRESSION) STATEMENT;
|
||||
|
||||
//{ __compGen = EXPRESSION; defer { __compGen.Dispose(); } {}(unrolled) OR STATEMENT; }
|
||||
|
||||
if(std::holds_alternative<AdvancedSyntaxNode>(adv.nodes[1]))
|
||||
{
|
||||
auto asn2 = std::get<AdvancedSyntaxNode>(adv.nodes[1]);
|
||||
if(asn2.nodeName == ScopeNode)
|
||||
{
|
||||
scope++;
|
||||
instructions.push_back(new SimpleInstruction(SCOPEBEGIN));
|
||||
|
||||
uint32_t exprId = NewId();
|
||||
std::string exprStr = "__compGenUsing";
|
||||
exprStr.append(std::to_string(exprId));
|
||||
|
||||
auto _assign=AdvancedSyntaxNode::Create(AssignExpression,true,{
|
||||
AdvancedSyntaxNode::Create(DeclareExpression,true,{exprStr}),
|
||||
adv.nodes[0]
|
||||
});
|
||||
|
||||
GenNode(instructions,_assign,scope,contscope,brkscope,contI,brkI);
|
||||
GenPop(instructions,_assign);
|
||||
|
||||
|
||||
auto _defer=AdvancedSyntaxNode::Create(DeferStatement,false,{
|
||||
AdvancedSyntaxNode::Create(ReturnStatement,false,{
|
||||
AdvancedSyntaxNode::Create(FunctionCallExpression,true,{
|
||||
AdvancedSyntaxNode::Create(GetFieldExpression,true,{
|
||||
AdvancedSyntaxNode::Create(GetVariableExpression, true, {
|
||||
exprStr
|
||||
}),
|
||||
"Dispose"
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
GenNode(instructions,_defer,scope,contscope,brkscope,contI,brkI);
|
||||
|
||||
for(size_t i = 0; i < asn2.nodes.size(); i++)
|
||||
{
|
||||
GenNode(instructions,asn2.nodes[i],scope,contscope,brkscope,contI,brkI);
|
||||
if(!asn2.isExpression || i < asn2.nodes.size()-1)
|
||||
GenPop(instructions,asn2.nodes[i]);
|
||||
}
|
||||
instructions.push_back(new SimpleInstruction(SCOPEEND));
|
||||
scope--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
scope++;
|
||||
instructions.push_back(new SimpleInstruction(SCOPEBEGIN));
|
||||
|
||||
uint32_t exprId = NewId();
|
||||
std::string exprStr = "__compGenUsing";
|
||||
exprStr.append(std::to_string(exprId));
|
||||
|
||||
auto _assign=AdvancedSyntaxNode::Create(AssignExpression,true,{
|
||||
AdvancedSyntaxNode::Create(DeclareExpression,true,{exprStr}),
|
||||
adv.nodes[0]
|
||||
});
|
||||
|
||||
GenNode(instructions,_assign,scope,contscope,brkscope,contI,brkI);
|
||||
GenPop(instructions,_assign);
|
||||
|
||||
|
||||
auto _defer=AdvancedSyntaxNode::Create(DeferStatement,false,{
|
||||
AdvancedSyntaxNode::Create(ReturnStatement,false,{
|
||||
AdvancedSyntaxNode::Create(FunctionCallExpression,true,{
|
||||
AdvancedSyntaxNode::Create(GetFieldExpression,true,{
|
||||
AdvancedSyntaxNode::Create(GetVariableExpression, true, {
|
||||
exprStr
|
||||
}),
|
||||
"Dispose"
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
GenNode(instructions,_defer,scope,contscope,brkscope,contI,brkI);
|
||||
|
||||
|
||||
GenNode(instructions,adv.nodes[1],scope,contscope,brkscope,contI,brkI);
|
||||
if(!adv.isExpression)
|
||||
GenPop(instructions,adv.nodes[1]);
|
||||
|
||||
instructions.push_back(new SimpleInstruction(SCOPEEND));
|
||||
scope--;
|
||||
}
|
||||
}
|
||||
else if(adv.nodeName == WhileStatement && adv.nodes.size() == 2)
|
||||
{
|
||||
auto old_contI = contI;
|
||||
|
||||
@@ -615,7 +615,7 @@ namespace Tesses::CrossLang
|
||||
EnsureSymbol("(");
|
||||
SyntaxNode list = ParseExpression();
|
||||
SyntaxNode body = nullptr;
|
||||
if(IsSymbol(":"))
|
||||
if(IsSymbol(":") || IsIdentifier("in"))
|
||||
{
|
||||
item = list;
|
||||
list = ParseExpression();
|
||||
@@ -1406,6 +1406,20 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return AdvancedSyntaxNode::Create(WhileStatement,false,{cond,body});
|
||||
}
|
||||
if(IsIdentifier("using"))
|
||||
{
|
||||
EnsureSymbol("(");
|
||||
SyntaxNode expr = ParseExpression();
|
||||
EnsureSymbol(")");
|
||||
|
||||
SyntaxNode body = nullptr;
|
||||
if(!IsSymbol(";"))
|
||||
{
|
||||
body = ParseNode();
|
||||
}
|
||||
|
||||
return AdvancedSyntaxNode::Create(UsingStatement, false, {expr,body});
|
||||
}
|
||||
if(IsIdentifier("do"))
|
||||
{
|
||||
EnsureSymbol("(");
|
||||
|
||||
@@ -264,14 +264,14 @@ namespace Tesses::CrossLang
|
||||
{
|
||||
if(enable)
|
||||
{
|
||||
RegisterIO(gc,env,std::make_shared<RelativeFilesystem>(Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
RegisterIO(gc,env,std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
}
|
||||
else
|
||||
{
|
||||
RegisterIO(gc,env,nullptr);
|
||||
}
|
||||
}
|
||||
void TStd::RegisterIO(std::shared_ptr<GC> gc,TRootEnvironment* env,std::shared_ptr<RelativeFilesystem> fs)
|
||||
void TStd::RegisterIO(std::shared_ptr<GC> gc,TRootEnvironment* env,std::shared_ptr<Tesses::Framework::Filesystem::RelativeFilesystem> fs)
|
||||
{
|
||||
|
||||
env->permissions.canRegisterIO=true;
|
||||
@@ -332,8 +332,14 @@ namespace Tesses::CrossLang
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
if(GetArgumentAsPath(args,0,path))
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
fs->SetWorking(path.MakeAbsolute(fs->GetWorking()));
|
||||
}
|
||||
else {
|
||||
fs->SetWorking(path);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,6 +33,58 @@ namespace Tesses::CrossLang {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
TObject Sqlite_Prepare(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::string str;
|
||||
TList* list;
|
||||
|
||||
std::string newStr = "";
|
||||
if(GetArgument(args,0,str) && GetArgumentHeap(args,1,list))
|
||||
{
|
||||
int64_t item = 0;
|
||||
|
||||
|
||||
for(size_t i = 0; i < str.size(); i++)
|
||||
{
|
||||
if(str[i] == '@' && (i+1>=str.size() || str[i+1] != '@'))
|
||||
{
|
||||
auto v = list->Get(item);
|
||||
int64_t n;
|
||||
double d;
|
||||
bool b;
|
||||
|
||||
|
||||
std::string str;
|
||||
if(GetObject(v,str))
|
||||
{
|
||||
newStr+= SQLiteDatabase::Escape(str);
|
||||
}
|
||||
else if(GetObject(v,n))
|
||||
{
|
||||
newStr+= std::to_string(n);
|
||||
}
|
||||
else if(GetObject(v,b))
|
||||
{
|
||||
newStr+= (b ? "1" : "0");
|
||||
}
|
||||
else if(GetObject(v,d))
|
||||
{
|
||||
newStr+= std::to_string(d);
|
||||
}
|
||||
else {
|
||||
|
||||
newStr+= "NULL";
|
||||
}
|
||||
}
|
||||
else {
|
||||
newStr+=str[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
|
||||
class SQLiteObject : public TNativeObject
|
||||
{
|
||||
@@ -65,6 +117,9 @@ namespace Tesses::CrossLang {
|
||||
if(name == "Escape") {
|
||||
return Sqlite_Escape(ls,args);
|
||||
}
|
||||
if(name == "Prepare") {
|
||||
return Sqlite_Prepare(ls,args);
|
||||
}
|
||||
if(name == "Exec")
|
||||
{
|
||||
std::string arg;
|
||||
@@ -105,6 +160,7 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TObject Sqlite_Open(GCList& ls, std::vector<TObject> args,TRootEnvironment* env)
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath p;
|
||||
@@ -149,6 +205,7 @@ namespace Tesses::CrossLang {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
void TStd::RegisterSqlite(std::shared_ptr<GC> gc,TRootEnvironment* env)
|
||||
{
|
||||
@@ -163,6 +220,7 @@ namespace Tesses::CrossLang {
|
||||
dict->DeclareFunction(gc,"Exec","Execute sql (returns dictionary of columns key=value, an error message as string or undefined)",{"handle","sql"},Sqlite_Exec);
|
||||
dict->DeclareFunction(gc,"Close","Close sql database",{"handle"},Sqlite_Close);
|
||||
dict->DeclareFunction(gc,"Escape","Escape sql text",{"text"},Sqlite_Escape);
|
||||
dict->DeclareFunction(gc,"Prepare", "Prepare sql",{"sql","items"}, Sqlite_Prepare);
|
||||
|
||||
gc->BarrierBegin();
|
||||
env->DeclareVariable("Sqlite", dict);
|
||||
|
||||
@@ -610,6 +610,12 @@ namespace Tesses::CrossLang
|
||||
std::shared_ptr<Tesses::Framework::Date::TimeSpan> dt;
|
||||
return GetArgument(args,0,dt);
|
||||
}
|
||||
static TObject TypeIsQueryable(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return nullptr;
|
||||
TQueryable* queryable;
|
||||
return GetArgumentHeap(args,0,queryable);
|
||||
}
|
||||
static TObject New_SubdirFilesystem(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
@@ -864,20 +870,12 @@ namespace Tesses::CrossLang
|
||||
auto vfs = std::get<std::shared_ptr<Tesses::Framework::Filesystem::VFS>>(_obj);
|
||||
if(vfs != nullptr)
|
||||
{
|
||||
auto rfs = std::dynamic_pointer_cast<RelativeFilesystem>(vfs);
|
||||
auto rfs = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs);
|
||||
auto localVFS = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::LocalFilesystem>(vfs);
|
||||
auto mountableVFS = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::MountableFilesystem>(vfs);
|
||||
auto subFS = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::SubdirFilesystem>(vfs);
|
||||
auto tempFS = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::TempFS>(vfs);
|
||||
if(rfs)
|
||||
{
|
||||
auto fs=rfs->GetVFS();
|
||||
if(fs)
|
||||
{
|
||||
return GetObjectTypeString(fs);
|
||||
}
|
||||
return "RelativeFilesystem";
|
||||
}
|
||||
if(rfs) return "RelativeFilesystem";
|
||||
if(localVFS != nullptr) return "LocalFilesystem";
|
||||
if(subFS != nullptr) return "SubdirFilesystem";
|
||||
if(mountableVFS != nullptr) return "MountableFilesystem";
|
||||
@@ -910,6 +908,7 @@ namespace Tesses::CrossLang
|
||||
auto cobj = dynamic_cast<TClassObject*>(obj);
|
||||
auto aarray = dynamic_cast<TAssociativeArray*>(obj);
|
||||
auto file = dynamic_cast<TFile*>(obj);
|
||||
auto queryable = dynamic_cast<TQueryable*>(obj);
|
||||
|
||||
if(rootEnv != nullptr) return "RootEnvironment";
|
||||
if(subEnv != nullptr) return "SubEnvironment";
|
||||
@@ -931,6 +930,7 @@ namespace Tesses::CrossLang
|
||||
if(native != nullptr) return "Native";
|
||||
if(any != nullptr) return "Any";
|
||||
if(file != nullptr) return "File";
|
||||
if(queryable != nullptr) return "Queryable";
|
||||
|
||||
return "HeapObject";
|
||||
}
|
||||
@@ -1301,6 +1301,27 @@ namespace Tesses::CrossLang
|
||||
return Tesses::Framework::TF_Timer(empty, 1000L, false);
|
||||
}
|
||||
|
||||
static TObject New_RelativeFilesystem(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
if(GetArgument(args,0,vfs) && GetArgumentAsPath(args,1,path) && !path.relative)
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs,path);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static TObject New_Queryable(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(!args.empty())
|
||||
{
|
||||
return TQueryable::Create(ls, args.front());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void TStd::RegisterRoot(std::shared_ptr<GC> gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
@@ -1363,6 +1384,7 @@ namespace Tesses::CrossLang
|
||||
newTypes->DeclareFunction(gc, "SubdirFilesystem","Create a subdir filesystem",{"fs","subdir"}, New_SubdirFilesystem);
|
||||
newTypes->DeclareFunction(gc, "MemoryStream","Create a memory stream",{"writable"}, New_MemoryStream);
|
||||
newTypes->DeclareFunction(gc, "Filesystem","Create filesystem", {"fs"},New_Filesystem);
|
||||
newTypes->DeclareFunction(gc, "RelativeFilesystem", "Create relativefs",{"parent", "absoluteDir"}, New_RelativeFilesystem);
|
||||
newTypes->DeclareFunction(gc, "TempFS","Create a temp directory",{"",""}, New_TempFS);
|
||||
newTypes->DeclareFunction(gc, "Timer", "Create a timer",{"$cb","$interval","$enabled"}, New_Timer);
|
||||
newTypes->DeclareFunction(gc, "Stream","Create stream", {"strm"},New_Stream);
|
||||
@@ -1426,7 +1448,7 @@ namespace Tesses::CrossLang
|
||||
env->DeclareFunction(gc, "TypeIsByteReader","Get whether object is a ByteReader",{"object"},TypeIsByteReader);
|
||||
env->DeclareFunction(gc, "TypeIsByteWriter","Get whether object is a ByteWriter",{"object"},TypeIsByteWriter);
|
||||
env->DeclareFunction(gc, "TypeIsUuid","Get whether object is a Uuid",{"object"},TypeIsUuid);
|
||||
|
||||
env->DeclareFunction(gc, "TypeIsQueryable","Get whether object is a Queryable",{"object"},TypeIsQueryable);
|
||||
|
||||
newTypes->DeclareFunction(gc, "Regex", "Create regex object",{"regex"},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
std::string str;
|
||||
@@ -1472,6 +1494,7 @@ namespace Tesses::CrossLang
|
||||
return TAssociativeArray::Create(ls);
|
||||
});
|
||||
newTypes->DeclareFunction(gc,"ByteArray","Create bytearray, with optional either size (to size it) or string argument (to fill byte array)",{"$data"},ByteArray);
|
||||
newTypes->DeclareFunction(gc, "Queryable", "Create a queryable", {"enumerable"}, New_Queryable);
|
||||
|
||||
env->DeclareVariable("Version", TDictionary::Create(ls,{
|
||||
TDItem("Parse",TExternalMethod::Create(ls,"Parse version from string",{"versionStr"},[](GCList& ls, std::vector<TObject> args)->TObject{
|
||||
@@ -1519,14 +1542,15 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
void TStd::RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env)
|
||||
{
|
||||
RegisterStd(gc, env, std::make_shared<RelativeFilesystem>(Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
RegisterStd(gc, env, std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
}
|
||||
void TStd::RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env,std::shared_ptr<RelativeFilesystem> localfs)
|
||||
void TStd::RegisterStd(std::shared_ptr<GC> gc, TRootEnvironment* env,std::shared_ptr<Tesses::Framework::Filesystem::RelativeFilesystem> localfs)
|
||||
{
|
||||
env->permissions.canRegisterEverything=true;
|
||||
RegisterEnv(gc, env);
|
||||
RegisterRoot(gc,env);
|
||||
RegisterPath(gc,env);
|
||||
|
||||
RegisterConsole(gc, env);
|
||||
RegisterIO(gc, env, localfs);
|
||||
RegisterNet(gc, env);
|
||||
|
||||
@@ -132,6 +132,7 @@ namespace Tesses::CrossLang
|
||||
TDynamicDictionary* dynDict;
|
||||
TDictionary* dict;
|
||||
TEnumerator* enumerator;
|
||||
TQueryable* q;
|
||||
if(GetObject(obj,str))
|
||||
{
|
||||
return TStringEnumerator::Create(ls, str);
|
||||
@@ -156,6 +157,14 @@ namespace Tesses::CrossLang
|
||||
return enumerator;
|
||||
}
|
||||
}
|
||||
else if(GetObjectHeap(obj, q))
|
||||
{
|
||||
return q->GetEnumerator(ls);
|
||||
}
|
||||
else if(GetObjectHeap(obj, enumerator))
|
||||
{
|
||||
return enumerator;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
TVFSPathEnumerator* TVFSPathEnumerator::Create(GCList& ls, Tesses::Framework::Filesystem::VFSPathEnumerator enumerator)
|
||||
|
||||
522
src/types/queryable.cpp
Normal file
522
src/types/queryable.cpp
Normal file
@@ -0,0 +1,522 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
TQueryable::TQueryable(TObject parent) : TQueryable(parent,TQueryableMode::Passthrough, {})
|
||||
{
|
||||
|
||||
}
|
||||
TQueryable::TQueryable(TObject parent, TQueryableMode mode, std::vector<TObject> args): parent(parent), mode(mode), args(args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TQueryable* TQueryable::Skip(GCList& ls,int64_t no)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::Skip, {no});
|
||||
}
|
||||
TQueryable* TQueryable::SkipWhile(GCList& ls, TCallable* call)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::SkipWhile, {call});
|
||||
}
|
||||
TQueryable* TQueryable::Take(GCList& ls, int64_t no)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::Take, {no});
|
||||
}
|
||||
TQueryable* TQueryable::TakeWhile(GCList& ls, TCallable* call)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::TakeWhile, {call});
|
||||
}
|
||||
TQueryable* TQueryable::Select(GCList& ls, TCallable* call)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::Select, {call});
|
||||
}
|
||||
TQueryable* TQueryable::Where(GCList& ls, TCallable* call)
|
||||
{
|
||||
return TQueryable::Create(ls,this,TQueryableMode::Where, {call});
|
||||
}
|
||||
|
||||
TList* TQueryable::ToList(GCList& ls)
|
||||
{
|
||||
auto gc = ls.GetGC();
|
||||
GCList ls2(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return nullptr;
|
||||
auto list = TList::Create(ls);
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
list->Add(enumerator->GetCurrent(ls));
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
TQueryable* TQueryable::Create(GCList& ls, TObject parent)
|
||||
{
|
||||
TQueryable* queryable = new TQueryable(parent);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
TQueryable* TQueryable::Create(GCList& ls, TObject parent, TQueryableMode mode, std::vector<TObject> args)
|
||||
{
|
||||
TQueryable* queryable = new TQueryable(parent, mode,args);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
|
||||
|
||||
void TQueryable::Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
GC::Mark(this->parent);
|
||||
for(auto& item : args)
|
||||
GC::Mark(item);
|
||||
}
|
||||
|
||||
void TQueryable::ForEach(std::shared_ptr<GC> gc, TCallable* call)
|
||||
{
|
||||
if(call == nullptr) return;
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return;
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
GCList ls2(gc);
|
||||
call->Call(ls2,{enumerator->GetCurrent(ls2)});
|
||||
}
|
||||
}
|
||||
int64_t TQueryable::Count(std::shared_ptr<GC> gc, TCallable* call)
|
||||
{
|
||||
if(call == nullptr) return 0;
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return 0;
|
||||
int64_t count=0;
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
GCList ls2(gc);
|
||||
if(ToBool(call->Call(ls2,{enumerator->GetCurrent(ls2)}))) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
int64_t TQueryable::Count(std::shared_ptr<GC> gc)
|
||||
{
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return 0;
|
||||
int64_t count=0;
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
bool TQueryable::Contains(std::shared_ptr<GC> gc, TObject value)
|
||||
{
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return false;
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
GCList ls2(gc);
|
||||
|
||||
|
||||
if(Equals(gc,value,enumerator->GetCurrent(ls2)))
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool TQueryable::Any(std::shared_ptr<GC> gc, TCallable* call)
|
||||
{
|
||||
if(call == nullptr) return false;
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return false;
|
||||
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
GCList ls2(gc);
|
||||
if(ToBool(call->Call(ls2,{enumerator->GetCurrent(ls2)}))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool TQueryable::All(std::shared_ptr<GC> gc, TCallable* call)
|
||||
{
|
||||
if(call == nullptr) return true;
|
||||
GCList ls(gc);
|
||||
auto enumerator = this->GetEnumerator(ls);
|
||||
if(enumerator == nullptr) return true;
|
||||
|
||||
while(enumerator->MoveNext(gc))
|
||||
{
|
||||
GCList ls2(gc);
|
||||
if(!ToBool(call->Call(ls2,{enumerator->GetCurrent(ls2)}))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class SkipItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
int64_t skipCount;
|
||||
SkipItterator(TEnumerator* parentEnum, int64_t skipCount) : parentEnum(parentEnum), skipCount(skipCount)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static SkipItterator* Create(GCList& ls, TEnumerator* parentEnum, int64_t skipCount)
|
||||
{
|
||||
SkipItterator* queryable = new SkipItterator(parentEnum, skipCount);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr) return false;
|
||||
while(skipCount > 0)
|
||||
{
|
||||
if(!this->parentEnum->MoveNext(ls)) {
|
||||
skipCount=0;
|
||||
return false;
|
||||
}
|
||||
skipCount--;
|
||||
}
|
||||
return this->parentEnum->MoveNext(ls);
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
return this->parentEnum->GetCurrent(ls);
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
}
|
||||
};
|
||||
class TakeItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
int64_t takeCount;
|
||||
TakeItterator(TEnumerator* parentEnum, int64_t takeCount) : parentEnum(parentEnum), takeCount(takeCount)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static TakeItterator* Create(GCList& ls, TEnumerator* parentEnum, int64_t takeCount)
|
||||
{
|
||||
TakeItterator* queryable = new TakeItterator(parentEnum, takeCount);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr) return false;
|
||||
if(takeCount > 0)
|
||||
{
|
||||
takeCount--;
|
||||
return this->parentEnum->MoveNext(ls);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
return this->parentEnum->GetCurrent(ls);
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
}
|
||||
};
|
||||
class SkipWhileItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
TCallable* callable;
|
||||
SkipWhileItterator(TEnumerator* parentEnum, TCallable* callable) : parentEnum(parentEnum), callable(callable)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static SkipWhileItterator* Create(GCList& ls, TEnumerator* parentEnum, TCallable* callable)
|
||||
{
|
||||
SkipWhileItterator* queryable = new SkipWhileItterator(parentEnum, callable);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr) return false;
|
||||
ls->BarrierBegin();
|
||||
auto callable = this->callable;
|
||||
ls->BarrierEnd();
|
||||
|
||||
if(callable != nullptr)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
if(this->parentEnum->MoveNext(ls))
|
||||
{
|
||||
GCList ls2(ls);
|
||||
auto result = callable->Call(ls2,{this->parentEnum->GetCurrent(ls2)});
|
||||
if(!ToBool(result))
|
||||
{
|
||||
ls->BarrierBegin();
|
||||
this->callable=nullptr;
|
||||
ls->BarrierEnd();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ls->BarrierBegin();
|
||||
this->callable=nullptr;
|
||||
ls->BarrierEnd();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return this->parentEnum->MoveNext(ls);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
return this->parentEnum->GetCurrent(ls);
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
if(callable != nullptr) callable->Mark();
|
||||
}
|
||||
};
|
||||
class TakeWhileItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
TCallable* callable;
|
||||
TakeWhileItterator(TEnumerator* parentEnum, TCallable* callable) : parentEnum(parentEnum), callable(callable)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static TakeWhileItterator* Create(GCList& ls, TEnumerator* parentEnum, TCallable* callable)
|
||||
{
|
||||
TakeWhileItterator* queryable = new TakeWhileItterator(parentEnum, callable);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr) return false;
|
||||
ls->BarrierBegin();
|
||||
auto callable = this->callable;
|
||||
ls->BarrierEnd();
|
||||
if(callable != nullptr)
|
||||
{
|
||||
if(this->parentEnum->MoveNext(ls))
|
||||
{
|
||||
GCList ls2(ls);
|
||||
auto result = callable->Call(ls2,{this->parentEnum->GetCurrent(ls2)});
|
||||
if(!ToBool(result))
|
||||
{
|
||||
ls->BarrierBegin();
|
||||
this->callable=nullptr;
|
||||
ls->BarrierEnd();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
return this->parentEnum->GetCurrent(ls);
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
if(callable != nullptr) callable->Mark();
|
||||
}
|
||||
};
|
||||
class WhereItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
TCallable* callable;
|
||||
WhereItterator(TEnumerator* parentEnum, TCallable* callable) : parentEnum(parentEnum), callable(callable)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static WhereItterator* Create(GCList& ls, TEnumerator* parentEnum, TCallable* callable)
|
||||
{
|
||||
WhereItterator* queryable = new WhereItterator(parentEnum, callable);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr || this->callable == nullptr) return false;
|
||||
while(this->parentEnum->MoveNext(ls))
|
||||
{
|
||||
GCList ls2(ls);
|
||||
auto cur = this->parentEnum->GetCurrent(ls2);
|
||||
if(ToBool(callable->Call(ls2,{cur})))
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
return this->parentEnum->GetCurrent(ls);
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
if(callable != nullptr) callable->Mark();
|
||||
}
|
||||
};
|
||||
class SelectItterator : public TEnumerator {
|
||||
private:
|
||||
TEnumerator* parentEnum;
|
||||
TCallable* callable;
|
||||
TObject value;
|
||||
SelectItterator(TEnumerator* parentEnum, TCallable* callable) : parentEnum(parentEnum), callable(callable)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
static SelectItterator* Create(GCList& ls, TEnumerator* parentEnum, TCallable* callable)
|
||||
{
|
||||
SelectItterator* queryable = new SelectItterator(parentEnum, callable);
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
ls.Add(queryable);
|
||||
gc->Watch(queryable);
|
||||
return queryable;
|
||||
}
|
||||
bool MoveNext(std::shared_ptr<GC> ls)
|
||||
{
|
||||
if(this->parentEnum == nullptr || this->callable == nullptr) return false;
|
||||
if(this->parentEnum->MoveNext(ls))
|
||||
{
|
||||
GCList ls2(ls);
|
||||
auto cur = this->parentEnum->GetCurrent(ls2);
|
||||
auto value = this->callable->Call(ls2,{cur});
|
||||
|
||||
ls->BarrierBegin();
|
||||
this->value = value;
|
||||
ls->BarrierEnd();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject GetCurrent(GCList& ls)
|
||||
{
|
||||
ls.GetGC()->BarrierBegin();
|
||||
auto value=this->value;
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return value;
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
if(parentEnum != nullptr) parentEnum->Mark();
|
||||
if(callable != nullptr) callable->Mark();
|
||||
|
||||
GC::Mark(this->value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TEnumerator* TQueryable::GetEnumerator(GCList& ls)
|
||||
{
|
||||
switch(this->mode)
|
||||
{
|
||||
case TQueryableMode::Skip:
|
||||
{
|
||||
int64_t skipCount;
|
||||
if(GetArgument(args,0,skipCount))
|
||||
return SkipItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), skipCount);
|
||||
}
|
||||
break;
|
||||
case TQueryableMode::Take:
|
||||
{
|
||||
int64_t takeCount;
|
||||
if(GetArgument(args,0,takeCount))
|
||||
return TakeItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), takeCount);
|
||||
|
||||
}
|
||||
break;
|
||||
case TQueryableMode::SkipWhile:
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
return SkipWhileItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), callable);
|
||||
|
||||
}
|
||||
break;
|
||||
case TQueryableMode::TakeWhile:
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
return TakeWhileItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), callable);
|
||||
|
||||
}
|
||||
break;
|
||||
case TQueryableMode::Select:
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
return SelectItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), callable);
|
||||
|
||||
}
|
||||
break;
|
||||
case TQueryableMode::Where:
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
return WhereItterator::Create(ls, TEnumerator::CreateFromObject(ls, this->parent), callable);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return TEnumerator::CreateFromObject(ls, this->parent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
RelativeFilesystem::RelativeFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath working)
|
||||
{
|
||||
this->vfs = vfs;
|
||||
this->path = working;
|
||||
}
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> RelativeFilesystem::OpenFile(Tesses::Framework::Filesystem::VFSPath path, std::string mode)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->OpenFile(path.MakeAbsolute(GetWorking()), mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->OpenFile(path,mode);
|
||||
}
|
||||
}
|
||||
|
||||
void RelativeFilesystem::CreateDirectory(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->CreateDirectory(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
void RelativeFilesystem::DeleteDirectory(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->DeleteDirectory(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->DeleteDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RelativeFilesystem::DeleteFile(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->DeleteFile(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->DeleteFile(path);
|
||||
}
|
||||
}
|
||||
void RelativeFilesystem::CreateSymlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath symlinkFile)
|
||||
{
|
||||
if(symlinkFile.relative)
|
||||
{
|
||||
this->vfs->CreateSymlink(existingFile,symlinkFile.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->CreateSymlink(existingFile, symlinkFile);
|
||||
}
|
||||
}
|
||||
Tesses::Framework::Filesystem::VFSPathEnumerator RelativeFilesystem::EnumeratePaths(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->EnumeratePaths(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->EnumeratePaths(path);
|
||||
}
|
||||
}
|
||||
void RelativeFilesystem::CreateHardlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath newName)
|
||||
{
|
||||
auto working = GetWorking();
|
||||
if(existingFile.relative)
|
||||
{
|
||||
existingFile = existingFile.MakeAbsolute(working);
|
||||
existingFile = existingFile.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
if(newName.relative)
|
||||
{
|
||||
newName = newName.MakeAbsolute(working);
|
||||
newName = newName.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
this->vfs->CreateHardlink(existingFile, newName);
|
||||
}
|
||||
|
||||
void RelativeFilesystem::MoveFile(Tesses::Framework::Filesystem::VFSPath src, Tesses::Framework::Filesystem::VFSPath dest)
|
||||
{
|
||||
auto working = GetWorking();
|
||||
if(src.relative)
|
||||
{
|
||||
src = src.MakeAbsolute(working);
|
||||
src = src.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
if(dest.relative)
|
||||
{
|
||||
dest = dest.MakeAbsolute(working);
|
||||
dest = dest.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
this->vfs->MoveFile(src, dest);
|
||||
}
|
||||
|
||||
void RelativeFilesystem::MoveDirectory(Tesses::Framework::Filesystem::VFSPath src, Tesses::Framework::Filesystem::VFSPath dest)
|
||||
{
|
||||
|
||||
auto working = GetWorking();
|
||||
if(src.relative)
|
||||
{
|
||||
src = src.MakeAbsolute(working);
|
||||
src = src.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
if(dest.relative)
|
||||
{
|
||||
dest = dest.MakeAbsolute(working);
|
||||
dest = dest.CollapseRelativeParents();
|
||||
}
|
||||
|
||||
this->vfs->MoveFile(src, dest);
|
||||
}
|
||||
Tesses::Framework::Filesystem::VFSPath RelativeFilesystem::ReadLink(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->ReadLink(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->ReadLink(path);
|
||||
}
|
||||
}
|
||||
std::string RelativeFilesystem::VFSPathToSystem(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
return this->vfs->VFSPathToSystem(path);
|
||||
}
|
||||
Tesses::Framework::Filesystem::VFSPath RelativeFilesystem::SystemToVFSPath(std::string path)
|
||||
{
|
||||
return this->vfs->SystemToVFSPath(path);
|
||||
}
|
||||
|
||||
void RelativeFilesystem::SetDate(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Date::DateTime lastWrite, Tesses::Framework::Date::DateTime lastAccess)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->SetDate(path.MakeAbsolute(GetWorking()), lastWrite,lastAccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->SetDate(path,lastWrite,lastAccess);
|
||||
}
|
||||
}
|
||||
bool RelativeFilesystem::Stat(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatData& stat)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->Stat(path.MakeAbsolute(GetWorking()), stat);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->Stat(path,stat);
|
||||
}
|
||||
}
|
||||
bool RelativeFilesystem::StatVFS(Tesses::Framework::Filesystem::VFSPath path, Tesses::Framework::Filesystem::StatVFSData& vfsData)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->StatVFS(path.MakeAbsolute(GetWorking()), vfsData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->StatVFS(path,vfsData);
|
||||
}
|
||||
}
|
||||
|
||||
void RelativeFilesystem::Chmod(Tesses::Framework::Filesystem::VFSPath path, uint32_t mode)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->Chmod(path.MakeAbsolute(GetWorking()), mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->Chmod(path,mode);
|
||||
}
|
||||
}
|
||||
void RelativeFilesystem::Chown(Tesses::Framework::Filesystem::VFSPath path, uint32_t uid, uint32_t gid)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->Chown(path.MakeAbsolute(GetWorking()), uid, gid);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->Chown(path,uid,gid);
|
||||
}
|
||||
}
|
||||
|
||||
void RelativeFilesystem::Lock(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->Lock(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->Lock(path);
|
||||
}
|
||||
}
|
||||
void RelativeFilesystem::Unlock(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
this->vfs->Unlock(path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->vfs->Unlock(path);
|
||||
}
|
||||
}
|
||||
|
||||
Tesses::Framework::Filesystem::FIFOCreationResult RelativeFilesystem::CreateFIFO(Tesses::Framework::Filesystem::VFSPath path, uint32_t mod)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return this->vfs->CreateFIFO(path.MakeAbsolute(GetWorking()), mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->vfs->CreateFIFO(path, mod);
|
||||
}
|
||||
}
|
||||
Tesses::Framework::Filesystem::VFSPath RelativeFilesystem::GetWorking()
|
||||
{
|
||||
mtx.Lock();
|
||||
auto path = this->path;
|
||||
mtx.Unlock();
|
||||
return path;
|
||||
}
|
||||
void RelativeFilesystem::SetWorking(Tesses::Framework::Filesystem::VFSPath working)
|
||||
{
|
||||
mtx.Lock();
|
||||
this->path = working;
|
||||
mtx.Unlock();
|
||||
}
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> RelativeFilesystem::GetVFS()
|
||||
{
|
||||
return this->vfs;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::FSWatcher> RelativeFilesystem::CreateWatcher(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
return Tesses::Framework::Filesystem::FSWatcher::Create(vfs, path.MakeAbsolute(GetWorking()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Tesses::Framework::Filesystem::FSWatcher::Create(vfs,path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -205,7 +205,7 @@ namespace Tesses::CrossLang
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls,"Close",{});
|
||||
dict->CallMethod(*ls,"Dispose",{});
|
||||
}
|
||||
}
|
||||
TObjectStream::~TObjectStream()
|
||||
@@ -213,7 +213,7 @@ namespace Tesses::CrossLang
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls,"Close",{});
|
||||
dict->CallMethod(*ls,"Dispose",{});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
|
||||
@@ -281,45 +281,45 @@ namespace Tesses::CrossLang {
|
||||
if(GetObjectHeap(res,_dict))
|
||||
{
|
||||
this->ls->GetGC()->BarrierBegin();
|
||||
_o = dict->GetValue("BlockSize");
|
||||
_o = _dict->GetValue("BlockSize");
|
||||
if(GetObject(_o,_num)) data.BlockSize = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("BlockCount");
|
||||
_o = _dict->GetValue("BlockCount");
|
||||
if(GetObject(_o,_num)) data.BlockCount = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("Device");
|
||||
_o = _dict->GetValue("Device");
|
||||
if(GetObject(_o,_num)) data.Device = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("DeviceId");
|
||||
_o = _dict->GetValue("DeviceId");
|
||||
if(GetObject(_o,_num)) data.DeviceId = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("GroupId");
|
||||
_o = _dict->GetValue("GroupId");
|
||||
if(GetObject(_o,_num)) data.GroupId = (uint32_t)_num;
|
||||
|
||||
_o = dict->GetValue("HardLinks");
|
||||
_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");
|
||||
_o = _dict->GetValue("LastAccess");
|
||||
if(GetObject(_o,dt)) data.LastAccess = dt ? *dt : Tesses::Framework::Date::DateTime(0);
|
||||
|
||||
|
||||
_o = dict->GetValue("LastModified");
|
||||
_o = _dict->GetValue("LastModified");
|
||||
if(GetObject(_o,dt)) data.LastModified = dt ? *dt : Tesses::Framework::Date::DateTime(0);
|
||||
|
||||
|
||||
|
||||
_o = dict->GetValue("LastStatus");
|
||||
_o = _dict->GetValue("LastStatus");
|
||||
if(GetObject(_o,dt)) data.LastStatus = dt ? *dt : Tesses::Framework::Date::DateTime(0);
|
||||
|
||||
|
||||
|
||||
_o = dict->GetValue("Mode");
|
||||
_o = _dict->GetValue("Mode");
|
||||
if(GetObject(_o,_num)) data.Mode = (uint32_t)_num;
|
||||
|
||||
_o = dict->GetValue("Size");
|
||||
_o = _dict->GetValue("Size");
|
||||
if(GetObject(_o,_num)) data.Size = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("UserId");
|
||||
_o = _dict->GetValue("UserId");
|
||||
if(GetObject(_o,_num)) data.UserId = (uint32_t)_num;
|
||||
|
||||
|
||||
@@ -344,28 +344,28 @@ namespace Tesses::CrossLang {
|
||||
if(GetObjectHeap(res,_dict))
|
||||
{
|
||||
this->ls->GetGC()->BarrierBegin();
|
||||
_o = dict->GetValue("BlockSize");
|
||||
_o = _dict->GetValue("BlockSize");
|
||||
if(GetObject(_o,_num)) data.BlockSize = (uint64_t)_num;
|
||||
|
||||
_o = dict->GetValue("FragmentSize");
|
||||
_o = _dict->GetValue("FragmentSize");
|
||||
if(GetObject(_o,_num)) data.FragmentSize = (uint64_t)_num;
|
||||
_o = dict->GetValue("Blocks");
|
||||
_o = _dict->GetValue("Blocks");
|
||||
if(GetObject(_o,_num)) data.Blocks = (uint64_t)_num;
|
||||
_o = dict->GetValue("BlocksFree");
|
||||
_o = _dict->GetValue("BlocksFree");
|
||||
if(GetObject(_o,_num)) data.BlocksFree = (uint64_t)_num;
|
||||
_o = dict->GetValue("BlocksAvailable");
|
||||
_o = _dict->GetValue("BlocksAvailable");
|
||||
if(GetObject(_o,_num)) data.BlocksAvailable = (uint64_t)_num;
|
||||
_o = dict->GetValue("TotalInodes");
|
||||
_o = _dict->GetValue("TotalInodes");
|
||||
if(GetObject(_o,_num)) data.TotalInodes = (uint64_t)_num;
|
||||
_o = dict->GetValue("FreeInodes");
|
||||
_o = _dict->GetValue("FreeInodes");
|
||||
if(GetObject(_o,_num)) data.FreeInodes = (uint64_t)_num;
|
||||
_o = dict->GetValue("AvailableInodes");
|
||||
_o = _dict->GetValue("AvailableInodes");
|
||||
if(GetObject(_o,_num)) data.AvailableInodes = (uint64_t)_num;
|
||||
_o = dict->GetValue("Id");
|
||||
_o = _dict->GetValue("Id");
|
||||
if(GetObject(_o,_num)) data.Id = (uint64_t)_num;
|
||||
_o = dict->GetValue("Flags");
|
||||
_o = _dict->GetValue("Flags");
|
||||
if(GetObject(_o,_num)) data.Flags = (uint64_t)_num;
|
||||
_o = dict->GetValue("MaxNameLength");
|
||||
_o = _dict->GetValue("MaxNameLength");
|
||||
if(GetObject(_o,_num)) data.MaxNameLength = (uint64_t)_num;
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace Tesses::CrossLang {
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls(this->ls->GetGC());
|
||||
dict->CallMethod(ls,"Close",{});
|
||||
dict->CallMethod(ls,"Dispose",{});
|
||||
}
|
||||
}
|
||||
TObjectVFS::~TObjectVFS()
|
||||
@@ -395,7 +395,7 @@ namespace Tesses::CrossLang {
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls(this->ls->GetGC());
|
||||
dict->CallMethod(ls,"Close",{});
|
||||
dict->CallMethod(ls,"Dispose",{});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
|
||||
@@ -668,7 +668,8 @@ namespace Tesses::CrossLang {
|
||||
{
|
||||
if(str[i] != c) break;
|
||||
}
|
||||
cse.back()->Push(gc,str.substr(i));
|
||||
|
||||
cse.back()->Push(gc,(!str.empty() && i < str.size()) ? str.substr(i) : "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -682,7 +683,8 @@ namespace Tesses::CrossLang {
|
||||
{
|
||||
if(str[i] != c) break;
|
||||
}
|
||||
cse.back()->Push(gc,str.substr(0,i+1));
|
||||
|
||||
cse.back()->Push(gc, (!str.empty() && i < str.size()) ? str.substr(0,i+1) : "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1677,6 +1679,8 @@ namespace Tesses::CrossLang {
|
||||
auto myvfs = std::dynamic_pointer_cast<TObjectVFS>(vfs);
|
||||
|
||||
auto mountable = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::MountableFilesystem>(vfs);
|
||||
|
||||
|
||||
if(myvfs != nullptr)
|
||||
{
|
||||
TDictionary* dict2;
|
||||
@@ -2166,6 +2170,136 @@ namespace Tesses::CrossLang {
|
||||
auto ttask = dynamic_cast<TTask*>(obj);
|
||||
auto file = dynamic_cast<TFile*>(obj);
|
||||
|
||||
auto queryable = dynamic_cast<TQueryable*>(obj);
|
||||
|
||||
if(queryable != nullptr)
|
||||
{
|
||||
if(key == "Skip")
|
||||
{
|
||||
int64_t count;
|
||||
if(GetArgument(args,0,count))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Skip(ls,count));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "Take")
|
||||
{
|
||||
int64_t count;
|
||||
if(GetArgument(args,0,count))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Take(ls,count));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "SkipWhile")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args, 0, callable))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->SkipWhile(ls,callable));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "TakeWhile")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args, 0, callable))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->TakeWhile(ls,callable));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "Select")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args, 0, callable))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Select(ls,callable));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "Where")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args, 0, callable))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Where(ls,callable));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "ToList")
|
||||
{
|
||||
cse.back()->Push(gc, queryable->ToList(ls));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(key == "ForEach")
|
||||
{
|
||||
TCallable* call;
|
||||
if(GetArgumentHeap(args,0,call))
|
||||
{
|
||||
queryable->ForEach(gc, call);
|
||||
}
|
||||
|
||||
cse.back()->Push(gc, Undefined());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(key == "Count")
|
||||
{
|
||||
TCallable* call;
|
||||
if(GetArgumentHeap(args,0,call))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Count(gc, call));
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
cse.back()->Push(gc, queryable->Count(gc));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "Contains")
|
||||
{
|
||||
if(!args.empty())
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Contains(gc, args[0]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "All")
|
||||
{
|
||||
TCallable* call;
|
||||
if(GetArgumentHeap(args,0,call))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->All(gc, call));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "Any")
|
||||
{
|
||||
TCallable* call;
|
||||
if(GetArgumentHeap(args,0,call))
|
||||
{
|
||||
cse.back()->Push(gc, queryable->Any(gc, call));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(key == "GetEnumerator")
|
||||
{
|
||||
cse.back()->Push(gc, queryable->GetEnumerator(ls));
|
||||
return false;
|
||||
}
|
||||
|
||||
cse.back()->Push(gc, Undefined());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(file != nullptr)
|
||||
{
|
||||
if(key == "MetadataDecode")
|
||||
@@ -2284,10 +2418,36 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
if(key == "RegisterEverything")
|
||||
{
|
||||
if(myEnv->permissions.canRegisterEverything && myEnv->permissions.localfs)
|
||||
if(rootEnv->permissions.locked)
|
||||
{
|
||||
TStd::RegisterStd(gc, rootEnv, std::make_shared<RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
cse.back()->Push(gc,nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(myEnv->permissions.canRegisterEverything)
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
if(GetArgument(args,0, vfs))
|
||||
{
|
||||
|
||||
auto rfs = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs);
|
||||
if(rfs)
|
||||
{
|
||||
TStd::RegisterStd(gc,rootEnv, rfs);
|
||||
cse.back()->Push(gc,nullptr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(myEnv->permissions.localfs)
|
||||
TStd::RegisterStd(gc, rootEnv, std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
else
|
||||
TStd::RegisterStd(gc, rootEnv, nullptr);
|
||||
|
||||
|
||||
|
||||
cse.back()->Push(gc,nullptr);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2308,7 +2468,7 @@ namespace Tesses::CrossLang {
|
||||
{
|
||||
if(myEnv->permissions.localfs)
|
||||
{
|
||||
TStd::RegisterIO(gc, rootEnv, std::make_shared<RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
TStd::RegisterIO(gc, rootEnv, std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
}
|
||||
else {
|
||||
TStd::RegisterIO(gc, rootEnv, nullptr);
|
||||
@@ -2388,6 +2548,8 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
if(key == "RegisterIO")
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
|
||||
bool r;
|
||||
if(GetArgument(args,0,r))
|
||||
{
|
||||
@@ -2395,13 +2557,21 @@ namespace Tesses::CrossLang {
|
||||
{
|
||||
if(myEnv->permissions.localfs)
|
||||
{
|
||||
TStd::RegisterIO(gc, rootEnv, std::make_shared<RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
TStd::RegisterIO(gc, rootEnv, std::make_shared<Tesses::Framework::Filesystem::RelativeFilesystem>(myEnv->permissions.localfs->GetVFS(),myEnv->permissions.localfs->GetWorking()));
|
||||
}
|
||||
else {
|
||||
TStd::RegisterIO(gc, rootEnv, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(GetArgument(args,0,vfs))
|
||||
{
|
||||
auto rfs = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs);
|
||||
if(rfs && (myEnv->permissions.canRegisterEverything || myEnv->permissions.canRegisterIO) && !rootEnv->permissions.locked)
|
||||
{
|
||||
TStd::RegisterIO(gc, rootEnv, rfs);
|
||||
}
|
||||
}
|
||||
cse.back()->Push(gc,nullptr);
|
||||
return false;
|
||||
|
||||
|
||||
@@ -70,6 +70,29 @@ namespace Tesses::CrossLang {
|
||||
{
|
||||
auto vfs = std::get<std::shared_ptr<Tesses::Framework::Filesystem::VFS>>(instance);
|
||||
auto tmpFS=std::dynamic_pointer_cast<Tesses::Framework::Filesystem::TempFS>(vfs);
|
||||
auto relative = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs);
|
||||
auto myFS = std::dynamic_pointer_cast<TObjectVFS>(vfs);
|
||||
if(relative)
|
||||
{
|
||||
if(key == "Working")
|
||||
{
|
||||
cse.back()->Push(gc, relative->GetWorking());
|
||||
return false;
|
||||
}
|
||||
if(key == "Filesystem")
|
||||
{
|
||||
cse.back()->Push(gc, relative->GetVFS());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(myFS)
|
||||
{
|
||||
if(key == "Inner")
|
||||
{
|
||||
cse.back()->Push(gc, myFS->obj);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(tmpFS)
|
||||
{
|
||||
if(key == "TempDirectoryName")
|
||||
|
||||
@@ -116,6 +116,34 @@ namespace Tesses::CrossLang {
|
||||
cse.back()->Push(gc,Undefined());
|
||||
return false;
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Filesystem::VFS>>(instance))
|
||||
{
|
||||
|
||||
auto vfs = std::get<std::shared_ptr<Tesses::Framework::Filesystem::VFS>>(instance);
|
||||
auto relative = std::dynamic_pointer_cast<Tesses::Framework::Filesystem::RelativeFilesystem>(vfs);
|
||||
|
||||
if(relative)
|
||||
{
|
||||
if(key == "Working")
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
if(GetObjectAsPath(value,path))
|
||||
{
|
||||
if(path.relative)
|
||||
{
|
||||
relative->SetWorking(path.MakeAbsolute(relative->GetWorking()));
|
||||
}
|
||||
else {
|
||||
relative->SetWorking(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cse.back()->Push(gc,Undefined());
|
||||
return false;
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Http::IHttpServer>>(instance))
|
||||
{
|
||||
auto svr = std::get<std::shared_ptr<Tesses::Framework::Http::IHttpServer>>(instance);
|
||||
|
||||
Reference in New Issue
Block a user