1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:04:41 -07:00

now method/interface code

R=r
OCL=15627
CL=15627
This commit is contained in:
Ken Thompson 2008-09-22 12:16:19 -07:00
parent 128f052891
commit 8231e94520
13 changed files with 667 additions and 589 deletions

View File

@ -154,10 +154,6 @@ cgen(Node *n, Node *res)
regfree(&n1);
break;
case OS2I:
case OI2I:
case OI2S:
case OINDEXPTR:
case OINDEX:
case ODOT:
@ -345,12 +341,6 @@ agen(Node *n, Node *res)
cgen_aret(n, res);
break;
case OS2I:
case OI2I:
case OI2S:
agen_inter(n, res);
break;
case OINDEXPTR:
w = n->type->width;
if(nr->addable)
@ -678,10 +668,10 @@ int32
stkof(Node *n)
{
switch(n->op) {
case OS2I:
return 2*widthptr;
case OI2I:
return 1*widthptr;
// case OS2I:
// return 2*widthptr;
// case OI2I:
// return 1*widthptr;
case OINDREG:
return n->xoffset;
}

View File

@ -373,7 +373,7 @@ agen_inter(Node *n, Node *res)
default:
fatal("agen_inter %O\n", n->op);
case OS2I:
// case OS2I:
// ifaces2i(*sigi, *sigs, i.map, i.s)
// i.s is input
// (i.map, i.s) is output
@ -398,7 +398,7 @@ agen_inter(Node *n, Node *res)
o = 2*widthptr;
break;
case OI2I:
// case OI2I:
// ifacei2i(*sigi, i.map, i.s)
// (i.map, i.s) is input
// (i.map, i.s) is output
@ -424,7 +424,7 @@ agen_inter(Node *n, Node *res)
o = 1*widthptr;
break;
case OI2S:
// case OI2S:
// ifacei2s(*sigs, i.map, i.s)
// (i.map, i.s) is input
// i.s is output

View File

@ -294,45 +294,6 @@ nodconst(Node *n, Type *t, vlong v)
}
}
Sym*
signame(Type *t)
{
Sym *s;
char *e;
loop:
if(t == T)
fatal("signame: nil type");
switch(t->etype) {
default:
e = "sigs";
break;
case TPTR32:
case TPTR64:
t = t->type;
goto loop;
case TSTRUCT:
case TINTER:
e = "sigi";
break;
}
s = t->sym;
if(s == S)
fatal("signame: no sym for type");
// mark it as used so signature will be generated
if(s->local == 1)
s->local = 2;
snprint(namebuf, sizeof(namebuf), "%s_%s", e, s->name);
s = pkglookup(namebuf, s->opackage);
return s;
}
void
nodtypesig(Node *n, Type *t)
{
@ -1055,8 +1016,10 @@ naddr(Node *n, Addr *a)
a->etype = n->etype;
a->offset = n->xoffset;
a->sym = n->sym;
if(a->sym == S)
if(a->sym == S) {
a->sym = lookup(".noname");
fatal("noname");
}
if(n->method) {
if(n->type != T)
if(n->type->sym != S)

View File

@ -161,8 +161,6 @@ dumpobj(void)
}
}
Bterm(bout);
return;
Bterm(bout);
}
Bputdot(Biobuf *b)
@ -477,31 +475,14 @@ dumpsignatures(void)
if(t == T)
continue;
et = t->etype;
if(t->method == T && et != TINTER)
continue;
s = d->dsym;
s = signame(t);
if(s == S)
continue;
if(s->name[0] == '_')
continue;
// if it was imported
if(s->local == 0)
continue;
// until i can figure out
// when/if it is used, do them all
// // if not used and not exported
// if(s->local == 1 && !s->export)
// continue;
x = mal(sizeof(*d));
x->op = OTYPE;
x->dsym = s;
x->dtype = t;
x->dsym = d->dsym;
x->dtype = d->dtype;
x->forw = signatlist;
signatlist = x;
}
@ -548,9 +529,15 @@ dumpsignatures(void)
continue;
t = d->dtype;
et = t->etype;
if(t->method == T && et != TINTER)
at.sym = signame(t);
if(at.sym == S)
continue;
if(!at.sym->local)
continue;
//print("SIGNAME = %lS\n", at.sym);
et = t->etype;
s = d->dsym;
if(s == S)
@ -562,14 +549,13 @@ dumpsignatures(void)
if(strcmp(s->opackage, package) != 0)
continue;
at.sym = signame(t);
a = nil;
o = 0;
f = t->type;
if(et != TINTER)
f = t->method;
f = t->method;
if(et == TINTER)
f = t->type;
for(; f!=T; f=f->down) {
if(f->type->etype != TFUNC)

View File

@ -260,7 +260,7 @@ enum
ODCLFUNC, ODCLFIELD, ODCLARG,
OLIST, OCMP,
OPTR, OARRAY,
ORETURN, OFOR, OIF, OSWITCH, OI2S, OS2I, OI2I,
ORETURN, OFOR, OIF, OSWITCH,
OAS, OASOP, OCASE, OXCASE, OFALL, OXFALL,
OGOTO, OPROC, ONEW, OEMPTY, OSELECT,
OLEN, OCAP, OPANIC, OPRINT, OTYPEOF,
@ -564,6 +564,7 @@ int isptrarray(Type*);
int isptrdarray(Type*);
int isinter(Type*);
int ismethod(Type*);
Sym* signame(Type*);
int bytearraysz(Type*);
int eqtype(Type*, Type*, int);
void argtype(Node*, Type*);
@ -692,7 +693,8 @@ Node* mapop(Node*, int);
Type* fixchan(Type*);
Node* chanop(Node*, int);
Node* arrayop(Node*, int);
Node* isandss(Type*, Node*);
Node* ifaceop(Type*, Node*, int);
int isandss(Type*, Node*);
Node* convas(Node*);
void arrayconv(Type*, Node*);
Node* colas(Node*, Node*);

View File

@ -644,9 +644,6 @@ opnames[] =
[OPTR] = "PTR",
[ORETURN] = "RETURN",
[ORSH] = "RSH",
[OI2S] = "I2S",
[OS2I] = "S2I",
[OI2I] = "I2I",
[OSLICE] = "SLICE",
[OSUB] = "SUB",
[OSELECT] = "SELECT",
@ -1238,6 +1235,58 @@ ismethod(Type *t)
return 0;
}
Sym*
signame(Type *t)
{
Sym *s, *ss;
char *e;
loop:
if(t == T) {
print("signame: nil type\n");
goto bad;
}
switch(t->etype) {
default:
e = "sigs";
break;
case TPTR32:
case TPTR64:
t = t->type;
goto loop;
case TINTER:
e = "sigi";
break;
}
s = t->sym;
if(s == S) {
print("signame: no type name\n");
goto bad;
}
if(s->name[0] == '_') {
// print("signame: temp type name %S\n", s);
goto bad;
}
snprint(namebuf, sizeof(namebuf), "%s_%s", e, s->name);
ss = pkglookup(namebuf, s->opackage);
if(ss->oname == N) {
ss->oname = newname(ss);
ss->oname->type = types[TUINT8];
ss->oname->class = PEXTERN;
ss->local = s->local;
//print("signame: %d %lS\n", ss->local, ss);
}
return ss;
bad:
return S;
}
int
bytearraysz(Type *t)
{
@ -1620,9 +1669,6 @@ ullmancalc(Node *n)
case ONAME:
ul = 0;
goto out;
case OS2I:
case OI2S:
case OI2I:
case OCALL:
case OCALLMETH:
case OCALLINTER:

View File

@ -23,7 +23,10 @@ func slicestring(string, int32, int32) string;
func indexstring(string, int32) byte;
func intstring(int64) string;
func byteastring(*byte, int32) string;
func mkiface(*byte, *byte, *struct{}) interface{};
func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{});
func ifaceI2T(sigt *byte, iface interface{}) (ret any);
func ifaceI2I(sigi *byte, iface any) (ret any);
func argc() int32;
func envc() int32;
@ -95,7 +98,11 @@ export
indexstring
intstring
byteastring
mkiface
// interface
ifaceT2I
ifaceI2T
ifaceI2I
// args
argc

