/
BindingEnvironment.cs
85 lines (69 loc) · 1.99 KB
/
BindingEnvironment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
namespace PythonSharp
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PythonSharp.Language;
public class BindingEnvironment : IContext
{
private IContext parent;
private Dictionary<string, object> values = new Dictionary<string, object>();
private object returnValue;
private bool hasReturnValue;
public BindingEnvironment()
{
}
public BindingEnvironment(IContext parent)
{
this.parent = parent;
}
public IContext Parent { get { return this.parent; } }
public IContext GlobalContext
{
get
{
if (this.parent == null)
return this;
return this.parent.GlobalContext;
}
}
public bool WasContinue { get; set; }
public bool WasBreak { get; set; }
public bool HasReturnValue()
{
return this.hasReturnValue;
}
public object GetReturnValue()
{
return this.returnValue;
}
public void SetReturnValue(object value)
{
this.returnValue = value;
this.hasReturnValue = true;
}
public object GetValue(string name)
{
if (!this.values.ContainsKey(name))
{
if (this.parent != null)
return this.parent.GetValue(name);
return null;
}
return this.values[name];
}
public void SetValue(string name, object value)
{
this.values[name] = value;
}
public bool HasValue(string name)
{
return this.values.ContainsKey(name);
}
public ICollection<string> GetNames()
{
return this.values.Keys.ToList();
}
}
}