1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 typedef struct __go_type_descriptor descriptor;
11 typedef const struct __go_type_descriptor const_descriptor;
12 typedef struct __go_interface interface;
13 typedef struct __go_empty_interface empty_interface;
15 // Compare two type descriptors.
16 func ifacetypeeq(a *descriptor, b *descriptor) (eq bool) {
17 eq = __go_type_descriptors_equal(a, b);
20 // Return the descriptor for an empty interface type.n
21 func efacetype(e empty_interface) (d *const_descriptor) {
22 return e.__type_descriptor;
25 // Return the descriptor for a non-empty interface type.
26 func ifacetype(i interface) (d *const_descriptor) {
27 if (i.__methods == nil) {
33 // Convert an empty interface to an empty interface.
34 func ifaceE2E2(e empty_interface) (ret empty_interface, ok bool) {
36 ok = ret.__type_descriptor != nil;
39 // Convert a non-empty interface to an empty interface.
40 func ifaceI2E2(i interface) (ret empty_interface, ok bool) {
41 if (i.__methods == nil) {
42 ret.__type_descriptor = nil;
46 ret.__type_descriptor = i.__methods[0];
47 ret.__object = i.__object;
52 // Convert an empty interface to a non-empty interface.
53 func ifaceE2I2(inter *descriptor, e empty_interface) (ret interface, ok bool) {
54 if (e.__type_descriptor == nil) {
59 ret.__methods = __go_convert_interface_2(inter,
62 ret.__object = e.__object;
63 ok = ret.__methods != nil;
67 // Convert a non-empty interface to a non-empty interface.
68 func ifaceI2I2(inter *descriptor, i interface) (ret interface, ok bool) {
69 if (i.__methods == nil) {
74 ret.__methods = __go_convert_interface_2(inter,
76 ret.__object = i.__object;
77 ok = ret.__methods != nil;
81 // Convert an empty interface to a pointer type.
82 func ifaceE2T2P(inter *descriptor, e empty_interface) (ret *void, ok bool) {
83 if (!__go_type_descriptors_equal(inter, e.__type_descriptor)) {
92 // Convert a non-empty interface to a pointer type.
93 func ifaceI2T2P(inter *descriptor, i interface) (ret *void, ok bool) {
94 if (i.__methods == nil
95 || !__go_type_descriptors_equal(inter, i.__methods[0])) {
104 // Convert an empty interface to a non-pointer type.
105 func ifaceE2T2(inter *descriptor, e empty_interface, ret *void) (ok bool) {
106 if (!__go_type_descriptors_equal(inter, e.__type_descriptor)) {
107 __builtin_memset(ret, 0, inter->__size);
110 __builtin_memcpy(ret, e.__object, inter->__size);
115 // Convert a non-empty interface to a non-pointer type.
116 func ifaceI2T2(inter *descriptor, i interface, ret *void) (ok bool) {
117 if (i.__methods == nil
118 || !__go_type_descriptors_equal(inter, i.__methods[0])) {
119 __builtin_memset(ret, 0, inter->__size);
122 __builtin_memcpy(ret, i.__object, inter->__size);
127 // Return whether we can convert an interface to a type.
128 func ifaceI2Tp(to *descriptor, from *descriptor) (ok bool) {
129 ok = __go_can_convert_to_interface(to, from);