tlang-runtime-compiler/TLang.VM/ClassEnvironment.cs

56 lines
1.4 KiB
C#

namespace TLang.VM
{
internal class ClassEnvironment : TLangEnvironment
{
private TLangEnvironment oGenv;
private TClassInstance classInstance;
public ClassEnvironment(TLangEnvironment oGenv, TClassInstance classInstance)
{
this.oGenv = oGenv;
this.classInstance = classInstance;
}
public override TObject GetObject(string key)
{
if(key == "this")
{
return classInstance;
}
return oGenv.GetObject(key);
}
public override TLangEnvironment GetParentEnvironment()
{
return oGenv;
}
public override RootEnvironment GetRootEnvironment()
{
return oGenv.GetRootEnvironment();
}
public override TLangEnvironment GetSubEnvironment()
{
return new SubEnvironment(this);
}
public override bool HasObject(string key)
{
if(key == "this") return true;
return oGenv.HasObject(key);
}
public override bool HasObjectRecurse(string key)
{
if(key == "this") return true;
return oGenv.HasObjectRecurse(key);
}
public override void SetObject(string key, TObject value)
{
if(key == "this") return;
oGenv.SetObject(key,value);
}
}
}