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

56 lines
1.4 KiB
C#
Raw Normal View History

2023-07-29 00:11:09 +00:00
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)
{
2023-07-30 07:55:10 +00:00
if(key == "this")
{
return classInstance;
}
return oGenv.GetObject(key);
2023-07-29 00:11:09 +00:00
}
public override TLangEnvironment GetParentEnvironment()
{
2023-07-30 07:55:10 +00:00
return oGenv;
2023-07-29 00:11:09 +00:00
}
public override RootEnvironment GetRootEnvironment()
{
2023-07-30 07:55:10 +00:00
return oGenv.GetRootEnvironment();
2023-07-29 00:11:09 +00:00
}
public override TLangEnvironment GetSubEnvironment()
{
2023-07-30 07:55:10 +00:00
return new SubEnvironment(this);
2023-07-29 00:11:09 +00:00
}
public override bool HasObject(string key)
{
2023-07-30 07:55:10 +00:00
if(key == "this") return true;
return oGenv.HasObject(key);
2023-07-29 00:11:09 +00:00
}
public override bool HasObjectRecurse(string key)
{
2023-07-30 07:55:10 +00:00
if(key == "this") return true;
return oGenv.HasObjectRecurse(key);
2023-07-29 00:11:09 +00:00
}
public override void SetObject(string key, TObject value)
{
2023-07-30 07:55:10 +00:00
if(key == "this") return;
oGenv.SetObject(key,value);
2023-07-29 00:11:09 +00:00
}
}
}