internal/lib/reflect: closure keep orgtype
This commit is contained in:
@@ -642,58 +642,43 @@ func (t *rtype) NumField() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *rtype) In(i int) Type {
|
func (t *rtype) In(i int) Type {
|
||||||
/*
|
|
||||||
if t.Kind() != Func {
|
if t.Kind() != Func {
|
||||||
panic("reflect: In of non-func type " + t.String())
|
panic("reflect: In of non-func type " + t.String())
|
||||||
}
|
}
|
||||||
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
||||||
return toType(tt.InSlice()[i])
|
return toType(tt.In[i])
|
||||||
*/
|
|
||||||
panic("todo: reflect.rtype.In")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rtype) NumIn() int {
|
func (t *rtype) NumIn() int {
|
||||||
/*
|
|
||||||
if t.Kind() != Func {
|
if t.Kind() != Func {
|
||||||
panic("reflect: NumIn of non-func type " + t.String())
|
panic("reflect: NumIn of non-func type " + t.String())
|
||||||
}
|
}
|
||||||
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
||||||
return tt.NumIn()
|
return len(tt.In)
|
||||||
*/
|
|
||||||
panic("todo: reflect.rtype.NumIn")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rtype) NumOut() int {
|
func (t *rtype) NumOut() int {
|
||||||
/*
|
|
||||||
if t.Kind() != Func {
|
if t.Kind() != Func {
|
||||||
panic("reflect: NumOut of non-func type " + t.String())
|
panic("reflect: NumOut of non-func type " + t.String())
|
||||||
}
|
}
|
||||||
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
||||||
return tt.NumOut()
|
return len(tt.Out)
|
||||||
*/
|
|
||||||
panic("todo: reflect.rtype.NumOut")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rtype) Out(i int) Type {
|
func (t *rtype) Out(i int) Type {
|
||||||
/*
|
|
||||||
if t.Kind() != Func {
|
if t.Kind() != Func {
|
||||||
panic("reflect: Out of non-func type " + t.String())
|
panic("reflect: Out of non-func type " + t.String())
|
||||||
}
|
}
|
||||||
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
||||||
return toType(tt.OutSlice()[i])
|
return toType(tt.Out[i])
|
||||||
*/
|
|
||||||
panic("todo: reflect.rtype.Out")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rtype) IsVariadic() bool {
|
func (t *rtype) IsVariadic() bool {
|
||||||
/*
|
|
||||||
if t.Kind() != Func {
|
if t.Kind() != Func {
|
||||||
panic("reflect: IsVariadic of non-func type " + t.String())
|
panic("reflect: IsVariadic of non-func type " + t.String())
|
||||||
}
|
}
|
||||||
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
tt := (*abi.FuncType)(unsafe.Pointer(t))
|
||||||
return tt.IsVariadic()
|
return tt.Variadic()
|
||||||
*/
|
|
||||||
panic("todo: reflect.rtype.IsVariadic")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add returns p+x.
|
// add returns p+x.
|
||||||
|
|||||||
@@ -183,9 +183,6 @@ func unpackEface(i any) Value {
|
|||||||
}
|
}
|
||||||
if t.TFlag&abi.TFlagClosure != 0 {
|
if t.TFlag&abi.TFlagClosure != 0 {
|
||||||
f = (f & flag(^Struct)) | flag(Func) | flagClosure
|
f = (f & flag(^Struct)) | flag(Func) | flagClosure
|
||||||
ft := *t.StructType().Fields[0].Typ.FuncType()
|
|
||||||
ft.In = ft.In[1:]
|
|
||||||
t = &ft.Type
|
|
||||||
}
|
}
|
||||||
return Value{t, e.word, f}
|
return Value{t, e.word, f}
|
||||||
}
|
}
|
||||||
@@ -1528,7 +1525,7 @@ func (v Value) TrySend(x Value) bool {
|
|||||||
|
|
||||||
// Type returns v's type.
|
// Type returns v's type.
|
||||||
func (v Value) Type() Type {
|
func (v Value) Type() Type {
|
||||||
if v.flag != 0 && v.flag&flagMethod == 0 {
|
if v.flag != 0 && v.flag&flagMethod == 0 && v.flag&flagClosure == 0 {
|
||||||
return (*rtype)(unsafe.Pointer(v.typ_)) // inline of toRType(v.typ()), for own inlining in inline test
|
return (*rtype)(unsafe.Pointer(v.typ_)) // inline of toRType(v.typ()), for own inlining in inline test
|
||||||
}
|
}
|
||||||
return v.typeSlow()
|
return v.typeSlow()
|
||||||
@@ -1539,6 +1536,11 @@ func (v Value) typeSlow() Type {
|
|||||||
panic(&ValueError{"reflect.Value.Type", Invalid})
|
panic(&ValueError{"reflect.Value.Type", Invalid})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// closure func
|
||||||
|
if v.flag&flagClosure != 0 {
|
||||||
|
return toRType(&v.funcType().Type)
|
||||||
|
}
|
||||||
|
|
||||||
typ := v.typ()
|
typ := v.typ()
|
||||||
if v.flag&flagMethod == 0 {
|
if v.flag&flagMethod == 0 {
|
||||||
return toRType(v.typ())
|
return toRType(v.typ())
|
||||||
@@ -2081,6 +2083,16 @@ func toFFISig(typ *abi.FuncType, closure bool) (*ffi.Signature, error) {
|
|||||||
return ffi.NewSignature(ret, args...)
|
return ffi.NewSignature(ret, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Value) funcType() *abi.FuncType {
|
||||||
|
if v.flag&flagClosure != 0 {
|
||||||
|
t := v.typ()
|
||||||
|
ft := *t.StructType().Fields[0].Typ.FuncType()
|
||||||
|
ft.In = ft.In[1:]
|
||||||
|
return &ft
|
||||||
|
}
|
||||||
|
return v.typ().FuncType()
|
||||||
|
}
|
||||||
|
|
||||||
func (v Value) call(op string, in []Value) (out []Value) {
|
func (v Value) call(op string, in []Value) (out []Value) {
|
||||||
var (
|
var (
|
||||||
fn unsafe.Pointer
|
fn unsafe.Pointer
|
||||||
@@ -2098,7 +2110,7 @@ func (v Value) call(op string, in []Value) (out []Value) {
|
|||||||
fn = v.ptr
|
fn = v.ptr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ft := v.typ().FuncType()
|
ft := v.funcType()
|
||||||
sig, err := toFFISig(ft, v.flag&flagClosure != 0)
|
sig, err := toFFISig(ft, v.flag&flagClosure != 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user