View File

@ -3,10 +3,10 @@ char* sysimport =
"type sys._esys_002 {}\n"
"type sys.any 24\n"
"type sys._esys_003 *sys.any\n"
"type sys._osys_429 {_esys_427 sys._esys_003}\n"
"type sys._osys_445 {_esys_443 sys._esys_003}\n"
"type sys.uint32 6\n"
"type sys._isys_431 {_esys_428 sys.uint32}\n"
"type sys._esys_001 (sys._esys_002 sys._osys_429 sys._isys_431)\n"
"type sys._isys_447 {_esys_444 sys.uint32}\n"
"type sys._esys_001 (sys._esys_002 sys._osys_445 sys._isys_447)\n"
"var !sys.mal sys._esys_001\n"
"type sys._esys_005 {}\n"
"type sys._esys_006 {}\n"
@ -26,320 +26,331 @@ char* sysimport =
"type sys._esys_017 {}\n"
"type sys._esys_018 {}\n"
"type sys.int32 5\n"
"type sys._isys_439 {_esys_438 sys.int32}\n"
"type sys._esys_016 (sys._esys_017 sys._esys_018 sys._isys_439)\n"
"type sys._isys_455 {_esys_454 sys.int32}\n"
"type sys._esys_016 (sys._esys_017 sys._esys_018 sys._isys_455)\n"
"var !sys.panicl sys._esys_016\n"
"type sys._esys_020 {}\n"
"type sys._esys_021 {}\n"
"type sys.bool 12\n"
"type sys._isys_444 {_esys_443 sys.bool}\n"
"type sys._esys_019 (sys._esys_020 sys._esys_021 sys._isys_444)\n"
"type sys._isys_460 {_esys_459 sys.bool}\n"
"type sys._esys_019 (sys._esys_020 sys._esys_021 sys._isys_460)\n"
"var !sys.printbool sys._esys_019\n"
"type sys._esys_023 {}\n"
"type sys._esys_024 {}\n"
"type sys.float64 10\n"
"type sys._isys_449 {_esys_448 sys.float64}\n"
"type sys._esys_022 (sys._esys_023 sys._esys_024 sys._isys_449)\n"
"type sys._isys_465 {_esys_464 sys.float64}\n"
"type sys._esys_022 (sys._esys_023 sys._esys_024 sys._isys_465)\n"
"var !sys.printfloat sys._esys_022\n"
"type sys._esys_026 {}\n"
"type sys._esys_027 {}\n"
"type sys.int64 7\n"
"type sys._isys_454 {_esys_453 sys.int64}\n"
"type sys._esys_025 (sys._esys_026 sys._esys_027 sys._isys_454)\n"
"type sys._isys_470 {_esys_469 sys.int64}\n"
"type sys._esys_025 (sys._esys_026 sys._esys_027 sys._isys_470)\n"
"var !sys.printint sys._esys_025\n"
"type sys._esys_029 {}\n"
"type sys._esys_030 {}\n"
"type sys._esys_031 25\n"
"type sys.string *sys._esys_031\n"
"type sys._isys_459 {_esys_458 sys.string}\n"
"type sys._esys_028 (sys._esys_029 sys._esys_030 sys._isys_459)\n"
"type sys._isys_475 {_esys_474 sys.string}\n"
"type sys._esys_028 (sys._esys_029 sys._esys_030 sys._isys_475)\n"
"var !sys.printstring sys._esys_028\n"
"type sys._esys_033 {}\n"
"type sys._esys_034 {}\n"
"type sys._esys_035 *sys.any\n"
"type sys._isys_464 {_esys_463 sys._esys_035}\n"
"type sys._esys_032 (sys._esys_033 sys._esys_034 sys._isys_464)\n"
"type sys._isys_480 {_esys_479 sys._esys_035}\n"
"type sys._esys_032 (sys._esys_033 sys._esys_034 sys._isys_480)\n"
"var !sys.printpointer sys._esys_032\n"
"type sys._esys_037 {}\n"
"type sys._osys_471 {_esys_468 sys.string}\n"
"type sys._isys_473 {_esys_469 sys.string _esys_470 sys.string}\n"
"type sys._esys_036 (sys._esys_037 sys._osys_471 sys._isys_473)\n"
"type sys._osys_487 {_esys_484 sys.string}\n"
"type sys._isys_489 {_esys_485 sys.string _esys_486 sys.string}\n"
"type sys._esys_036 (sys._esys_037 sys._osys_487 sys._isys_489)\n"
"var !sys.catstring sys._esys_036\n"
"type sys._esys_039 {}\n"
"type sys._osys_481 {_esys_478 sys.int32}\n"
"type sys._isys_483 {_esys_479 sys.string _esys_480 sys.string}\n"
"type sys._esys_038 (sys._esys_039 sys._osys_481 sys._isys_483)\n"
"type sys._osys_497 {_esys_494 sys.int32}\n"
"type sys._isys_499 {_esys_495 sys.string _esys_496 sys.string}\n"
"type sys._esys_038 (sys._esys_039 sys._osys_497 sys._isys_499)\n"
"var !sys.cmpstring sys._esys_038\n"
"type sys._esys_041 {}\n"
"type sys._osys_492 {_esys_488 sys.string}\n"
"type sys._isys_494 {_esys_489 sys.string _esys_490 sys.int32 _esys_491 sys.int32}\n"
"type sys._esys_040 (sys._esys_041 sys._osys_492 sys._isys_494)\n"
"type sys._osys_508 {_esys_504 sys.string}\n"
"type sys._isys_510 {_esys_505 sys.string _esys_506 sys.int32 _esys_507 sys.int32}\n"
"type sys._esys_040 (sys._esys_041 sys._osys_508 sys._isys_510)\n"
"var !sys.slicestring sys._esys_040\n"
"type sys._esys_043 {}\n"
"type sys.uint8 2\n"
"type sys._osys_503 {_esys_500 sys.uint8}\n"
"type sys._isys_505 {_esys_501 sys.string _esys_502 sys.int32}\n"
"type sys._esys_042 (sys._esys_043 sys._osys_503 sys._isys_505)\n"
"type sys._osys_519 {_esys_516 sys.uint8}\n"
"type sys._isys_521 {_esys_517 sys.string _esys_518 sys.int32}\n"
"type sys._esys_042 (sys._esys_043 sys._osys_519 sys._isys_521)\n"
"var !sys.indexstring sys._esys_042\n"
"type sys._esys_045 {}\n"
"type sys._osys_512 {_esys_510 sys.string}\n"
"type sys._isys_514 {_esys_511 sys.int64}\n"
"type sys._esys_044 (sys._esys_045 sys._osys_512 sys._isys_514)\n"
"type sys._osys_528 {_esys_526 sys.string}\n"
"type sys._isys_530 {_esys_527 sys.int64}\n"
"type sys._esys_044 (sys._esys_045 sys._osys_528 sys._isys_530)\n"
"var !sys.intstring sys._esys_044\n"
"type sys._esys_047 {}\n"
"type sys._osys_521 {_esys_518 sys.string}\n"
"type sys._osys_537 {_esys_534 sys.string}\n"
"type sys._esys_048 *sys.uint8\n"
"type sys._isys_523 {_esys_519 sys._esys_048 _esys_520 sys.int32}\n"
"type sys._esys_046 (sys._esys_047 sys._osys_521 sys._isys_523)\n"
"type sys._isys_539 {_esys_535 sys._esys_048 _esys_536 sys.int32}\n"
"type sys._esys_046 (sys._esys_047 sys._osys_537 sys._isys_539)\n"
"var !sys.byteastring sys._esys_046\n"
"type sys._esys_050 {}\n"
"type sys._esys_051 <>\n"
"type sys._osys_532 {_esys_528 sys._esys_051}\n"
"type sys._osys_544 {ret sys._esys_051}\n"
"type sys._esys_052 *sys.uint8\n"
"type sys._esys_053 *sys.uint8\n"
"type sys._ssys_539 {}\n"
"type sys._esys_054 *sys._ssys_539\n"
"type sys._isys_534 {_esys_529 sys._esys_052 _esys_530 sys._esys_053 _esys_531 sys._esys_054}\n"
"type sys._esys_049 (sys._esys_050 sys._osys_532 sys._isys_534)\n"
"var !sys.mkiface sys._esys_049\n"
"type sys._esys_056 {}\n"
"type sys._osys_543 {_esys_542 sys.int32}\n"
"type sys._esys_057 {}\n"
"type sys._esys_055 (sys._esys_056 sys._osys_543 sys._esys_057)\n"
"var !sys.argc sys._esys_055\n"
"type sys._isys_546 {sigi sys._esys_052 sigt sys._esys_053 elem sys.any}\n"
"type sys._esys_049 (sys._esys_050 sys._osys_544 sys._isys_546)\n"
"var !sys.ifaceT2I sys._esys_049\n"
"type sys._esys_055 {}\n"
"type sys._osys_553 {ret sys.any}\n"
"type sys._esys_056 *sys.uint8\n"
"type sys._esys_057 <>\n"
"type sys._isys_555 {sigt sys._esys_056 iface sys._esys_057}\n"
"type sys._esys_054 (sys._esys_055 sys._osys_553 sys._isys_555)\n"
"var !sys.ifaceI2T sys._esys_054\n"
"type sys._esys_059 {}\n"
"type sys._osys_547 {_esys_546 sys.int32}\n"
"type sys._esys_060 {}\n"
"type sys._esys_058 (sys._esys_059 sys._osys_547 sys._esys_060)\n"
"var !sys.envc sys._esys_058\n"
"type sys._osys_561 {ret sys.any}\n"
"type sys._esys_060 *sys.uint8\n"
"type sys._isys_563 {sigi sys._esys_060 iface sys.any}\n"
"type sys._esys_058 (sys._esys_059 sys._osys_561 sys._isys_563)\n"
"var !sys.ifaceI2I sys._esys_058\n"
"type sys._esys_062 {}\n"
"type sys._osys_552 {_esys_550 sys.string}\n"
"type sys._isys_554 {_esys_551 sys.int32}\n"
"type sys._esys_061 (sys._esys_062 sys._osys_552 sys._isys_554)\n"
"var !sys.argv sys._esys_061\n"
"type sys._esys_064 {}\n"
"type sys._osys_560 {_esys_558 sys.string}\n"
"type sys._isys_562 {_esys_559 sys.int32}\n"
"type sys._esys_063 (sys._esys_064 sys._osys_560 sys._isys_562)\n"
"var !sys.envv sys._esys_063\n"
"type sys._osys_570 {_esys_569 sys.int32}\n"
"type sys._esys_063 {}\n"
"type sys._esys_061 (sys._esys_062 sys._osys_570 sys._esys_063)\n"
"var !sys.argc sys._esys_061\n"
"type sys._esys_065 {}\n"
"type sys._osys_574 {_esys_573 sys.int32}\n"
"type sys._esys_066 {}\n"
"type sys._osys_569 {_esys_566 sys.float64 _esys_567 sys.int32}\n"
"type sys._isys_571 {_esys_568 sys.float64}\n"
"type sys._esys_065 (sys._esys_066 sys._osys_569 sys._isys_571)\n"
"var !sys.frexp sys._esys_065\n"
"type sys._esys_064 (sys._esys_065 sys._osys_574 sys._esys_066)\n"
"var !sys.envc sys._esys_064\n"
"type sys._esys_068 {}\n"
"type sys._osys_578 {_esys_575 sys.float64}\n"
"type sys._isys_580 {_esys_576 sys.float64 _esys_577 sys.int32}\n"
"type sys._esys_067 (sys._esys_068 sys._osys_578 sys._isys_580)\n"
"var !sys.ldexp sys._esys_067\n"
"type sys._osys_579 {_esys_577 sys.string}\n"
"type sys._isys_581 {_esys_578 sys.int32}\n"
"type sys._esys_067 (sys._esys_068 sys._osys_579 sys._isys_581)\n"
"var !sys.argv sys._esys_067\n"
"type sys._esys_070 {}\n"
"type sys._osys_588 {_esys_585 sys.float64 _esys_586 sys.float64}\n"
"type sys._isys_590 {_esys_587 sys.float64}\n"
"type sys._esys_069 (sys._esys_070 sys._osys_588 sys._isys_590)\n"
"var !sys.modf sys._esys_069\n"
"type sys._osys_587 {_esys_585 sys.string}\n"
"type sys._isys_589 {_esys_586 sys.int32}\n"
"type sys._esys_069 (sys._esys_070 sys._osys_587 sys._isys_589)\n"
"var !sys.envv sys._esys_069\n"
"type sys._esys_072 {}\n"
"type sys._osys_597 {_esys_594 sys.bool}\n"
"type sys._isys_599 {_esys_595 sys.float64 _esys_596 sys.int32}\n"
"type sys._esys_071 (sys._esys_072 sys._osys_597 sys._isys_599)\n"
"var !sys.isInf sys._esys_071\n"
"type sys._osys_596 {_esys_593 sys.float64 _esys_594 sys.int32}\n"
"type sys._isys_598 {_esys_595 sys.float64}\n"
"type sys._esys_071 (sys._esys_072 sys._osys_596 sys._isys_598)\n"
"var !sys.frexp sys._esys_071\n"
"type sys._esys_074 {}\n"
"type sys._osys_606 {_esys_604 sys.bool}\n"
"type sys._isys_608 {_esys_605 sys.float64}\n"
"type sys._esys_073 (sys._esys_074 sys._osys_606 sys._isys_608)\n"
"var !sys.isNaN sys._esys_073\n"
"type sys._osys_605 {_esys_602 sys.float64}\n"
"type sys._isys_607 {_esys_603 sys.float64 _esys_604 sys.int32}\n"
"type sys._esys_073 (sys._esys_074 sys._osys_605 sys._isys_607)\n"
"var !sys.ldexp sys._esys_073\n"
"type sys._esys_076 {}\n"
"type sys._osys_614 {_esys_612 sys.float64}\n"
"type sys._isys_616 {_esys_613 sys.int32}\n"
"type sys._esys_075 (sys._esys_076 sys._osys_614 sys._isys_616)\n"
"var !sys.Inf sys._esys_075\n"
"type sys._osys_615 {_esys_612 sys.float64 _esys_613 sys.float64}\n"
"type sys._isys_617 {_esys_614 sys.float64}\n"
"type sys._esys_075 (sys._esys_076 sys._osys_615 sys._isys_617)\n"
"var !sys.modf sys._esys_075\n"
"type sys._esys_078 {}\n"
"type sys._osys_621 {_esys_620 sys.float64}\n"
"type sys._esys_079 {}\n"
"type sys._esys_077 (sys._esys_078 sys._osys_621 sys._esys_079)\n"
"var !sys.NaN sys._esys_077\n"
"type sys._esys_081 {}\n"
"type sys._esys_083 [sys.any] sys.any\n"
"type sys._esys_082 *sys._esys_083\n"
"type sys._osys_624 {hmap sys._esys_082}\n"
"type sys._isys_626 {keysize sys.uint32 valsize sys.uint32 keyalg sys.uint32 valalg sys.uint32 hint sys.uint32}\n"
"type sys._esys_080 (sys._esys_081 sys._osys_624 sys._isys_626)\n"
"var !sys.newmap sys._esys_080\n"
"type sys._osys_624 {_esys_621 sys.bool}\n"
"type sys._isys_626 {_esys_622 sys.float64 _esys_623 sys.int32}\n"
"type sys._esys_077 (sys._esys_078 sys._osys_624 sys._isys_626)\n"
"var !sys.isInf sys._esys_077\n"
"type sys._esys_080 {}\n"
"type sys._osys_633 {_esys_631 sys.bool}\n"
"type sys._isys_635 {_esys_632 sys.float64}\n"
"type sys._esys_079 (sys._esys_080 sys._osys_633 sys._isys_635)\n"
"var !sys.isNaN sys._esys_079\n"
"type sys._esys_082 {}\n"
"type sys._osys_641 {_esys_639 sys.float64}\n"
"type sys._isys_643 {_esys_640 sys.int32}\n"
"type sys._esys_081 (sys._esys_082 sys._osys_641 sys._isys_643)\n"
"var !sys.Inf sys._esys_081\n"
"type sys._esys_084 {}\n"
"type sys._osys_648 {_esys_647 sys.float64}\n"
"type sys._esys_085 {}\n"
"type sys._osys_635 {val sys.any}\n"
"type sys._esys_087 [sys.any] sys.any\n"
"type sys._esys_086 *sys._esys_087\n"
"type sys._isys_637 {hmap sys._esys_086 key sys.any}\n"
"type sys._esys_084 (sys._esys_085 sys._osys_635 sys._isys_637)\n"
"var !sys.mapaccess1 sys._esys_084\n"
"type sys._esys_089 {}\n"
"type sys._osys_643 {val sys.any pres sys.bool}\n"
"type sys._esys_091 [sys.any] sys.any\n"
"type sys._esys_090 *sys._esys_091\n"
"type sys._isys_645 {hmap sys._esys_090 key sys.any}\n"
"type sys._esys_088 (sys._esys_089 sys._osys_643 sys._isys_645)\n"
"var !sys.mapaccess2 sys._esys_088\n"
"type sys._esys_093 {}\n"
"type sys._esys_094 {}\n"
"type sys._esys_096 [sys.any] sys.any\n"
"type sys._esys_095 *sys._esys_096\n"
"type sys._isys_652 {hmap sys._esys_095 key sys.any val sys.any}\n"
"type sys._esys_092 (sys._esys_093 sys._esys_094 sys._isys_652)\n"
"var !sys.mapassign1 sys._esys_092\n"
"type sys._esys_098 {}\n"
"type sys._esys_083 (sys._esys_084 sys._osys_648 sys._esys_085)\n"
"var !sys.NaN sys._esys_083\n"
"type sys._esys_087 {}\n"
"type sys._esys_089 [sys.any] sys.any\n"
"type sys._esys_088 *sys._esys_089\n"
"type sys._osys_651 {hmap sys._esys_088}\n"
"type sys._isys_653 {keysize sys.uint32 valsize sys.uint32 keyalg sys.uint32 valalg sys.uint32 hint sys.uint32}\n"
"type sys._esys_086 (sys._esys_087 sys._osys_651 sys._isys_653)\n"
"var !sys.newmap sys._esys_086\n"
"type sys._esys_091 {}\n"
"type sys._osys_662 {val sys.any}\n"
"type sys._esys_093 [sys.any] sys.any\n"
"type sys._esys_092 *sys._esys_093\n"
"type sys._isys_664 {hmap sys._esys_092 key sys.any}\n"
"type sys._esys_090 (sys._esys_091 sys._osys_662 sys._isys_664)\n"
"var !sys.mapaccess1 sys._esys_090\n"
"type sys._esys_095 {}\n"
"type sys._osys_670 {val sys.any pres sys.bool}\n"
"type sys._esys_097 [sys.any] sys.any\n"
"type sys._esys_096 *sys._esys_097\n"
"type sys._isys_672 {hmap sys._esys_096 key sys.any}\n"
"type sys._esys_094 (sys._esys_095 sys._osys_670 sys._isys_672)\n"
"var !sys.mapaccess2 sys._esys_094\n"
"type sys._esys_099 {}\n"
"type sys._esys_101 [sys.any] sys.any\n"
"type sys._esys_100 *sys._esys_101\n"
"type sys._isys_658 {hmap sys._esys_100 key sys.any val sys.any pres sys.bool}\n"
"type sys._esys_097 (sys._esys_098 sys._esys_099 sys._isys_658)\n"
"var !sys.mapassign2 sys._esys_097\n"
"type sys._esys_103 {}\n"
"type sys._esys_105 1 sys.any\n"
"type sys._esys_104 *sys._esys_105\n"
"type sys._osys_665 {hchan sys._esys_104}\n"
"type sys._isys_667 {elemsize sys.uint32 elemalg sys.uint32 hint sys.uint32}\n"
"type sys._esys_102 (sys._esys_103 sys._osys_665 sys._isys_667)\n"
"var !sys.newchan sys._esys_102\n"
"type sys._esys_107 {}\n"
"type sys._osys_674 {elem sys.any}\n"
"type sys._esys_109 1 sys.any\n"
"type sys._esys_108 *sys._esys_109\n"
"type sys._isys_676 {hchan sys._esys_108}\n"
"type sys._esys_106 (sys._esys_107 sys._osys_674 sys._isys_676)\n"
"var !sys.chanrecv1 sys._esys_106\n"
"type sys._esys_111 {}\n"
"type sys._osys_681 {elem sys.any pres sys.bool}\n"
"type sys._esys_113 1 sys.any\n"
"type sys._esys_112 *sys._esys_113\n"
"type sys._isys_683 {hchan sys._esys_112}\n"
"type sys._esys_110 (sys._esys_111 sys._osys_681 sys._isys_683)\n"
"var !sys.chanrecv2 sys._esys_110\n"
"type sys._esys_115 {}\n"
"type sys._osys_689 {pres sys.bool}\n"
"type sys._esys_117 1 sys.any\n"
"type sys._esys_116 *sys._esys_117\n"
"type sys._esys_118 *sys.any\n"
"type sys._isys_691 {hchan sys._esys_116 elem sys._esys_118}\n"
"type sys._esys_114 (sys._esys_115 sys._osys_689 sys._isys_691)\n"
"var !sys.chanrecv3 sys._esys_114\n"
"type sys._esys_120 {}\n"
"type sys._esys_100 {}\n"
"type sys._esys_102 [sys.any] sys.any\n"
"type sys._esys_101 *sys._esys_102\n"
"type sys._isys_679 {hmap sys._esys_101 key sys.any val sys.any}\n"
"type sys._esys_098 (sys._esys_099 sys._esys_100 sys._isys_679)\n"
"var !sys.mapassign1 sys._esys_098\n"
"type sys._esys_104 {}\n"
"type sys._esys_105 {}\n"
"type sys._esys_107 [sys.any] sys.any\n"
"type sys._esys_106 *sys._esys_107\n"
"type sys._isys_685 {hmap sys._esys_106 key sys.any val sys.any pres sys.bool}\n"
"type sys._esys_103 (sys._esys_104 sys._esys_105 sys._isys_685)\n"
"var !sys.mapassign2 sys._esys_103\n"
"type sys._esys_109 {}\n"
"type sys._esys_111 1 sys.any\n"
"type sys._esys_110 *sys._esys_111\n"
"type sys._osys_692 {hchan sys._esys_110}\n"
"type sys._isys_694 {elemsize sys.uint32 elemalg sys.uint32 hint sys.uint32}\n"
"type sys._esys_108 (sys._esys_109 sys._osys_692 sys._isys_694)\n"
"var !sys.newchan sys._esys_108\n"
"type sys._esys_113 {}\n"
"type sys._osys_701 {elem sys.any}\n"
"type sys._esys_115 1 sys.any\n"
"type sys._esys_114 *sys._esys_115\n"
"type sys._isys_703 {hchan sys._esys_114}\n"
"type sys._esys_112 (sys._esys_113 sys._osys_701 sys._isys_703)\n"
"var !sys.chanrecv1 sys._esys_112\n"
"type sys._esys_117 {}\n"
"type sys._osys_708 {elem sys.any pres sys.bool}\n"
"type sys._esys_119 1 sys.any\n"
"type sys._esys_118 *sys._esys_119\n"
"type sys._isys_710 {hchan sys._esys_118}\n"
"type sys._esys_116 (sys._esys_117 sys._osys_708 sys._isys_710)\n"
"var !sys.chanrecv2 sys._esys_116\n"
"type sys._esys_121 {}\n"
"type sys._osys_716 {pres sys.bool}\n"
"type sys._esys_123 1 sys.any\n"
"type sys._esys_122 *sys._esys_123\n"
"type sys._isys_697 {hchan sys._esys_122 elem sys.any}\n"
"type sys._esys_119 (sys._esys_120 sys._esys_121 sys._isys_697)\n"
"var !sys.chansend1 sys._esys_119\n"
"type sys._esys_125 {}\n"
"type sys._osys_702 {pres sys.bool}\n"
"type sys._esys_127 1 sys.any\n"
"type sys._esys_126 *sys._esys_127\n"
"type sys._isys_704 {hchan sys._esys_126 elem sys.any}\n"
"type sys._esys_124 (sys._esys_125 sys._osys_702 sys._isys_704)\n"
"var !sys.chansend2 sys._esys_124\n"
"type sys._esys_129 {}\n"
"type sys._esys_130 *sys.uint8\n"
"type sys._osys_710 {sel sys._esys_130}\n"
"type sys._isys_712 {size sys.uint32}\n"
"type sys._esys_128 (sys._esys_129 sys._osys_710 sys._isys_712)\n"
"var !sys.newselect sys._esys_128\n"
"type sys._esys_132 {}\n"
"type sys._osys_717 {selected sys.bool}\n"
"type sys._esys_133 *sys.uint8\n"
"type sys._esys_135 1 sys.any\n"
"type sys._esys_134 *sys._esys_135\n"
"type sys._isys_719 {sel sys._esys_133 hchan sys._esys_134 elem sys.any}\n"
"type sys._esys_131 (sys._esys_132 sys._osys_717 sys._isys_719)\n"
"var !sys.selectsend sys._esys_131\n"
"type sys._esys_137 {}\n"
"type sys._osys_726 {selected sys.bool}\n"
"type sys._esys_138 *sys.uint8\n"
"type sys._esys_140 1 sys.any\n"
"type sys._esys_139 *sys._esys_140\n"
"type sys._esys_141 *sys.any\n"
"type sys._isys_728 {sel sys._esys_138 hchan sys._esys_139 elem sys._esys_141}\n"
"type sys._esys_136 (sys._esys_137 sys._osys_726 sys._isys_728)\n"
"var !sys.selectrecv sys._esys_136\n"
"type sys._esys_124 *sys.any\n"
"type sys._isys_718 {hchan sys._esys_122 elem sys._esys_124}\n"
"type sys._esys_120 (sys._esys_121 sys._osys_716 sys._isys_718)\n"
"var !sys.chanrecv3 sys._esys_120\n"
"type sys._esys_126 {}\n"
"type sys._esys_127 {}\n"
"type sys._esys_129 1 sys.any\n"
"type sys._esys_128 *sys._esys_129\n"
"type sys._isys_724 {hchan sys._esys_128 elem sys.any}\n"
"type sys._esys_125 (sys._esys_126 sys._esys_127 sys._isys_724)\n"
"var !sys.chansend1 sys._esys_125\n"
"type sys._esys_131 {}\n"
"type sys._osys_729 {pres sys.bool}\n"
"type sys._esys_133 1 sys.any\n"
"type sys._esys_132 *sys._esys_133\n"
"type sys._isys_731 {hchan sys._esys_132 elem sys.any}\n"
"type sys._esys_130 (sys._esys_131 sys._osys_729 sys._isys_731)\n"
"var !sys.chansend2 sys._esys_130\n"
"type sys._esys_135 {}\n"
"type sys._esys_136 *sys.uint8\n"
"type sys._osys_737 {sel sys._esys_136}\n"
"type sys._isys_739 {size sys.uint32}\n"
"type sys._esys_134 (sys._esys_135 sys._osys_737 sys._isys_739)\n"
"var !sys.newselect sys._esys_134\n"
"type sys._esys_138 {}\n"
"type sys._osys_744 {selected sys.bool}\n"
"type sys._esys_139 *sys.uint8\n"
"type sys._esys_141 1 sys.any\n"
"type sys._esys_140 *sys._esys_141\n"
"type sys._isys_746 {sel sys._esys_139 hchan sys._esys_140 elem sys.any}\n"
"type sys._esys_137 (sys._esys_138 sys._osys_744 sys._isys_746)\n"
"var !sys.selectsend sys._esys_137\n"
"type sys._esys_143 {}\n"
"type sys._esys_144 {}\n"
"type sys._esys_145 *sys.uint8\n"
"type sys._isys_735 {sel sys._esys_145}\n"
"type sys._esys_142 (sys._esys_143 sys._esys_144 sys._isys_735)\n"
"var !sys.selectgo sys._esys_142\n"
"type sys._esys_147 {}\n"
"type sys._esys_149 [] sys.any\n"
"type sys._esys_148 *sys._esys_149\n"
"type sys._osys_739 {ary sys._esys_148}\n"
"type sys._isys_741 {nel sys.uint32 cap sys.uint32 width sys.uint32}\n"
"type sys._esys_146 (sys._esys_147 sys._osys_739 sys._isys_741)\n"
"var !sys.newarray sys._esys_146\n"
"type sys._esys_151 {}\n"
"type sys._esys_153 [] sys.any\n"
"type sys._esys_152 *sys._esys_153\n"
"type sys._osys_748 {ary sys._esys_152}\n"
"type sys._osys_753 {selected sys.bool}\n"
"type sys._esys_144 *sys.uint8\n"
"type sys._esys_146 1 sys.any\n"
"type sys._esys_145 *sys._esys_146\n"
"type sys._esys_147 *sys.any\n"
"type sys._isys_755 {sel sys._esys_144 hchan sys._esys_145 elem sys._esys_147}\n"
"type sys._esys_142 (sys._esys_143 sys._osys_753 sys._isys_755)\n"
"var !sys.selectrecv sys._esys_142\n"
"type sys._esys_149 {}\n"
"type sys._esys_150 {}\n"
"type sys._esys_151 *sys.uint8\n"
"type sys._isys_762 {sel sys._esys_151}\n"
"type sys._esys_148 (sys._esys_149 sys._esys_150 sys._isys_762)\n"
"var !sys.selectgo sys._esys_148\n"
"type sys._esys_153 {}\n"
"type sys._esys_155 [] sys.any\n"
"type sys._esys_154 *sys._esys_155\n"
"type sys._isys_750 {old sys._esys_154 lb sys.uint32 hb sys.uint32 width sys.uint32}\n"
"type sys._esys_150 (sys._esys_151 sys._osys_748 sys._isys_750)\n"
"var !sys.arraysliced sys._esys_150\n"
"type sys._osys_766 {ary sys._esys_154}\n"
"type sys._isys_768 {nel sys.uint32 cap sys.uint32 width sys.uint32}\n"
"type sys._esys_152 (sys._esys_153 sys._osys_766 sys._isys_768)\n"
"var !sys.newarray sys._esys_152\n"
"type sys._esys_157 {}\n"
"type sys._esys_159 [] sys.any\n"
"type sys._esys_158 *sys._esys_159\n"
"type sys._osys_758 {ary sys._esys_158}\n"
"type sys._esys_160 *sys.any\n"
"type sys._isys_760 {old sys._esys_160 nel sys.uint32 lb sys.uint32 hb sys.uint32 width sys.uint32}\n"
"type sys._esys_156 (sys._esys_157 sys._osys_758 sys._isys_760)\n"
"var !sys.arrayslices sys._esys_156\n"
"type sys._esys_162 {}\n"
"type sys._esys_164 [] sys.any\n"
"type sys._esys_163 *sys._esys_164\n"
"type sys._osys_769 {ary sys._esys_163}\n"
"type sys._esys_165 *sys.any\n"
"type sys._isys_771 {old sys._esys_165 nel sys.uint32}\n"
"type sys._esys_161 (sys._esys_162 sys._osys_769 sys._isys_771)\n"
"var !sys.arrays2d sys._esys_161\n"
"type sys._esys_167 {}\n"
"type sys._osys_775 {ary sys._esys_158}\n"
"type sys._esys_161 [] sys.any\n"
"type sys._esys_160 *sys._esys_161\n"
"type sys._isys_777 {old sys._esys_160 lb sys.uint32 hb sys.uint32 width sys.uint32}\n"
"type sys._esys_156 (sys._esys_157 sys._osys_775 sys._isys_777)\n"
"var !sys.arraysliced sys._esys_156\n"
"type sys._esys_163 {}\n"
"type sys._esys_165 [] sys.any\n"
"type sys._esys_164 *sys._esys_165\n"
"type sys._osys_785 {ary sys._esys_164}\n"
"type sys._esys_166 *sys.any\n"
"type sys._isys_787 {old sys._esys_166 nel sys.uint32 lb sys.uint32 hb sys.uint32 width sys.uint32}\n"
"type sys._esys_162 (sys._esys_163 sys._osys_785 sys._isys_787)\n"
"var !sys.arrayslices sys._esys_162\n"
"type sys._esys_168 {}\n"
"type sys._esys_169 {}\n"
"type sys._esys_166 (sys._esys_167 sys._esys_168 sys._esys_169)\n"
"var !sys.gosched sys._esys_166\n"
"type sys._esys_171 {}\n"
"type sys._esys_172 {}\n"
"type sys._esys_170 [] sys.any\n"
"type sys._esys_169 *sys._esys_170\n"
"type sys._osys_796 {ary sys._esys_169}\n"
"type sys._esys_171 *sys.any\n"
"type sys._isys_798 {old sys._esys_171 nel sys.uint32}\n"
"type sys._esys_167 (sys._esys_168 sys._osys_796 sys._isys_798)\n"
"var !sys.arrays2d sys._esys_167\n"
"type sys._esys_173 {}\n"
"type sys._esys_170 (sys._esys_171 sys._esys_172 sys._esys_173)\n"
"var !sys.goexit sys._esys_170\n"
"type sys._esys_174 {}\n"
"type sys._esys_175 {}\n"
"type sys._osys_782 {_esys_779 sys.string _esys_780 sys.bool}\n"
"type sys._isys_784 {_esys_781 sys.string}\n"
"type sys._esys_174 (sys._esys_175 sys._osys_782 sys._isys_784)\n"
"var !sys.readfile sys._esys_174\n"
"type sys._esys_172 (sys._esys_173 sys._esys_174 sys._esys_175)\n"
"var !sys.gosched sys._esys_172\n"
"type sys._esys_177 {}\n"
"type sys._osys_791 {_esys_788 sys.bool}\n"
"type sys._isys_793 {_esys_789 sys.string _esys_790 sys.string}\n"
"type sys._esys_176 (sys._esys_177 sys._osys_791 sys._isys_793)\n"
"var !sys.writefile sys._esys_176\n"
"type sys._esys_178 {}\n"
"type sys._esys_179 {}\n"
"type sys._osys_803 {_esys_798 sys.int32 _esys_799 sys.int32}\n"
"type sys._esys_180 *sys.uint8\n"
"type sys._isys_805 {_esys_800 sys._esys_180 _esys_801 sys.int32 _esys_802 sys.int32}\n"
"type sys._esys_178 (sys._esys_179 sys._osys_803 sys._isys_805)\n"
"var !sys.bytestorune sys._esys_178\n"
"type sys._esys_182 {}\n"
"type sys._osys_816 {_esys_811 sys.int32 _esys_812 sys.int32}\n"
"type sys._isys_818 {_esys_813 sys.string _esys_814 sys.int32 _esys_815 sys.int32}\n"
"type sys._esys_181 (sys._esys_182 sys._osys_816 sys._isys_818)\n"
"var !sys.stringtorune sys._esys_181\n"
"type sys._esys_184 {}\n"
"type sys._esys_176 (sys._esys_177 sys._esys_178 sys._esys_179)\n"
"var !sys.goexit sys._esys_176\n"
"type sys._esys_181 {}\n"
"type sys._osys_809 {_esys_806 sys.string _esys_807 sys.bool}\n"
"type sys._isys_811 {_esys_808 sys.string}\n"
"type sys._esys_180 (sys._esys_181 sys._osys_809 sys._isys_811)\n"
"var !sys.readfile sys._esys_180\n"
"type sys._esys_183 {}\n"
"type sys._osys_818 {_esys_815 sys.bool}\n"
"type sys._isys_820 {_esys_816 sys.string _esys_817 sys.string}\n"
"type sys._esys_182 (sys._esys_183 sys._osys_818 sys._isys_820)\n"
"var !sys.writefile sys._esys_182\n"
"type sys._esys_185 {}\n"
"type sys._isys_824 {ms sys.int64}\n"
"type sys._esys_183 (sys._esys_184 sys._esys_185 sys._isys_824)\n"
"var !sys.sleep sys._esys_183\n"
"type sys._esys_187 {}\n"
"type sys._osys_830 {_esys_825 sys.int32 _esys_826 sys.int32}\n"
"type sys._esys_186 *sys.uint8\n"
"type sys._isys_832 {_esys_827 sys._esys_186 _esys_828 sys.int32 _esys_829 sys.int32}\n"
"type sys._esys_184 (sys._esys_185 sys._osys_830 sys._isys_832)\n"
"var !sys.bytestorune sys._esys_184\n"
"type sys._esys_188 {}\n"
"type sys._isys_829 {_esys_828 sys.int32}\n"
"type sys._esys_186 (sys._esys_187 sys._esys_188 sys._isys_829)\n"
"var !sys.exit sys._esys_186\n"
"type sys._osys_843 {_esys_838 sys.int32 _esys_839 sys.int32}\n"
"type sys._isys_845 {_esys_840 sys.string _esys_841 sys.int32 _esys_842 sys.int32}\n"
"type sys._esys_187 (sys._esys_188 sys._osys_843 sys._isys_845)\n"
"var !sys.stringtorune sys._esys_187\n"
"type sys._esys_190 {}\n"
"type sys._esys_191 {}\n"
"type sys._esys_192 {}\n"
"type sys._esys_189 (sys._esys_190 sys._esys_191 sys._esys_192)\n"
"type sys._isys_851 {ms sys.int64}\n"
"type sys._esys_189 (sys._esys_190 sys._esys_191 sys._isys_851)\n"
"var !sys.sleep sys._esys_189\n"
"type sys._esys_193 {}\n"
"type sys._esys_194 {}\n"
"type sys._isys_856 {_esys_855 sys.int32}\n"
"type sys._esys_192 (sys._esys_193 sys._esys_194 sys._isys_856)\n"
"var !sys.exit sys._esys_192\n"
"type sys._esys_196 {}\n"
"type sys._esys_197 {}\n"
"type sys._esys_198 {}\n"
"type sys._esys_195 (sys._esys_196 sys._esys_197 sys._esys_198)\n"
"))\n"
;

