OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "go.h" | 5 #include "go.h" |
6 | 6 |
7 /* | 7 /* |
8 * runtime interface and reflection data structures | 8 * runtime interface and reflection data structures |
9 */ | 9 */ |
10 | 10 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 && f->embedded != 2 && !isifacemethod(f->type)) | 167 && f->embedded != 2 && !isifacemethod(f->type)) |
168 continue; | 168 continue; |
169 | 169 |
170 b = mal(sizeof(*b)); | 170 b = mal(sizeof(*b)); |
171 b->link = a; | 171 b->link = a; |
172 a = b; | 172 a = b; |
173 | 173 |
174 a->name = method->name; | 174 a->name = method->name; |
175 a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type); | 175 a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type); |
176 if(!exportname(a->name)) { | 176 if(!exportname(a->name)) { |
177 » » » a->package = method->package; | 177 » » » a->pkg = method->pkg; |
178 » » » a->hash += PRIME10*stringhash(a->package); | 178 » » » a->hash += PRIME10*stringhash(a->pkg->name); |
179 } | 179 } |
180 a->perm = o++; | 180 a->perm = o++; |
181 a->isym = methodsym(method, it); | 181 a->isym = methodsym(method, it); |
182 a->tsym = methodsym(method, t); | 182 a->tsym = methodsym(method, t); |
183 a->type = methodfunc(f->type); | 183 a->type = methodfunc(f->type); |
184 | 184 |
185 if(!(a->isym->flags & SymSiggen)) { | 185 if(!(a->isym->flags & SymSiggen)) { |
186 a->isym->flags |= SymSiggen; | 186 a->isym->flags |= SymSiggen; |
187 if(!eqtype(this, it)) { | 187 if(!eqtype(this, it)) { |
188 if(oldlist == nil) | 188 if(oldlist == nil) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 fatal("imethods: not field"); | 243 fatal("imethods: not field"); |
244 if(f->type->etype != TFUNC || f->sym == nil) | 244 if(f->type->etype != TFUNC || f->sym == nil) |
245 continue; | 245 continue; |
246 b = mal(sizeof(*b)); | 246 b = mal(sizeof(*b)); |
247 b->link = a; | 247 b->link = a; |
248 a = b; | 248 a = b; |
249 | 249 |
250 a->name = f->sym->name; | 250 a->name = f->sym->name; |
251 a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type); | 251 a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type); |
252 if(!exportname(a->name)) { | 252 if(!exportname(a->name)) { |
253 » » » a->package = f->sym->package; | 253 » » » a->pkg = f->sym->pkg; |
254 » » » a->hash += PRIME10*stringhash(a->package); | 254 » » » a->hash += PRIME10*stringhash(a->pkg->name); |
255 } | 255 } |
256 a->perm = o++; | 256 a->perm = o++; |
257 a->offset = 0; | 257 a->offset = 0; |
258 a->type = methodfunc(f->type); | 258 a->type = methodfunc(f->type); |
259 } | 259 } |
260 | 260 |
261 return lsort(a, sigcmp); | 261 return lsort(a, sigcmp); |
262 } | 262 } |
263 | 263 |
| 264 static int |
| 265 dgopkgpath(Sym *s, int ot, Pkg *pkg) |
| 266 { |
| 267 if(pkg == nil) |
| 268 return dgostringptr(s, ot, nil); |
| 269 |
| 270 // PGNS: This needs to be import path instead of pkg->name, |
| 271 // but we need to figure out how to fill it in during 6l when |
| 272 // trying to refer to localpkg. |
| 273 return dgostringptr(s, ot, pkg->name); |
| 274 } |
| 275 |
| 276 |
264 /* | 277 /* |
265 * uncommonType | 278 * uncommonType |
266 * ../../pkg/runtime/type.go:/uncommonType | 279 * ../../pkg/runtime/type.go:/uncommonType |
267 */ | 280 */ |
268 static Sym* | 281 static Sym* |
269 dextratype(Type *t) | 282 dextratype(Type *t) |
270 { | 283 { |
271 int ot, n; | 284 int ot, n; |
272 char *p; | 285 char *p; |
273 Sym *s; | 286 Sym *s; |
274 Sig *a, *m; | 287 Sig *a, *m; |
275 | 288 |
276 m = methods(t); | 289 m = methods(t); |
277 if(t->sym == nil && m == nil) | 290 if(t->sym == nil && m == nil) |
278 return nil; | 291 return nil; |
279 | 292 |
280 n = 0; | 293 n = 0; |
281 for(a=m; a; a=a->link) { | 294 for(a=m; a; a=a->link) { |
282 dtypesym(a->type); | 295 dtypesym(a->type); |
283 n++; | 296 n++; |
284 } | 297 } |
285 | 298 |
286 » p = smprint("%#-T", t); | 299 » p = smprint("_.%#T", t); |
287 » s = pkglookup(p, "extratype"); | 300 » s = pkglookup(p, typepkg); |
288 ot = 0; | 301 ot = 0; |
289 if(t->sym) { | 302 if(t->sym) { |
290 ot = dgostringptr(s, ot, t->sym->name); | 303 ot = dgostringptr(s, ot, t->sym->name); |
291 if(t != types[t->etype]) | 304 if(t != types[t->etype]) |
292 » » » ot = dgostringptr(s, ot, t->sym->package); | 305 » » » ot = dgopkgpath(s, ot, t->sym->pkg); |
293 else | 306 else |
294 ot = dgostringptr(s, ot, nil); | 307 ot = dgostringptr(s, ot, nil); |
295 } else { | 308 } else { |
296 ot = dgostringptr(s, ot, nil); | 309 ot = dgostringptr(s, ot, nil); |
297 ot = dgostringptr(s, ot, nil); | 310 ot = dgostringptr(s, ot, nil); |
298 } | 311 } |
299 | 312 |
300 // slice header | 313 // slice header |
301 ot = dsymptr(s, ot, s, ot + widthptr + 2*4); | 314 ot = dsymptr(s, ot, s, ot + widthptr + 2*4); |
302 ot = duint32(s, ot, n); | 315 ot = duint32(s, ot, n); |
303 ot = duint32(s, ot, n); | 316 ot = duint32(s, ot, n); |
304 | 317 |
305 // methods | 318 // methods |
306 for(a=m; a; a=a->link) { | 319 for(a=m; a; a=a->link) { |
307 // method | 320 // method |
308 // ../../pkg/runtime/type.go:/method | 321 // ../../pkg/runtime/type.go:/method |
309 ot = duint32(s, ot, a->hash); | 322 ot = duint32(s, ot, a->hash); |
310 ot = rnd(ot, widthptr); | 323 ot = rnd(ot, widthptr); |
311 ot = dgostringptr(s, ot, a->name); | 324 ot = dgostringptr(s, ot, a->name); |
312 » » ot = dgostringptr(s, ot, a->package); | 325 » » ot = dgopkgpath(s, ot, a->pkg); |
313 ot = dsymptr(s, ot, dtypesym(a->type), 0); | 326 ot = dsymptr(s, ot, dtypesym(a->type), 0); |
314 if(a->isym) | 327 if(a->isym) |
315 ot = dsymptr(s, ot, a->isym, 0); | 328 ot = dsymptr(s, ot, a->isym, 0); |
316 else | 329 else |
317 ot = duintptr(s, ot, 0); | 330 ot = duintptr(s, ot, 0); |
318 if(a->tsym) | 331 if(a->tsym) |
319 ot = dsymptr(s, ot, a->tsym, 0); | 332 ot = dsymptr(s, ot, a->tsym, 0); |
320 else | 333 else |
321 ot = duintptr(s, ot, 0); | 334 ot = duintptr(s, ot, 0); |
322 } | 335 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 fatal("typestruct %lT", t); | 441 fatal("typestruct %lT", t); |
429 return nil; // silence gcc | 442 return nil; // silence gcc |
430 } | 443 } |
431 | 444 |
432 if(isslice(t)) | 445 if(isslice(t)) |
433 name = "*runtime.SliceType"; | 446 name = "*runtime.SliceType"; |
434 | 447 |
435 if(isptr[et] && t->type->etype == TANY) | 448 if(isptr[et] && t->type->etype == TANY) |
436 name = "*runtime.UnsafePointerType"; | 449 name = "*runtime.UnsafePointerType"; |
437 | 450 |
438 » return pkglookup(name, "type"); | 451 » return pkglookup(name, typepkg); |
439 } | 452 } |
440 | 453 |
441 static int | 454 static int |
442 haspointers(Type *t) | 455 haspointers(Type *t) |
443 { | 456 { |
444 Type *t1; | 457 Type *t1; |
445 | 458 |
446 switch(t->etype) { | 459 switch(t->etype) { |
447 case TINT: | 460 case TINT: |
448 case TUINT: | 461 case TUINT: |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 return ot; | 556 return ot; |
544 } | 557 } |
545 | 558 |
546 Sym* | 559 Sym* |
547 typesym(Type *t) | 560 typesym(Type *t) |
548 { | 561 { |
549 char *p; | 562 char *p; |
550 Sym *s; | 563 Sym *s; |
551 | 564 |
552 p = smprint("%#-T", t); | 565 p = smprint("%#-T", t); |
553 » s = pkglookup(p, "type"); | 566 » s = pkglookup(p, typepkg); |
554 free(p); | 567 free(p); |
555 return s; | 568 return s; |
556 } | 569 } |
557 | 570 |
558 Node* | 571 Node* |
559 typename(Type *t) | 572 typename(Type *t) |
560 { | 573 { |
561 Sym *s; | 574 Sym *s; |
562 Node *n; | 575 Node *n; |
563 | 576 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 // emit the type structures for int, float, etc. | 619 // emit the type structures for int, float, etc. |
607 t1 = T; | 620 t1 = T; |
608 if(isptr[t->etype]) | 621 if(isptr[t->etype]) |
609 t1 = t->type; | 622 t1 = t->type; |
610 tsym = S; | 623 tsym = S; |
611 if(t1) | 624 if(t1) |
612 tsym = t1->sym; | 625 tsym = t1->sym; |
613 else | 626 else |
614 tsym = t->sym; | 627 tsym = t->sym; |
615 | 628 |
616 » if(strcmp(package, "runtime") == 0) { | 629 » // PGNS: Fixme |
| 630 » if(strcmp(localpkg->name, "runtime") == 0) { |
617 if(t == types[t->etype]) | 631 if(t == types[t->etype]) |
618 goto ok; | 632 goto ok; |
619 if(t1 && t1 == types[t1->etype]) | 633 if(t1 && t1 == types[t1->etype]) |
620 goto ok; | 634 goto ok; |
621 if(t1 && t1->etype == tptr && t1->type->etype == TANY) | 635 if(t1 && t1->etype == tptr && t1->type->etype == TANY) |
622 goto ok; | 636 goto ok; |
623 } | 637 } |
624 | 638 |
625 // named types from other files are defined in those files | 639 // named types from other files are defined in those files |
626 if(t->sym && !t->local) | 640 if(t->sym && !t->local) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // ../../pkg/runtime/type.go:/InterfaceType | 709 // ../../pkg/runtime/type.go:/InterfaceType |
696 ot = dcommontype(s, ot, t); | 710 ot = dcommontype(s, ot, t); |
697 ot = dsymptr(s, ot, s, ot+widthptr+2*4); | 711 ot = dsymptr(s, ot, s, ot+widthptr+2*4); |
698 ot = duint32(s, ot, n); | 712 ot = duint32(s, ot, n); |
699 ot = duint32(s, ot, n); | 713 ot = duint32(s, ot, n); |
700 for(a=m; a; a=a->link) { | 714 for(a=m; a; a=a->link) { |
701 // ../../pkg/runtime/type.go:/imethod | 715 // ../../pkg/runtime/type.go:/imethod |
702 ot = duint32(s, ot, a->hash); | 716 ot = duint32(s, ot, a->hash); |
703 ot = duint32(s, ot, a->perm); | 717 ot = duint32(s, ot, a->perm); |
704 ot = dgostringptr(s, ot, a->name); | 718 ot = dgostringptr(s, ot, a->name); |
705 » » » ot = dgostringptr(s, ot, a->package); | 719 » » » ot = dgopkgpath(s, ot, a->pkg); |
706 ot = dsymptr(s, ot, dtypesym(a->type), 0); | 720 ot = dsymptr(s, ot, dtypesym(a->type), 0); |
707 } | 721 } |
708 break; | 722 break; |
709 | 723 |
710 case TMAP: | 724 case TMAP: |
711 // ../../pkg/runtime/type.go:/MapType | 725 // ../../pkg/runtime/type.go:/MapType |
712 s1 = dtypesym(t->down); | 726 s1 = dtypesym(t->down); |
713 s2 = dtypesym(t->type); | 727 s2 = dtypesym(t->type); |
714 ot = dcommontype(s, ot, t); | 728 ot = dcommontype(s, ot, t); |
715 ot = dsymptr(s, ot, s1, 0); | 729 ot = dsymptr(s, ot, s1, 0); |
(...skipping 24 matching lines...) Expand all Loading... |
740 ot = dsymptr(s, ot, s, ot+widthptr+2*4); | 754 ot = dsymptr(s, ot, s, ot+widthptr+2*4); |
741 ot = duint32(s, ot, n); | 755 ot = duint32(s, ot, n); |
742 ot = duint32(s, ot, n); | 756 ot = duint32(s, ot, n); |
743 for(t1=t->type; t1!=T; t1=t1->down) { | 757 for(t1=t->type; t1!=T; t1=t1->down) { |
744 // ../../pkg/runtime/type.go:/structField | 758 // ../../pkg/runtime/type.go:/structField |
745 if(t1->sym && !t1->embedded) { | 759 if(t1->sym && !t1->embedded) { |
746 ot = dgostringptr(s, ot, t1->sym->name); | 760 ot = dgostringptr(s, ot, t1->sym->name); |
747 if(exportname(t1->sym->name)) | 761 if(exportname(t1->sym->name)) |
748 ot = dgostringptr(s, ot, nil); | 762 ot = dgostringptr(s, ot, nil); |
749 else | 763 else |
750 » » » » » ot = dgostringptr(s, ot, t1->sym->packag
e); | 764 » » » » » ot = dgopkgpath(s, ot, t1->sym->pkg); |
751 } else { | 765 } else { |
752 ot = dgostringptr(s, ot, nil); | 766 ot = dgostringptr(s, ot, nil); |
753 ot = dgostringptr(s, ot, nil); | 767 ot = dgostringptr(s, ot, nil); |
754 } | 768 } |
755 ot = dsymptr(s, ot, dtypesym(t1->type), 0); | 769 ot = dsymptr(s, ot, dtypesym(t1->type), 0); |
756 ot = dgostrlitptr(s, ot, t1->note); | 770 ot = dgostrlitptr(s, ot, t1->note); |
757 ot = duintptr(s, ot, t1->width); // field offset | 771 ot = duintptr(s, ot, t1->width); // field offset |
758 } | 772 } |
759 break; | 773 break; |
760 } | 774 } |
(...skipping 28 matching lines...) Expand all Loading... |
789 if(t->sym && !isptr[t->etype]) | 803 if(t->sym && !isptr[t->etype]) |
790 dtypesym(ptrto(t)); | 804 dtypesym(ptrto(t)); |
791 } | 805 } |
792 | 806 |
793 // do basic types if compiling package runtime. | 807 // do basic types if compiling package runtime. |
794 // they have to be in at least one package, | 808 // they have to be in at least one package, |
795 // and reflect is always loaded implicitly, | 809 // and reflect is always loaded implicitly, |
796 // so this is as good as any. | 810 // so this is as good as any. |
797 // another possible choice would be package main, | 811 // another possible choice would be package main, |
798 // but using runtime means fewer copies in .6 files. | 812 // but using runtime means fewer copies in .6 files. |
799 » if(strcmp(package, "runtime") == 0) { | 813 » if(strcmp(localpkg->name, "runtime") == 0) {» // PGNS: fixme |
800 for(i=1; i<=TBOOL; i++) | 814 for(i=1; i<=TBOOL; i++) |
801 dtypesym(ptrto(types[i])); | 815 dtypesym(ptrto(types[i])); |
802 dtypesym(ptrto(types[TSTRING])); | 816 dtypesym(ptrto(types[TSTRING])); |
803 dtypesym(typ(TDDD)); | 817 dtypesym(typ(TDDD)); |
804 » » dtypesym(ptrto(pkglookup("Pointer", "unsafe")->def->type)); | 818 » » dtypesym(ptrto(pkglookup("Pointer", unsafepkg)->def->type)); |
805 } | 819 } |
806 } | 820 } |
OLD | NEW |