summaryrefslogtreecommitdiff
path: root/usr/austin/eval/value.go
diff options
context:
space:
mode:
authorAustin Clements <aclements@csail.mit.edu>2009-07-27 17:32:35 -0700
committerAustin Clements <aclements@csail.mit.edu>2009-07-27 17:32:35 -0700
commit9373126645c1900bcf5b48ef0baaac2f4c91e96a (patch)
treedb50a9cbb6d538f2949388fbec09b77ba5fb0e3f /usr/austin/eval/value.go
parent754ca000573feaaf13064f2813330378336cd3f7 (diff)
downloadgolang-9373126645c1900bcf5b48ef0baaac2f4c91e96a.tar.gz
Implement multi-valued functions, multi-valued return, and
unpacking for assignments, call arguments, and returns. This change revamps the whole assignment compilation system to be multi-valued, using the new MultiType type and multiV value. Function calls, returns, and assignments now share a lot of code and produce very consistent error messages. R=rsc APPROVED=rsc DELTA=510 (335 added, 74 deleted, 101 changed) OCL=32248 CL=32258
Diffstat (limited to 'usr/austin/eval/value.go')
-rw-r--r--usr/austin/eval/value.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/usr/austin/eval/value.go b/usr/austin/eval/value.go
index b050448a7..de5813e6d 100644
--- a/usr/austin/eval/value.go
+++ b/usr/austin/eval/value.go
@@ -537,6 +537,38 @@ func (t *FuncType) Zero() Value {
}
/*
+ * Multi-values
+ */
+
+type multiV []Value
+
+func (v multiV) String() string {
+ res := "(";
+ for i, v := range v {
+ if i > 0 {
+ res += ", ";
+ }
+ res += v.String();
+ }
+ return res + ")";
+}
+
+func (v multiV) Assign(o Value) {
+ omv := o.(multiV);
+ for i := range v {
+ v[i].Assign(omv[i]);
+ }
+}
+
+func (t *MultiType) Zero() Value {
+ res := make([]Value, len(t.Elems));
+ for i := 0; i < len(t.Elems); i++ {
+ res[i] = t.Elems[i].Zero();
+ }
+ return multiV(res);
+}
+
+/*
* Universal constants
*/