Add better error message
This commit is contained in:
@@ -154,6 +154,7 @@ namespace Tesses::CrossLang
|
||||
else
|
||||
{
|
||||
auto clos = TClosure::Create(ls,obj->env,file,entry.chunkId);
|
||||
clos->closure->name = obj->name + "::" + ent.name;
|
||||
clos->className = ownerNow;
|
||||
clos->documentation = entry.documentation;
|
||||
ent.value = clos;
|
||||
@@ -163,6 +164,7 @@ namespace Tesses::CrossLang
|
||||
if(entry.isAbstract) ent.value = Undefined();
|
||||
else {
|
||||
auto clos = TClosure::Create(ls,obj->env,file,entry.chunkId);
|
||||
clos->closure->name = obj->name + "::" + ent.name;
|
||||
clos->className = ownerNow;
|
||||
ent.value = clos->Call(*ls,{});
|
||||
}
|
||||
|
||||
@@ -126,6 +126,33 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TObject TDictionary::CallMethodWithFatalError(GCList& ls, std::string key, std::vector<TObject> args)
|
||||
{
|
||||
ls.GetGC()->BarrierBegin();
|
||||
auto res = this->GetValue(key);
|
||||
ls.GetGC()->BarrierEnd();
|
||||
TCallable* callable;
|
||||
|
||||
if(GetObjectHeap(res,callable))
|
||||
{
|
||||
auto closure = dynamic_cast<TClosure*>(callable);
|
||||
if(closure != nullptr && !closure->closure->args.empty() && closure->closure->args.front() == "this")
|
||||
{
|
||||
std::vector<TObject> args2;
|
||||
args2.push_back(this);
|
||||
args2.insert(args2.end(), args.begin(),args.end());
|
||||
return closure->CallWithFatalError(ls,args2);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return callable->CallWithFatalError(ls,args);
|
||||
|
||||
}
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
void TDictionary::DeclareFunction(GC* gc,std::string key,std::string documentation, std::vector<std::string> argNames, std::function<TObject(GCList& ls, std::vector<TObject> args)> cb)
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
@@ -204,4 +231,5 @@ namespace Tesses::CrossLang {
|
||||
_gc->Watch(dict);
|
||||
return dict;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -118,6 +118,7 @@ namespace Tesses::CrossLang {
|
||||
throw VMException("Lex error at line: " + std::to_string(res));
|
||||
}
|
||||
Parser parser(tokens);
|
||||
|
||||
SyntaxNode n = parser.ParseRoot();
|
||||
CodeGen gen;
|
||||
gen.GenRoot(n);
|
||||
@@ -230,6 +231,9 @@ namespace Tesses::CrossLang {
|
||||
std::vector<std::string> method=file->classes[i].name;
|
||||
method.push_back(meth.name);
|
||||
auto clo = TClosure::Create(ls,this,file,meth.chunkId);
|
||||
clo->closure->name = JoinPeriod(method);
|
||||
|
||||
|
||||
clo->documentation = meth.documentation;
|
||||
this->DeclareVariable(gc, method, clo);
|
||||
}
|
||||
@@ -239,7 +243,6 @@ namespace Tesses::CrossLang {
|
||||
for(auto fn : file->functions)
|
||||
{
|
||||
|
||||
std::string name;
|
||||
|
||||
|
||||
if(fn.first.size() < 2) throw VMException("No function name.");
|
||||
@@ -248,6 +251,7 @@ namespace Tesses::CrossLang {
|
||||
|
||||
if(fn.second >= file->chunks.size()) throw VMException("ChunkId out of bounds.");
|
||||
TFileChunk* chunk = file->chunks[fn.second];
|
||||
chunk->name = JoinPeriod(items);
|
||||
GCList ls(gc);
|
||||
TClosure* closure=TClosure::Create(ls,this,file,fn.second);
|
||||
closure->documentation = fn.first[0];
|
||||
|
||||
@@ -163,6 +163,19 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TObject TEnvironment::CallFunctionWithFatalError(GCList& ls, std::string key, std::vector<TObject> args)
|
||||
{
|
||||
ls.GetGC()->BarrierBegin();
|
||||
auto res = this->GetVariable(key);
|
||||
ls.GetGC()->BarrierEnd();
|
||||
TCallable* callable;
|
||||
|
||||
if(GetObjectHeap(res,callable))
|
||||
{
|
||||
return callable->CallWithFatalError(ls,args);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TSubEnvironment* TEnvironment::GetSubEnvironment(GCList* gc)
|
||||
{
|
||||
auto dict=TDictionary::Create(gc);
|
||||
|
||||
Reference in New Issue
Block a user