mirror of
https://onedev.site.tesses.net/crosslang
synced 2026-02-09 01:25:45 +00:00
Remove OnItteration due to bugs in multithreaded registering in tytd
This commit is contained in:
@@ -863,7 +863,7 @@ namespace Tesses::CrossLang
|
||||
EnsureSymbol("]");
|
||||
continue;
|
||||
}
|
||||
if(tokens[i].type != LexTokenType::Identifier) throw std::exception();
|
||||
if(tokens[i].type != LexTokenType::Identifier) throw std::runtime_error("Not an identifier (member)");
|
||||
std::string name = tokens[i].text;
|
||||
if(name == "operator")
|
||||
{
|
||||
|
||||
@@ -6,100 +6,6 @@
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
|
||||
class OnItterationObj : public TNativeObject
|
||||
{
|
||||
private:
|
||||
GC* gc;
|
||||
std::vector<TCallable*> callables;
|
||||
std::shared_ptr<Tesses::Framework::FunctionalEvent<uint64_t>> fevent;
|
||||
public:
|
||||
OnItterationObj(GC* gc)
|
||||
{
|
||||
this->gc=gc;
|
||||
this->fevent = std::make_shared<Tesses::Framework::FunctionalEvent<uint64_t>>(
|
||||
[this](uint64_t n)->void{
|
||||
this->Exec(n);
|
||||
}
|
||||
);
|
||||
Tesses::Framework::OnItteraton += this->fevent;
|
||||
}
|
||||
~OnItterationObj()
|
||||
{
|
||||
Tesses::Framework::OnItteraton -= this->fevent;
|
||||
}
|
||||
std::string TypeName()
|
||||
{
|
||||
return "OnItteration";
|
||||
}
|
||||
TObject CallMethod(GCList& ls, std::string key, std::vector<TObject> args)
|
||||
{
|
||||
if(key == "operator+")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
bool found=false;
|
||||
for(auto item : this->callables)
|
||||
{
|
||||
if(item == callable) {found=true; break;}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
this->callables.push_back(callable);
|
||||
}
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if(key == "operator-")
|
||||
{
|
||||
TCallable* callable;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
|
||||
for(auto index = this->callables.begin(); index < this->callables.end(); index++)
|
||||
{
|
||||
if(*index == callable) {
|
||||
this->callables.erase(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if(key == "ToString")
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
std::string str = "Registered: " + std::to_string(this->callables.size());
|
||||
gc->BarrierEnd();
|
||||
return str;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
void Mark()
|
||||
{
|
||||
if(this->marked) return;
|
||||
this->marked=true;
|
||||
|
||||
for(auto item : callables) item->Mark();
|
||||
}
|
||||
void Exec(uint64_t n)
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
for(auto item : callables)
|
||||
{
|
||||
gc->BarrierEnd();
|
||||
GCList ls(gc);
|
||||
item->Call(ls,{(int64_t)n});
|
||||
gc->BarrierBegin();
|
||||
}
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
};
|
||||
static TObject AstToTObject(GCList& ls,SyntaxNode node)
|
||||
{
|
||||
if(std::holds_alternative<std::nullptr_t>(node))
|
||||
@@ -378,7 +284,6 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
void TStd::RegisterVM(GC* gc,TRootEnvironment* env)
|
||||
{
|
||||
|
||||
env->permissions.canRegisterVM=true;
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls);
|
||||
@@ -458,13 +363,12 @@ namespace Tesses::CrossLang
|
||||
return Undefined();
|
||||
});
|
||||
|
||||
|
||||
gc->BarrierBegin();
|
||||
auto ittrobj = TNativeObject::Create<OnItterationObj>(ls,gc);
|
||||
|
||||
|
||||
dict->SetValue("OnItteration", ittrobj);
|
||||
|
||||
env->DeclareVariable("VM", dict);
|
||||
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,14 @@ namespace Tesses::CrossLang
|
||||
|
||||
void GC::BarrierBegin()
|
||||
{
|
||||
|
||||
this->mtx->Lock();
|
||||
}
|
||||
void GC::BarrierEnd()
|
||||
{
|
||||
|
||||
this->mtx->Unlock();
|
||||
|
||||
}
|
||||
void GC::Watch(TObject obj)
|
||||
{
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace Tesses::CrossLang {
|
||||
|
||||
if(GetObjectHeap(obj,callable))
|
||||
{
|
||||
return ToBool(callable->Call(ls,{}));
|
||||
return ToBool(callable->Call(ls,{right}));
|
||||
|
||||
}
|
||||
else if(std::holds_alternative<std::nullptr_t>(right)) {
|
||||
@@ -235,9 +235,21 @@ namespace Tesses::CrossLang {
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return dict == std::get<THeapObjectHolder>(right).obj;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return dict == std::get<THeapObjectHolder>(right).obj;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
return dict == std::get<THeapObjectHolder>(right).obj;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -404,7 +416,7 @@ namespace Tesses::CrossLang {
|
||||
auto env = cse.back()->env;
|
||||
if(!env->GetRootEnvironment()->HandleBreakpoint(gc, env, res))
|
||||
{
|
||||
throw std::exception();
|
||||
throw std::runtime_error("Breakpoint unhandled");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user