Commit a91af04c authored by Russ Cox's avatar Russ Cox

6g cleanup suggested by ken.

remove TPTR wrapper around TMAP, TCHAN, TSTRING.

R=ken
OCL=22406
CL=22409
parent 484ba939
...@@ -219,6 +219,10 @@ belexinit(int lextype) ...@@ -219,6 +219,10 @@ belexinit(int lextype)
Sym *s; Sym *s;
Type *t; Type *t;
simtype[TMAP] = tptr;
simtype[TCHAN] = tptr;
simtype[TSTRING] = tptr;
zprog.link = P; zprog.link = P;
zprog.as = AGOK; zprog.as = AGOK;
zprog.from.type = D_NONE; zprog.from.type = D_NONE;
......
...@@ -218,7 +218,7 @@ cgen(Node *n, Node *res) ...@@ -218,7 +218,7 @@ cgen(Node *n, Node *res)
break; break;
case OLEN: case OLEN:
if(isptrto(nl->type, TSTRING)) { if(istype(nl->type, TSTRING)) {
regalloc(&n1, types[tptr], res); regalloc(&n1, types[tptr], res);
cgen(nl, &n1); cgen(nl, &n1);
...@@ -237,7 +237,7 @@ cgen(Node *n, Node *res) ...@@ -237,7 +237,7 @@ cgen(Node *n, Node *res)
regfree(&n1); regfree(&n1);
break; break;
} }
if(isptrto(nl->type, TMAP)) { if(istype(nl->type, TMAP)) {
regalloc(&n1, types[tptr], res); regalloc(&n1, types[tptr], res);
cgen(nl, &n1); cgen(nl, &n1);
n1.op = OINDREG; n1.op = OINDREG;
...@@ -964,7 +964,7 @@ sgen(Node *n, Node *ns, int32 w) ...@@ -964,7 +964,7 @@ sgen(Node *n, Node *ns, int32 w)
gconreg(AMOVQ, c, D_CX); gconreg(AMOVQ, c, D_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+ gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+
} else } else
while(c > 0) { while(c > 0) {
gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+ gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+
......
...@@ -1141,13 +1141,11 @@ cgen_as(Node *nl, Node *nr) ...@@ -1141,13 +1141,11 @@ cgen_as(Node *nl, Node *nr)
iszer = 1; iszer = 1;
nr = &nc; nr = &nc;
memset(nr, 0, sizeof(*nr)); memset(nr, 0, sizeof(*nr));
switch(tl->etype) { switch(simtype[tl->etype]) {
default: default:
fatal("cgen_as: tl %T", tl); fatal("cgen_as: tl %T", tl);
break; break;
case TINT:
case TUINT:
case TINT8: case TINT8:
case TUINT8: case TUINT8:
case TINT16: case TINT16:
...@@ -1156,13 +1154,11 @@ cgen_as(Node *nl, Node *nr) ...@@ -1156,13 +1154,11 @@ cgen_as(Node *nl, Node *nr)
case TUINT32: case TUINT32:
case TINT64: case TINT64:
case TUINT64: case TUINT64:
case TUINTPTR:
nr->val.u.xval = mal(sizeof(*nr->val.u.xval)); nr->val.u.xval = mal(sizeof(*nr->val.u.xval));
mpmovecfix(nr->val.u.xval, 0); mpmovecfix(nr->val.u.xval, 0);
nr->val.ctype = CTINT; nr->val.ctype = CTINT;
break; break;
case TFLOAT:
case TFLOAT32: case TFLOAT32:
case TFLOAT64: case TFLOAT64:
case TFLOAT80: case TFLOAT80:
...@@ -1195,7 +1191,7 @@ cgen_as(Node *nl, Node *nr) ...@@ -1195,7 +1191,7 @@ cgen_as(Node *nl, Node *nr)
cgen(nr, nl); cgen(nr, nl);
if(iszer && nl->addable) if(iszer && nl->addable)
gins(ANOP, nl, N); // used gins(ANOP, nl, N); // used
ret: ret:
; ;
......
...@@ -998,7 +998,7 @@ naddr(Node *n, Addr *a) ...@@ -998,7 +998,7 @@ naddr(Node *n, Addr *a)
case ONAME: case ONAME:
a->etype = 0; a->etype = 0;
if(n->type != T) if(n->type != T)
a->etype = n->type->etype; a->etype = simtype[n->type->etype];
a->offset = n->xoffset; a->offset = n->xoffset;
a->sym = n->sym; a->sym = n->sym;
if(a->sym == S) if(a->sym == S)
...@@ -1045,7 +1045,7 @@ naddr(Node *n, Addr *a) ...@@ -1045,7 +1045,7 @@ naddr(Node *n, Addr *a)
a->offset = mpgetfix(n->val.u.xval); a->offset = mpgetfix(n->val.u.xval);
break; break;
case CTSTR: case CTSTR:
a->etype = n->etype; a->etype = simtype[n->etype];
a->sym = symstringo; a->sym = symstringo;
a->type = D_ADDR; a->type = D_ADDR;
a->index = D_STATIC; a->index = D_STATIC;
......
...@@ -61,8 +61,6 @@ convlit1(Node *n, Type *t, int conv) ...@@ -61,8 +61,6 @@ convlit1(Node *n, Type *t, int conv)
goto bad1; goto bad1;
case Wlitnil: case Wlitnil:
if(isptrto(t, TSTRING))
goto bad1;
switch(et) { switch(et) {
default: default:
goto bad1; goto bad1;
...@@ -71,6 +69,8 @@ convlit1(Node *n, Type *t, int conv) ...@@ -71,6 +69,8 @@ convlit1(Node *n, Type *t, int conv)
case TPTR64: case TPTR64:
case TINTER: case TINTER:
case TARRAY: case TARRAY:
case TMAP:
case TCHAN:
break; break;
} }
break; break;
...@@ -80,7 +80,7 @@ convlit1(Node *n, Type *t, int conv) ...@@ -80,7 +80,7 @@ convlit1(Node *n, Type *t, int conv)
defaultlit(n); defaultlit(n);
return; return;
} }
if(isptrto(t, TSTRING)) if(et == TSTRING)
break; break;
goto bad1; goto bad1;
...@@ -127,7 +127,7 @@ convlit1(Node *n, Type *t, int conv) ...@@ -127,7 +127,7 @@ convlit1(Node *n, Type *t, int conv)
goto bad1; goto bad1;
// only done as string(CONST) // only done as string(CONST)
if(isptrto(t, TSTRING)) { if(et == TSTRING) {
Rune rune; Rune rune;
int l; int l;
String *s; String *s;
...@@ -180,7 +180,7 @@ convlit1(Node *n, Type *t, int conv) ...@@ -180,7 +180,7 @@ convlit1(Node *n, Type *t, int conv)
goto bad1; goto bad1;
} }
n->type = t; n->type = t;
return; return;
bad1: bad1:
......
...@@ -495,14 +495,6 @@ loop: ...@@ -495,14 +495,6 @@ loop:
if(n->op != ODCLFIELD || n->type == T) if(n->op != ODCLFIELD || n->type == T)
fatal("stotype: oops %N\n", n); fatal("stotype: oops %N\n", n);
switch(n->type->etype) {
case TCHAN:
case TMAP:
case TSTRING:
yyerror("%T can exist only in pointer form", n->type);
break;
}
switch(n->val.ctype) { switch(n->val.ctype) {
case CTSTR: case CTSTR:
note = n->val.u.sval; note = n->val.u.sval;
...@@ -749,15 +741,6 @@ addvar(Node *n, Type *t, int ctxt) ...@@ -749,15 +741,6 @@ addvar(Node *n, Type *t, int ctxt)
pushdcl(s); pushdcl(s);
} }
if(t != T) {
switch(t->etype) {
case TCHAN:
case TMAP:
case TSTRING:
yyerror("%T can exist only in pointer form", t);
}
}
redeclare("variable", s); redeclare("variable", s);
s->vargen = gen; s->vargen = gen;
s->oname = n; s->oname = n;
......
...@@ -59,7 +59,7 @@ dumpprereq(Type *t) ...@@ -59,7 +59,7 @@ dumpprereq(Type *t)
if(t == T) if(t == T)
return; return;
if(t->printed || t == types[t->etype] || t == types[TSTRING]) if(t->printed || t == types[t->etype])
return; return;
t->printed = 1; t->printed = 1;
......
...@@ -626,6 +626,7 @@ void dump(char*, Node*); ...@@ -626,6 +626,7 @@ void dump(char*, Node*);
Type* aindex(Node*, Type*); Type* aindex(Node*, Type*);
int isnil(Node*); int isnil(Node*);
int isptrto(Type*, int); int isptrto(Type*, int);
int istype(Type*, int);
int isptrsarray(Type*); int isptrsarray(Type*);
int isptrdarray(Type*); int isptrdarray(Type*);
int issarray(Type*); int issarray(Type*);
......
...@@ -1031,7 +1031,6 @@ convtype: ...@@ -1031,7 +1031,6 @@ convtype:
$$ = typ(TMAP); $$ = typ(TMAP);
$$->down = $3; $$->down = $3;
$$->type = $5; $$->type = $5;
$$ = ptrto($$);
} }
| structtype | structtype
...@@ -1116,21 +1115,18 @@ Aothertype: ...@@ -1116,21 +1115,18 @@ Aothertype:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Crecv; $$->chan = Crecv;
$$ = ptrto($$);
} }
| LCHAN LCOMM Anon_chan_type | LCHAN LCOMM Anon_chan_type
{ {
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Csend; $$->chan = Csend;
$$ = ptrto($$);
} }
| LMAP '[' type ']' Atype | LMAP '[' type ']' Atype
{ {
$$ = typ(TMAP); $$ = typ(TMAP);
$$->down = $3; $$->down = $3;
$$->type = $5; $$->type = $5;
$$ = ptrto($$);
} }
| '*' Atype | '*' Atype
{ {
...@@ -1153,21 +1149,18 @@ Bothertype: ...@@ -1153,21 +1149,18 @@ Bothertype:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Crecv; $$->chan = Crecv;
$$ = ptrto($$);
} }
| LCHAN LCOMM Bnon_chan_type | LCHAN LCOMM Bnon_chan_type
{ {
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Csend; $$->chan = Csend;
$$ = ptrto($$);
} }
| LMAP '[' type ']' Btype | LMAP '[' type ']' Btype
{ {
$$ = typ(TMAP); $$ = typ(TMAP);
$$->down = $3; $$->down = $3;
$$->type = $5; $$->type = $5;
$$ = ptrto($$);
} }
| '*' Btype | '*' Btype
{ {
...@@ -1184,7 +1177,6 @@ Achantype: ...@@ -1184,7 +1177,6 @@ Achantype:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $2; $$->type = $2;
$$->chan = Cboth; $$->chan = Cboth;
$$ = ptrto($$);
} }
Bchantype: Bchantype:
...@@ -1193,7 +1185,6 @@ Bchantype: ...@@ -1193,7 +1185,6 @@ Bchantype:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $2; $$->type = $2;
$$->chan = Cboth; $$->chan = Cboth;
$$ = ptrto($$);
} }
structtype: structtype:
...@@ -1865,7 +1856,6 @@ hidden_type1: ...@@ -1865,7 +1856,6 @@ hidden_type1:
$$ = typ(TMAP); $$ = typ(TMAP);
$$->down = $3; $$->down = $3;
$$->type = $5; $$->type = $5;
$$ = ptrto($$);
} }
| LSTRUCT '{' ohidden_structdcl_list '}' | LSTRUCT '{' ohidden_structdcl_list '}'
{ {
...@@ -1886,14 +1876,12 @@ hidden_type1: ...@@ -1886,14 +1876,12 @@ hidden_type1:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Crecv; $$->chan = Crecv;
$$ = ptrto($$);
} }
| LCHAN LCOMM hidden_type1 | LCHAN LCOMM hidden_type1
{ {
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = Csend; $$->chan = Csend;
$$ = ptrto($$);
} }
| LDDD | LDDD
{ {
...@@ -1906,7 +1894,6 @@ hidden_type2: ...@@ -1906,7 +1894,6 @@ hidden_type2:
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $2; $$->type = $2;
$$->chan = Cboth; $$->chan = Cboth;
$$ = ptrto($$);
} }
| '(' ohidden_funarg_list ')' ohidden_funres | '(' ohidden_funarg_list ')' ohidden_funres
{ {
......
...@@ -1150,6 +1150,8 @@ lexinit(void) ...@@ -1150,6 +1150,8 @@ lexinit(void)
case TPTR32: case TPTR32:
case TPTR64: case TPTR64:
case TINTER: case TINTER:
case TMAP:
case TCHAN:
okforeq[i] = 1; okforeq[i] = 1;
break; break;
} }
...@@ -1196,8 +1198,6 @@ lexinit(void) ...@@ -1196,8 +1198,6 @@ lexinit(void)
continue; continue;
} }
t = typ(etype); t = typ(etype);
if(etype == TSTRING)
t = ptrto(t);
t->sym = s; t->sym = s;
dowidth(t); dowidth(t);
......
...@@ -295,10 +295,10 @@ algtype(Type *t) ...@@ -295,10 +295,10 @@ algtype(Type *t)
if(issimple[t->etype]) if(issimple[t->etype])
a = ASIMP; // simple mem a = ASIMP; // simple mem
else else
if(isptrto(t, TSTRING)) if(t->etype == TSTRING)
a = ASTRING; // string a = ASTRING; // string
else else
if(isptr[t->etype]) if(isptr[simtype[t->etype]])
a = APTR; // pointer a = APTR; // pointer
else else
if(t->etype == TARRAY && t->bound < 0) if(t->etype == TARRAY && t->bound < 0)
...@@ -608,12 +608,8 @@ whatis(Node *n) ...@@ -608,12 +608,8 @@ whatis(Node *n)
return Wtfloat; return Wtfloat;
case TBOOL: case TBOOL:
return Wtbool; return Wtbool;
case TSTRING:
case TPTR32: return Wtstr;
case TPTR64:
if(isptrto(t, TSTRING))
return Wtstr;
break;
} }
return Wtunkn; return Wtunkn;
} }
...@@ -976,6 +972,7 @@ basicnames[] = ...@@ -976,6 +972,7 @@ basicnames[] =
[TBOOL] = "bool", [TBOOL] = "bool",
[TANY] = "any", [TANY] = "any",
[TDDD] = "...", [TDDD] = "...",
[TSTRING] = "string",
}; };
int int
...@@ -988,7 +985,7 @@ Tpretty(Fmt *fp, Type *t) ...@@ -988,7 +985,7 @@ Tpretty(Fmt *fp, Type *t)
&& t->sym != S && t->sym != S
&& !(fp->flags&FmtLong)) { && !(fp->flags&FmtLong)) {
s = t->sym; s = t->sym;
if(t == types[t->etype] || t == types[TSTRING]) if(t == types[t->etype])
return fmtprint(fp, "%s", s->name); return fmtprint(fp, "%s", s->name);
if(exporting) { if(exporting) {
if(fp->flags & FmtShort) if(fp->flags & FmtShort)
...@@ -1012,28 +1009,21 @@ Tpretty(Fmt *fp, Type *t) ...@@ -1012,28 +1009,21 @@ Tpretty(Fmt *fp, Type *t)
switch(t->etype) { switch(t->etype) {
case TPTR32: case TPTR32:
case TPTR64: case TPTR64:
t1 = t->type;
if(t1 != T) {
switch(t1->etype) {
case TSTRING:
return fmtprint(fp, "string");
case TMAP:
return fmtprint(fp, "map[%T] %T", t1->down, t1->type);
case TCHAN:
return fmtprint(fp, "chan %T", t1->type);
}
}
if(fp->flags&FmtShort) // pass flag thru for methodsym if(fp->flags&FmtShort) // pass flag thru for methodsym
return fmtprint(fp, "*%hT", t1); return fmtprint(fp, "*%hT", t->type);
return fmtprint(fp, "*%T", t1); return fmtprint(fp, "*%T", t->type);
// Should not see these: should see ptr instead, handled above.
case TSTRING:
return fmtprint(fp, "STRING", t->type);
case TCHAN: case TCHAN:
return fmtprint(fp, "CHAN %T", t->type); switch(t->chan) {
case Crecv:
return fmtprint(fp, "<-chan %T", t->type);
case Csend:
return fmtprint(fp, "chan<- %T", t->type);
}
return fmtprint(fp, "chan %T", t->type);
case TMAP: case TMAP:
return fmtprint(fp, "MAP[%T] %T", t->down, t->type); return fmtprint(fp, "map[%T] %T", t->down, t->type);
case TFUNC: case TFUNC:
// t->type is method struct // t->type is method struct
...@@ -1124,8 +1114,6 @@ Tpretty(Fmt *fp, Type *t) ...@@ -1124,8 +1114,6 @@ Tpretty(Fmt *fp, Type *t)
return -1; return -1;
} }
int int
Tconv(Fmt *fp) Tconv(Fmt *fp)
{ {
...@@ -1158,7 +1146,7 @@ Tconv(Fmt *fp) ...@@ -1158,7 +1146,7 @@ Tconv(Fmt *fp)
} }
et = t->etype; et = t->etype;
snprint(buf, sizeof buf, "%E.", et); snprint(buf, sizeof buf, "%E ", et);
if(t->sym != S) { if(t->sym != S) {
snprint(buf1, sizeof(buf1), "<%S>", t->sym); snprint(buf1, sizeof(buf1), "<%S>", t->sym);
strncat(buf, buf1, sizeof(buf)); strncat(buf, buf1, sizeof(buf));
...@@ -1190,7 +1178,7 @@ Tconv(Fmt *fp) ...@@ -1190,7 +1178,7 @@ Tconv(Fmt *fp)
break; break;
case TINTER: case TINTER:
strncat(buf, "I{", sizeof(buf)); strncat(buf, "{", sizeof(buf));
if(fp->flags & FmtLong) { if(fp->flags & FmtLong) {
for(t1=t->type; t1!=T; t1=t1->down) { for(t1=t->type; t1!=T; t1=t1->down) {
snprint(buf1, sizeof(buf1), "%lT;", t1); snprint(buf1, sizeof(buf1), "%lT;", t1);
...@@ -1212,7 +1200,7 @@ Tconv(Fmt *fp) ...@@ -1212,7 +1200,7 @@ Tconv(Fmt *fp)
break; break;
case TMAP: case TMAP:
snprint(buf, sizeof(buf), "MAP[%T]%T", t->down, t->type); snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type);
break; break;
case TARRAY: case TARRAY:
...@@ -1225,7 +1213,7 @@ Tconv(Fmt *fp) ...@@ -1225,7 +1213,7 @@ Tconv(Fmt *fp)
case TPTR32: case TPTR32:
case TPTR64: case TPTR64:
snprint(buf1, sizeof(buf1), "*%T", t->type); snprint(buf1, sizeof(buf1), "%T", t->type);
strncat(buf, buf1, sizeof(buf)); strncat(buf, buf1, sizeof(buf));
break; break;
} }
...@@ -1441,6 +1429,12 @@ isptrto(Type *t, int et) ...@@ -1441,6 +1429,12 @@ isptrto(Type *t, int et)
return 1; return 1;
} }
int
istype(Type *t, int et)
{
return t != T && t->etype == et;
}
int int
isptrsarray(Type *t) isptrsarray(Type *t)
{ {
...@@ -1627,10 +1621,9 @@ iscomposite(Type *t) ...@@ -1627,10 +1621,9 @@ iscomposite(Type *t)
switch(t->etype) { switch(t->etype) {
case TARRAY: case TARRAY:
case TSTRUCT: case TSTRUCT:
case TMAP:
return 1; return 1;
} }
if(isptr[t->etype] && t->type != T && t->type->etype == TMAP)
return 1;
return 0; return 0;
} }
......
...@@ -441,7 +441,7 @@ loop: ...@@ -441,7 +441,7 @@ loop:
if(cl == 2 && cr == 1) { if(cl == 2 && cr == 1) {
// a,b = map[] - mapaccess2 // a,b = map[] - mapaccess2
walktype(r->left, Erv); walktype(r->left, Erv);
if(!isptrto(r->left->type, TMAP)) if(!istype(r->left->type, TMAP))
break; break;
l = mapop(n, top); l = mapop(n, top);
if(l == N) if(l == N)
...@@ -455,7 +455,7 @@ loop: ...@@ -455,7 +455,7 @@ loop:
if(cl == 2 && cr == 1) { if(cl == 2 && cr == 1) {
// a,b = <chan - chanrecv2 // a,b = <chan - chanrecv2
walktype(r->left, Erv); walktype(r->left, Erv);
if(!isptrto(r->left->type, TCHAN)) if(!istype(r->left->type, TCHAN))
break; break;
l = chanop(n, top); l = chanop(n, top);
if(l == N) if(l == N)
...@@ -499,7 +499,7 @@ loop: ...@@ -499,7 +499,7 @@ loop:
case OINDEXPTR: case OINDEXPTR:
if(cl == 1 && cr == 2) { if(cl == 1 && cr == 2) {
// map[] = a,b - mapassign2 // map[] = a,b - mapassign2
if(!isptrto(l->left->type, TMAP)) if(!istype(l->left->type, TMAP))
break; break;
l = mapop(n, top); l = mapop(n, top);
if(l == N) if(l == N)
...@@ -580,7 +580,7 @@ loop: ...@@ -580,7 +580,7 @@ loop:
// to string // to string
if(l->type != T) if(l->type != T)
if(isptrto(t, TSTRING)) { if(istype(t, TSTRING)) {
if(isint[l->type->etype]) { if(isint[l->type->etype]) {
indir(n, stringop(n, top)); indir(n, stringop(n, top));
goto ret; goto ret;
...@@ -659,7 +659,7 @@ loop: ...@@ -659,7 +659,7 @@ loop:
} }
// map literal // map literal
if(isptr[t->etype] && t->type != t && t->type->etype == TMAP) { if(t->etype == TMAP) {
r = maplit(n); r = maplit(n);
indir(n, r); indir(n, r);
goto ret; goto ret;
...@@ -700,7 +700,7 @@ loop: ...@@ -700,7 +700,7 @@ loop:
goto shft; goto shft;
goto com; goto com;
} }
if(!isptrto(l->left->type, TMAP)) if(!istype(l->left->type, TMAP))
goto com; goto com;
indir(n, mapop(n, top)); indir(n, mapop(n, top));
goto ret; goto ret;
...@@ -771,7 +771,7 @@ loop: ...@@ -771,7 +771,7 @@ loop:
case OGT: case OGT:
case OADD: case OADD:
case OASOP: case OASOP:
if(isptrto(n->left->type, TSTRING)) { if(istype(n->left->type, TSTRING)) {
indir(n, stringop(n, top)); indir(n, stringop(n, top));
goto ret; goto ret;
} }
...@@ -854,8 +854,7 @@ loop: ...@@ -854,8 +854,7 @@ loop:
// BOTCH - convert each index opcode // BOTCH - convert each index opcode
// to look like this and get rid of OINDEXPTR // to look like this and get rid of OINDEXPTR
if(isptr[t->etype]) if(istype(t, TSTRING) || isptrto(t, TSTRING)) {
if(isptrto(t, TSTRING) || isptrto(t->type, TSTRING)) {
// right side must be an int // right side must be an int
if(top != Erv) if(top != Erv)
goto nottop; goto nottop;
...@@ -889,8 +888,6 @@ loop: ...@@ -889,8 +888,6 @@ loop:
} }
if(!eqtype(n->right->type, t->down, 0)) if(!eqtype(n->right->type, t->down, 0))
goto badt; goto badt;
if(n->op != OINDEXPTR)
goto badt;
n->op = OINDEX; n->op = OINDEX;
n->type = t->type; n->type = t->type;
if(top == Erv) if(top == Erv)
...@@ -945,7 +942,7 @@ loop: ...@@ -945,7 +942,7 @@ loop:
t = n->left->type; t = n->left->type;
if(t == T) if(t == T)
goto ret; goto ret;
if(isptr[t->etype]) if(isptr[t->etype]) //XXX?
t = t->type; t = t->type;
if(t->etype == TSTRING) { if(t->etype == TSTRING) {
indir(n, stringop(n, top)); indir(n, stringop(n, top));
...@@ -1088,9 +1085,8 @@ loop: ...@@ -1088,9 +1085,8 @@ loop:
if(n->left->type == T) if(n->left->type == T)
goto ret; goto ret;
et = n->left->type->etype; et = n->left->type->etype;
if(!okforadd[et]) if(!okforadd[et] && et != TSTRING)
if(!isptrto(n->left->type, TSTRING)) goto badt;
goto badt;
t = types[TBOOL]; t = types[TBOOL];
break; break;
...@@ -1422,10 +1418,6 @@ selectas(Node *name, Node *expr) ...@@ -1422,10 +1418,6 @@ selectas(Node *name, Node *expr)
if(expr == N || expr->op != ORECV) if(expr == N || expr->op != ORECV)
goto bad; goto bad;
t = expr->left->type; t = expr->left->type;
if(t == T)
goto bad;
if(isptr[t->etype])
t = t->type;
if(t == T) if(t == T)
goto bad; goto bad;
if(t->etype != TCHAN) if(t->etype != TCHAN)
...@@ -2042,55 +2034,29 @@ nodpanic(int32 lineno) ...@@ -2042,55 +2034,29 @@ nodpanic(int32 lineno)
Node* Node*
makecompat(Node *n) makecompat(Node *n)
{ {
Node *r, *on; Type *t;
Type *t, *t0;
t0 = n->type;
if(t0 == T)
goto bad;
if(t0->etype == TARRAY)
return arrayop(n, Erv);
if(!isptr[t0->etype])
goto bad;
t = t0->type; t = n->type;
if(t == T)
goto bad;
if(t != T)
switch(t->etype) { switch(t->etype) {
case TSTRING: case TARRAY:
goto bad; return arrayop(n, Erv);
// the call looks like new(MAP[int]int)
// but internally we see new(*MAP[int]int)
case TMAP: case TMAP:
r = mapop(n, Erv); return mapop(n, Erv);
break;
// the call looks like new(CHAN int)
// but internally we see new(*CHAN int)
case TCHAN: case TCHAN:
r = chanop(n, Erv); return chanop(n, Erv);
break;
default:
if(n->left != N)
yyerror("cannot make(%T, expr)", t0);
dowidth(t);
on = syslook("mal", 1);
argtype(on, t);
r = nodintconst(t->width);
r = nod(OCALL, on, r);
walktype(r, Erv);
break;
} }
return r; /*
* ken had code to malloc here,
* but rsc cut it out so that make(int)
* is diagnosed as an error (probably meant new).
* might come back once we know the
* language semantics for make(int).
*/
bad: yyerror("cannot make(%T)", t);
yyerror("cannot make(%T)", t0);
return n; return n;
} }
...@@ -2101,17 +2067,7 @@ newcompat(Node *n) ...@@ -2101,17 +2067,7 @@ newcompat(Node *n)
Type *t; Type *t;
t = n->type; t = n->type;
if(t == T) if(t != T && t->etype != TFUNC) {
goto bad;
switch(t->etype) {
case TFUNC:
case TSTRING:
case TMAP:
case TCHAN:
goto bad;
default:
if(n->left != N) if(n->left != N)
yyerror("cannot new(%T, expr)", t); yyerror("cannot new(%T, expr)", t);
dowidth(t); dowidth(t);
...@@ -2120,12 +2076,9 @@ newcompat(Node *n) ...@@ -2120,12 +2076,9 @@ newcompat(Node *n)
r = nodintconst(t->width); r = nodintconst(t->width);
r = nod(OCALL, on, r); r = nod(OCALL, on, r);
walktype(r, Erv); walktype(r, Erv);
break; return r;
} }
return r;
bad:
yyerror("cannot new(%T)", t); yyerror("cannot new(%T)", t);
return n; return n;
} }
...@@ -2195,7 +2148,7 @@ stringop(Node *n, int top) ...@@ -2195,7 +2148,7 @@ stringop(Node *n, int top)
case OINDEX: case OINDEX:
// sys_indexstring(s, i) // sys_indexstring(s, i)
c = n->left; c = n->left;
if(isptrto(c->type->type, TSTRING)) { if(istype(c->type->type, TSTRING)) {
// lhs is string or *string // lhs is string or *string
c = nod(OIND, c, N); c = nod(OIND, c, N);
c->type = c->left->type->type; c->type = c->left->type->type;
...@@ -2228,11 +2181,8 @@ stringop(Node *n, int top) ...@@ -2228,11 +2181,8 @@ stringop(Node *n, int top)
} }
Type* Type*
fixmap(Type *tm) fixmap(Type *t)
{ {
Type *t;
t = tm->type;
if(t == T) if(t == T)
goto bad; goto bad;
if(t->etype != TMAP) if(t->etype != TMAP)
...@@ -2246,18 +2196,13 @@ fixmap(Type *tm) ...@@ -2246,18 +2196,13 @@ fixmap(Type *tm)
return t; return t;
bad: bad:
yyerror("not a map: %lT", tm); yyerror("not a map: %lT", t);
return T; return T;
} }
Type* Type*
fixchan(Type *tm) fixchan(Type *t)
{ {
Type *t;
if(tm == T)
goto bad;
t = tm->type;
if(t == T) if(t == T)
goto bad; goto bad;
if(t->etype != TCHAN) if(t->etype != TCHAN)
...@@ -2270,7 +2215,7 @@ fixchan(Type *tm) ...@@ -2270,7 +2215,7 @@ fixchan(Type *tm)
return t; return t;
bad: bad:
yyerror("not a channel: %lT", tm); yyerror("not a channel: %lT", t);
return T; return T;
} }
...@@ -2282,8 +2227,6 @@ mapop(Node *n, int top) ...@@ -2282,8 +2227,6 @@ mapop(Node *n, int top)
Node *on; Node *on;
int cl, cr; int cl, cr;
//dump("mapop", n);
r = n; r = n;
switch(n->op) { switch(n->op) {
default: default:
...@@ -2460,7 +2403,7 @@ mapop(Node *n, int top) ...@@ -2460,7 +2403,7 @@ mapop(Node *n, int top)
// rewrite map[index] op= right // rewrite map[index] op= right
// into tmpi := index; map[tmpi] = map[tmpi] op right // into tmpi := index; map[tmpi] = map[tmpi] op right
t = n->left->left->type->type; t = n->left->left->type;
a = nod(OXXX, N, N); a = nod(OXXX, N, N);
tempname(a, t->down); // tmpi tempname(a, t->down); // tmpi
r = nod(OAS, a, n->left->right); // tmpi := index r = nod(OAS, a, n->left->right); // tmpi := index
...@@ -2968,7 +2911,7 @@ convas(Node *n) ...@@ -2968,7 +2911,7 @@ convas(Node *n)
goto out; goto out;
if(n->left->op == OINDEX) if(n->left->op == OINDEX)
if(isptrto(n->left->left->type, TMAP)) { if(istype(n->left->left->type, TMAP)) {
indir(n, mapop(n, Elv)); indir(n, mapop(n, Elv));
goto out; goto out;
} }
...@@ -3134,9 +3077,9 @@ multi: ...@@ -3134,9 +3077,9 @@ multi:
goto badt; goto badt;
walktype(nr->left, Erv); walktype(nr->left, Erv);
t = nr->left->type; t = nr->left->type;
if(!isptrto(t, TCHAN)) if(!istype(t, TCHAN))
goto badt; goto badt;
a = old2new(nl->left, t->type->type); a = old2new(nl->left, t->type);
n = a; n = a;
a = old2new(nl->right, types[TBOOL]); a = old2new(nl->right, types[TBOOL]);
n = list(n, a); n = list(n, a);
...@@ -3575,6 +3518,7 @@ arraylit(Node *n) ...@@ -3575,6 +3518,7 @@ arraylit(Node *n)
var = nod(OXXX, N, N); var = nod(OXXX, N, N);
tempname(var, t); tempname(var, t);
nnew = nil;
if(b < 0) { if(b < 0) {
// slice // slice
nnew = nod(OMAKE, N, N); nnew = nod(OMAKE, N, N);
...@@ -3617,7 +3561,7 @@ maplit(Node *n) ...@@ -3617,7 +3561,7 @@ maplit(Node *n)
Node *var, *r, *a; Node *var, *r, *a;
t = n->type; t = n->type;
if(!isptr[t->etype] || t->type == T || t->type->etype != TMAP) if(t->etype != TMAP)
fatal("maplit: not map"); fatal("maplit: not map");
var = nod(OXXX, N, N); var = nod(OXXX, N, N);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment