aboutsummaryrefslogtreecommitdiff
path: root/object/environment.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-20 16:27:42 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-20 16:27:42 +0200
commit69fc902f8f5fd8f36db0991f6ba4faeabb3090fa (patch)
tree36b77847cb8548047f3c8bc7a9d40ae017b86658 /object/environment.go
parentce78935009d931faf2db7e882929a7a4c95ce3e0 (diff)
03
Diffstat (limited to 'object/environment.go')
-rw-r--r--object/environment.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/object/environment.go b/object/environment.go
new file mode 100644
index 0000000..6f31070
--- /dev/null
+++ b/object/environment.go
@@ -0,0 +1,30 @@
+package object
+
+func NewEnclosedEnvironment(outer *Environment) *Environment {
+ env := NewEnvironment()
+ env.outer = outer
+ return env
+}
+
+func NewEnvironment() *Environment {
+ s := make(map[string]Object)
+ return &Environment{store: s, outer: nil}
+}
+
+type Environment struct {
+ store map[string]Object
+ outer *Environment
+}
+
+func (e *Environment) Get(name string) (Object, bool) {
+ obj, ok := e.store[name]
+ if !ok && e.outer != nil {
+ obj, ok = e.outer.Get(name)
+ }
+ return obj, ok
+}
+
+func (e *Environment) Set(name string, val Object) Object {
+ e.store[name] = val
+ return val
+}