Replace time-based GC with allocation-count trigger, migrate all Create factories to GCList::Create(), fix VFSPath root path, reorder TObject variant
Build and Deploy on Tag / 🔨 Build for PowerPC (push) Successful in 1m11s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-riscv64:latest, riscv64-linux-gnu, riscv64) (push) Successful in 3m22s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-x64:latest, x86_64-linux-gnu, amd64) (push) Successful in 3m34s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-arm:latest, arm-linux-gnueabihf, arm7) (push) Successful in 3m37s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-arm64:latest, aarch64-linux-gnu, arm64) (push) Successful in 3m39s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-x86:latest, i386-linux-gnu, 386) (push) Successful in 55s
Build and Deploy on Tag / update-tap (push) Failing after 4m8s

This commit is contained in:
2026-09-01 05:15:43 -05:00
parent 56b74dc6fc
commit 2430b62232
38 changed files with 888 additions and 806 deletions
+2 -16
View File
@@ -1,22 +1,8 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TAny *TAny::Create(GCList &ls) {
TAny *anyObj = new TAny();
std::shared_ptr<GC> gc = ls.GetGC();
ls.Add(anyObj);
gc->Watch(anyObj);
return anyObj;
}
TAny *TAny::Create(GCList *ls) {
TAny *anyObj = new TAny();
std::shared_ptr<GC> gc = ls->GetGC();
ls->Add(anyObj);
gc->Watch(anyObj);
return anyObj;
}
TAny *TAny::Create(GCList &ls) { return ls.Create<TAny>(); }
TAny *TAny::Create(GCList *ls) { return ls->Create<TAny>(); }
void TAny::Mark() {
if (this->marked)
return;
+2 -10
View File
@@ -3,18 +3,10 @@
namespace Tesses::CrossLang {
TAssociativeArray *TAssociativeArray::Create(GCList &ls) {
TAssociativeArray *list = new TAssociativeArray();
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(list);
_gc->Watch(list);
return list;
return ls.Create<TAssociativeArray>();
}
TAssociativeArray *TAssociativeArray::Create(GCList *ls) {
TAssociativeArray *list = new TAssociativeArray();
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(list);
_gc->Watch(list);
return list;
return ls->Create<TAssociativeArray>();
}
void TAssociativeArray::Set(std::shared_ptr<GC> gc, TObject key,
TObject value) {
+9 -12
View File
@@ -9,22 +9,12 @@ bool TClassEnvironment::HasConstForSet(std::string key) {
TClassEnvironment *TClassEnvironment::Create(GCList *gc, TEnvironment *env,
TClassObject *obj) {
TClassEnvironment *env2 = new TClassEnvironment(env, obj);
std::shared_ptr<GC> _gc = gc->GetGC();
gc->Add(env2);
_gc->Watch(env2);
return env2;
return gc->Create<TClassEnvironment>(env, obj);
}
TClassEnvironment *TClassEnvironment::Create(GCList &gc, TEnvironment *env,
TClassObject *obj) {
TClassEnvironment *env2 = new TClassEnvironment(env, obj);
std::shared_ptr<GC> _gc = gc.GetGC();
gc.Add(env2);
_gc->Watch(env2);
return env2;
return gc.Create<TClassEnvironment>(env, obj);
}
TClassEnvironment::TClassEnvironment(TEnvironment *env, TClassObject *obj) {
this->env = env;
@@ -33,6 +23,7 @@ TClassEnvironment::TClassEnvironment(TEnvironment *env, TClassObject *obj) {
bool TClassEnvironment::HasVariable(std::string key) {
if (key == "this")
return true;
auto current_function = GC::GetCurrentFunction();
if (this->clsObj->HasValue(current_function == nullptr
? ""
: current_function->callable->className,
@@ -49,6 +40,8 @@ bool TClassEnvironment::HasVariableOrFieldRecurse(std::string key,
bool setting) {
if (key == "this")
return true;
auto current_function = GC::GetCurrentFunction();
std::string clsName = current_function == nullptr
? ""
: current_function->callable->className;
@@ -63,6 +56,7 @@ TObject TClassEnvironment::GetVariable(std::string key) {
if (key == "this")
return this->clsObj;
auto current_function = GC::GetCurrentFunction();
std::string clsName = current_function == nullptr
? ""
: current_function->callable->className;
@@ -75,6 +69,7 @@ void TClassEnvironment::SetVariable(std::string key, TObject value) {
if (key == "this")
return;
auto current_function = GC::GetCurrentFunction();
std::string clsName = current_function == nullptr
? ""
: current_function->callable->className;
@@ -90,6 +85,7 @@ TObject TClassEnvironment::GetVariable(GCList &ls, std::string key) {
if (key == "this")
return this->clsObj;
auto current_function = GC::GetCurrentFunction();
std::string clsName = current_function == nullptr
? ""
: current_function->callable->className;
@@ -107,6 +103,7 @@ TObject TClassEnvironment::SetVariable(GCList &ls, std::string key, TObject v) {
if (key == "this")
return this->clsObj;
auto current_function = GC::GetCurrentFunction();
std::string clsName = current_function == nullptr
? ""
: current_function->callable->className;
+23 -45
View File
@@ -1,27 +1,18 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TArgWrapper::TArgWrapper(TCallable *callable) : callable(callable) {}
TArgWrapper *TArgWrapper::Create(GCList &ls, TCallable *callable) {
TArgWrapper *argWrapper = new TArgWrapper();
argWrapper->callable = callable;
std::shared_ptr<GC> gc = ls.GetGC();
ls.Add(argWrapper);
gc->Watch(argWrapper);
return argWrapper;
return ls.Create<TArgWrapper>(callable);
}
TArgWrapper *TArgWrapper::Create(GCList *ls, TCallable *callable) {
TArgWrapper *argWrapper = new TArgWrapper();
argWrapper->callable = callable;
std::shared_ptr<GC> gc = ls->GetGC();
ls->Add(argWrapper);
gc->Watch(argWrapper);
return argWrapper;
return ls->Create<TArgWrapper>(callable);
}
TObject TArgWrapper::Call(GCList &ls, std::vector<TObject> args) {
auto cse = current_function;
auto cse = GC::GetCurrentFunction();
TList *argList = TList::Create(ls);
argList->items = args;
TObject v = this->callable->Call(ls, {argList});
current_function = cse;
GC::SetCurrentFunction(cse);
return v;
}
void TArgWrapper::Mark() {
@@ -46,52 +37,39 @@ void TClosure::Mark() {
this->closure->Mark();
GC::Mark(this->tag);
}
TClosure *TClosure::Create(GCList &ls, TEnvironment *env, TFile *file,
uint32_t chunkId, bool ownScope) {
TClosure *closure = new TClosure();
closure->className = "";
closure->ownScope = ownScope;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(closure);
_gc->Watch(closure);
closure->chunkId = chunkId;
TClosure::TClosure(TEnvironment *env, TFile *file, uint32_t chunkId,
bool ownScope) {
this->className = "";
this->ownScope = ownScope;
this->chunkId = chunkId;
if (chunkId < file->chunks.size())
closure->closure = file->chunks[chunkId];
this->closure = file->chunks[chunkId];
else
throw VMException("ChunkId out of bounds.");
closure->env = env;
closure->file = file;
return closure;
this->env = env;
this->file = file;
}
TClosure *TClosure::Create(GCList &ls, TEnvironment *env, TFile *file,
uint32_t chunkId, bool ownScope) {
return ls.Create<TClosure>(env, file, chunkId, ownScope);
}
TClosure *TClosure::Create(GCList *ls, TEnvironment *env, TFile *file,
uint32_t chunkId, bool ownScope) {
TClosure *closure = new TClosure();
closure->className = "";
closure->ownScope = ownScope;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(closure);
_gc->Watch(closure);
closure->chunkId = chunkId;
if (chunkId < file->chunks.size())
closure->closure = file->chunks[chunkId];
else
throw VMException("ChunkId out of bounds.");
closure->env = env;
closure->file = file;
return closure;
return ls->Create<TClosure>(env, file, chunkId, ownScope);
}
TObject TClosure::Call(GCList &ls, std::vector<TObject> args) {
auto cse = current_function;
auto cse = GC::GetCurrentFunction();
InterperterThread *thrd = InterperterThread::Create(ls);
thrd->AddCallStackEntry(ls, this, args);
thrd->Execute(ls.GetGC());
TObject v = thrd->call_stack_entries[0]->Pop(ls);
current_function = cse;
GC::SetCurrentFunction(cse);
// current_function = cse;
return v;
}
} // namespace Tesses::CrossLang
+8 -24
View File
@@ -1,24 +1,15 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TDynamicDictionary::TDynamicDictionary(TCallable *callable) : cb(callable) {}
TDynamicDictionary *TDynamicDictionary::Create(GCList &ls,
TCallable *callable) {
TDynamicDictionary *dict = new TDynamicDictionary();
dict->cb = callable;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(dict);
_gc->Watch(dict);
return dict;
return ls.Create<TDynamicDictionary>(callable);
}
TDynamicDictionary *TDynamicDictionary::Create(GCList *ls,
TCallable *callable) {
TDynamicDictionary *dict = new TDynamicDictionary();
dict->cb = callable;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(dict);
_gc->Watch(dict);
return dict;
return ls->Create<TDynamicDictionary>(callable);
}
void TDynamicDictionary::Mark() {
@@ -165,8 +156,9 @@ void TDictionary::DeclareFunction(
TObject TDictionary::GetValue(std::string key) {
if (this->items.empty())
return Undefined();
if (this->items.count(key) > 0)
return this->items[key];
auto item = this->items.find(key);
if (item != this->items.end())
return item->second;
return Undefined();
}
void TDictionary::SetValue(std::string key, TObject value) {
@@ -189,18 +181,10 @@ void TDictionary::Mark() {
}
}
TDictionary *TDictionary::Create(GCList *gc) {
TDictionary *dict = new TDictionary();
std::shared_ptr<GC> _gc = gc->GetGC();
gc->Add(dict);
_gc->Watch(dict);
return dict;
return gc->Create<TDictionary>();
}
TDictionary *TDictionary::Create(GCList &gc) {
TDictionary *dict = new TDictionary();
std::shared_ptr<GC> _gc = gc.GetGC();
gc.Add(dict);
_gc->Watch(dict);
return dict;
return gc.Create<TDictionary>();
}
}; // namespace Tesses::CrossLang
+168
View File
@@ -0,0 +1,168 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TException::TException(std::string message, std::string type,
TDictionary *extraFields, TObject innerException)
: message(message), type(type), extraFields(extraFields),
innerException(innerException) {}
TObject TException::CallMethod(GCList &ls, std::string key,
std::vector<TObject> args) {
if (key == "getMessage" ||
key == "getText") // Text is for compatibility reasons
return this->message;
if (key == "getInnerException")
return this->innerException;
if (key == "getType")
return this->type;
if (key == "getLine")
return static_cast<int64_t>(this->line.value_or(0));
if (key == "getOffset")
return static_cast<int64_t>(this->offset.value_or(0));
if (key == "getColumn")
return static_cast<int64_t>(this->column.value_or(0));
if (key == "getFileName")
return this->filename.value_or("");
if (key == "setLine") {
int64_t v;
if (!this->line && GetArgument(args, 0, v))
this->line = static_cast<uint32_t>(v);
return Undefined();
}
if (key == "setColumn") {
int64_t v;
if (!this->column && GetArgument(args, 0, v))
this->column = static_cast<uint32_t>(v);
return Undefined();
}
if (key == "setOffset") {
int64_t v;
if (!this->offset && GetArgument(args, 0, v))
this->offset = static_cast<uint32_t>(v);
return Undefined();
}
if (key == "setFileName") {
std::string v;
if (!this->filename && GetArgument(args, 0, v))
this->filename = v;
return Undefined();
}
if (key == "ToString") {
std::string text;
text.reserve(this->type.size() + this->message.size() + 3);
text.append(this->type);
text.append(": ");
text.append(this->message);
text.push_back('\n');
if (this->filename) {
auto &filename = *this->filename;
text.reserve(text.size() + filename.size() + 4);
text.append("At: ");
text.append(filename);
if (this->line) {
text.push_back(':');
text.append(std::to_string(*this->line));
if (this->column) {
text.push_back(':');
text.append(std::to_string(*this->column));
}
}
text.push_back('\n');
if (!this->line && this->column) {
text.append("Column: ");
text.append(std::to_string(*this->column));
text.push_back('\n');
}
} else {
if (this->line) {
text.append("Line: ");
text.append(std::to_string(*this->line));
text.push_back('\n');
}
if (this->column) {
text.append("Column: ");
text.append(std::to_string(*this->column));
text.push_back('\n');
}
}
if (this->offset) {
text.append("Offset: ");
text.append(std::to_string(*this->offset));
text.push_back('\n');
}
if (!std::holds_alternative<Undefined>(this->innerException)) {
text.append("InnerException:");
std::string textInner = ToString(ls.GetGC(), this->innerException);
for (auto item : Tesses::Framework::Http::HttpUtils::SplitString(
textInner, "\n")) {
if (item.empty()) {
text.push_back('\n');
continue;
}
text.append("\n\t");
text.append(item);
}
}
return text;
}
if (extraFields != nullptr) {
GCList ls2(ls.GetGC());
if (extraFields->MethodExists(ls2, key)) {
return extraFields->CallMethod(ls, key, args);
}
if (key.size() > 3 && key[0] == 'g' && key[1] == 'e' && key[2] == 't') {
ls.GetGC()->BarrierBegin();
auto val = extraFields->GetValue(key.substr(3));
ls.GetGC()->BarrierEnd();
return val;
}
}
return Undefined();
}
std::string TException::TypeName() { return this->type; }
bool TException::ToBool() { return true; }
void TException::Mark() {
if (marked)
return;
marked = true;
if (this->extraFields)
this->extraFields->Mark();
GC::Mark(this->innerException);
}
TNativeException::TNativeException(const char *what, std::exception_ptr ptr)
: what(what != nullptr ? what : ""), ptr(ptr) {}
TObject TNativeException::CallMethod(GCList &ls, std::string key,
std::vector<TObject> args) {
if (key == "getMessage" || key == "getText")
return this->what;
if (key == "getType")
return "NativeException";
if (key == "ToString") {
return "NativeException: " + this->what;
}
return Undefined();
}
std::string TNativeException::TypeName() { return "NativeException"; }
std::string TNativeException::What() { return this->what; }
std::exception_ptr TNativeException::GetPointer() { return this->ptr; }
void TNativeException::ThrowIt() { std::rethrow_exception(this->ptr); }
} // namespace Tesses::CrossLang
+6 -25
View File
@@ -1,8 +1,8 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TExternalMethod::TExternalMethod(
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb,
std::string documentation, std::vector<std::string> argNames,
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb,
std::function<void()> destroy) {
this->cb = cb;
@@ -14,43 +14,24 @@ TExternalMethod *TExternalMethod::Create(
GCList &ls, std::string documentation, std::vector<std::string> argNames,
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb,
std::function<void()> destroy) {
auto gc = ls.GetGC();
TExternalMethod *method =
new TExternalMethod(cb, documentation, argNames, destroy);
ls.Add(method);
gc->Watch(method);
return method;
return ls.Create<TExternalMethod>(documentation, argNames, cb, destroy);
}
TExternalMethod *TExternalMethod::Create(
GCList *ls, std::string documentation, std::vector<std::string> argNames,
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb,
std::function<void()> destroy) {
auto gc = ls->GetGC();
TExternalMethod *method =
new TExternalMethod(cb, documentation, argNames, destroy);
ls->Add(method);
gc->Watch(method);
return method;
return ls->Create<TExternalMethod>(documentation, argNames, cb, destroy);
}
TExternalMethod *TExternalMethod::Create(
GCList &ls, std::string documentation, std::vector<std::string> argNames,
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb) {
auto gc = ls.GetGC();
TExternalMethod *method =
new TExternalMethod(cb, documentation, argNames, []() -> void {});
ls.Add(method);
gc->Watch(method);
return method;
return ls.Create<TExternalMethod>(documentation, argNames, cb);
}
TExternalMethod *TExternalMethod::Create(
GCList *ls, std::string documentation, std::vector<std::string> argNames,
std::function<TObject(GCList &ls, std::vector<TObject> args)> cb) {
auto gc = ls->GetGC();
TExternalMethod *method =
new TExternalMethod(cb, documentation, argNames, []() -> void {});
ls->Add(method);
gc->Watch(method);
return method;
return ls->Create<TExternalMethod>(documentation, argNames, cb);
}
TObject TExternalMethod::Call(GCList &ls, std::vector<TObject> args) {
if (cb == nullptr)
+35 -114
View File
@@ -44,28 +44,15 @@ void TYieldEnumerator::Mark() {
GC::Mark(this->current);
GC::Mark(this->enumerator);
}
TYieldEnumerator *TYieldEnumerator::Create(GCList &ls, TObject v) {
TYieldEnumerator *yieldEnum = new TYieldEnumerator();
yieldEnum->current = nullptr;
yieldEnum->hasStarted = false;
yieldEnum->enumerator = v;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(yieldEnum);
_gc->Watch(yieldEnum);
return yieldEnum;
TYieldEnumerator::TYieldEnumerator(TObject v)
: current(nullptr), hasStarted(false), enumerator(v) {}
TYieldEnumerator *TYieldEnumerator::Create(GCList &ls, TObject v) {
return ls.Create<TYieldEnumerator>(v);
}
TYieldEnumerator *TYieldEnumerator::Create(GCList *ls, TObject v) {
TYieldEnumerator *yieldEnum = new TYieldEnumerator();
yieldEnum->current = nullptr;
yieldEnum->hasStarted = false;
yieldEnum->enumerator = v;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(yieldEnum);
_gc->Watch(yieldEnum);
return yieldEnum;
return ls->Create<TYieldEnumerator>(v);
}
bool TCustomEnumerator::MoveNext(std::shared_ptr<GC> ls) {
@@ -97,21 +84,12 @@ void TCustomEnumerator::Mark() {
return;
this->dict->Mark();
}
TCustomEnumerator::TCustomEnumerator(TDictionary *dict) : dict(dict) {}
TCustomEnumerator *TCustomEnumerator::Create(GCList *ls, TDictionary *dict) {
TCustomEnumerator *customEnum = new TCustomEnumerator();
customEnum->dict = dict;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(customEnum);
_gc->Watch(customEnum);
return customEnum;
return ls->Create<TCustomEnumerator>(dict);
}
TCustomEnumerator *TCustomEnumerator::Create(GCList &ls, TDictionary *dict) {
TCustomEnumerator *customEnum = new TCustomEnumerator();
customEnum->dict = dict;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(customEnum);
_gc->Watch(customEnum);
return customEnum;
return ls.Create<TCustomEnumerator>(dict);
}
TEnumerator *TEnumerator::CreateFromObject(GCList &ls, TObject obj) {
std::string str;
@@ -141,23 +119,16 @@ TEnumerator *TEnumerator::CreateFromObject(GCList &ls, TObject obj) {
}
return nullptr;
}
TVFSPathEnumerator::TVFSPathEnumerator(
Tesses::Framework::Filesystem::VFSPathEnumerator enumerator)
: enumerator(enumerator) {}
TVFSPathEnumerator *TVFSPathEnumerator::Create(
GCList &ls, Tesses::Framework::Filesystem::VFSPathEnumerator enumerator) {
TVFSPathEnumerator *vfspathe = new TVFSPathEnumerator();
vfspathe->enumerator = enumerator;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(vfspathe);
_gc->Watch(vfspathe);
return vfspathe;
return ls.Create<TVFSPathEnumerator>(enumerator);
}
TVFSPathEnumerator *TVFSPathEnumerator::Create(
GCList *ls, Tesses::Framework::Filesystem::VFSPathEnumerator enumerator) {
TVFSPathEnumerator *vfspathe = new TVFSPathEnumerator();
vfspathe->enumerator = enumerator;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(vfspathe);
_gc->Watch(vfspathe);
return vfspathe;
return ls->Create<TVFSPathEnumerator>(enumerator);
}
bool TVFSPathEnumerator::MoveNext(std::shared_ptr<GC> ls) {
return enumerator.MoveNext();
@@ -165,25 +136,15 @@ bool TVFSPathEnumerator::MoveNext(std::shared_ptr<GC> ls) {
TObject TVFSPathEnumerator::GetCurrent(GCList &ls) {
return enumerator.Current;
}
TDictionaryEnumerator::TDictionaryEnumerator(TDictionary *dict)
: dict(dict), hasStarted(false) {}
TDictionaryEnumerator *TDictionaryEnumerator::Create(GCList &ls,
TDictionary *dict) {
TDictionaryEnumerator *dicte = new TDictionaryEnumerator();
dicte->dict = dict;
dicte->hasStarted = false;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(dicte);
_gc->Watch(dicte);
return dicte;
return ls.Create<TDictionaryEnumerator>(dict);
}
TDictionaryEnumerator *TDictionaryEnumerator::Create(GCList *ls,
TDictionary *dict) {
TDictionaryEnumerator *dicte = new TDictionaryEnumerator();
dicte->dict = dict;
dicte->hasStarted = false;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(dicte);
_gc->Watch(dicte);
return dicte;
return ls->Create<TDictionaryEnumerator>(dict);
}
bool TDictionaryEnumerator::MoveNext(std::shared_ptr<GC> ls) {
@@ -217,24 +178,13 @@ void TDictionaryEnumerator::Mark() {
this->marked = true;
this->dict->Mark();
}
TListEnumerator::TListEnumerator(TList *list) : ls(list), index(-1) {}
TListEnumerator *TListEnumerator::Create(GCList &ls, TList *list) {
TListEnumerator *liste = new TListEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(liste);
_gc->Watch(liste);
return liste;
return ls.Create<TListEnumerator>(list);
}
TListEnumerator *TListEnumerator::Create(GCList *ls, TList *list) {
TListEnumerator *liste = new TListEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(liste);
_gc->Watch(liste);
return liste;
return ls->Create<TListEnumerator>(list);
}
bool TListEnumerator::MoveNext(std::shared_ptr<GC> ls) {
this->index++;
@@ -260,25 +210,17 @@ void TListEnumerator::Mark() {
this->ls->Mark();
}
TAssociativeArrayEnumerator::TAssociativeArrayEnumerator(
TAssociativeArray *list)
: ls(list), index(-1) {}
TAssociativeArrayEnumerator *
TAssociativeArrayEnumerator::Create(GCList &ls, TAssociativeArray *list) {
TAssociativeArrayEnumerator *liste = new TAssociativeArrayEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(liste);
_gc->Watch(liste);
return liste;
return ls.Create<TAssociativeArrayEnumerator>(list);
}
TAssociativeArrayEnumerator *
TAssociativeArrayEnumerator::Create(GCList *ls, TAssociativeArray *list) {
TAssociativeArrayEnumerator *liste = new TAssociativeArrayEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(liste);
_gc->Watch(liste);
return liste;
return ls->Create<TAssociativeArrayEnumerator>(list);
}
bool TAssociativeArrayEnumerator::MoveNext(std::shared_ptr<GC> ls) {
this->index++;
@@ -305,26 +247,16 @@ void TAssociativeArrayEnumerator::Mark() {
this->marked = true;
this->ls->Mark();
}
TDynamicListEnumerator::TDynamicListEnumerator(TDynamicList *list)
: ls(list), index(-1) {}
TDynamicListEnumerator *TDynamicListEnumerator::Create(GCList &ls,
TDynamicList *list) {
TDynamicListEnumerator *liste = new TDynamicListEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(liste);
_gc->Watch(liste);
return liste;
return ls.Create<TDynamicListEnumerator>(list);
}
TDynamicListEnumerator *TDynamicListEnumerator::Create(GCList *ls,
TDynamicList *list) {
TDynamicListEnumerator *liste = new TDynamicListEnumerator();
liste->ls = list;
liste->index = -1;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(liste);
_gc->Watch(liste);
return liste;
return ls->Create<TDynamicListEnumerator>(list);
}
bool TDynamicListEnumerator::MoveNext(std::shared_ptr<GC> ls) {
this->index++;
@@ -351,24 +283,13 @@ void TDynamicListEnumerator::Mark() {
this->marked = true;
this->ls->Mark();
}
TStringEnumerator::TStringEnumerator(std::string str)
: str(str), hasStarted(false) {}
TStringEnumerator *TStringEnumerator::Create(GCList &ls, std::string str) {
TStringEnumerator *stre = new TStringEnumerator();
stre->str = str;
stre->hasStarted = false;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(stre);
_gc->Watch(stre);
return stre;
return ls.Create<TStringEnumerator>(str);
}
TStringEnumerator *TStringEnumerator::Create(GCList *ls, std::string str) {
TStringEnumerator *stre = new TStringEnumerator();
stre->str = str;
stre->hasStarted = false;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(stre);
_gc->Watch(stre);
return stre;
return ls->Create<TStringEnumerator>(str);
}
bool TStringEnumerator::MoveNext(std::shared_ptr<GC> ls) {
if (!this->hasStarted) {
+8 -41
View File
@@ -1,20 +1,11 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TDynamicList::TDynamicList(TCallable *callable) : cb(callable) {}
TDynamicList *TDynamicList::Create(GCList &ls, TCallable *callable) {
TDynamicList *list = new TDynamicList();
list->cb = callable;
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(list);
_gc->Watch(list);
return list;
return ls.Create<TDynamicList>(callable);
}
TDynamicList *TDynamicList::Create(GCList *ls, TCallable *callable) {
TDynamicList *list = new TDynamicList();
list->cb = callable;
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(list);
_gc->Watch(list);
return list;
return ls->Create<TDynamicList>(callable);
}
void TDynamicList::Mark() {
@@ -120,35 +111,11 @@ TObject TDynamicList::SetAt(GCList &ls, int64_t index, TObject val) {
TDynamicList::~TDynamicList() {}
TByteArray *TByteArray::Create(GCList &ls) {
TByteArray *arr = new TByteArray();
std::shared_ptr<GC> _gc = ls.GetGC();
ls.Add(arr);
_gc->Watch(arr);
return arr;
}
TByteArray *TByteArray::Create(GCList &ls) { return ls.Create<TByteArray>(); }
TByteArray *TByteArray::Create(GCList *ls) {
TByteArray *arr = new TByteArray();
std::shared_ptr<GC> _gc = ls->GetGC();
ls->Add(arr);
_gc->Watch(arr);
return arr;
}
TList *TList::Create(GCList *gc) {
TList *list = new TList();
std::shared_ptr<GC> _gc = gc->GetGC();
gc->Add(list);
_gc->Watch(list);
return list;
}
TList *TList::Create(GCList &gc) {
TList *list = new TList();
std::shared_ptr<GC> _gc = gc.GetGC();
gc.Add(list);
_gc->Watch(list);
return list;
}
TByteArray *TByteArray::Create(GCList *ls) { return ls->Create<TByteArray>(); }
TList *TList::Create(GCList *gc) { return gc->Create<TList>(); }
TList *TList::Create(GCList &gc) { return gc.Create<TList>(); }
void TList::Add(TObject value) { this->items.push_back(value); }
void TList::Set(int64_t index, TObject value) {
if (index >= 0 && index < this->Count()) {
@@ -161,7 +128,7 @@ TObject TList::Get(int64_t index) {
}
return Undefined();
}
int64_t TList::Count() { return (int64_t)this->items.size(); }
int64_t TList::Count() { return this->items.size(); }
void TList::Insert(int64_t index, TObject value) {
if (index >= 0 && index <= this->Count()) {
this->items.insert(this->items.begin() + index, value);
+2 -11
View File
@@ -1,7 +1,6 @@
#include "CrossLang.hpp"
namespace Tesses::CrossLang {
TNativeObject::~TNativeObject() {}
TNative::TNative(void *ptr, std::function<void(void *)> destroy) {
this->ptr = ptr;
@@ -34,19 +33,11 @@ bool TNativeObject::Equals(std::shared_ptr<GC> gc, TObject right) {
}
TNative *TNative::Create(GCList &ls, void *ptr,
std::function<void(void *)> destroy) {
TNative *native = new TNative(ptr, destroy);
std::shared_ptr<GC> gc = ls.GetGC();
ls.Add(native);
gc->Watch(native);
return native;
return ls.Create<TNative>(ptr, destroy);
}
TNative *TNative::Create(GCList *ls, void *ptr,
std::function<void(void *)> destroy) {
TNative *native = new TNative(ptr, destroy);
std::shared_ptr<GC> gc = ls->GetGC();
ls->Add(native);
gc->Watch(native);
return native;
return ls->Create<TNative>(ptr, destroy);
}
TNative::~TNative() { this->Destroy(); }
+2 -10
View File
@@ -41,19 +41,11 @@ TList *TQueryable::ToList(GCList &ls) {
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;
return ls.Create<TQueryable>(parent);
}
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;
return ls.Create<TQueryable>(parent, mode, args);
}
void TQueryable::Mark() {
+9 -16
View File
@@ -9,12 +9,11 @@ void ThrowConstError(std::string key) {
void TEnvironment::DeclareConstVariable(std::string key, TObject value) {
this->DeclareVariable(key, value);
this->consts.push_back(key);
this->decls[key] = TEnvironmentDeclType::TEDT_CONST;
}
bool TEnvironment::HasConstForDeclare(std::string key) {
for (auto item : this->consts)
if (item == key)
return true;
if (this->decls.count(key) > 0)
return this->decls[key] == TEnvironmentDeclType::TEDT_CONST;
return false;
}
bool TEnvironment::HasConstForSet(std::string key) {
@@ -308,13 +307,15 @@ void TRootEnvironment::SetVariable(std::string key, TObject value) {
this->dict->SetValue(key, value);
}
void TRootEnvironment::DeclareVariable(std::string key, TObject value) {
if (this->decls.count(key) == 0)
this->decls[key] = TEnvironmentDeclType::TEDT_VAR;
return this->dict->SetValue(key, value);
}
bool TRootEnvironment::HasVariable(std::string key) {
return this->dict->HasValue(key);
return this->dict->HasValue(key) || this->decls.count(key) > 0;
}
bool TRootEnvironment::HasVariableRecurse(std::string key) {
return this->dict->HasValue(key);
return this->dict->HasValue(key) || this->decls.count(key) > 0;
}
TEnvironment *TRootEnvironment::GetParentEnvironment() { return this; }
TRootEnvironment *TRootEnvironment::GetRootEnvironment() { return this; }
@@ -338,18 +339,10 @@ void TRootEnvironment::Mark() {
cls.first->Mark();
}
TRootEnvironment *TRootEnvironment::Create(GCList *gc, TDictionary *dict) {
TRootEnvironment *env = new TRootEnvironment(dict);
std::shared_ptr<GC> _gc = gc->GetGC();
gc->Add(env);
_gc->Watch(env);
return env;
return gc->Create<TRootEnvironment>(dict);
}
TRootEnvironment *TRootEnvironment::Create(GCList &gc, TDictionary *dict) {
TRootEnvironment *env = new TRootEnvironment(dict);
std::shared_ptr<GC> _gc = gc.GetGC();
gc.Add(env);
_gc->Watch(env);
return env;
return gc.Create<TRootEnvironment>(dict);
}
bool TRootEnvironment::HandleException(std::shared_ptr<GC> gc,
+13 -13
View File
@@ -82,16 +82,24 @@ TObject TSubEnvironment::GetVariable(std::string key) {
if (this->dict->HasValue(key)) {
return this->dict->GetValue(key);
}
if (this->decls.count(key) > 0 &&
this->decls[key] == TEnvironmentDeclType::TEDT_VAR) {
return Undefined();
}
if (this->env->HasVariableRecurse(key)) {
return this->env->GetVariable(key);
}
return Undefined();
}
void TSubEnvironment::DeclareVariable(std::string key, TObject value) {
if (this->decls.count(key) == 0)
this->decls[key] = TEnvironmentDeclType::TEDT_VAR;
this->dict->SetValue(key, value);
}
void TSubEnvironment::SetVariable(std::string key, TObject value) {
if (this->dict->HasValue(key)) {
if (this->dict->HasValue(key) || this->decls.count(key) > 0) {
this->dict->SetValue(key, value);
return;
}
@@ -102,10 +110,10 @@ void TSubEnvironment::SetVariable(std::string key, TObject value) {
}
}
bool TSubEnvironment::HasVariable(std::string key) {
return this->dict->HasValue(key);
return this->dict->HasValue(key) || this->decls.count(key) > 0;
}
bool TSubEnvironment::HasVariableRecurse(std::string key) {
if (this->dict->HasValue(key))
if (this->dict->HasValue(key) || this->decls.count(key) > 0)
return true;
return this->env->HasVariableRecurse(key);
}
@@ -159,19 +167,11 @@ TSubEnvironment *TEnvironment::GetSubEnvironment(GCList &gc) {
}
TSubEnvironment *TSubEnvironment::Create(GCList *gc, TEnvironment *env,
TDictionary *dict) {
TSubEnvironment *senv = new TSubEnvironment(env, dict);
std::shared_ptr<GC> _gc = gc->GetGC();
gc->Add(senv);
_gc->Watch(senv);
return senv;
return gc->Create<TSubEnvironment>(env, dict);
}
TSubEnvironment *TSubEnvironment::Create(GCList &gc, TEnvironment *env,
TDictionary *dict) {
TSubEnvironment *senv = new TSubEnvironment(env, dict);
std::shared_ptr<GC> _gc = gc.GetGC();
gc.Add(senv);
_gc->Watch(senv);
return senv;
return gc.Create<TSubEnvironment>(env, dict);
}
TEnvironment *TSubEnvironment::GetParentEnvironment() { return this->env; }
TRootEnvironment *TSubEnvironment::GetRootEnvironment() {