@@ -5,6 +5,8 @@ package reflectlite
55import (
66 "unsafe"
77
8+ "internal/abi"
9+
810 "github.com/gopherjs/gopherjs/js"
911)
1012
@@ -14,8 +16,6 @@ func init() {
1416 // avoid dead code elimination
1517 used := func (i any ) {}
1618 used (rtype {})
17- used (uncommonType {})
18- used (method {})
1919 used (arrayType {})
2020 used (chanType {})
2121 used (funcType {})
@@ -25,7 +25,6 @@ func init() {
2525 used (sliceType {})
2626 used (structType {})
2727 used (imethod {})
28- used (structField {})
2928
3029 initialized = true
3130 uint8Type = TypeOf (uint8 (0 )).(* rtype ) // set for real
@@ -47,29 +46,29 @@ func jsType(typ Type) *js.Object {
4746func reflectType (typ * js.Object ) * rtype {
4847 if typ .Get (idReflectType ) == js .Undefined {
4948 rt := & rtype {
50- size : uintptr (typ .Get ("size" ).Int ()),
51- kind : uint8 (typ .Get ("kind" ).Int ()),
52- str : newNameOff (newName (internalStr (typ .Get ("string" )), "" , typ .Get ("exported" ).Bool (), false )),
49+ Size : uintptr (typ .Get ("size" ).Int ()),
50+ Kind : uint8 (typ .Get ("kind" ).Int ()),
51+ Str : newNameOff (newName (internalStr (typ .Get ("string" )), "" , typ .Get ("exported" ).Bool (), false )),
5352 }
5453 js .InternalObject (rt ).Set (idJsType , typ )
5554 typ .Set (idReflectType , js .InternalObject (rt ))
5655
5756 methodSet := js .Global .Call ("$methodSet" , typ )
5857 if methodSet .Length () != 0 || typ .Get ("named" ).Bool () {
59- rt .tflag |= tflagUncommon
58+ rt .TFlag |= abi . TFlagUncommon
6059 if typ .Get ("named" ).Bool () {
61- rt .tflag |= tflagNamed
60+ rt .TFlag |= abi . TFlagNamed
6261 }
63- var reflectMethods []method
62+ var reflectMethods []abi. Method
6463 for i := 0 ; i < methodSet .Length (); i ++ { // Exported methods first.
6564 m := methodSet .Index (i )
6665 exported := internalStr (m .Get ("pkg" )) == ""
6766 if ! exported {
6867 continue
6968 }
70- reflectMethods = append (reflectMethods , method {
71- name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
72- mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
69+ reflectMethods = append (reflectMethods , abi. Method {
70+ Name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
71+ Mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
7372 })
7473 }
7574 xcount := uint16 (len (reflectMethods ))
@@ -79,18 +78,18 @@ func reflectType(typ *js.Object) *rtype {
7978 if exported {
8079 continue
8180 }
82- reflectMethods = append (reflectMethods , method {
83- name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
84- mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
81+ reflectMethods = append (reflectMethods , abi. Method {
82+ Name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
83+ Mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
8584 })
8685 }
87- ut := & uncommonType {
88- pkgPath : newNameOff (newName (internalStr (typ .Get ("pkg" )), "" , false , false )),
89- mcount : uint16 (methodSet .Length ()),
90- xcount : xcount ,
91- _methods : reflectMethods ,
86+ ut := & abi. UncommonType {
87+ PkgPath : newNameOff (newName (internalStr (typ .Get ("pkg" )), "" , false , false )),
88+ Mcount : uint16 (methodSet .Length ()),
89+ Xcount : xcount ,
90+ Methods_ : reflectMethods ,
9291 }
93- uncommonTypeMap [rt ] = ut
92+ abi . UncommonTypeMap [rt ] = ut
9493 js .InternalObject (ut ).Set (idJsType , typ )
9594 }
9695
@@ -164,13 +163,13 @@ func reflectType(typ *js.Object) *rtype {
164163 })
165164 case Struct :
166165 fields := typ .Get ("fields" )
167- reflectFields := make ([]structField , fields .Length ())
166+ reflectFields := make ([]abi. StructField , fields .Length ())
168167 for i := range reflectFields {
169168 f := fields .Index (i )
170- reflectFields [i ] = structField {
171- name : newName (internalStr (f .Get ("name" )), internalStr (f .Get ("tag" )), f .Get ("exported" ).Bool (), f .Get ("embedded" ).Bool ()),
172- typ : reflectType (f .Get ("typ" )),
173- offset : uintptr (i ),
169+ reflectFields [i ] = abi. StructField {
170+ Name : newName (internalStr (f .Get ("name" )), internalStr (f .Get ("tag" )), f .Get ("exported" ).Bool (), f .Get ("embedded" ).Bool ()),
171+ Typ : reflectType (f .Get ("typ" )),
172+ Offset : uintptr (i ),
174173 }
175174 }
176175 setKindType (rt , & structType {
@@ -189,29 +188,6 @@ func setKindType(rt *rtype, kindType any) {
189188 js .InternalObject (kindType ).Set (idRtype , js .InternalObject (rt ))
190189}
191190
192- type uncommonType struct {
193- pkgPath nameOff
194- mcount uint16
195- xcount uint16
196- moff uint32
197-
198- _methods []method
199- }
200-
201- func (t * uncommonType ) methods () []method {
202- return t ._methods
203- }
204-
205- func (t * uncommonType ) exportedMethods () []method {
206- return t ._methods [:t .xcount :t .xcount ]
207- }
208-
209- var uncommonTypeMap = make (map [* rtype ]* uncommonType )
210-
211- func (t * rtype ) uncommon () * uncommonType {
212- return uncommonTypeMap [t ]
213- }
214-
215191type funcType struct {
216192 rtype `reflect:"func"`
217193 inCount uint16
@@ -229,10 +205,6 @@ func (t *funcType) out() []*rtype {
229205 return t ._out
230206}
231207
232- type name struct {
233- bytes * byte
234- }
235-
236208type nameData struct {
237209 name string
238210 tag string
@@ -244,7 +216,6 @@ var nameMap = make(map[*byte]*nameData)
244216
245217func (n name ) name () (s string ) { return nameMap [n .bytes ].name }
246218func (n name ) tag () (s string ) { return nameMap [n .bytes ].tag }
247- func (n name ) pkgPath () string { return "" }
248219func (n name ) isExported () bool { return nameMap [n .bytes ].exported }
249220func (n name ) embedded () bool { return nameMap [n .bytes ].embedded }
250221
@@ -261,29 +232,7 @@ func newName(n, tag string, exported, embedded bool) name {
261232 }
262233}
263234
264- var nameOffList []name
265-
266- func (t * rtype ) nameOff (off nameOff ) name {
267- return nameOffList [int (off )]
268- }
269-
270- func newNameOff (n name ) nameOff {
271- i := len (nameOffList )
272- nameOffList = append (nameOffList , n )
273- return nameOff (i )
274- }
275-
276- var typeOffList []* rtype
277-
278- func (t * rtype ) typeOff (off typeOff ) * rtype {
279- return typeOffList [int (off )]
280- }
281-
282- func newTypeOff (t * rtype ) typeOff {
283- i := len (typeOffList )
284- typeOffList = append (typeOffList , t )
285- return typeOff (i )
286- }
235+ func pkgPath (n abi.Name ) string { return "" }
287236
288237func internalStr (strObj * js.Object ) string {
289238 var c struct { str string }
@@ -390,7 +339,7 @@ func Zero(typ Type) Value {
390339 return makeValue (typ , jsType (typ ).Call ("zero" ), 0 )
391340}
392341
393- func unsafe_New (typ * rtype ) unsafe.Pointer {
342+ func unsafe_New (typ * abi. Type ) unsafe.Pointer {
394343 switch typ .Kind () {
395344 case Struct :
396345 return unsafe .Pointer (jsType (typ ).Get ("ptr" ).New ().Unsafe ())
@@ -457,7 +406,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
457406 return Value {t , unsafe .Pointer (fv .Unsafe ()), flag (Func )}
458407}
459408
460- func typedmemmove (t * rtype , dst , src unsafe.Pointer ) {
409+ func typedmemmove (t * abi. Type , dst , src unsafe.Pointer ) {
461410 js .InternalObject (dst ).Call ("$set" , js .InternalObject (src ).Call ("$get" ))
462411}
463412
0 commit comments