mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
reflect: implement New function
This is very important for some use cases, for example for Vecty.
This commit is contained in:
committed by
Ron Evans
parent
57271d7eaa
commit
e587b1d1b4
Vendored
+15
@@ -124,6 +124,21 @@ func main() {
|
||||
showValue(reflect.ValueOf(v), "")
|
||||
}
|
||||
|
||||
// Test reflect.New().
|
||||
newInt8 := reflect.New(reflect.TypeOf(int8(0)))
|
||||
newInt8.Elem().SetInt(5)
|
||||
newInt16 := reflect.New(reflect.TypeOf(int16(0)))
|
||||
newInt16.Elem().SetInt(-800)
|
||||
newInt32 := reflect.New(reflect.TypeOf(int32(0)))
|
||||
newInt32.Elem().SetInt(1e8)
|
||||
newInt64 := reflect.New(reflect.TypeOf(int64(0)))
|
||||
newInt64.Elem().SetInt(-1e12)
|
||||
newComplex128 := reflect.New(reflect.TypeOf(0 + 0i))
|
||||
newComplex128.Elem().SetComplex(-8 - 20e5i)
|
||||
for _, val := range []reflect.Value{newInt8, newInt16, newInt32, newInt64, newComplex128} {
|
||||
showValue(val, "")
|
||||
}
|
||||
|
||||
// test sizes
|
||||
println("\nsizes:")
|
||||
for _, tc := range []struct {
|
||||
|
||||
Vendored
+25
@@ -321,6 +321,31 @@ reflect type: ptr
|
||||
embedded: false
|
||||
reflect type: int addrable=true
|
||||
int: 42
|
||||
reflect type: ptr
|
||||
pointer: true int8
|
||||
nil: false
|
||||
reflect type: int8 settable=true addrable=true
|
||||
int: 5
|
||||
reflect type: ptr
|
||||
pointer: true int16
|
||||
nil: false
|
||||
reflect type: int16 settable=true addrable=true
|
||||
int: -800
|
||||
reflect type: ptr
|
||||
pointer: true int32
|
||||
nil: false
|
||||
reflect type: int32 settable=true addrable=true
|
||||
int: 100000000
|
||||
reflect type: ptr
|
||||
pointer: true int64
|
||||
nil: false
|
||||
reflect type: int64 settable=true addrable=true
|
||||
int: -1000000000000
|
||||
reflect type: ptr
|
||||
pointer: true complex128
|
||||
nil: false
|
||||
reflect type: complex128 settable=true addrable=true
|
||||
complex: (-8.000000e+000-2.000000e+006i)
|
||||
|
||||
sizes:
|
||||
int8 1 8
|
||||
|
||||
Reference in New Issue
Block a user