]> Cypherpunks repositories - gostls13.git/commitdiff
gc: remove &[10]int -> []int conversion
authorRuss Cox <rsc@golang.org>
Fri, 10 Sep 2010 15:53:27 +0000 (11:53 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 10 Sep 2010 15:53:27 +0000 (11:53 -0400)
Fixes #829.

R=ken2
CC=golang-dev
https://golang.org/cl/2124044

src/cmd/gc/go.h
src/cmd/gc/print.c
src/cmd/gc/sinit.c
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c

index 12541029f5ada699427a272915cd015c4b2e90e6..cadaf0aafbda5430de18c2cccd94de7bd761661c 100644 (file)
@@ -262,7 +262,7 @@ struct      Node
        Sym*    sym;            // various
        int32   vargen;         // unique name for OTYPE/ONAME
        int32   lineno;
-       int32   endlineno;
+       int32   endlineno;
        vlong   xoffset;
        int32   ostk;
        int32   iota;
@@ -358,7 +358,7 @@ enum
        OCLOSURE,
        OCMPIFACE, OCMPSTR,
        OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
-       OCONV, OCONVIFACE, OCONVNOP, OCONVSLICE,
+       OCONV, OCONVIFACE, OCONVNOP,
        OCOPY,
        ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
        ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
index 7c65d5a7a19624037198bd00b56fb94be4e16289..bb6ebfe36b29dfee89df14e26af2a12a7032ec95 100644 (file)
@@ -55,7 +55,6 @@ exprfmt(Fmt *f, Node *n, int prec)
        case OCALL:
        case OCONV:
        case OCONVNOP:
-       case OCONVSLICE:
        case OMAKESLICE:
        case ORUNESTR:
        case OADDR:
@@ -319,9 +318,12 @@ exprfmt(Fmt *f, Node *n, int prec)
                break;
 
        case OSLICE:
+       case OSLICESTR:
+       case OSLICEARR:
                exprfmt(f, n->left, 7);
                fmtprint(f, "[");
-               exprfmt(f, n->right->left, 0);
+               if(n->right->left != N)
+                       exprfmt(f, n->right->left, 0);
                fmtprint(f, ":");
                if(n->right->right != N)
                        exprfmt(f, n->right->right, 0);
@@ -361,7 +363,6 @@ exprfmt(Fmt *f, Node *n, int prec)
        case OCONV:
        case OCONVIFACE:
        case OCONVNOP:
-       case OCONVSLICE:
        case OARRAYBYTESTR:
        case ORUNESTR:
                if(n->type == T || n->type->sym == S)
index e984e99c3ea0afe009708e1cda8633fc22275ec8..fa0f5dcdc5edb56e6ccfed7c15f76b2c7d55a85b 100644 (file)
@@ -401,7 +401,7 @@ slicelit(int ctxt, Node *n, Node *var, NodeList **init)
                arraylit(ctxt, 2, n, vstat, init);
 
                // copy static to slice
-               a = nod(OADDR, vstat, N);
+               a = nod(OSLICE, vstat, nod(OKEY, N, N));
                a = nod(OAS, var, a);
                typecheck(&a, Etop);
                a->dodata = 2;
@@ -459,7 +459,7 @@ slicelit(int ctxt, Node *n, Node *var, NodeList **init)
        }
 
        // make slice out of heap (5)
-       a = nod(OAS, var, vauto);
+       a = nod(OAS, var, nod(OSLICE, vauto, nod(OKEY, N, N)));
        typecheck(&a, Etop);
        walkexpr(&a, init);
        *init = list(*init, a);
@@ -864,8 +864,18 @@ gen_as_init(Node *n)
        default:
                goto no;
 
-       case OCONVSLICE:
-               goto slice;
+       case OCONVNOP:
+               nr = nr->left;
+               if(nr == N || nr->op != OSLICEARR)
+                       goto no;
+               // fall through
+       
+       case OSLICEARR:
+               if(nr->right->op == OKEY && nr->right->left == N && nr->right->right == N) {
+                       nr = nr->left;
+                       goto slice;
+               }
+               goto no;
 
        case OLITERAL:
                break;
@@ -914,7 +924,7 @@ yes:
 
 slice:
        gused(N); // in case the data is the dest of a goto
-       nr = n->right->left;
+       nl = nr;
        if(nr == N || nr->op != OADDR)
                goto no;
        nr = nr->left;
@@ -926,7 +936,7 @@ slice:
                goto no;
 
        nam.xoffset += Array_array;
-       gdata(&nam, n->right->left, types[tptr]->width);
+       gdata(&nam, nl, types[tptr]->width);
 
        nam.xoffset += Array_nel-Array_array;
        nodconst(&nod1, types[TINT32], nr->type->bound);
