]> Cypherpunks.ru repositories - gostls13.git/commitdiff
1. decommit complex(float) conversion
authorKen Thompson <ken@golang.org>
Wed, 10 Mar 2010 01:51:30 +0000 (17:51 -0800)
committerKen Thompson <ken@golang.org>
Wed, 10 Mar 2010 01:51:30 +0000 (17:51 -0800)
2. add complex algorithm for map/chan
3. test for use of complex in
   array, slice, field, chan, map,
   field, pointer.

R=rsc
CC=golang-dev
https://golang.org/cl/384041

src/cmd/gc/const.c
src/cmd/gc/cplx.c
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
test/ken/cplx3.go
test/ken/cplx4.go
test/ken/cplx5.go [new file with mode: 0644]

index 7debb370839f3acc21e6d0307abe89454a45c462..be351def652d88ea945e63183cf69c6010826cc6 100644 (file)
@@ -76,14 +76,12 @@ convlit1(Node **np, Type *t, int explicit)
        if(!explicit && !isideal(n->type))
                return;
 
-//dump("convlit1", n);
        if(n->op == OLITERAL) {
                nn = nod(OXXX, N, N);
                *nn = *n;
                n = nn;
                *np = n;
        }
-//dump("convlit2", n);
 
        switch(n->op) {
        default:
@@ -203,6 +201,8 @@ convlit1(Node **np, Type *t, int explicit)
                                goto bad;
                        case CTFLT:
                        case CTINT:
+                               if(explicit)
+                                       goto bad;
                                n->val = tocplx(n->val);
                                break;
                        case CTCPLX:
index 7538a432a350b4b1c87c430c621d79170c268a3e..d7f29d837012ab0906aa1f3e6eaa9973065705db 100644 (file)
@@ -58,18 +58,6 @@ complexmove(Node *f, Node *t)
                cgen(&n1, &n3);
                cgen(&n2, &n4);
                break;
-
-       // these are depricated
-       case CASE(TFLOAT32,TCOMPLEX64):
-       case CASE(TFLOAT32,TCOMPLEX128):
-       case CASE(TFLOAT64,TCOMPLEX64):
-       case CASE(TFLOAT64,TCOMPLEX128):
-               // float to complex goes to real part
-
-               subnode(&n1, &n2, t);
-               cgen(f, &n1);
-               zero(&n2);
-               break;
        }
 }
 
index 97bb60d2e1cff76e3995c8aa351c29a54bf33589..0c01e728ce972475181b803ea1ed4ff1f0800224 100644 (file)
@@ -458,7 +458,8 @@ algtype(Type *t)
 {
        int a;
 
-       if(issimple[t->etype] || isptr[t->etype] || t->etype == TCHAN || t->etype == TFUNC || t->etype == TMAP)
+       if(issimple[t->etype] || isptr[t->etype] || iscomplex[t->etype] ||
+          t->etype == TCHAN || t->etype == TFUNC || t->etype == TMAP)
                a = AMEM;       // just bytes (int, ptr, etc)
        else if(t->etype == TSTRING)
                a = ASTRING;    // string
@@ -476,6 +477,7 @@ maptype(Type *key, Type *val)
 {
        Type *t;
 
+
        if(key != nil && key->etype != TANY && algtype(key) == ANOEQ) {
                if(key->etype == TFORW) {
                        // map[key] used during definition of key.
index 654e72b5f725a4628a83e3c867a7dc23c2b48501..4e5b5bbcd59beb1ced9d8236e27748018bcf2da0 100644 (file)
@@ -1449,9 +1449,14 @@ checkconv(Type *nt, Type *t, int explicit, int *op, int *et, char *desc)
                return 1;
        }
 
-       // simple fix-float-complex
-       if(isint[t->etype] || isfloat[t->etype] || iscomplex[t->etype])
-       if(isint[nt->etype] || isfloat[nt->etype] || iscomplex[nt->etype])
+       // simple fix-float
+       if(isint[t->etype] || isfloat[t->etype])
+       if(isint[nt->etype] || isfloat[nt->etype])
+               return 1;
+
+       // simple complex-complex
+       if(iscomplex[t->etype])
+       if(iscomplex[nt->etype])
                return 1;
 
        // to string
index 8d796464931467f559e1d96f162cf2465b2d3bba..6c3826df6a2332c7d8378ff088d0d44d5465ffa5 100644 (file)
@@ -20,7 +20,7 @@ var complexBits = reflect.Typeof(complex(0i)).Size() * 8
 
 func main() {
        c0 := C1
-       c0 = (c0+c0+c0) / (c0+c0+3i)
+       c0 = (c0 + c0 + c0) / (c0 + c0 + 3i)
        println(c0)
 
        c := *(*complex)(unsafe.Pointer(&c0))
@@ -32,11 +32,11 @@ func main() {
        switch c := reflect.NewValue(a).(type) {
        case *reflect.Complex64Value:
                v := c.Get()
-               _,_ = complex64(v), true
+               _, _ = complex64(v), true
        case *reflect.ComplexValue:
                if complexBits == 64 {
                        v := c.Get()
-                       _,_ = complex64(v), true
+                       _, _ = complex64(v), true
                }
        }
 }
index 34577a21e129023bfff500778b09f96eec8ba7af..c9ba2e9b934e689167cbbe18daae0d45e097bfca 100644 (file)
@@ -15,9 +15,7 @@ const (
        C1 = R + I // ADD(5,6)
 )
 
-func doprint(c complex) {
-       fmt.Printf("c = %f\n", c)
-}
+func doprint(c complex) { fmt.Printf("c = %f\n", c) }
 
 func main() {
 
diff --git a/test/ken/cplx5.go b/test/ken/cplx5.go
new file mode 100644 (file)
index 0000000..af2a1c5
--- /dev/null
@@ -0,0 +1,54 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var a [12]complex
+var s []complex
+var c chan complex
+var f struct {
+       c complex
+}
+var m map[complex]complex
+
+func main() {
+       // array of complex
+       for i := 0; i < len(a); i++ {
+               a[i] = cmplx(float(i), float(-i))
+       }
+       println(a[5])
+
+       // slice of complex
+       s = make([]complex, len(a))
+       for i := 0; i < len(s); i++ {
+               s[i] = a[i]
+       }
+       println(s[5])
+
+       // chan
+       c = make(chan complex)
+       go chantest(c)
+       println(<-c)
+
+       // pointer of complex
+       v := a[5]
+       pv := &v
+       println(*pv)
+
+       // field of complex
+       f.c = a[5]
+       println(f.c)
+
+       // map of complex
+       m = make(map[complex]complex)
+       for i := 0; i < len(s); i++ {
+               m[-a[i]] = a[i]
+       }
+       println(m[5i-5])
+       println(m[cmplx(-5, 5)])
+}
+
+func chantest(c chan complex) { c <- a[5] }