remove TPTR wrapper around TMAP, TCHAN, TSTRING.
R=ken
OCL=22406
CL=22409
Sym *s;
Type *t;
+ simtype[TMAP] = tptr;
+ simtype[TCHAN] = tptr;
+ simtype[TSTRING] = tptr;
+
zprog.link = P;
zprog.as = AGOK;
zprog.from.type = D_NONE;
break;
case OLEN:
- if(isptrto(nl->type, TSTRING)) {
+ if(istype(nl->type, TSTRING)) {
regalloc(&n1, types[tptr], res);
cgen(nl, &n1);
regfree(&n1);
break;
}
- if(isptrto(nl->type, TMAP)) {
+ if(istype(nl->type, TMAP)) {
regalloc(&n1, types[tptr], res);
cgen(nl, &n1);
n1.op = OINDREG;
gconreg(AMOVQ, c, D_CX);
gins(AREP, N, N); // repeat
gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+
-
+
} else
while(c > 0) {
gins(AMOVSB, N, N); // MOVB *(SI)+,*(DI)+
iszer = 1;
nr = &nc;
memset(nr, 0, sizeof(*nr));
- switch(tl->etype) {
+ switch(simtype[tl->etype]) {
default:
fatal("cgen_as: tl %T", tl);
break;
- case TINT:
- case TUINT:
case TINT8:
case TUINT8:
case TINT16:
case TUINT32:
case TINT64:
case TUINT64:
- case TUINTPTR:
nr->val.u.xval = mal(sizeof(*nr->val.u.xval));
mpmovecfix(nr->val.u.xval, 0);
nr->val.ctype = CTINT;
break;
- case TFLOAT:
case TFLOAT32:
case TFLOAT64:
case TFLOAT80:
cgen(nr, nl);
if(iszer && nl->addable)
gins(ANOP, nl, N); // used
-
+
ret:
;
case ONAME:
a->etype = 0;
if(n->type != T)
- a->etype = n->type->etype;
+ a->etype = simtype[n->type->etype];
a->offset = n->xoffset;
a->sym = n->sym;
if(a->sym == S)
a->offset = mpgetfix(n->val.u.xval);
break;
case CTSTR:
- a->etype = n->etype;
+ a->etype = simtype[n->etype];
a->sym = symstringo;
a->type = D_ADDR;
a->index = D_STATIC;
goto bad1;
case Wlitnil:
- if(isptrto(t, TSTRING))
- goto bad1;
switch(et) {
default:
goto bad1;
case TPTR64:
case TINTER:
case TARRAY:
+ case TMAP:
+ case TCHAN:
break;
}
break;
defaultlit(n);
return;
}
- if(isptrto(t, TSTRING))
+ if(et == TSTRING)
break;
goto bad1;
goto bad1;
// only done as string(CONST)
- if(isptrto(t, TSTRING)) {
+ if(et == TSTRING) {
Rune rune;
int l;
String *s;
goto bad1;
}
n->type = t;
-
+
return;
bad1:
if(n->op != ODCLFIELD || n->type == T)
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) {
case CTSTR:
note = n->val.u.sval;
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);
s->vargen = gen;
s->oname = n;
if(t == T)
return;
- if(t->printed || t == types[t->etype] || t == types[TSTRING])
+ if(t->printed || t == types[t->etype])
return;
t->printed = 1;
Type* aindex(Node*, Type*);
int isnil(Node*);
int isptrto(Type*, int);
+int istype(Type*, int);
int isptrsarray(Type*);
int isptrdarray(Type*);
int issarray(Type*);
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| structtype
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM Anon_chan_type
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LMAP '[' type ']' Atype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| '*' Atype
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM Bnon_chan_type
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LMAP '[' type ']' Btype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| '*' Btype
{
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
Bchantype:
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
structtype:
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| LSTRUCT '{' ohidden_structdcl_list '}'
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM hidden_type1
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LDDD
{
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
| '(' ohidden_funarg_list ')' ohidden_funres
{
case TPTR32:
case TPTR64:
case TINTER:
+ case TMAP:
+ case TCHAN:
okforeq[i] = 1;
break;
}
continue;
}
t = typ(etype);
- if(etype == TSTRING)
- t = ptrto(t);
t->sym = s;
dowidth(t);
if(issimple[t->etype])
a = ASIMP; // simple mem
else
- if(isptrto(t, TSTRING))
+ if(t->etype == TSTRING)
a = ASTRING; // string
else
- if(isptr[t->etype])
+ if(isptr[simtype[t->etype]])
a = APTR; // pointer
else
if(t->etype == TARRAY && t->bound < 0)
return Wtfloat;
case TBOOL:
return Wtbool;
-
- case TPTR32:
- case TPTR64:
- if(isptrto(t, TSTRING))
- return Wtstr;
- break;
+ case TSTRING:
+ return Wtstr;
}
return Wtunkn;
}
[TBOOL] = "bool",
[TANY] = "any",
[TDDD] = "...",
+ [TSTRING] = "string",
};
int
&& t->sym != S
&& !(fp->flags&FmtLong)) {
s = t->sym;
- if(t == types[t->etype] || t == types[TSTRING])
+ if(t == types[t->etype])
return fmtprint(fp, "%s", s->name);
if(exporting) {
if(fp->flags & FmtShort)
switch(t->etype) {
case TPTR32:
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
- return fmtprint(fp, "*%hT", t1);
- return fmtprint(fp, "*%T", t1);
+ return fmtprint(fp, "*%hT", t->type);
+ 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:
- 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:
- return fmtprint(fp, "MAP[%T] %T", t->down, t->type);
+ return fmtprint(fp, "map[%T] %T", t->down, t->type);
case TFUNC:
// t->type is method struct
return -1;
}
-
-
int
Tconv(Fmt *fp)
{
}
et = t->etype;
- snprint(buf, sizeof buf, "%E.", et);
+ snprint(buf, sizeof buf, "%E ", et);
if(t->sym != S) {
snprint(buf1, sizeof(buf1), "<%S>", t->sym);
strncat(buf, buf1, sizeof(buf));
break;
case TINTER:
- strncat(buf, "I{", sizeof(buf));
+ strncat(buf, "{", sizeof(buf));
if(fp->flags & FmtLong) {
for(t1=t->type; t1!=T; t1=t1->down) {
snprint(buf1, sizeof(buf1), "%lT;", t1);
break;
case TMAP:
- snprint(buf, sizeof(buf), "MAP[%T]%T", t->down, t->type);
+ snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type);
break;
case TARRAY:
case TPTR32:
case TPTR64:
- snprint(buf1, sizeof(buf1), "*%T", t->type);
+ snprint(buf1, sizeof(buf1), "%T", t->type);
strncat(buf, buf1, sizeof(buf));
break;
}
return 1;
}
+int
+istype(Type *t, int et)
+{
+ return t != T && t->etype == et;
+}
+
int
isptrsarray(Type *t)
{
switch(t->etype) {
case TARRAY:
case TSTRUCT:
+ case TMAP:
return 1;
}
- if(isptr[t->etype] && t->type != T && t->type->etype == TMAP)
- return 1;
return 0;
}
if(cl == 2 && cr == 1) {
// a,b = map[] - mapaccess2
walktype(r->left, Erv);
- if(!isptrto(r->left->type, TMAP))
+ if(!istype(r->left->type, TMAP))
break;
l = mapop(n, top);
if(l == N)
if(cl == 2 && cr == 1) {
// a,b = <chan - chanrecv2
walktype(r->left, Erv);
- if(!isptrto(r->left->type, TCHAN))
+ if(!istype(r->left->type, TCHAN))
break;
l = chanop(n, top);
if(l == N)
case OINDEXPTR:
if(cl == 1 && cr == 2) {
// map[] = a,b - mapassign2
- if(!isptrto(l->left->type, TMAP))
+ if(!istype(l->left->type, TMAP))
break;
l = mapop(n, top);
if(l == N)
// to string
if(l->type != T)
- if(isptrto(t, TSTRING)) {
+ if(istype(t, TSTRING)) {
if(isint[l->type->etype]) {
indir(n, stringop(n, top));
goto ret;
}
// map literal
- if(isptr[t->etype] && t->type != t && t->type->etype == TMAP) {
+ if(t->etype == TMAP) {
r = maplit(n);
indir(n, r);
goto ret;
goto shft;
goto com;
}
- if(!isptrto(l->left->type, TMAP))
+ if(!istype(l->left->type, TMAP))
goto com;
indir(n, mapop(n, top));
goto ret;
case OGT:
case OADD:
case OASOP:
- if(isptrto(n->left->type, TSTRING)) {
+ if(istype(n->left->type, TSTRING)) {
indir(n, stringop(n, top));
goto ret;
}
// BOTCH - convert each index opcode
// to look like this and get rid of OINDEXPTR
- if(isptr[t->etype])
- if(isptrto(t, TSTRING) || isptrto(t->type, TSTRING)) {
+ if(istype(t, TSTRING) || isptrto(t, TSTRING)) {
// right side must be an int
if(top != Erv)
goto nottop;
}
if(!eqtype(n->right->type, t->down, 0))
goto badt;
- if(n->op != OINDEXPTR)
- goto badt;
n->op = OINDEX;
n->type = t->type;
if(top == Erv)
t = n->left->type;
if(t == T)
goto ret;
- if(isptr[t->etype])
+ if(isptr[t->etype]) //XXX?
t = t->type;
if(t->etype == TSTRING) {
indir(n, stringop(n, top));
if(n->left->type == T)
goto ret;
et = n->left->type->etype;
- if(!okforadd[et])
- if(!isptrto(n->left->type, TSTRING))
- goto badt;
+ if(!okforadd[et] && et != TSTRING)
+ goto badt;
t = types[TBOOL];
break;
if(expr == N || expr->op != ORECV)
goto bad;
t = expr->left->type;
- if(t == T)
- goto bad;
- if(isptr[t->etype])
- t = t->type;
if(t == T)
goto bad;
if(t->etype != TCHAN)
Node*
makecompat(Node *n)
{
- Node *r, *on;
- 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;
+ Type *t;
- t = t0->type;
- if(t == T)
- goto bad;
+ t = n->type;
+ if(t != T)
switch(t->etype) {
- case TSTRING:
- goto bad;
-
- // the call looks like new(MAP[int]int)
- // but internally we see new(*MAP[int]int)
+ case TARRAY:
+ return arrayop(n, Erv);
case TMAP:
- r = mapop(n, Erv);
- break;
-
- // the call looks like new(CHAN int)
- // but internally we see new(*CHAN int)
+ return mapop(n, Erv);
case TCHAN:
- r = 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 chanop(n, Erv);
}
- 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)", t0);
+ yyerror("cannot make(%T)", t);
return n;
}
Type *t;
t = n->type;
- if(t == T)
- goto bad;
-
- switch(t->etype) {
- case TFUNC:
- case TSTRING:
- case TMAP:
- case TCHAN:
- goto bad;
-
- default:
+ if(t != T && t->etype != TFUNC) {
if(n->left != N)
yyerror("cannot new(%T, expr)", t);
dowidth(t);
r = nodintconst(t->width);
r = nod(OCALL, on, r);
walktype(r, Erv);
- break;
+ return r;
}
- return r;
-
-bad:
yyerror("cannot new(%T)", t);
return n;
}
case OINDEX:
// sys_indexstring(s, i)
c = n->left;
- if(isptrto(c->type->type, TSTRING)) {
+ if(istype(c->type->type, TSTRING)) {
// lhs is string or *string
c = nod(OIND, c, N);
c->type = c->left->type->type;
}
Type*
-fixmap(Type *tm)
+fixmap(Type *t)
{
- Type *t;
-
- t = tm->type;
if(t == T)
goto bad;
if(t->etype != TMAP)
return t;
bad:
- yyerror("not a map: %lT", tm);
+ yyerror("not a map: %lT", t);
return T;
}
Type*
-fixchan(Type *tm)
+fixchan(Type *t)
{
- Type *t;
-
- if(tm == T)
- goto bad;
- t = tm->type;
if(t == T)
goto bad;
if(t->etype != TCHAN)
return t;
bad:
- yyerror("not a channel: %lT", tm);
+ yyerror("not a channel: %lT", t);
return T;
}
Node *on;
int cl, cr;
-//dump("mapop", n);
-
r = n;
switch(n->op) {
default:
// rewrite map[index] 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);
tempname(a, t->down); // tmpi
r = nod(OAS, a, n->left->right); // tmpi := index
goto out;
if(n->left->op == OINDEX)
- if(isptrto(n->left->left->type, TMAP)) {
+ if(istype(n->left->left->type, TMAP)) {
indir(n, mapop(n, Elv));
goto out;
}
goto badt;
walktype(nr->left, Erv);
t = nr->left->type;
- if(!isptrto(t, TCHAN))
+ if(!istype(t, TCHAN))
goto badt;
- a = old2new(nl->left, t->type->type);
+ a = old2new(nl->left, t->type);
n = a;
a = old2new(nl->right, types[TBOOL]);
n = list(n, a);
var = nod(OXXX, N, N);
tempname(var, t);
+ nnew = nil;
if(b < 0) {
// slice
nnew = nod(OMAKE, N, N);
Node *var, *r, *a;
t = n->type;
- if(!isptr[t->etype] || t->type == T || t->type->etype != TMAP)
+ if(t->etype != TMAP)
fatal("maplit: not map");
var = nod(OXXX, N, N);