LEFT | RIGHT |
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 "runtime.h" | 5 #include "runtime.h" |
6 #include "type.h" | 6 #include "type.h" |
7 | 7 |
8 //static Lock debuglock; | 8 //static Lock debuglock; |
9 | 9 |
10 static void vprintf(int8*, byte*); | 10 static void vprintf(int8*, byte*); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 { | 342 { |
343 write(fd, " ", 1); | 343 write(fd, " ", 1); |
344 } | 344 } |
345 | 345 |
346 void | 346 void |
347 ·printnl(void) | 347 ·printnl(void) |
348 { | 348 { |
349 write(fd, "\n", 1); | 349 write(fd, "\n", 1); |
350 } | 350 } |
351 | 351 |
| 352 // print an empty interface, for use by panic. |
| 353 // this could be arbitrarily complex in general, |
| 354 // so we pick off only a few important cases: |
| 355 // int, string, and values with a String() string method. |
352 void | 356 void |
353 printany(Eface e) | 357 printany(Eface e) |
354 { | 358 { |
355 int32 i; | 359 int32 i; |
356 FuncType *ft; | 360 FuncType *ft; |
357 Method *m; | 361 Method *m; |
358 String s; | 362 String s; |
359 Type *rt; | 363 Type *rt; |
360 UncommonType *x; | 364 UncommonType *x; |
361 | 365 |
(...skipping 13 matching lines...) Expand all Loading... |
375 (ft = (FuncType*)m->mtyp)->in.len == 0 && | 379 (ft = (FuncType*)m->mtyp)->in.len == 0 && |
376 ft->out.len == 1 && | 380 ft->out.len == 1 && |
377 // Found single output. Is it string? | 381 // Found single output. Is it string? |
378 // Only base types have name != nil but pkgPath == ni
l. | 382 // Only base types have name != nil but pkgPath == ni
l. |
379 (rt = *(Type**)ft->out.array)->kind == KindString && | 383 (rt = *(Type**)ft->out.array)->kind == KindString && |
380 rt->x != nil && | 384 rt->x != nil && |
381 rt->x->name != nil && rt->x->pkgPath == nil) { | 385 rt->x->name != nil && rt->x->pkgPath == nil) { |
382 // Found the method! | 386 // Found the method! |
383 // Have to use assembly to call it | 387 // Have to use assembly to call it |
384 // and save the return value. | 388 // and save the return value. |
385 » » » » callstring(m->ifn, e.data, &s); | 389 » » » » callString(m->ifn, e.data, &s); |
386 ·printstring(s); | 390 ·printstring(s); |
387 return; | 391 return; |
388 } | 392 } |
389 } | 393 } |
390 } | 394 } |
391 | 395 |
392 » switch(e.type->kind) { | 396 » switch(e.type->kind & ~KindNoPointers) { |
393 case KindInt: | 397 case KindInt: |
394 mcpy((byte*)&i, (byte*)&e.data, sizeof(i)); | 398 mcpy((byte*)&i, (byte*)&e.data, sizeof(i)); |
395 ·printint(i); | 399 ·printint(i); |
396 break; | 400 break; |
397 | 401 |
398 case KindString: | 402 case KindString: |
399 ·printstring(*(String*)e.data); | 403 ·printstring(*(String*)e.data); |
400 break; | 404 break; |
401 | 405 |
402 default: | 406 default: |
403 // Could print the other numeric types, | 407 // Could print the other numeric types, |
404 // but that's overkill: good panics have | 408 // but that's overkill: good panics have |
405 // a string method anyway. | 409 // a string method anyway. |
406 ·printstring(*e.type->string); | 410 ·printstring(*e.type->string); |
407 write(fd, "(???)", 5); | 411 write(fd, "(???)", 5); |
408 break; | 412 break; |
409 } | 413 } |
410 | 414 |
411 } | 415 } |
LEFT | RIGHT |