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) {
35 if(((uintptr_t)e.__type_descriptor&reflectFlags) != 0)
36 runtime_panicstring("invalid interface value");
38 ok = ret.__type_descriptor != nil;
41 // Convert a non-empty interface to an empty interface.
42 func ifaceI2E2(i interface) (ret empty_interface, ok bool) {
43 if (i.__methods == nil) {
44 ret.__type_descriptor = nil;
48 ret.__type_descriptor = i.__methods[0];
49 ret.__object = i.__object;
54 // Convert an empty interface to a non-empty interface.
55 func ifaceE2I2(inter *descriptor, e empty_interface) (ret interface, ok bool) {
56 if(((uintptr_t)e.__type_descriptor&reflectFlags) != 0)
57 runtime_panicstring("invalid interface value");
58 if (e.__type_descriptor == nil) {
63 ret.__methods = __go_convert_interface_2(inter,
66 ret.__object = e.__object;
67 ok = ret.__methods != nil;
71 // Convert a non-empty interface to a non-empty interface.
72 func ifaceI2I2(inter *descriptor, i interface) (ret interface, ok bool) {
73 if (i.__methods == nil) {
78 ret.__methods = __go_convert_interface_2(inter,
80 ret.__object = i.__object;
81 ok = ret.__methods != nil;
85 // Convert an empty interface to a pointer type.
86 func ifaceE2T2P(inter *descriptor, e empty_interface) (ret *void, ok bool) {
87 if(((uintptr_t)e.__type_descriptor&reflectFlags) != 0)
88 runtime_panicstring("invalid interface value");
89 if (!__go_type_descriptors_equal(inter, e.__type_descriptor)) {
98 // Convert a non-empty interface to a pointer type.
99 func ifaceI2T2P(inter *descriptor, i interface) (ret *void, ok bool) {
100 if (i.__methods == nil
101 || !__go_type_descriptors_equal(inter, i.__methods[0])) {
110 // Convert an empty interface to a non-pointer type.
111 func ifaceE2T2(inter *descriptor, e empty_interface, ret *void) (ok bool) {
112 if(((uintptr_t)e.__type_descriptor&reflectFlags) != 0)
113 runtime_panicstring("invalid interface value");
114 if (!__go_type_descriptors_equal(inter, e.__type_descriptor)) {
115 __builtin_memset(ret, 0, inter->__size);
118 __builtin_memcpy(ret, e.__object, inter->__size);
123 // Convert a non-empty interface to a non-pointer type.
124 func ifaceI2T2(inter *descriptor, i interface, ret *void) (ok bool) {
125 if (i.__methods == nil
126 || !__go_type_descriptors_equal(inter, i.__methods[0])) {
127 __builtin_memset(ret, 0, inter->__size);
130 __builtin_memcpy(ret, i.__object, inter->__size);
135 // Return whether we can convert an interface to a type.
136 func ifaceI2Tp(to *descriptor, from *descriptor) (ok bool) {
137 ok = __go_can_convert_to_interface(to, from);