summaryrefslogtreecommitdiff
path: root/usr/austin/eval/value.go
diff options
context:
space:
mode:
authorAustin Clements <aclements@csail.mit.edu>2009-08-21 18:37:38 -0700
committerAustin Clements <aclements@csail.mit.edu>2009-08-21 18:37:38 -0700
commit68f8a487eb86116c49eb950dbef306726b1bfa57 (patch)
tree2ff39cae9065e47e3950b341c8526523b0a2e123 /usr/austin/eval/value.go
parent3e1d4a03c8ef47ae0138217098abe5a8d1d0c7ae (diff)
downloadgolang-68f8a487eb86116c49eb950dbef306726b1bfa57.tar.gz
Implement map types
R=rsc APPROVED=rsc DELTA=329 (301 added, 2 deleted, 26 changed) OCL=33696 CL=33706
Diffstat (limited to 'usr/austin/eval/value.go')
-rw-r--r--usr/austin/eval/value.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/usr/austin/eval/value.go b/usr/austin/eval/value.go
index 8950dd00a..3aa231997 100644
--- a/usr/austin/eval/value.go
+++ b/usr/austin/eval/value.go
@@ -505,6 +505,69 @@ func (v *sliceV) Set(x Slice) {
}
/*
+ * Maps
+ */
+
+type mapV struct {
+ target Map;
+}
+
+func (v *mapV) String() string {
+ res := "map[";
+ i := 0;
+ v.target.Iter(func(key interface{}, val Value) bool {
+ if i > 0 {
+ res += ", ";
+ }
+ i++;
+ res += fmt.Sprint(key) + ":" + val.String();
+ return true;
+ });
+ return res + "]";
+}
+
+func (v *mapV) Assign(o Value) {
+ v.target = o.(MapValue).Get();
+}
+
+func (v *mapV) Get() Map {
+ return v.target;
+}
+
+func (v *mapV) Set(x Map) {
+ v.target = x;
+}
+
+type evalMap map[interface{}] Value
+
+func (m evalMap) Len() int64 {
+ return int64(len(m));
+}
+
+func (m evalMap) Elem(key interface{}) Value {
+ if v, ok := m[key]; ok {
+ return v;
+ }
+ return nil;
+}
+
+func (m evalMap) SetElem(key interface{}, val Value) {
+ if val == nil {
+ m[key] = nil, false;
+ } else {
+ m[key] = val;
+ }
+}
+
+func (m evalMap) Iter(cb func(key interface{}, val Value) bool) {
+ for k, v := range m {
+ if !cb(k, v) {
+ break;
+ }
+ }
+}
+
+/*
* Multi-values
*/