Commit 3856e45e authored by Ken Thompson's avatar Ken Thompson

more on channels

arg space magic number for morestack

SVN=126936
parent 2da9783e
......@@ -22,7 +22,7 @@ compile(Node *fn)
Plist *pl;
Node nod1;
Prog *ptxt;
long lno;
long lno, argsiz;
if(newproc == N) {
newproc = nod(ONAME, N, N);
......@@ -69,8 +69,15 @@ if(newproc == N) {
pc->as = ARET; // overwrite AEND
pc->lineno = lineno;
// fill in argument size
argsiz = getthisx(curfn->type) -> width;
argsiz += getinargx(curfn->type) -> width;
argsiz += getoutargx(curfn->type) -> width;
ptxt->to.offset = rnd(argsiz, maxround);
// fill in final stack size
ptxt->to.offset = rnd(stksize+maxarg, maxround);
ptxt->to.offset <<= 32;
ptxt->to.offset |= rnd(stksize+maxarg, maxround);
if(debug['f'])
frame(0);
......
......@@ -50,14 +50,23 @@ Pconv(Fmt *fp)
p = va_arg(fp->args, Prog*);
sconsize = 8;
if(p->as == ADATA) {
switch(p->as) {
default:
snprint(str, sizeof(str), "%.4ld (%4ld) %-7A %D,%D",
p->loc, p->lineno, p->as, &p->from, &p->to);
break;
case ADATA:
sconsize = p->from.scale;
snprint(str, sizeof(str), "%.4ld (%4ld) %-7A %D/%d,%D",
p->loc, p->lineno, p->as, &p->from, sconsize, &p->to);
return fmtstrcpy(fp, str);
}
snprint(str, sizeof(str), "%.4ld (%4ld) %-7A %D,%D",
break;
case ATEXT:
snprint(str, sizeof(str), "%.4ld (%4ld) %-7A %D,%lD",
p->loc, p->lineno, p->as, &p->from, &p->to);
break;
}
return fmtstrcpy(fp, str);
}
......@@ -67,6 +76,7 @@ Dconv(Fmt *fp)
char str[40], s[20];
Addr *a;
int i;
ulong d1, d2;
a = va_arg(fp->args, Addr*);
i = a->type;
......@@ -111,6 +121,12 @@ Dconv(Fmt *fp)
break;
case D_CONST:
if(fp->flags & FmtLong) {
d1 = a->offset & 0xffffffffLL;
d2 = (a->offset>>32) & 0xffffffffLL;
sprint(str, "$%lud-%lud", d1, d2);
break;
}
sprint(str, "$%lld", a->offset);
break;
......
......@@ -233,6 +233,16 @@ dumpexporttype(Sym *s)
Bprint(bout, "!");
Bprint(bout, "%lS [%lS] %lS\n", s, t->down->sym, t->type->sym);
break;
case TCHAN:
reexport(t->type);
/* type 8 */
Bprint(bout, "\ttype ");
if(s->export != 0)
Bprint(bout, "!");
Bprint(bout, "%lS %d %lS\n", s, t->chan, t->type->sym);
break;
}
}
......@@ -624,3 +634,25 @@ doimport7(Node *ss, Node *n)
importaddtyp(ss, t);
}
/*
* LTYPE importsym chdir importsym
* interface type
*/
void
doimport8(Node *ss, Val *v, Node *st)
{
Type *t;
Sym *s;
int dir;
s = pkglookup(st->sym->name, st->psym->name);
dir = v->vval;
t = typ(TCHAN);
s = pkglookup(st->sym->name, st->psym->name);
t->type = s->otype;
t->chan = dir;
importaddtyp(ss, t);
}
......@@ -96,9 +96,9 @@ struct Type
Type* nforw;
// TFUNCT
Type* this;
Type* argout;
Type* argin;
// Type* this;
// Type* argout;
// Type* argin;
Node* nname;
// TARRAY
......@@ -563,6 +563,7 @@ void doimport4(Node*, Node*);
void doimport5(Node*, Val*);
void doimport6(Node*, Node*);
void doimport7(Node*, Node*);
void doimport8(Node*, Val*, Node*);
/*
* walk.c
......@@ -583,6 +584,7 @@ Node* nodpanic(long);
Node* newcompat(Node*);
Node* stringop(Node*, int);
Node* mapop(Node*, int);
Node* chanop(Node*, int);
Node* convas(Node*);
void arrayconv(Type*, Node*);
Node* colas(Node*, Node*);
......
......@@ -910,6 +910,14 @@ chandir:
{
$$ = Csend;
}
| LLT LGT
{
$$ = Cboth;
}
| LGT LLT
{
$$ = 0;
}
keyval:
expr ':' expr
......@@ -1481,6 +1489,11 @@ hidden_import:
// type interface
doimport7($2, $4);
}
| LTYPE hidden_importsym LLITERAL hidden_importsym
{
// type interface
doimport8($2, &$3, $4);
}
isym:
sym '.' sym
......
......@@ -1295,6 +1295,7 @@ loop:
case TPTR32:
case TPTR64:
case TCHAN:
stp = &st->type;
goto loop;
......
......@@ -44,6 +44,8 @@ func mapaccess2(hmap *map[any]any, key any) (val any, pres bool);
func mapassign1(hmap *map[any]any, key any, val any);
func mapassign2(hmap *map[any]any, key any, val any, pres bool);
func newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
func gosched();
func goexit();
......@@ -89,13 +91,16 @@ export
Inf,
NaN,
// op map
// map
newmap
mapaccess1
mapaccess2
mapassign1
mapassign2
// chan
newchan
// go routines
gosched
goexit
......
This diff is collapsed.
......@@ -1219,6 +1219,10 @@ newcompat(Node *n)
r = mapop(n, Erv);
return r;
}
if(t->etype == TCHAN) {
r = chanop(n, Erv);
return r;
}
if(n->left != N)
yyerror("dont know what new(,e) means");
......@@ -1371,6 +1375,32 @@ fixmap(Type *tm)
return t;
}
Type*
fixchan(Type *tm)
{
Type *t;
t = tm->type;
if(t == T) {
fatal("fixchan: t nil");
return T;
}
if(t->etype != TCHAN) {
fatal("fixchan: %O not map");
return T;
}
if(t->type == T) {
fatal("fixchan: chan element type is nil");
return T;
}
dowidth(t->type);
return t;
}
static int
algtype(Type *t)
{
......@@ -1593,6 +1623,49 @@ nottop:
return N;
}
Node*
chanop(Node *n, int top)
{
Node *r, *a;
Type *t;
Node *on;
int alg, cl, cr;
//dump("chanop", n);
r = n;
switch(n->op) {
default:
fatal("mapop: unknown op %E", n->op);
case ONEW:
// newchan(elemsize uint32, elemalg uint32,
// hint uint32) (hmap *chan[any-1]);
t = fixchan(n->type);
if(t == T)
break;
a = n->left; // hint
if(n->left == N)
a = nodintconst(0);
r = a;
a = nodintconst(algtype(t->type)); // elem algorithm
r = nod(OLIST, a, r);
a = nodintconst(t->type->width); // elem width
r = nod(OLIST, a, r);
on = syslook("newchan", 1);
argtype(on, t->type); // any-1
r = nod(OCALL, on, r);
walktype(r, top);
r->type = n->type;
break;
}
return r;
}
void
diagnamed(Type *t)
{
......
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