index a84f04e2afd19b43651cf8c1ea0167a36e4ec996..277c252013342823c52ca0af61ab05fbad92a13d 100644 (file)
@@ -1924,13 +1924,6 @@ assignop(Type *src, Type *dst, char **why)
        // 7. Any typed value can be assigned to the blank identifier.
        if(dst->etype == TBLANK)
                return OCONVNOP;
-       
-       // 8. Array to slice.
-       // TODO(rsc): Not for long.
-       if(!src->sym || !dst->sym)
-       if(isptr[src->etype] && isfixedarray(src->type) && isslice(dst))
-       if(eqtype(src->type->type, dst->type))
-               return OCONVSLICE;
 
        return 0;
 }
index dcf862a0feb6d6d1a0e331404b5dd7faeacc24a4..ea2cf49973089b72f370544a9999e583f8624754 100644 (file)
@@ -648,19 +648,16 @@ reswitch:
                defaultlit(&n->right->left, T);
                defaultlit(&n->right->right, T);
                if(isfixedarray(n->left->type)) {
-                       // Insert explicit & before fixed array
-                       // so that back end knows to move to heap.
                        n->left = nod(OADDR, n->left, N);
                        typecheck(&n->left, top);
                }
-               implicitstar(&n->left);
                if(n->right->left != N) {
                        if((t = n->right->left->type) == T)
                                goto error;
                        if(!isint[t->etype]) {
                                yyerror("invalid slice index %#N (type %T)", n->right->left, t);
                                goto error;
-               }
+                       }
                }
                if(n->right->right != N) {
                        if((t = n->right->right->type) == T)
@@ -678,9 +675,9 @@ reswitch:
                        n->op = OSLICESTR;
                        goto ret;
                }
-               if(isfixedarray(t)) {
+               if(isptr[t->etype] && isfixedarray(t->type)) {
                        n->type = typ(TARRAY);
-                       n->type->type = t->type;
+                       n->type->type = t->type->type;
                        n->type->bound = -1;
                        dowidth(n->type);
                        n->op = OSLICEARR;
@@ -1269,7 +1266,7 @@ implicitstar(Node **nn)
        Type *t;
        Node *n;
 
-       // insert implicit * if needed
+       // insert implicit * if needed for fixed array
        n = *nn;
        t = n->type;
        if(t == T || !isptr[t->etype])
index c22781c42642d655a38a43bb813748d046ea044e..e51b750b6c2e2ce78fa55aaeac495c2e80e45f2e 100644 (file)
@@ -1124,35 +1124,23 @@ walkexpr(Node **np, NodeList **init)
                // slicearray(old *any, uint64 nel, lb uint64, hb uint64, width uint64) (ary []any)
                t = n->type;
                fn = syslook("slicearray", 1);
-               argtype(fn, n->left->type);     // any-1
+               argtype(fn, n->left->type->type);       // any-1
                argtype(fn, t->type);                   // any-2
                if(n->right->left == N)
                        l = nodintconst(0);
                else
                        l = conv(n->right->left, types[TUINT64]);
                if(n->right->right == N)
-                       r = nodintconst(n->left->type->bound);
+                       r = nodintconst(n->left->type->type->bound);
                else
                        r = conv(n->right->right, types[TUINT64]);
                n = mkcall1(fn, t, init,
-                       nod(OADDR, n->left, N), nodintconst(n->left->type->bound),
+                       n->left, nodintconst(n->left->type->type->bound),
                        l,
                        r,
                        nodintconst(t->type->width));
                goto ret;
 
-       case OCONVSLICE:
-               // slicearray(old *any, uint64 nel, lb uint64, hb uint64, width uint64) (ary []any)
-               fn = syslook("slicearray", 1);
-               argtype(fn, n->left->type->type);               // any-1
-               argtype(fn, n->type->type);                     // any-2
-               n = mkcall1(fn, n->type, init, n->left,
-                       nodintconst(n->left->type->type->bound),
-                       nodintconst(0),
-                       nodintconst(n->left->type->type->bound),
-                       nodintconst(n->type->type->width));
-               goto ret;
-
        case OADDR:;
                Node *nvar, *nstar;
 
@@ -2140,12 +2128,17 @@ static void
 heapmoves(void)
 {
        NodeList *nn;
-
+       int32 lno;
+       
+       lno = lineno;
+       lineno = curfn->lineno;
        nn = paramstoheap(getthis(curfn->type), 0);
        nn = concat(nn, paramstoheap(getinarg(curfn->type), 0));
        nn = concat(nn, paramstoheap(getoutarg(curfn->type), 1));
        curfn->enter = concat(curfn->enter, nn);
+       lineno = curfn->endlineno;
        curfn->exit = returnsfromheap(getoutarg(curfn->type));
+       lineno = lno;
 }
 
 static Node*