View File

@ -10,6 +10,14 @@ static Type* sw3(Node*, Type*);
static Node* curfn;
static Node* addtop;
enum
{
Inone,
I2T,
I2I,
T2I
};
// can this code branch reach the end
// without an undcontitional RETURN
// this is hard, so it is conservative
@ -494,15 +502,6 @@ loop:
case OINDREG:
goto ret;
case OS2I:
case OI2S:
case OI2I:
if(top != Erv)
goto nottop;
n->addable = 0;
walktype(n->left, Erv);
goto ret;
case OCONV:
if(top == Etop)
goto nottop;
@ -551,9 +550,9 @@ loop:
goto ret;
// interface and structure
r = isandss(n->type, l);
if(r != N) {
indir(n, r);
et = isandss(n->type, l);
if(et != Inone) {
indir(n, ifaceop(n->type, l, et));
goto ret;
}
@ -2454,18 +2453,7 @@ arrayop(Node *n, int top)
return r;
}
void
diagnamed(Type *t)
{
if(isinter(t))
if(t->sym == S)
yyerror("interface type must be named");
if(ismethod(t))
if(t->type == T || t->type->sym == S)
yyerror("structure type must be named");
}
Node*
int
isandss(Type *lt, Node *r)
{
Type *rt;
@ -2474,32 +2462,98 @@ isandss(Type *lt, Node *r)
rt = r->type;
if(isinter(lt)) {
if(ismethod(rt)) {
o = OS2I;
goto ret;
}
if(isinter(rt)) {
o = OI2I;
goto ret;
}
if(ismethod(rt))
return T2I;
if(isinter(rt) && !eqtype(rt, lt, 0))
return I2I;
}
if(ismethod(lt)) {
if(isinter(rt)) {
o = OI2S;
goto ret;
}
if(isinter(rt))
return I2T;
}
return N;
return Inone;
}
ret:
diagnamed(lt);
diagnamed(rt);
Node*
ifaceop(Type *tl, Node *n, int op)
{
Type *tr;
Node *r, *a, *on;
Sym *s;
n = nod(o, r, N);
n->type = lt;
return n;
tr = n->type;
switch(op) {
default:
fatal("ifaceop: unknown op %d\n", op);
case I2T:
// ifaceI2T(sigt *byte, iface interface{}) (ret any);
a = n; // interface
r = a;
s = signame(tl); // sigi
if(s == S)
fatal("ifaceop: signame I2T");
a = s->oname;
a = nod(OADDR, a, N);
r = list(a, r);
on = syslook("ifaceI2T", 1);
argtype(on, tl);
break;
case T2I:
// ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{});
a = n; // elem
r = a;
s = signame(tr); // sigt
if(s == S)
fatal("ifaceop: signame-1 T2I: %lT", tr);
a = s->oname;
a = nod(OADDR, a, N);
r = list(a, r);
s = signame(tl); // sigi
if(s == S) {
fatal("ifaceop: signame-2 T2I: %lT", tl);
}
a = s->oname;
a = nod(OADDR, a, N);
r = list(a, r);
on = syslook("ifaceT2I", 1);
argtype(on, tr);
break;
case I2I:
// ifaceI2I(sigi *byte, iface any-1) (ret any-2);
a = n; // interface
r = a;
s = signame(tr); // sigi
if(s == S)
fatal("ifaceop: signame I2I");
a = s->oname;
a = nod(OADDR, a, N);
r = list(a, r);
on = syslook("ifaceI2I", 1);
argtype(on, n->type);
argtype(on, tr);
break;
}
r = nod(OCALL, on, r);
walktype(r, Erv);
return r;
}
Node*
@ -2507,6 +2561,7 @@ convas(Node *n)
{
Node *l, *r;
Type *lt, *rt;
int et;
if(n->op != OAS)
fatal("convas: not OAS %O", n->op);
@ -2542,10 +2597,9 @@ convas(Node *n)
if(eqtype(lt, rt, 0))
goto out;
r = isandss(lt, r);
if(r != N) {
n->right = r;
walktype(n, Etop);
et = isandss(lt, r);
if(et != Inone) {
n->right = ifaceop(lt, r, et);
goto out;
}
@ -2994,11 +3048,15 @@ arraylit(Node *n)
fatal("arraylit: not array");
if(t->bound < 0) {
// make a shallow copy
t = typ(0);
*t = *n->type;
n->type = t;
// make it a closed array
r = listfirst(&saver, &n->left);
for(idx=0; r!=N; idx++)
r = listnext(&saver);
t = deep(t);
t->bound = idx;
}

View File

@ -20,6 +20,7 @@ LIBOFILES=\
runtime.$O\
map.$O\
chan.$O\
iface.$O\
array.$O\
print.$O\
rune.$O\

211
src/runtime/iface.c Normal file
View File

@ -0,0 +1,211 @@
// Copyright 2009 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.
#include "runtime.h"
typedef struct Sigt Sigt;
typedef struct Sigi Sigi;
typedef struct Map Map;
struct Sigt
{
byte* name;
uint32 hash;
void (*fun)(void);
};
struct Sigi
{
byte* name;
uint32 hash;
uint32 offset;
};
struct Map
{
Sigi* sigi;
Sigt* sigt;
Map* link;
int32 bad;
int32 unused;
void (*fun[])(void);
};
static Map* hash[1009];
static int32 debug = 0;
static Map*
hashmap(Sigi *si, Sigt *ss)
{
int32 ns, ni;
uint32 ihash, h;
byte *sname, *iname;
Map *m;
h = ((uint32)(uint64)si + (uint32)(uint64)ss) % nelem(hash);
for(m=hash[h]; m!=nil; m=m->link) {
if(m->sigi == si && m->sigt == ss) {
if(m->bad) {
throw("bad hashmap");
m = nil;
}
// prints("old hashmap\n");
return m;
}
}
ni = si[0].offset; // first word has size
m = mal(sizeof(*m) + ni*sizeof(m->fun[0]));
m->sigi = si;
m->sigt = ss;
ni = 1; // skip first word
ns = 0;
loop1:
// pick up next name from
// interface signature
iname = si[ni].name;
if(iname == nil) {
m->link = hash[h];
hash[h] = m;
// prints("new hashmap\n");
return m;
}
ihash = si[ni].hash;
loop2:
// pick up and comapre next name
// from structure signature
sname = ss[ns].name;
if(sname == nil) {
prints((int8*)iname);
prints(": ");
throw("hashmap: failed to find method");
m->bad = 1;
m->link = hash[h];
hash[h] = m;
return nil;
}
if(ihash != ss[ns].hash ||
strcmp(sname, iname) != 0) {
ns++;
goto loop2;
}
m->fun[si[ni].offset] = ss[ns].fun;
ni++;
goto loop1;
}
static void
printsigi(Sigi *si)
{
sys·printpointer(si);
}
static void
printsigt(Sigt *st)
{
sys·printpointer(st);
}
static void
printiface(Map *im, void *it)
{
prints("(");
sys·printpointer(im);
prints(",");
sys·printpointer(it);
prints(")");
}
// ifaceT2I(sigi *byte, sigt *byte, elem any) (ret interface{});
void
sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit)
{
if(debug) {
prints("T2I sigi=");
printsigi(si);
prints(" sigt=");
printsigt(st);
prints(" elem=");
sys·printpointer(elem);
prints("\n");
}
retim = hashmap(si, st);
retit = elem;
if(debug) {
prints("T2I ret=");
printiface(retim, retit);
prints("\n");
}
FLUSH(&retim);
}
// ifaceI2T(sigt *byte, iface interface{}) (ret any);
void
sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
{
if(debug) {
prints("I2T sigt=");
printsigt(st);
prints(" iface=");
printiface(im, it);
prints("\n");
}
if(im == nil)
throw("ifaceI2T: nil map");
if(im->sigt != st)
throw("ifaceI2T: wrong type");
ret = it;
if(debug) {
prints("I2T ret=");
sys·printpointer(ret);
prints("\n");
}
FLUSH(&ret);
}
// ifaceI2I(sigi *byte, iface interface{}) (ret interface{});
void
sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit)
{
if(debug) {
prints("I2I sigi=");
sys·printpointer(si);
prints(" iface=");
printiface(im, it);
prints("\n");
}
if(im == nil) {
throw("ifaceI2I: nil map");
return;
}
retit = it;
retim = im;
if(im->sigi != si)
retim = hashmap(si, im->sigt);
if(debug) {
prints("I2I ret=");
printiface(retim, retit);
prints("\n");
}
FLUSH(&retim);
}

