2023-07-29 00:11:09 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace TLang.VM
|
|
|
|
{
|
|
|
|
public class SubEnvironment : TLangEnvironment
|
|
|
|
{
|
|
|
|
public SubEnvironment(TLangEnvironment env)
|
|
|
|
{
|
|
|
|
this.pEnv=env;
|
|
|
|
}
|
|
|
|
TLangEnvironment pEnv;
|
|
|
|
|
|
|
|
Dictionary<string,TObject> items = new Dictionary<string, TObject>();
|
|
|
|
public override TObject GetObject(string key)
|
|
|
|
{
|
|
|
|
if(pEnv.HasObjectRecurse(key))
|
|
|
|
{
|
|
|
|
return pEnv.GetObject(key);
|
|
|
|
}
|
|
|
|
if(HasObject(key))
|
|
|
|
{
|
|
|
|
return items[key];
|
|
|
|
}
|
|
|
|
return new TUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool HasObject(string key)
|
|
|
|
{
|
|
|
|
return items.ContainsKey(key);
|
|
|
|
}
|
|
|
|
public override bool HasObjectRecurse(string key)
|
|
|
|
{
|
2023-07-30 07:55:10 +00:00
|
|
|
return HasObject(key) || pEnv.HasObjectRecurse(key);
|
2023-07-29 00:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override TLangEnvironment GetParentEnvironment()
|
|
|
|
{
|
|
|
|
return pEnv;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override RootEnvironment GetRootEnvironment()
|
|
|
|
{
|
|
|
|
return pEnv.GetRootEnvironment();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetObject(string key, TObject value)
|
|
|
|
{
|
|
|
|
if(pEnv.HasObjectRecurse(key))
|
|
|
|
{
|
|
|
|
pEnv.SetObject(key,value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
items[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override TLangEnvironment GetSubEnvironment()
|
|
|
|
{
|
|
|
|
return new SubEnvironment(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|