mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
compiler,reflect: add tagged pointers for **T etc
This commit is contained in:
+22
-1
@@ -477,7 +477,15 @@ func (t *rawType) underlying() *rawType {
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *rawType) ptrtag() uintptr {
|
||||
return uintptr(unsafe.Pointer(t)) & 0b11
|
||||
}
|
||||
|
||||
func (t *rawType) isNamed() bool {
|
||||
if tag := t.ptrtag(); tag != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return t.meta&flagNamed != 0
|
||||
}
|
||||
|
||||
@@ -502,9 +510,13 @@ func pointerTo(t *rawType) *rawType {
|
||||
|
||||
switch t.Kind() {
|
||||
case Pointer:
|
||||
if tag := t.ptrtag(); tag < 3 {
|
||||
return (*rawType)(unsafe.Add(unsafe.Pointer(t), 1))
|
||||
}
|
||||
|
||||
// TODO(dgryski): This is blocking https://github.com/tinygo-org/tinygo/issues/3131
|
||||
// We need to be able to create types that match existing types to prevent typecode equality.
|
||||
panic("reflect: cannot make **T type")
|
||||
panic("reflect: cannot make *****T type")
|
||||
case Struct:
|
||||
return (*structType)(unsafe.Pointer(t)).ptrTo
|
||||
default:
|
||||
@@ -581,6 +593,11 @@ func (t *rawType) Kind() Kind {
|
||||
if t == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
if tag := t.ptrtag(); tag != 0 {
|
||||
return Pointer
|
||||
}
|
||||
|
||||
return Kind(t.meta & kindMask)
|
||||
}
|
||||
|
||||
@@ -591,6 +608,10 @@ func (t *rawType) Elem() Type {
|
||||
}
|
||||
|
||||
func (t *rawType) elem() *rawType {
|
||||
if tag := t.ptrtag(); tag != 0 {
|
||||
return (*rawType)(unsafe.Add(unsafe.Pointer(t), -1))
|
||||
}
|
||||
|
||||
underlying := t.underlying()
|
||||
switch underlying.Kind() {
|
||||
case Pointer:
|
||||
|
||||
Reference in New Issue
Block a user