View File

@ -4,7 +4,6 @@
#include "runtime.h"
int32 debug = 0;
int32 panicking = 0;
void
@ -146,175 +145,6 @@ sys·mal(uint32 n, uint8 *ret)
FLUSH(&ret);
}
static Map* hash[1009];
static Map*
hashmap(Sigi *si, Sigs *ss)
{
int32 ns, ni;
uint32 ihash, h;
byte *sname, *iname;
Map *m;
h = ((uint32)(uint64)si + (uint32)(uint64)ss) % nelem(hash);
for(m=hash[h]; m!=nil; m=m->link) {
if(m->si == si && m->ss == ss) {
if(m->bad) {
throw("bad hashmap");
m = nil;
}
// prints("old hashmap\n");
return m;
}
}
ni = si[0].offset; // first word has size
m = mal(sizeof(*m) + ni*sizeof(m->fun[0]));
m->si = si;
m->ss = ss;
ni = 1; // skip first word
ns = 0;
loop1:
// pick up next name from
// interface signature
iname = si[ni].name;
if(iname == nil) {
m->link = hash[h];
hash[h] = m;
// prints("new hashmap\n");
return m;
}
ihash = si[ni].hash;
loop2:
// pick up and comapre next name
// from structure signature
sname = ss[ns].name;
if(sname == nil) {
prints((int8*)iname);
prints(": ");
throw("hashmap: failed to find method");
m->bad = 1;
m->link = hash[h];
hash[h] = m;
return nil;
}
if(ihash != ss[ns].hash ||
strcmp(sname, iname) != 0) {
ns++;
goto loop2;
}
m->fun[si[ni].offset] = ss[ns].fun;
ni++;
goto loop1;
}
void
sys·ifaces2i(Sigi *si, Sigs *ss, Map *m, void *s)
{
if(debug) {
prints("s2i sigi=");
sys·printpointer(si);
prints(" sigs=");
sys·printpointer(ss);
prints(" s=");
sys·printpointer(s);
}
if(s == nil) {
throw("ifaces2i: nil pointer");
m = nil;
FLUSH(&m);
return;
}
m = hashmap(si, ss);
if(debug) {
prints(" returning m=");
sys·printpointer(m);
prints(" s=");
sys·printpointer(s);
prints("\n");
dump((byte*)m, 64);
}
FLUSH(&m);
}
void
sys·ifacei2i(Sigi *si, Map *m, void *s)
{
if(debug) {
prints("i2i sigi=");
sys·printpointer(si);
prints(" m=");
sys·printpointer(m);
prints(" s=");
sys·printpointer(s);
}
if(m == nil) {
throw("ifacei2i: nil map");
s = nil;
FLUSH(&s);
return;
}
if(m->si == nil) {
throw("ifacei2i: nil pointer");
return;
}
if(m->si != si) {
m = hashmap(si, m->ss);
FLUSH(&m);
}
if(debug) {
prints(" returning m=");
sys·printpointer(m);
prints(" s=");
sys·printpointer(s);
prints("\n");
dump((byte*)m, 64);
}
}
void
sys·ifacei2s(Sigs *ss, Map *m, void *s)
{
if(debug) {
prints("i2s m=");
sys·printpointer(m);
prints(" s=");
sys·printpointer(s);
prints("\n");
}
if(m == nil) {
throw("ifacei2s: nil map");
s = nil;
FLUSH(&s);
return;
}
if(m->ss != ss) {
dump((byte*)m, 64);
throw("ifacei2s: wrong pointer");
s = nil;
FLUSH(&s);
return;
}
}
enum
{
NANEXP = 2047<<20,

View File

@ -34,9 +34,6 @@ typedef double float64;
typedef uint8 bool;
typedef uint8 byte;
typedef struct String *string;
typedef struct Sigs Sigs;
typedef struct Sigi Sigi;
typedef struct Map Map;
typedef struct Array Array;
typedef struct Gobuf Gobuf;
typedef struct G G;
@ -95,18 +92,6 @@ struct String
int32 len;
byte str[1];
};
struct Sigs
{
byte* name;
uint32 hash;
void (*fun)(void);
};
struct Sigi
{
byte* name;
uint32 hash;
uint32 offset;
};
struct Array
{ // must not move anything
@ -115,15 +100,6 @@ struct Array
uint32 cap; // allocate3d number of elements
byte b[8]; // actual array - may not be contig
};
struct Map
{
Sigi* si;
Sigs* ss;
Map* link;
int32 bad;
int32 unused;
void (*fun[])(void);
};
struct Gobuf
{
byte* SP;
@ -305,9 +281,6 @@ void sys·cmpstring(string, string, int32);
void sys·slicestring(string, int32, int32, string);
void sys·indexstring(string, int32, byte);
void sys·intstring(int64, string);
void sys·ifaces2i(Sigi*, Sigs*, Map*, void*);
void sys·ifacei2i(Sigi*, Map*, void*);
void sys·ifacei2s(Sigs*, Map*, void*);
/*
* User go-called