Add const variables
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
#include "CrossLang.hpp"
|
||||
namespace Tesses::CrossLang {
|
||||
|
||||
bool TClassEnvironment::HasConstForSet(std::string key)
|
||||
{
|
||||
if(this->env->HasVariableRecurse(key))
|
||||
{
|
||||
return this->env->HasConstForSet(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TClassEnvironment* TClassEnvironment::Create(GCList* gc,TEnvironment* env,TClassObject* obj)
|
||||
{
|
||||
|
||||
@@ -95,6 +102,7 @@ namespace Tesses::CrossLang {
|
||||
if(GetObjectHeap(res,call)) return call->Call(ls,{v});
|
||||
}
|
||||
if(this->clsObj->HasValue(clsName,key)) { this->clsObj->SetValue(clsName,key,v); return v;}
|
||||
|
||||
return this->env->SetVariable(ls,key,v);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,27 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
namespace Tesses::CrossLang {
|
||||
void ThrowConstError(std::string key)
|
||||
{
|
||||
throw std::runtime_error("Cannot set \"" + key + "\" because it is a const");
|
||||
}
|
||||
|
||||
void TEnvironment::DeclareConstVariable(std::string key, TObject value)
|
||||
{
|
||||
this->DeclareVariable(key,value);
|
||||
this->consts.push_back(key);
|
||||
}
|
||||
bool TEnvironment::HasConstForDeclare(std::string key)
|
||||
{
|
||||
for(auto item : this->consts)
|
||||
if(item == key)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool TEnvironment::HasConstForSet(std::string key)
|
||||
{
|
||||
return HasConstForDeclare(key);
|
||||
}
|
||||
bool TRootEnvironment::TryFindClass(std::vector<std::string>& name, size_t& index)
|
||||
{
|
||||
for(size_t i = 0; i < this->classes.size(); i++)
|
||||
|
||||
@@ -50,6 +50,18 @@ namespace Tesses::CrossLang {
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
bool TSubEnvironment::HasConstForSet(std::string key)
|
||||
{
|
||||
if(this->dict->HasValue(key))
|
||||
{
|
||||
return this->HasConstForDeclare(key);
|
||||
}
|
||||
if(this->env->HasVariableRecurse(key))
|
||||
{
|
||||
return this->env->HasConstForSet(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TObject TSubEnvironment::SetVariable(GCList& ls, std::string key, TObject value)
|
||||
{
|
||||
ls.GetGC()->BarrierBegin();
|
||||
|
||||
Reference in New Issue
Block a user