using System; using System.Collections.Generic; namespace TLang.VM { public class SubEnvironment : TLangEnvironment { public SubEnvironment(TLangEnvironment env) { this.pEnv=env; } TLangEnvironment pEnv; Dictionary items = new Dictionary(); 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) { return HasObject(key) || pEnv.HasObjectRecurse(key); } 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); } } }