@@ -38,6 +38,10 @@ var Method *types.Type
38
38
var StructField * types.Type
39
39
var UncommonType * types.Type
40
40
41
+ // Type switches and asserts
42
+ var InterfaceSwitch * types.Type
43
+ var TypeAssert * types.Type
44
+
41
45
func Init () {
42
46
// Note: this has to be called explicitly instead of being
43
47
// an init function so it runs after the types package has
@@ -57,6 +61,9 @@ func Init() {
57
61
StructField = fromReflect (reflect .TypeOf (abi.StructField {}))
58
62
UncommonType = fromReflect (reflect .TypeOf (abi.UncommonType {}))
59
63
64
+ InterfaceSwitch = fromReflect (reflect .TypeOf (abi.InterfaceSwitch {}))
65
+ TypeAssert = fromReflect (reflect .TypeOf (abi.TypeAssert {}))
66
+
60
67
// Make sure abi functions are correct. These functions are used
61
68
// by the linker which doesn't have the ability to do type layout,
62
69
// so we check the functions it uses here.
@@ -87,6 +94,8 @@ func fromReflect(rt reflect.Type) *types.Type {
87
94
// must be CalcSize'd before using.
88
95
func reflectToType (rt reflect.Type ) * types.Type {
89
96
switch rt .Kind () {
97
+ case reflect .Bool :
98
+ return types .Types [types .TBOOL ]
90
99
case reflect .Int :
91
100
return types .Types [types .TINT ]
92
101
case reflect .Int32 :
@@ -181,6 +190,12 @@ func (c Cursor) WriteInt32(val int32) {
181
190
}
182
191
objw .Uint32 (c .lsym , int (c .offset ), uint32 (val ))
183
192
}
193
+ func (c Cursor ) WriteBool (val bool ) {
194
+ if c .typ .Kind () != types .TBOOL {
195
+ base .Fatalf ("can't write bool, it has kind %s" , c .typ .Kind ())
196
+ }
197
+ objw .Bool (c .lsym , int (c .offset ), val )
198
+ }
184
199
185
200
// WriteSymPtrOff writes a "pointer" to the given symbol. The symbol
186
201
// is encoded as a uint32 offset from the start of the section.
@@ -255,3 +270,14 @@ func (a ArrayCursor) Elem(i int) Cursor {
255
270
}
256
271
return Cursor {lsym : a .c .lsym , offset : a .c .offset + int64 (i )* a .c .typ .Size (), typ : a .c .typ }
257
272
}
273
+
274
+ // ModifyArray converts a cursor pointing at a type [k]T to a cursor pointing
275
+ // at a type [n]T.
276
+ // Also returns the size delta, aka (n-k)*sizeof(T).
277
+ func (c Cursor ) ModifyArray (n int ) (ArrayCursor , int64 ) {
278
+ if c .typ .Kind () != types .TARRAY {
279
+ base .Fatalf ("can't call ModifyArray on non-array %v" , c .typ )
280
+ }
281
+ k := c .typ .NumElem ()
282
+ return ArrayCursor {c : Cursor {lsym : c .lsym , offset : c .offset , typ : c .typ .Elem ()}, n : n }, (int64 (n ) - k ) * c .typ .Elem ().Size ()
283
+ }
0 commit comments