go源碼閱讀——value.go

【博文目錄>>>】 【項目地址>>>】


基本內容

value文件主要提供值的一些調用方法,value所需要的值在在type.go文件中定義

package reflect

import (
	"math"
	"runtime"
	"unsafe"
)

const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const

// Value is the reflection interface to a Go value.
//
// Not all methods apply to all kinds of values. Restrictions,
// if any, are noted in the documentation for each method.
// Use the Kind method to find out the kind of value before
// calling kind-specific methods. Calling a method
// inappropriate to the kind of type causes a run time panic.
//
// The zero Value represents no value.
// Its IsValid method returns false, its Kind method returns Invalid,
// its String method returns "<invalid Value>", and all other methods panic.
// Most functions and methods never return an invalid value.
// If one does, its documentation states the conditions explicitly.
//
// A Value can be used concurrently by multiple goroutines provided that
// the underlying Go value can be used concurrently for the equivalent
// direct operations.
//
// To compare two Values, compare the results of the Interface method.
// Using == on two Values does not compare the underlying values
// they represent.
/**
 *  Value是Go值的反射接口。
 *
 * 並非所有方法都適用於所有類型的值。 在每種方法的文檔中都註明了限制(如果有)。
 * 在調用特定於種類的方法之前,使用Kind方法找出值的種類。 調用不適合該類型的方法會導致運行時恐慌。
 *
 * 零值表示無值。
 * 它的IsValid方法返回false,其Kind方法返回Invalid,其String方法返回"<invalid Value>",所有其他方法均會出現恐慌情況。
 * 大多數函數和方法從不返回無效值。
 * 如果是,則其文檔會明確說明條件。
 *
 * 一個值可以由多個goroutine併發使用,前提是可以將基礎Go值同時用於等效的直接操作。
 *
 * 要比較兩個值,請比較Interface方法的結果。
 * 在兩個值上使用==不會比較它們表示的基礎值。
 */
type Value struct {
	// typ holds the type of the value represented by a Value.
	/**
	 * typ包含由值表示的值的類型。
	 */
	typ *rtype

	// Pointer-valued data or, if flagIndir is set, pointer to data.
	// Valid when either flagIndir is set or typ.pointers() is true.
	/**
	 * 指針值的數據;如果設置了flagIndir,則爲數據的指針。
     * 在設置flagIndir或typ.pointers()爲true時有效。
	 */
	ptr unsafe.Pointer

	// flag holds metadata about the value.
	// The lowest bits are flag bits:
	//	- flagStickyRO: obtained via unexported not embedded field, so read-only
	//	- flagEmbedRO: obtained via unexported embedded field, so read-only
	//	- flagIndir: val holds a pointer to the data
	//	- flagAddr: v.CanAddr is true (implies flagIndir)
	//	- flagMethod: v is a method value.
	// The next five bits give the Kind of the value.
	// This repeats typ.Kind() except for method values.
	// The remaining 23+ bits give a method number for method values.
	// If flag.kind() != Func, code can assume that flagMethod is unset.
	// If ifaceIndir(typ), code can assume that flagIndir is set.
	/**
	 * 標誌保存有關該值的元數據。
     * 最低位是標誌位:
     * -flagStickyRO:通過未導出的未嵌入字段獲取,因此爲只讀
     * -flagEmbedRO:通過未導出的嵌入式字段獲取,因此爲只讀
     * -flagIndir:val保存指向數據的指針
     * -flagAddr:v.CanAddr爲true(暗示flagIndir)
     * -flagMethod:v是方法值。
     * 接下來的五位給出值的種類。
     * 重複typ.Kind()中的值,方法值除外。
     * 其餘的23+位給出方法值的方法編號。
     * 如果flag.kind() != Func,則代碼可以假定flagMethod未設置。
     * 如果是ifaceIndir(typ),則代碼可以假定設置了flagIndir。
	 */
	flag

	// A method value represents a curried method invocation
	// like r.Read for some receiver r. The typ+val+flag bits describe
	// the receiver r, but the flag's Kind bits say Func (methods are
	// functions), and the top bits of the flag give the method number
	// in r's type's method table.
	/**
	 * 方法值表示類似r.Read的經過當前(curried)的方法調用,用於某些接收方r。
     * typ + val + flag位描述接收方r,但標誌的Kind位表示Func(方法是函數),
     * 並且標誌的高位給出r的類型的方法表中的方法編號。
	 */
}

type flag uintptr

/**
 * flag類型是uintptr,此類型文檔並未說明是多少位,只是說位數足夠多,可以納任何指針的位模式
 * 爲了方便解理,這裏假設uintptr是uint32
 * flag的位模式分成幾組,從高位到底位:[31:10][9][8][7][6][5][4:0]
 * [4:0]: 第0~4位:共計5位,用於表示值類型,最多可表示32種類型,值類型參見同包下的,type.go Kind枚舉
 * [5]: 第5位:只讀類型,設置爲1表示:通過未導出的未嵌入字段獲取
 * [6]: 第6位:只讀類型,設置爲1表示:通過未導出的嵌入式字段獲取
 * [7]: 第7位:間接指針標記,設置爲1表示:Value的val屬性保存指向數據的指針
 * [8]: 第8位:可取址標記,設置爲1表示:可取址,並且暗示flagIndir已經設置成1
 * [9]: 第9位:方法標記,對於Value類型,第9位爲1表示其是方法類型,
 * [31:10]: 第10~31位:只對於Value是方法類型有用,用於表示第i個方法,將i<<flagMethodShift(10)位得到
 *
 */
const (
	flagKindWidth        = 5 // there are 27 kinds // 種類的寬度,具體種類在type.go文件中
	flagKindMask    flag = 1<<flagKindWidth - 1 // 數據類型的掩碼
	flagStickyRO    flag = 1 << 5 // 通過未導出的未嵌入字段獲取,因此爲只讀
	flagEmbedRO     flag = 1 << 6 // 通過未導出的嵌入式字段獲取,因此爲只讀
	flagIndir       flag = 1 << 7 // val保存指向數據的指針,val指的是Value中的ptr屬性
	flagAddr        flag = 1 << 8 // v.CanAddr爲true(暗示flagIndir),v指Value的實例
	flagMethod      flag = 1 << 9 // v是方法值,v指Value的實例
	flagMethodShift      = 10 // 計算是第幾個方法需要的位移數
	flagRO          flag = flagStickyRO | flagEmbedRO // 表示是否只讀
)

/**
 * 求數值類型
 * @return 數值類型
 **/
func (f flag) kind() Kind {
	return Kind(f & flagKindMask)
}

/**
 * 獲取只讀標記
 */
func (f flag) ro() flag {
	if f&flagRO != 0 {
		return flagStickyRO
	}
	return 0
}

// pointer returns the underlying pointer represented by v.
// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
/**
 * 指針返回v表示的底層指針。
 * v.Kind()必須是Ptr,Map,Chan,Func或UnsafePointer
 * @return
 **/
func (v Value) pointer() unsafe.Pointer {
	if v.typ.size != ptrSize || !v.typ.pointers() {
		panic("can't call pointer on a non-pointer Value")
	}
	if v.flag&flagIndir != 0 {
		return *(*unsafe.Pointer)(v.ptr)
	}
	return v.ptr
}

// packEface converts v to the empty interface.
/**
 * packEface將v轉換爲空接口。
 * @return 空接口
 **/
func packEface(v Value) interface{} {
	t := v.typ
	var i interface{}
	e := (*emptyInterface)(unsafe.Pointer(&i))
	// First, fill in the data portion of the interface.
	// 首先,填寫接口的數據部分。
	switch {
	case ifaceIndir(t): // ifaceIndir報告t是否間接存儲在接口值中。
		if v.flag&flagIndir == 0 {
			panic("bad indir")
		}
		// Value is indirect, and so is the interface we're making.
		// 值是間接的,我們正在建立的接口也是間接的。
		ptr := v.ptr
		if v.flag&flagAddr != 0 {
			// TODO: pass safe boolean from valueInterface so
			// we don't need to copy if safe==true?
			// TODO:從valueInterface傳遞安全布爾值,因此如果safe == true,我們不需要複製嗎?
			c := unsafe_New(t) // 在runtime包中實驗,用於創建一個Pointer類型
			typedmemmove(t, c, ptr) // typedmemmove將類型t的值從prt複製到c。
			ptr = c
		}
		e.word = ptr
	case v.flag&flagIndir != 0:
		// Value is indirect, but interface is direct. We need
		// to load the data at v.ptr into the interface data word.
		// 值是間接的,但接口是直接的。 我們需要將v.ptr處的數據加載到接口數據字中。
		e.word = *(*unsafe.Pointer)(v.ptr)
	default:
		// Value is direct, and so is the interface.
		// 值是直接的,接口也是直接的。
		e.word = v.ptr
	}
	// Now, fill in the type portion. We're very careful here not
	// to have any operation between the e.word and e.typ assignments
	// that would let the garbage collector observe the partially-built
	// interface value.
	// 現在,填寫類型部分。 在這裏,我們非常小心,不要在e.word和e.typ分配之間進行任何操作,
	// 以免垃圾回收器觀察部分構建的接口值。
	e.typ = t
	return i
}

// unpackEface converts the empty interface i to a Value.
/**
 * unpackEface將空接口i轉換爲Value。
 * @param 接口
 * @return Value類型
 **/
func unpackEface(i interface{}) Value {
	e := (*emptyInterface)(unsafe.Pointer(&i))
	// NOTE: don't read e.word until we know whether it is really a pointer or not.
	// 注意:在我們知道e.word是否真的是指針之前,不要讀它。
	t := e.typ
	if t == nil { // i對應的類型爲空,則不需要設置相關值
		return Value{}
	}
	f := flag(t.Kind())
	if ifaceIndir(t) { // 設置接口值標記
		f |= flagIndir
	}
	return Value{t, e.word, f}
}

// A ValueError occurs when a Value method is invoked on
// a Value that does not support it. Such cases are documented
// in the description of each method.
/**
 * 在不支持Value的Value方法上調用Value方法時,發生ValueError。
 * 在每種方法的說明中都記錄了這種情況。
 */
type ValueError struct {
	Method string
	Kind   Kind
}

func (e *ValueError) Error() string {
	if e.Kind == 0 {
		return "reflect: call of " + e.Method + " on zero Value"
	}
	return "reflect: call of " + e.Method + " on " + e.Kind.String() + " Value"
}

// methodName returns the name of the calling method,
// assumed to be two stack frames above.
/**
 * methodName返回調用方法的名稱,假定爲上面有兩個堆棧幀。
 */
func methodName() string {
    /**
     * func Caller(skip int) (pc uintptr, file string, line int, ok bool)
     * Caller報告有關調用goroutine堆棧上函數調用的文件和行號信息。
     * 參數skip是要提升的堆棧幀數,其中0標識Caller的調用者。
     *(由於歷史原因,在Caller和Callers之間,跳過的含義有所不同。)
     * 返回值報告相應調用文件中的程序計數器,文件名和行號。 如果該信息不可能恢復,
     * 則ok布爾值爲False。
     */
	pc, _, _, _ := runtime.Caller(2) // Question: 爲什麼是2?
	/**
	 * 給定程序計數器地址,否則爲nil。
     * 如果pc由於內聯而表示多個函數,它將返回一個* Func描述最內部的函數,
     * 但帶有最外部的函數的條目。
	 */
	f := runtime.FuncForPC(pc)
	if f == nil {
		return "unknown method"
	}
	return f.Name()
}

// emptyInterface is the header for an interface{} value.
/**
 * emptyInterface是interface{}值的頭部。
 */
type emptyInterface struct {
	typ  *rtype
	word unsafe.Pointer
}

// nonEmptyInterface is the header for an interface value with methods.
/**
 * nonEmptyInterface是帶有方法的接口值的頭部。
 */
type nonEmptyInterface struct {
	// see ../runtime/iface.go:/Itab
	itab *struct {
		ityp *rtype // static interface type // 靜態接口類型
		typ  *rtype // dynamic concrete type // 動態創建類型
		hash uint32 // copy of typ.hash      // hash值
		_    [4]byte                         // Question: 用於對齊?
		fun  [100000]unsafe.Pointer // method table*  Question: 最多保存10W個方法?
	}
	word unsafe.Pointer
}

// mustBe panics if f's kind is not expected.
// Making this a method on flag instead of on Value
// (and embedding flag in Value) means that we can write
// the very clear v.mustBe(Bool) and have it compile into
// v.flag.mustBe(Bool), which will only bother to copy the
// single important word for the receiver.
/**
 * 如果f的種類不是期望類型,則必須驚慌。
 * 將此方法設置爲基於標誌而不是基於Value的方法(並在Value中嵌入flag標誌)
 * 意味着我們可以編寫非常清晰的v.mustBe(Bool)並將其編譯爲v.flag.mustBe(Bool),
 * 唯一麻煩是隻需要爲接收者複製一個重要的單詞。
 */
func (f flag) mustBe(expected Kind) {
	// TODO(mvdan): use f.kind() again once mid-stack inlining gets better
	// TODO(mvdan): mid-stack的內聯變得更好後,再次使用f.kind()
    // Question: mid-stack是什麼?
	if Kind(f&flagKindMask) != expected {
		panic(&ValueError{methodName(), f.kind()})
	}
}

// mustBeExported panics if f records that the value was obtained using
// an unexported field.
/**
 * 如果f記錄了使用未導出字段獲得的值,則必須驚慌。
 */
func (f flag) mustBeExported() {
    // Enhance: mustBeExported和mustBeExportedSlow兩個方法一樣,
	if f == 0 || f&flagRO != 0 {
		f.mustBeExportedSlow()
	}
}

func (f flag) mustBeExportedSlow() {
	if f == 0 {
		panic(&ValueError{methodName(), Invalid})
	}
	if f&flagRO != 0 {
		panic("reflect: " + methodName() + " using value obtained using unexported field")
	}
}

// mustBeAssignable panics if f records that the value is not assignable,
// which is to say that either it was obtained using an unexported field
// or it is not addressable.
/**
 * 如果f記錄該值不可分配,則mustBeAssignable會發生panic,
 * 這意味着它是使用未導出的字段獲取的,或者它是不可尋址的。
 */
func (f flag) mustBeAssignable() {
	if f&flagRO != 0 || f&flagAddr == 0 {
		f.mustBeAssignableSlow()
	}
}

func (f flag) mustBeAssignableSlow() {
	if f == 0 {
		panic(&ValueError{methodName(), Invalid})
	}
	// Assignable if addressable and not read-only.
	// 如果可尋址且不是隻讀,則可分配。
	if f&flagRO != 0 {
		panic("reflect: " + methodName() + " using value obtained using unexported field")
	}
	if f&flagAddr == 0 {
		panic("reflect: " + methodName() + " using unaddressable value")
	}
}

// Addr returns a pointer value representing the address of v.
// It panics if CanAddr() returns false.
// Addr is typically used to obtain a pointer to a struct field
// or slice element in order to call a method that requires a
// pointer receiver.
/**
 * Addr返回表示v地址的指針值。
 * 如果CanAddr()返回false,則會感到恐慌。
 * Addr通常用於獲取指向struct字段或slice元素的指針,以便調用需要指針接收器的方法。
 */
func (v Value) Addr() Value {
	if v.flag&flagAddr == 0 {
		panic("reflect.Value.Addr of unaddressable value")
	}
	return Value{v.typ.ptrTo(), v.ptr, v.flag.ro() | flag(Ptr)} // Ptr是指標類型的類型值
}

// Bool returns v's underlying value.
// It panics if v's kind is not Bool.
/**
 * Bool返回v的基礎值,如果v的種類不是Bool則會恐慌。
 */
func (v Value) Bool() bool {
	v.mustBe(Bool)
	return *(*bool)(v.ptr) // 先轉成bool類型指針,再取值
}

// Bytes returns v's underlying value.
// It panics if v's underlying value is not a slice of bytes.
/**
 * 字節返回v的底層值,如果v的底層值不是字節的片段則恐慌。
 */
func (v Value) Bytes() []byte {
	v.mustBe(Slice)
	if v.typ.Elem().Kind() != Uint8 {
		panic("reflect.Value.Bytes of non-byte slice")
	}
	// Slice is always bigger than a word; assume flagIndir.
	// 切片總是比字(word)大; 假設flagIndir已經被設置值。
	return *(*[]byte)(v.ptr)
}

// runes returns v's underlying value.
// It panics if v's underlying value is not a slice of runes (int32s).
/**
 * runes返回v的底層值。如果v的底層值不是一小段符文(int32s),它將驚慌。
 * @param 
 * @return 
 **/
func (v Value) runes() []rune {
	v.mustBe(Slice)
	if v.typ.Elem().Kind() != Int32 {
		panic("reflect.Value.Bytes of non-rune slice")
	}
	// Slice is always bigger than a word; assume flagIndir.
	return *(*[]rune)(v.ptr)
}

// CanAddr reports whether the value's address can be obtained with Addr.
// Such values are called addressable. A value is addressable if it is
// an element of a slice, an element of an addressable array,
// a field of an addressable struct, or the result of dereferencing a pointer.
// If CanAddr returns false, calling Addr will panic.
/**
 * CanAddr報告是否可以通過Addr獲取值的地址。
 * 這樣的值稱爲可尋址的。 如果值是切片的元素,可尋址數組的元素,可尋址結構的字段或取消引用指針的結果,則該值是可尋址的。
 * 如果CanAddr返回false,則調用Addr會引起恐慌。
 **/
func (v Value) CanAddr() bool {
	return v.flag&flagAddr != 0
}

// CanSet reports whether the value of v can be changed.
// A Value can be changed only if it is addressable and was not
// obtained by the use of unexported struct fields.
// If CanSet returns false, calling Set or any type-specific
// setter (e.g., SetBool, SetInt) will panic.
/**
 * CanSet報告v的值是否可以更改。
 * 僅當值是可尋址的並且不是通過使用未導出的結構字段獲得的,纔可以更改它。
 * 如果CanSet返回false,則調用Set或任何特定於類型的setter(例如SetBool,SetInt)都會引起恐慌。
 * @param
 * @return
 **/
func (v Value) CanSet() bool {
	return v.flag&(flagAddr|flagRO) == flagAddr
}

// Call calls the function v with the input arguments in.
// For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]).
// Call panics if v's Kind is not Func.
// It returns the output results as Values.
// As in Go, each input argument must be assignable to the
// type of the function's corresponding input parameter.
// If v is a variadic function, Call creates the variadic slice parameter
// itself, copying in the corresponding values.
/**
 * Call使用輸入參數調用函數v。
 * 例如,如果len(in)== 3,則v.Call(in)表示Go調用v(in[0], in[1], in[2])。
 * 如果v的Kind不是Func,則Call方法引起恐慌。
 * 將輸出結果作爲Value切片返回。
 * 和Go一樣,每個輸入參數必須可分配給函數相應輸入參數的類型。
 * 如果v是可變參數函數,則Call會自己創建可變參數切片參數,並複製相應的值。
 * @param
 * @return
 **/
func (v Value) Call(in []Value) []Value {
	v.mustBe(Func)
	v.mustBeExported()
	return v.call("Call", in)
}

// CallSlice calls the variadic function v with the input arguments in,
// assigning the slice in[len(in)-1] to v's final variadic argument.
// For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
// CallSlice panics if v's Kind is not Func or if v is not variadic.
// It returns the output results as Values.
// As in Go, each input argument must be assignable to the
// type of the function's corresponding input parameter.
/**
 * CallSlice使用輸入參數in調用可變參數函數v,將切片in [len(in)-1]分配給v的最終可變參數。
 * 例如,如果len(in) == 3,則v.CallSlice(in)表示Go調用v(in [0],in [1],in [2] ...)。
 * 如果v的Kind不是Func或v不是可變參數,則CallSlice會慌張。
 * 將輸出結果作爲Value切片返回。
 * 和Go一樣,每個輸入參數必須可分配給函數相應輸入參數的類型。
 * @param
 * @return
 **/
func (v Value) CallSlice(in []Value) []Value {
	v.mustBe(Func)
	v.mustBeExported()
	return v.call("CallSlice", in)
}

var callGC bool // for testing; see TestCallMethodJump

/**
 * 真正的方法調用在這裏
 * @param
 * @return
 **/
func (v Value) call(op string, in []Value) []Value {
	// Get function pointer, type.
	t := (*funcType)(unsafe.Pointer(v.typ))
	var (
		fn       unsafe.Pointer
		rcvr     Value
		rcvrtype *rtype
	)
	if v.flag&flagMethod != 0 { // v是方法的接收者
		rcvr = v
		rcvrtype, t, fn = methodReceiver(op, v, int(v.flag)>>flagMethodShift)
	} else if v.flag&flagIndir != 0 { // 有間接指針
		fn = *(*unsafe.Pointer)(v.ptr)
	} else {
		fn = v.ptr
	}

	if fn == nil {
		panic("reflect.Value.Call: call of nil function")
	}

	isSlice := op == "CallSlice"
	n := t.NumIn()
	if isSlice { // CallSlice方法
		if !t.IsVariadic() { // 必須要有可變參數
			panic("reflect: CallSlice of non-variadic function")
		}
		if len(in) < n { // 參數不足
			panic("reflect: CallSlice with too few input arguments")
		}
		if len(in) > n { // 參數過多
			panic("reflect: CallSlice with too many input arguments")
		}
	} else {
		if t.IsVariadic() { // 有可變參數
			n--
		}
		if len(in) < n {
			panic("reflect: Call with too few input arguments")
		}
		if !t.IsVariadic() && len(in) > n {
			panic("reflect: Call with too many input arguments")
		}
	}
	for _, x := range in { // 參數都要有效
		if x.Kind() == Invalid {
			panic("reflect: " + op + " using zero Value argument")
		}
	}
	for i := 0; i < n; i++ { // 對應參數可以賦值
		if xt, targ := in[i].Type(), t.In(i); !xt.AssignableTo(targ) {
			panic("reflect: " + op + " using " + xt.String() + " as type " + targ.String())
		}
	}
	if !isSlice && t.IsVariadic() { // 非CallSlice方法,且沒有可變參數
		// prepare slice for remaining values
		// 將[len(in)-n, len(n)-1]位置的元素裝入slice作爲最後一個參數
		m := len(in) - n
		slice := MakeSlice(t.In(n), m, m)
		elem := t.In(n).Elem()
		for i := 0; i < m; i++ {
			x := in[n+i]
			if xt := x.Type(); !xt.AssignableTo(elem) { // n位置之後的元素必須是可賦值成elem
				panic("reflect: cannot use " + xt.String() + " as type " + elem.String() + " in " + op)
			}
			slice.Index(i).Set(x)
		}
		origIn := in
		in = make([]Value, n+1)
		copy(in[:n], origIn)
		in[n] = slice
	}

	nin := len(in)
	if nin != t.NumIn() { // 入參個數和需要的不相同
		panic("reflect.Value.Call: wrong argument count")
	}
	nout := t.NumOut()

	// Compute frame type.
	// 計算幀類型
	frametype, _, retOffset, _, framePool := funcLayout(t, rcvrtype)

	// Allocate a chunk of memory for frame.
	// 爲幀分匹配大片內存
	var args unsafe.Pointer
	if nout == 0 { // 沒有出參
		args = framePool.Get().(unsafe.Pointer)
	} else {
		// Can't use pool if the function has return values.
		// We will leak pointer to args in ret, so its lifetime is not scoped.
		// 如果函數具有返回值,則不能使用緩存池。
        // 我們將在ret中泄漏指向args的指針,因此其生存期不受限制。
		args = unsafe_New(frametype)
	}
	off := uintptr(0)

	// Copy inputs into args.
	// 將輸入複製到args。
	if rcvrtype != nil {
		storeRcvr(rcvr, args)
		off = ptrSize
	}
	// 計算偏移量off
	for i, v := range in {
		v.mustBeExported()
		targ := t.In(i).(*rtype)
		a := uintptr(targ.align)
		off = (off + a - 1) &^ (a - 1)
		n := targ.size
		if n == 0 {
			// Not safe to compute args+off pointing at 0 bytes,
			// because that might point beyond the end of the frame,
			// but we still need to call assignTo to check assignability.
			// 計算指向0字節的args + off並不安全,因爲它可能指向超出幀末尾的位置,
			// 但是我們仍然需要調用assignTo來檢查可分配性。
			v.assignTo("reflect.Value.Call", targ, nil)
			continue
		}
		addr := add(args, off, "n > 0")
		v = v.assignTo("reflect.Value.Call", targ, addr)
		if v.flag&flagIndir != 0 {
			typedmemmove(targ, addr, v.ptr)
		} else {
			*(*unsafe.Pointer)(addr) = v.ptr
		}
		off += n
	}

	// Call.
	// 進行方法調用
	call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))

	// For testing; see TestCallMethodJump.
	if callGC {
		runtime.GC()
	}

	var ret []Value
	if nout == 0 { // 沒有出參
		typedmemclr(frametype, args)
		framePool.Put(args)
	} else { // 包裝返回值
		// Zero the now unused input area of args,
		// because the Values returned by this function contain pointers to the args object,
		// and will thus keep the args object alive indefinitely.
		// 將現在未使用的args輸入區域歸零,因爲此函數返回的值包含指向args對象的指針,
		// 因此將使args對象無限期地保持活動狀態。
		typedmemclrpartial(frametype, args, 0, retOffset)

		// Wrap Values around return values in args.
		// args中的返回值進行包裝
		ret = make([]Value, nout)
		off = retOffset
		for i := 0; i < nout; i++ {
			tv := t.Out(i)
			a := uintptr(tv.Align())
			off = (off + a - 1) &^ (a - 1)
			if tv.Size() != 0 {
				fl := flagIndir | flag(tv.Kind())
				ret[i] = Value{tv.common(), add(args, off, "tv.Size() != 0"), fl}
				// Note: this does introduce false sharing between results -
				// if any result is live, they are all live.
				// (And the space for the args is live as well, but as we've
				// cleared that space it isn't as big a deal.)
				// 注意:這確實會導致結果之間的錯誤共享-如果有任何結果存活,則它們都是在存活。
				// (並且用於args的空間也可以使用,但是正如我們已經清除的那樣,空間並不大。)
			} else {
				// For zero-sized return value, args+off may point to the next object.
				// In this case, return the zero value instead.
				// 對於零大小的返回值,args+off可能指向下一個對象。 在這種情況下,請返回零值。
				ret[i] = Zero(tv)
			}
			off += tv.Size()
		}
	}

	return ret
}

// callReflect is the call implementation used by a function
// returned by MakeFunc. In many ways it is the opposite of the
// method Value.call above. The method above converts a call using Values
// into a call of a function with a concrete argument frame, while
// callReflect converts a call of a function with a concrete argument
// frame into a call using Values.
// It is in this file so that it can be next to the call method above.
// The remainder of the MakeFunc implementation is in makefunc.go.
//
// NOTE: This function must be marked as a "wrapper" in the generated code,
// so that the linker can make it work correctly for panic and recover.
// The gc compilers know to do that for the name "reflect.callReflect".
//
// ctxt is the "closure" generated by MakeFunc.
// frame is a pointer to the arguments to that closure on the stack.
// retValid points to a boolean which should be set when the results
// section of frame is set.
/**
 * callReflect是MakeFunc返回的函數使用的調用實現。 在許多方面,它與上面的Value.call方法相反。
 * 上面的方法將使用Values的調用轉換爲具有具體參數框架的函數的調用,
 * 而callReflect將具有具體參數框架的函數調用轉換爲使用Values的調用。
 * 它在此文件中,因此可以位於上面的call方法旁邊。
 *  MakeFunc實現的其餘部分位於makefunc.go中。
 *
 * 注意:此函數必須在生成的代碼中標記爲“wrapper”,以便鏈接器可以使其正常工作,以免發生混亂和恢復。
 *  gc編譯器知道這樣做的名稱是“reflect.callReflect”。
 *
 *  ctxt是MakeFunc生成的“closure”。
 *  frame是指向堆棧上該閉包的參數的指針。
 *  retValid指向一個布爾值,當設置框架的結果部分時應設置此布爾值。
 * @param
 * @param
 * @param retValid 指標返回值是否有效
 **/
func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool) {
	ftyp := ctxt.ftyp
	f := ctxt.fn

	// Copy argument frame into Values.
	// 將參數框幀複製到Value結構體中。
	ptr := frame
	off := uintptr(0) // 計算偏移量off
	in := make([]Value, 0, int(ftyp.inCount))
	for _, typ := range ftyp.in() { // 處理入參
		off += -off & uintptr(typ.align-1)
		v := Value{typ, nil, flag(typ.Kind())}
		if ifaceIndir(typ) { // 有間接指針
			// value cannot be inlined in interface data.
			// Must make a copy, because f might keep a reference to it,
			// and we cannot let f keep a reference to the stack frame
			// after this function returns, not even a read-only reference.
			// 不能在接口數據中內聯值。
            // 必須創建一個副本,因爲f可能會保留對它的引用,並且在此函數返回後,
            // 我們不能讓f保留對堆棧幀的引用,甚至不能是隻讀引用。
			v.ptr = unsafe_New(typ)
			if typ.size > 0 {
				typedmemmove(typ, v.ptr, add(ptr, off, "typ.size > 0"))
			}
			v.flag |= flagIndir
		} else {
			v.ptr = *(*unsafe.Pointer)(add(ptr, off, "1-ptr"))
		}
		in = append(in, v)
		off += typ.size
	}

	// Call underlying function.
	// 調用底層函數
	out := f(in)
	numOut := ftyp.NumOut()
	if len(out) != numOut { // 出參和實際不同
		panic("reflect: wrong return count from function created by MakeFunc")
	}

	// Copy results back into argument frame.
	// 將結果拷貝回參數幀
	if numOut > 0 {
		off += -off & (ptrSize - 1)
		for i, typ := range ftyp.out() {
			v := out[i]
			if v.typ == nil {
				panic("reflect: function created by MakeFunc using " + funcName(f) +
					" returned zero Value")
			}
			if v.flag&flagRO != 0 {
				panic("reflect: function created by MakeFunc using " + funcName(f) +
					" returned value obtained from unexported field")
			}
			off += -off & uintptr(typ.align-1)
			if typ.size == 0 {
				continue
			}
			addr := add(ptr, off, "typ.size > 0")

			// Convert v to type typ if v is assignable to a variable
			// of type t in the language spec.
			// See issue 28761.
			// 如果在語言規範中v可分配給類型t的變量,則將v轉換爲typ類型。
            // 參見問題28761。
			v = v.assignTo("reflect.MakeFunc", typ, addr)

			// We are writing to stack. No write barrier.
			// 我們正在寫堆棧。 沒有寫屏障。
			if v.flag&flagIndir != 0 {
				memmove(addr, v.ptr, typ.size)
			} else {
				*(*uintptr)(addr) = uintptr(v.ptr)
			}
			off += typ.size
		}
	}

	// Announce that the return values are valid.
	// After this point the runtime can depend on the return values being valid.
	// 聲明返回值有效。
    // 在此之後,運行時可以依賴於有效的返回值。
	*retValid = true

	// We have to make sure that the out slice lives at least until
	// the runtime knows the return values are valid. Otherwise, the
	// return values might not be scanned by anyone during a GC.
	// (out would be dead, and the return slots not yet alive.)
	// 我們必須確保out輸出切片至少存在,直到運行時知道返回值有效爲止。
	// 否則,任何人都可能在GC期間不掃描返回值。(輸出將失效,返回slots還沒有激活。)
	runtime.KeepAlive(out)

	// runtime.getArgInfo expects to be able to find ctxt on the
	// stack when it finds our caller, makeFuncStub. Make sure it
	// doesn't get garbage collected.
	// runtime.getArgInfo期望能夠在找到我們的調用者makeFuncStub時在堆棧上找到ctxt。
	// 需求確保沒有收集垃圾。
	runtime.KeepAlive(ctxt)
}

// methodReceiver returns information about the receiver
// described by v. The Value v may or may not have the
// flagMethod bit set, so the kind cached in v.flag should
// not be used.
// The return value rcvrtype gives the method's actual receiver type.
// The return value t gives the method type signature (without the receiver).
// The return value fn is a pointer to the method code.
/**
 * methodReceiver返回有關v描述的接收者的信息。值v可能會或可能不會設置flagMethod位,因此不應使用在v.flag中緩存的種類。
 * 返回值rcvrtype給出了方法的實際接收者類型。
 * 返回值t給出方法類型簽名(沒有接收者)。
 * 返回值fn是方法代碼的指針。
 * @param
 * @return
 **/
func methodReceiver(op string, v Value, methodIndex int) (rcvrtype *rtype, t *funcType, fn unsafe.Pointer) {
	i := methodIndex
	if v.typ.Kind() == Interface { // 接口類型
		tt := (*interfaceType)(unsafe.Pointer(v.typ))
		if uint(i) >= uint(len(tt.methods)) { // 參數個數判斷
			panic("reflect: internal error: invalid method index")
		}
		m := &tt.methods[i]
		if !tt.nameOff(m.name).isExported() { // 非導出方法
			panic("reflect: " + op + " of unexported method")
		}
		iface := (*nonEmptyInterface)(v.ptr)
		if iface.itab == nil {
			panic("reflect: " + op + " of method on nil interface value")
		}
		rcvrtype = iface.itab.typ
		fn = unsafe.Pointer(&iface.itab.fun[i])
		t = (*funcType)(unsafe.Pointer(tt.typeOff(m.typ)))
	} else { // 非接口類型
		rcvrtype = v.typ
		ms := v.typ.exportedMethods()
		if uint(i) >= uint(len(ms)) {
			panic("reflect: internal error: invalid method index")
		}
		m := ms[i]
		if !v.typ.nameOff(m.name).isExported() {
			panic("reflect: " + op + " of unexported method")
		}
		ifn := v.typ.textOff(m.ifn)
		fn = unsafe.Pointer(&ifn)
		t = (*funcType)(unsafe.Pointer(v.typ.typeOff(m.mtyp)))
	}
	return
}

// v is a method receiver. Store at p the word which is used to
// encode that receiver at the start of the argument list.
// Reflect uses the "interface" calling convention for
// methods, which always uses one word to record the receiver.
/**
 * v是方法接收者。 在參數列表的開頭將用於對接收方進行編碼的字(word)存儲在p處。
 * Reflect使用方法的“interface”調用約定,該約定始終使用一個字(word)來記錄接收者。
 * @param
 * @return
 **/
func storeRcvr(v Value, p unsafe.Pointer) {
	t := v.typ
	if t.Kind() == Interface { // 接口類型
		// the interface data word becomes the receiver word
		// 接口數據字(word)成爲接收者(word)
		iface := (*nonEmptyInterface)(v.ptr)
		*(*unsafe.Pointer)(p) = iface.word
	} else if v.flag&flagIndir != 0 && !ifaceIndir(t) { // 間接指針
		*(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(v.ptr)
	} else {
		*(*unsafe.Pointer)(p) = v.ptr
	}
}

// align returns the result of rounding x up to a multiple of n.
// n must be a power of two.
/**
 * align返回將x舍入爲n的倍數的結果。 n必須是2的冪。
 * @param
 * @return
 **/
func align(x, n uintptr) uintptr {
	return (x + n - 1) &^ (n - 1)
}

// callMethod is the call implementation used by a function returned
// by makeMethodValue (used by v.Method(i).Interface()).
// It is a streamlined version of the usual reflect call: the caller has
// already laid out the argument frame for us, so we don't have
// to deal with individual Values for each argument.
// It is in this file so that it can be next to the two similar functions above.
// The remainder of the makeMethodValue implementation is in makefunc.go.
//
// NOTE: This function must be marked as a "wrapper" in the generated code,
// so that the linker can make it work correctly for panic and recover.
// The gc compilers know to do that for the name "reflect.callMethod".
//
// ctxt is the "closure" generated by makeVethodValue.
// frame is a pointer to the arguments to that closure on the stack.
// retValid points to a boolean which should be set when the results
// section of frame is set.
/**
 * callMethod是由makeMethodValue返回的函數使用的調用實現(由v.Method(i).Interface()使用)。
 * 這是常規反射調用的簡化版本:調用者已經爲我們設置了參數幀,因此我們不必爲每個參數處理單獨的Values。
 * 它在此文件中,因此可以位於上面的兩個類似函數的旁邊。
 * makeMethodValue實現的其餘部分位於makefunc.go中。
 *
 * 注意:此函數必須在生成的代碼中標記爲“wrapper”,以便鏈接器可以使其正常工作,以免發生混亂和恢復。
 * gc編譯器爲名稱是“reflect.callMethod”做什麼。
 *
 * @param ctxt是makeVethodValue生成的“closure”閉包。
 * @param frame是指向堆棧上該閉包的參數的指針。
 * @param retValid指向一個布爾值,當設置框架的結果部分時應設置此布爾值。
 * @return
 **/
func callMethod(ctxt *methodValue, frame unsafe.Pointer, retValid *bool) {
	rcvr := ctxt.rcvr
	rcvrtype, t, fn := methodReceiver("call", rcvr, ctxt.method)
	frametype, argSize, retOffset, _, framePool := funcLayout(t, rcvrtype)

	// Make a new frame that is one word bigger so we can store the receiver.
	// This space is used for both arguments and return values.
	// 製作一個新的幀,幀大一個字(word),這樣我們就可以存儲接收器。
    // 此空間用於參數和返回值。
	scratch := framePool.Get().(unsafe.Pointer)

	// Copy in receiver and rest of args.
	// 複製到接者和其他參數中。
	storeRcvr(rcvr, scratch)
	// Align the first arg. The alignment can't be larger than ptrSize.
	// 對齊第一個參數。 對齊不能大於ptrSize。
	argOffset := uintptr(ptrSize)
	if len(t.in()) > 0 {
		argOffset = align(argOffset, uintptr(t.in()[0].align))
	}
	// Avoid constructing out-of-bounds pointers if there are no args.
	// 如果沒有參數,請避免構造越界指針。
	if argSize-argOffset > 0 {
		typedmemmovepartial(frametype, add(scratch, argOffset, "argSize > argOffset"), frame, argOffset, argSize-argOffset)
	}

	// Call.
	// Call copies the arguments from scratch to the stack, calls fn,
	// and then copies the results back into scratch.
	// call將參數從scratch複製到堆棧,調用fn,然後將結果複製回scratch。
	call(frametype, fn, scratch, uint32(frametype.size), uint32(retOffset))

	// Copy return values.
	// Ignore any changes to args and just copy return values.
	// Avoid constructing out-of-bounds pointers if there are no return values.
	// 複製返回值。
    // 忽略對args的任何更改,僅複製返回值。
    // 如果沒有返回值,請避免構造越界指針。
	if frametype.size-retOffset > 0 {
		callerRetOffset := retOffset - argOffset
		// This copies to the stack. Write barriers are not needed.
		// 這將複製到堆棧。不需要寫障礙。
		memmove(add(frame, callerRetOffset, "frametype.size > retOffset"),
			add(scratch, retOffset, "frametype.size > retOffset"),
			frametype.size-retOffset)
	}

	// Tell the runtime it can now depend on the return values
	// being properly initialized.
	// 告訴運行(runtime)時,它現在可以依賴正確初始化的返回值。
	*retValid = true

	// Clear the scratch space and put it back in the pool.
	// This must happen after the statement above, so that the return
	// values will always be scanned by someone.
	// 清除scratch空間並將其放回池中。
    // 這必須在上面的語句之後發生,以便返回值將始終被掃描到。
	typedmemclr(frametype, scratch)
	framePool.Put(scratch)

	// See the comment in callReflect.
	// 請參閱callReflect中的註釋。
	runtime.KeepAlive(ctxt)
}

// funcName returns the name of f, for use in error messages.
/**
 * funcName返回f名稱,以用於錯誤消息。
 * @param
 * @return
 **/
func funcName(f func([]Value) []Value) string {
	pc := *(*uintptr)(unsafe.Pointer(&f))
	rf := runtime.FuncForPC(pc)
	if rf != nil {
		return rf.Name()
	}
	return "closure"
}

// Cap returns v's capacity.
// It panics if v's Kind is not Array, Chan, or Slice.
/**
 * Cap返回v的容量。
 * 如果v的Kind不是Array,Chan或Slice,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) Cap() int {
	k := v.kind()
	switch k {
	case Array:
		return v.typ.Len()
	case Chan:
		return chancap(v.pointer())
	case Slice:
		// Slice is always bigger than a word; assume flagIndir.
		// 切片總是比單字(word); 假設flagIndir已經被設置值。
		return (*sliceHeader)(v.ptr).Cap
	}
	panic(&ValueError{"reflect.Value.Cap", v.kind()})
}

// Close closes the channel v.
// It panics if v's Kind is not Chan.
/**
 * 關閉會關閉頻道v。
 * 如果v's Kind不是Chan,就會引起恐慌。
 * @param
 * @return
 **/
func (v Value) Close() {
	v.mustBe(Chan)
	v.mustBeExported()
	chanclose(v.pointer())
}

// Complex returns v's underlying value, as a complex128.
// It panics if v's Kind is not Complex64 or Complex128
/**
 * Complex返回v的基礎值,爲complex128。
 * 如果v的Kind不是Complex64或Complex128,它會感到恐慌
 * @param
 * @return
 **/
func (v Value) Complex() complex128 {
	k := v.kind()
	switch k {
	case Complex64:
		return complex128(*(*complex64)(v.ptr))
	case Complex128:
		return *(*complex128)(v.ptr)
	}
	panic(&ValueError{"reflect.Value.Complex", v.kind()})
}

// Elem returns the value that the interface v contains
// or that the pointer v points to.
// It panics if v's Kind is not Interface or Ptr.
// It returns the zero Value if v is nil.
/**
 * Elem返回接口v包含的值或指針v指向的值。
 * 如果v的Kind不是Interface或Ptr,它會引起恐慌。
 * 如果v爲nil,則返回零值。
 * @param
 * @return
 **/
func (v Value) Elem() Value {
	k := v.kind()
	switch k {
	case Interface:  // 接口類型
		var eface interface{}
		if v.typ.NumMethod() == 0 { // 沒有方法
			eface = *(*interface{})(v.ptr)
		} else {
			eface = (interface{})(*(*interface {
				M()
			})(v.ptr))
		}
		x := unpackEface(eface)
		if x.flag != 0 {
			x.flag |= v.flag.ro()
		}
		return x
	case Ptr: // 指針類型
		ptr := v.ptr
		if v.flag&flagIndir != 0 { // 間接指針
			ptr = *(*unsafe.Pointer)(ptr)
		}
		// The returned value's address is v's value.
		// 返回值的地址是v的值。
		if ptr == nil {
			return Value{}
		}
		tt := (*ptrType)(unsafe.Pointer(v.typ))
		typ := tt.elem
		fl := v.flag&flagRO | flagIndir | flagAddr
		fl |= flag(typ.Kind())
		return Value{typ, ptr, fl}
	}
	panic(&ValueError{"reflect.Value.Elem", v.kind()})
}

// Field returns the i'th field of the struct v.
// It panics if v's Kind is not Struct or i is out of range.
/**
 * Field返回結構v的第i個字段。
 * 如果v的Kind不是Struct或i超出範圍,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) Field(i int) Value {
	if v.kind() != Struct {
		panic(&ValueError{"reflect.Value.Field", v.kind()})
	}
	tt := (*structType)(unsafe.Pointer(v.typ))
	if uint(i) >= uint(len(tt.fields)) {
		panic("reflect: Field index out of range")
	}
	field := &tt.fields[i]
	typ := field.typ

	// Inherit permission bits from v, but clear flagEmbedRO.
	// 從v繼承權限位,但清除flagEmbedRO。
	fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind())
	// Using an unexported field forces flagRO.
	// 使用未導出的字段會強制flagRO。
	if !field.name.isExported() {
		if field.embedded() {
			fl |= flagEmbedRO
		} else {
			fl |= flagStickyRO
		}
	}
	// Either flagIndir is set and v.ptr points at struct,
	// or flagIndir is not set and v.ptr is the actual struct data.
	// In the former case, we want v.ptr + offset.
	// In the latter case, we must have field.offset = 0,
	// so v.ptr + field.offset is still the correct address.
	/**
	 * 要麼設置了flagIndir並且v.ptr指向結構體,要麼未設置flagIndir且v.ptr是實際的結構數據。
     * 在前一種情況下,我們需要v.ptr+偏移量。
     * 在後一種情況下,我們必須具有field.offset = 0,因此v.ptr + field.offset仍然是正確的地址。
	 */
	ptr := add(v.ptr, field.offset(), "same as non-reflect &v.field")
	return Value{typ, ptr, fl}
}

// FieldByIndex returns the nested field corresponding to index.
// It panics if v's Kind is not struct.
/**
 * FieldByIndex返回與索引對應的嵌套字段。
 * 如果v的Kind不是struct,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) FieldByIndex(index []int) Value {
	if len(index) == 1 {
		return v.Field(index[0])
	}
	v.mustBe(Struct)
	for i, x := range index { // 遞歸求屬性
		if i > 0 {
			if v.Kind() == Ptr && v.typ.Elem().Kind() == Struct {
				if v.IsNil() {
					panic("reflect: indirection through nil pointer to embedded struct")
				}
				v = v.Elem()
			}
		}
		v = v.Field(x)
	}
	return v
}

// FieldByName returns the struct field with the given name.
// It returns the zero Value if no field was found.
// It panics if v's Kind is not struct.
/**
 * FieldByName返回具有給定名稱的struct字段。
 * 如果未找到任何字段,則返回零值。
 * 如果v的Kind不是struct,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) FieldByName(name string) Value {
	v.mustBe(Struct)
	if f, ok := v.typ.FieldByName(name); ok {
		return v.FieldByIndex(f.Index)
	}
	return Value{}
}

// FieldByNameFunc returns the struct field with a name
// that satisfies the match function.
// It panics if v's Kind is not struct.
// It returns the zero Value if no field was found.
/**
 * FieldByNameFunc返回具有滿足match函數名稱的struct字段。
 * 如果v的Kind不是struct,它會引起恐慌。
 * 如果未找到任何字段,則返回零值。
 * @param
 * @return
 **/
func (v Value) FieldByNameFunc(match func(string) bool) Value {
	if f, ok := v.typ.FieldByNameFunc(match); ok {
		return v.FieldByIndex(f.Index)
	}
	return Value{}
}

// Float returns v's underlying value, as a float64.
// It panics if v's Kind is not Float32 or Float64
/**
 * Float返回v的底層值,作爲float64。
 * 如果v的Kind不是Float32或Float64,則會發生恐慌
 * @param
 * @return
 **/
func (v Value) Float() float64 {
	k := v.kind()
	switch k {
	case Float32:
		return float64(*(*float32)(v.ptr))
	case Float64:
		return *(*float64)(v.ptr)
	}
	panic(&ValueError{"reflect.Value.Float", v.kind()})
}

var uint8Type = TypeOf(uint8(0)).(*rtype)

// Index returns v's i'th element.
// It panics if v's Kind is not Array, Slice, or String or i is out of range.
/**
 * index返回v的第i個元素。
 * 如果v的Kind不是Array,Slice或String或i不在範圍之內,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) Index(i int) Value {
	switch v.kind() {
	case Array:
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		if uint(i) >= uint(tt.len) {
			panic("reflect: array index out of range")
		}
		typ := tt.elem
		offset := uintptr(i) * typ.size

		// Either flagIndir is set and v.ptr points at array,
		// or flagIndir is not set and v.ptr is the actual array data.
		// In the former case, we want v.ptr + offset.
		// In the latter case, we must be doing Index(0), so offset = 0,
		// so v.ptr + offset is still the correct address.
		// 或者設置了flagIndir並且v.ptr指向數組,或者沒有設置flagIndir且v.ptr是實際的數組數據。
        // 在前一種情況下,我們需要v.ptr+偏移量。
        // 在後一種情況下,我們必須執行Index(0),所以offset = 0,所以v.ptr + offset仍然是正確的地址。
		val := add(v.ptr, offset, "same as &v[i], i < tt.len")
		fl := v.flag&(flagIndir|flagAddr) | v.flag.ro() | flag(typ.Kind()) // bits same as overall array // 位標記和整個數據相同
		return Value{typ, val, fl}

	case Slice:
		// Element flag same as Elem of Ptr.
		// Addressable, indirect, possibly read-only.
		// 元素標誌與Ptr的Elem相同。 可尋址,間接或可能是隻讀的。
		s := (*sliceHeader)(v.ptr)
		if uint(i) >= uint(s.Len) {
			panic("reflect: slice index out of range")
		}
		tt := (*sliceType)(unsafe.Pointer(v.typ))
		typ := tt.elem
		val := arrayAt(s.Data, i, typ.size, "i < s.Len")
		fl := flagAddr | flagIndir | v.flag.ro() | flag(typ.Kind())
		return Value{typ, val, fl}

	case String:
		s := (*stringHeader)(v.ptr)
		if uint(i) >= uint(s.Len) {
			panic("reflect: string index out of range")
		}
		p := arrayAt(s.Data, i, 1, "i < s.Len")
		fl := v.flag.ro() | flag(Uint8) | flagIndir
		return Value{uint8Type, p, fl}
	}
	panic(&ValueError{"reflect.Value.Index", v.kind()})
}

// Int returns v's underlying value, as an int64.
// It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
/**
 * Int返回v的底層值,作爲int64。
 * 如果v的Kind不是Int,Int8,Int16,Int32或Int64,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) Int() int64 {
	k := v.kind()
	p := v.ptr
	switch k {
	case Int:
		return int64(*(*int)(p))
	case Int8:
		return int64(*(*int8)(p))
	case Int16:
		return int64(*(*int16)(p))
	case Int32:
		return int64(*(*int32)(p))
	case Int64:
		return *(*int64)(p)
	}
	panic(&ValueError{"reflect.Value.Int", v.kind()})
}

// CanInterface reports whether Interface can be used without panicking.
/**
 * CanInterface報告是否可以在不引起恐慌的情況下使用Interface。
 * @param
 * @return
 **/
func (v Value) CanInterface() bool {
	if v.flag == 0 {
		panic(&ValueError{"reflect.Value.CanInterface", Invalid})
	}
	return v.flag&flagRO == 0
}

// Interface returns v's current value as an interface{}.
// It is equivalent to:
//	var i interface{} = (v's underlying value)
// It panics if the Value was obtained by accessing
// unexported struct fields.
/**
 * Interface返回v的當前值作爲interface{}。
 * 等同於:
 *      var i interface {} =(v的底層值)
 * 如果通過訪問未導出的struct字段獲得了Value,則會感到恐慌。
 * @param 
 * @return 
 **/
func (v Value) Interface() (i interface{}) {
	return valueInterface(v, true)
}

/**
 * 將value值轉成interface
 * @param
 * @return 
 **/
func valueInterface(v Value, safe bool) interface{} {
	if v.flag == 0 { // 最低5位表類型,0表示非法類型
		panic(&ValueError{"reflect.Value.Interface", Invalid})
	}
	if safe && v.flag&flagRO != 0 {
		// Do not allow access to unexported values via Interface,
		// because they might be pointers that should not be
		// writable or methods or function that should not be callable.
		// 不允許通過接口訪問未導出的值,因爲它們可能是不應寫的指針或不應被調用的方法或函數。
		panic("reflect.Value.Interface: cannot return value obtained from unexported field or method")
	}
	if v.flag&flagMethod != 0 {
		v = makeMethodValue("Interface", v) // 構造方法值
	}

	if v.kind() == Interface { // 接口類型
		// Special case: return the element inside the interface.
		// Empty interface has one layout, all interfaces with
		// methods have a second layout.
		// 特殊情況:返回接口內的元素。
        // 空接口具有一種佈局,所有帶方法的接口具有另一種佈局。
		if v.NumMethod() == 0 {
			return *(*interface{})(v.ptr)
		}
		return *(*interface { // 非空接口的佈局
			M()
		})(v.ptr)
	}

	// TODO: pass safe to packEface so we don't need to copy if safe==true?
	// TODO: 將safe傳遞給packEface,這樣如果safe == true,我們不需要複製嗎?
	return packEface(v)
}

// InterfaceData returns the interface v's value as a uintptr pair.
// It panics if v's Kind is not Interface.
/**
 * InterfaceData接口返回v兩個uintptr值。
 * 如果v的Kind不是Interface,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) InterfaceData() [2]uintptr {
	// TODO: deprecate this
	v.mustBe(Interface)
	// We treat this as a read operation, so we allow
	// it even for unexported data, because the caller
	// has to import "unsafe" to turn it into something
	// that can be abused.
	// Interface value is always bigger than a word; assume flagIndir.
	// 我們將其視爲讀取操作,因此即使未導出的數據也允許,
	// 因爲調用者必須導入“unsafe”才能將其轉換爲可濫用的內容。
    // 接口值始終大於一個字(word); 假設flagIndir已經被設置值。
	return *(*[2]uintptr)(v.ptr)
}

// IsNil reports whether its argument v is nil. The argument must be
// a chan, func, interface, map, pointer, or slice value; if it is
// not, IsNil panics. Note that IsNil is not always equivalent to a
// regular comparison with nil in Go. For example, if v was created
// by calling ValueOf with an uninitialized interface variable i,
// i==nil will be true but v.IsNil will panic as v will be the zero
// Value.
/**
 * IsNil報告其參數v是否爲nil。 參數必須是chan,func,interface,map,pointer或slice值;
 * 如果不是,則IsNil引起恐慌。 請注意,IsNil並不總是等同於Go中與nil的常規比較。
 * 例如,如果v是通過使用未初始化的接口變量i調用ValueOf來創建的,則i == nil將爲true,
 * 但v.IsNil將引起恐慌,因爲v將爲零值。
 * @param
 * @return
 **/
func (v Value) IsNil() bool {
	k := v.kind()
	switch k {
	case Chan, Func, Map, Ptr, UnsafePointer:
		if v.flag&flagMethod != 0 { // 方法標記不爲0
			return false
		}
		ptr := v.ptr
		if v.flag&flagIndir != 0 { // 間接指針
			ptr = *(*unsafe.Pointer)(ptr)
		}
		return ptr == nil
	case Interface, Slice:
		// Both interface and slice are nil if first word is 0.
		// Both are always bigger than a word; assume flagIndir.
		// 如果第一個字爲0,則interface和slice均爲零。
		// 兩者值始終大於一個字(word); 假設flagIndir已經被設置值。
		return *(*unsafe.Pointer)(v.ptr) == nil
	}
	panic(&ValueError{"reflect.Value.IsNil", v.kind()})
}

// IsValid reports whether v represents a value.
// It returns false if v is the zero Value.
// If IsValid returns false, all other methods except String panic.
// Most functions and methods never return an invalid Value.
// If one does, its documentation states the conditions explicitly.
/**
 * IsValid報告v是否表示一個值。
 * 如果v爲零值,則返回false。
 * 如果IsValid返回false,則其他所有方法(除外String方法外)引起恐慌。
 * 大多數函數和方法從不返回無效的值。
 * 如果是,則其文檔會明確說明條件。
 * @param
 * @return
 **/
func (v Value) IsValid() bool {
	return v.flag != 0
}

// IsZero reports whether v is the zero value for its type.
// It panics if the argument is invalid.
/**
 * IsZero報告v是否爲其類型的零值。
 * 如果參數無效,則會出現恐慌。
 * @param
 * @return
 **/
func (v Value) IsZero() bool {
	switch v.kind() {
	case Bool:
		return !v.Bool()
	case Int, Int8, Int16, Int32, Int64:
		return v.Int() == 0
	case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
		return v.Uint() == 0
	case Float32, Float64:
		return math.Float64bits(v.Float()) == 0
	case Complex64, Complex128:
		c := v.Complex()
		return math.Float64bits(real(c)) == 0 && math.Float64bits(imag(c)) == 0
	case Array:
		for i := 0; i < v.Len(); i++ {
			if !v.Index(i).IsZero() {
				return false
			}
		}
		return true
	case Chan, Func, Interface, Map, Ptr, Slice, UnsafePointer:
		return v.IsNil()
	case String:
		return v.Len() == 0
	case Struct:
		for i := 0; i < v.NumField(); i++ {
			if !v.Field(i).IsZero() {
				return false
			}
		}
		return true
	default:
		// This should never happens, but will act as a safeguard for
		// later, as a default value doesn't makes sense here.
		// 這永遠都不會發生,但是以後會作爲一種保護措施,因爲默認值在這裏沒有意義。
		panic(&ValueError{"reflect.Value.IsZero", v.Kind()})
	}
}

// Kind returns v's Kind.
// If v is the zero Value (IsValid returns false), Kind returns Invalid.
/**
 * Kind返回v的值類型。 如果v爲零值(IsValid返回false),則Kind返回Invalid。
 * @param
 * @return
 **/
func (v Value) Kind() Kind {
	return v.kind()
}

// Len returns v's length.
// It panics if v's Kind is not Array, Chan, Map, Slice, or String.
/**
 * Len返回v的長度。
 * 如果v的Kind不是Array,Chan,Map,Slice或String,它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) Len() int {
	k := v.kind()
	switch k {
	case Array:
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		return int(tt.len)
	case Chan:
		return chanlen(v.pointer())
	case Map:
		return maplen(v.pointer())
	case Slice:
		// Slice is bigger than a word; assume flagIndir.
	  *  切片大於一個字; 假設flagIndir已經被設置值。
		return (*sliceHeader)(v.ptr).Len
	case String:
		// String is bigger than a word; assume flagIndir.
		// 字符串大於一個字; 假設flagIndir已經被設置值。
		return (*stringHeader)(v.ptr).Len
	}
	panic(&ValueError{"reflect.Value.Len", v.kind()})
}

// MapIndex returns the value associated with key in the map v.
// It panics if v's Kind is not Map.
// It returns the zero Value if key is not found in the map or if v represents a nil map.
// As in Go, the key's value must be assignable to the map's key type.
/**
 * MapIndex返回與map v中的key關聯的值。
 * 如果v的Kind不是Map,它會引起恐慌。
 * 如果在map中未找到鍵或v代表nil地圖,則返回零值。
 * 和Go一樣,鍵的值必須可分配給地圖的鍵類型。
 * @param
 * @return
 **/
func (v Value) MapIndex(key Value) Value {
	v.mustBe(Map)
	tt := (*mapType)(unsafe.Pointer(v.typ))

	// Do not require key to be exported, so that DeepEqual
	// and other programs can use all the keys returned by
	// MapKeys as arguments to MapIndex. If either the map
	// or the key is unexported, though, the result will be
	// considered unexported. This is consistent with the
	// behavior for structs, which allow read but not write
	// of unexported fields.
	// 不需要key是可導出的,以便DeepEqual和其他程序可以將MapKeys返回的所有key用作MapIndex的參數。
	// 但是,如果map或key是不可導出的,則結果將被視爲未導出。 這與結構的行爲一致,
	// 該結構允許讀取但不能寫入未導出的字段。
	key = key.assignTo("reflect.Value.MapIndex", tt.key, nil)

	var k unsafe.Pointer // 是間接指針
	if key.flag&flagIndir != 0 { // 間接指針
		k = key.ptr
	} else {
		k = unsafe.Pointer(&key.ptr) // 構造間接指針
	}
	e := mapaccess(v.typ, v.pointer(), k)
	if e == nil {
		return Value{}
	}
	typ := tt.elem
	fl := (v.flag | key.flag).ro()
	fl |= flag(typ.Kind())
	return copyVal(typ, fl, e)
}

// MapKeys returns a slice containing all the keys present in the map,
// in unspecified order.
// It panics if v's Kind is not Map.
// It returns an empty slice if v represents a nil map.
/**
 * MapKeys返回一個切片,其中包含未指定順序的map中存在的所有鍵。
 * 如果v的Kind不是Map,它會引起恐慌。
 * 如果v代表nil映射,則返回一個空切片。
 * @param
 * @return
 **/
func (v Value) MapKeys() []Value {
	v.mustBe(Map)
	tt := (*mapType)(unsafe.Pointer(v.typ))
	keyType := tt.key

	fl := v.flag.ro() | flag(keyType.Kind())

	m := v.pointer()
	mlen := int(0)
	if m != nil {
		mlen = maplen(m)
	}
	it := mapiterinit(v.typ, m)
	a := make([]Value, mlen)
	var i int
	for i = 0; i < len(a); i++ {
		key := mapiterkey(it)
		if key == nil {
			// Someone deleted an entry from the map since we
			// called maplen above. It's a data race, but nothing
			// we can do about it.
			// 自從我們在上面調用maplen以來,有人從map中刪除了一個條目。
			// 這是一場數據競賽,但是我們對此無能爲力。
			break
		}
		a[i] = copyVal(keyType, fl, key)
		mapiternext(it)
	}
	return a[:i]
}

// A MapIter is an iterator for ranging over a map.
// See Value.MapRange.
/**
 * MapIter是用於遍歷map的迭代器。請參見Value.MapRange。
 */
type MapIter struct {
	m  Value
	it unsafe.Pointer // map條件目的指針
}

// Key returns the key of the iterator's current map entry.
/**
 * Key返回迭代器的當前映射條目的key。
 */
func (it *MapIter) Key() Value {
	if it.it == nil {
		panic("MapIter.Key called before Next")
	}
	if mapiterkey(it.it) == nil {
		panic("MapIter.Key called on exhausted iterator")
	}

	t := (*mapType)(unsafe.Pointer(it.m.typ))
	ktype := t.key
	return copyVal(ktype, it.m.flag.ro()|flag(ktype.Kind()), mapiterkey(it.it))
}

// Value returns the value of the iterator's current map entry.
/**
 * Value返回迭代器的當前映射條目的value。
 */
func (it *MapIter) Value() Value {
	if it.it == nil {
		panic("MapIter.Value called before Next")
	}
	if mapiterkey(it.it) == nil {
		panic("MapIter.Value called on exhausted iterator")
	}

	t := (*mapType)(unsafe.Pointer(it.m.typ))
	vtype := t.elem
	return copyVal(vtype, it.m.flag.ro()|flag(vtype.Kind()), mapiterelem(it.it))
}

// Next advances the map iterator and reports whether there is another
// entry. It returns false when the iterator is exhausted; subsequent
// calls to Key, Value, or Next will panic.
/**
 * Next前進map迭代器並報告是否還有另一個條目。 迭代器用盡時,它返回false;否則,返回false。
 * 子序列隨後調用“鍵”,“值”或“下一步”將引起驚慌。
 * @param
 * @return
 **/
func (it *MapIter) Next() bool {
	if it.it == nil {
		it.it = mapiterinit(it.m.typ, it.m.pointer())
	} else {
		if mapiterkey(it.it) == nil {
			panic("MapIter.Next called on exhausted iterator")
		}
		mapiternext(it.it)
	}
	return mapiterkey(it.it) != nil
}

// MapRange returns a range iterator for a map.
// It panics if v's Kind is not Map.
//
// Call Next to advance the iterator, and Key/Value to access each entry.
// Next returns false when the iterator is exhausted.
// MapRange follows the same iteration semantics as a range statement.
//
// Example:
//
//	iter := reflect.ValueOf(m).MapRange()
// 	for iter.Next() {
//		k := iter.Key()
//		v := iter.Value()
//		...
//	}
//
/**
 * MapRange返回地圖的範圍迭代器。
 * 如果v的Kind不是Map,它會感到恐慌。
 *
 * 調用Next前進迭代器,並調用Key/Value訪問每個條目。
 * 迭代器用盡時,next返回false。
 * MapRange遵循與range語句相同的迭代語義。
 *
 * 示例:
 *  iter := reflect.ValueOf(m).MapRange()
 *      for iter.Next() {
 *      k := iter.Key()
 *      v := iter.Value()
 *      ...
 *  }
 * @param
 * @return
 **/
func (v Value) MapRange() *MapIter {
	v.mustBe(Map)
	return &MapIter{m: v}
}

// copyVal returns a Value containing the map key or value at ptr,
// allocating a new variable as needed.
/**
 * copyVal返回一個值,該值包含ptr處的映射鍵或值,並根據需要分配一個新變量。
 * @param
 * @return
 **/
func copyVal(typ *rtype, fl flag, ptr unsafe.Pointer) Value {
	if ifaceIndir(typ) { // 接口間接指針
		// Copy result so future changes to the map
		// won't change the underlying value.
		// 複製結果,以便將來對map所做的更改不會更改基礎值。
		c := unsafe_New(typ)
		typedmemmove(typ, c, ptr)
		return Value{typ, c, fl | flagIndir}
	}
	return Value{typ, *(*unsafe.Pointer)(ptr), fl}
}

// Method returns a function value corresponding to v's i'th method.
// The arguments to a Call on the returned function should not include
// a receiver; the returned function will always use v as the receiver.
// Method panics if i is out of range or if v is a nil interface value.
/**
 * 方法返回與v的第i個方法相對應的函數值。
 * 返回函數上的Call的參數不應包含接收方; 返回的函數將始終使用v作爲接收者。
 * 如果i超出範圍或v是一個nil接口值,則方法將出現恐慌。
 * @param
 * @return
 **/
func (v Value) Method(i int) Value {
	if v.typ == nil {
		panic(&ValueError{"reflect.Value.Method", Invalid})
	}
	if v.flag&flagMethod != 0 || uint(i) >= uint(v.typ.NumMethod()) {
		panic("reflect: Method index out of range")
	}
	if v.typ.Kind() == Interface && v.IsNil() { // 空接口
		panic("reflect: Method on nil interface value")
	}

	// 設置標記
	fl := v.flag & (flagStickyRO | flagIndir) // Clear flagEmbedRO // 清除flagEmbedRO標記
	fl |= flag(Func) // 添加函數類型標記
	fl |= flag(i)<<flagMethodShift | flagMethod // 添加方法標記,並且將i添加到標記中

	return Value{v.typ, v.ptr, fl}
}

// NumMethod returns the number of exported methods in the value's method set.
/**
 * NumMethod返回值的方法集中導出的方法的數量。
 * @param
 * @return
 **/
func (v Value) NumMethod() int {
	if v.typ == nil {
		panic(&ValueError{"reflect.Value.NumMethod", Invalid})
	}
	if v.flag&flagMethod != 0 {
		return 0
	}
	return v.typ.NumMethod()
}

// MethodByName returns a function value corresponding to the method
// of v with the given name.
// The arguments to a Call on the returned function should not include
// a receiver; the returned function will always use v as the receiver.
// It returns the zero Value if no method was found.
/**
 * MethodByName返回與具有給定名稱的v方法相對應的函數值。
 * 返回函數上的Call的參數不應包含接收方; 返回的函數將始終使用v作爲接收者。
 * 如果未找到任何方法,則返回零值。
 */
func (v Value) MethodByName(name string) Value {
	if v.typ == nil {
		panic(&ValueError{"reflect.Value.MethodByName", Invalid})
	}
	if v.flag&flagMethod != 0 { // value本身是方法類型
		return Value{}
	}
	m, ok := v.typ.MethodByName(name)
	if !ok {
		return Value{}
	}
	return v.Method(m.Index)
}

// NumField returns the number of fields in the struct v.
// It panics if v's Kind is not Struct.
/**
 * NumField返回結構v中的字段數。
 * 如果v的Kind不是Struct,則會引起恐慌。
 * @param
 * @return
 **/
func (v Value) NumField() int {
	v.mustBe(Struct)
	tt := (*structType)(unsafe.Pointer(v.typ))
	return len(tt.fields)
}

// OverflowComplex reports whether the complex128 x cannot be represented by v's type.
// It panics if v's Kind is not Complex64 or Complex128.
/**
 * OverflowComplex報告complex128 x是否不能用v的類型表示。
 * 如果v的Kind不是Complex64或Complex128,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) OverflowComplex(x complex128) bool {
	k := v.kind()
	switch k {
	case Complex64:
		return overflowFloat32(real(x)) || overflowFloat32(imag(x))
	case Complex128:
		return false
	}
	panic(&ValueError{"reflect.Value.OverflowComplex", v.kind()})
}

// OverflowFloat reports whether the float64 x cannot be represented by v's type.
// It panics if v's Kind is not Float32 or Float64.
/**
 * OverflowFloat報告float64 x是否不能用v的類型表示。
 * 如果v的Kind不是Float32或Float64,則會出現恐慌。
 */
func (v Value) OverflowFloat(x float64) bool {
	k := v.kind()
	switch k {
	case Float32:
		return overflowFloat32(x)
	case Float64:
		return false
	}
	panic(&ValueError{"reflect.Value.OverflowFloat", v.kind()})
}

func overflowFloat32(x float64) bool {
	if x < 0 {
		x = -x
	}
	return math.MaxFloat32 < x && x <= math.MaxFloat64
}

// OverflowInt reports whether the int64 x cannot be represented by v's type.
// It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
/**
 * OverflowInt報告int64 x是否不能用v的類型表示。
 * 如果v的Kind不是Int,Int8,Int16,Int32或Int64,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) OverflowInt(x int64) bool {
	k := v.kind()
	switch k {
	case Int, Int8, Int16, Int32, Int64:
		bitSize := v.typ.size * 8
		trunc := (x << (64 - bitSize)) >> (64 - bitSize // 先左移清除高位,右移還原低位
		return x != trunc
	}
	panic(&ValueError{"reflect.Value.OverflowInt", v.kind()})
}

// OverflowUint reports whether the uint64 x cannot be represented by v's type.
// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
/**
 * OverflowUint報告uint64 x是否不能用v的類型表示。
 * 如果v的Kind不是Uint,Uintptr,Uint8,Uint16,Uint32或Uint64,則會出現恐慌。
 * @param
 * @return
 **/
func (v Value) OverflowUint(x uint64) bool {
	k := v.kind()
	switch k {
	case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
		bitSize := v.typ.size * 8
		trunc := (x << (64 - bitSize)) >> (64 - bitSize) // 先左移清除高位,右移還原低位
		return x != trunc
	}
	panic(&ValueError{"reflect.Value.OverflowUint", v.kind()})
}

//go:nocheckptr
// This prevents inlining Value.Pointer when -d=checkptr is enabled,
// which ensures cmd/compile can recognize unsafe.Pointer(v.Pointer())
// and make an exception.

// Pointer returns v's value as a uintptr.
// It returns uintptr instead of unsafe.Pointer so that
// code using reflect cannot obtain unsafe.Pointers
// without importing the unsafe package explicitly.
// It panics if v's Kind is not Chan, Func, Map, Ptr, Slice, or UnsafePointer.
//
// If v's Kind is Func, the returned pointer is an underlying
// code pointer, but not necessarily enough to identify a
// single function uniquely. The only guarantee is that the
// result is zero if and only if v is a nil func Value.
//
// If v's Kind is Slice, the returned pointer is to the first
// element of the slice. If the slice is nil the returned value
// is 0.  If the slice is empty but non-nil the return value is non-zero.
/**
 * go:nocheckptr
 * 這樣可以防止在啓用-d = checkptr時內聯Value.Pointer,從而確保cmd/compile可以識別
 * unsafe.Pointer(v.Pointer())併產生異常。
 *
 * 指針以uintptr的形式返回v的值。
 * 它返回uintptr而不是unsafe.Pointer,因此使用反射的代碼無法獲取unsafe.Pointers而不顯式導入unsafe包。
 * 如果v的Kind不是Chan,Func,Map,Ptr,Slice或UnsafePointer,它會感到恐慌。
 *
 * 如果v的Kind爲Func,則返回的指針是底層代碼指針,但不一定足以唯一地標識單個函數。
 * 唯一的保證是,當且僅當v爲nil func值時,結果爲零。
 *
 * 如果v的Kind爲Slice,則返回的指針指向該切片的第一個元素。 如果切片爲nil,則返回值爲0。
 * 如果切片爲空但非nil,則返回值爲非零。
 * @param
 * @return
 **/
func (v Value) Pointer() uintptr {
	// TODO: deprecate
	k := v.kind()
	switch k {
	case Chan, Map, Ptr, UnsafePointer:
		return uintptr(v.pointer())
	case Func:
		if v.flag&flagMethod != 0 { // v本身是方法類型
			// As the doc comment says, the returned pointer is an
			// underlying code pointer but not necessarily enough to
			// identify a single function uniquely. All method expressions
			// created via reflect have the same underlying code pointer,
			// so their Pointers are equal. The function used here must
			// match the one used in makeMethodValue.
			// 如文檔註釋所述,返回的指針是底層代碼指針,但不一定足以唯一地標識單個函數。
			// 通過反射創建的所有方法表達式都具有相同的基礎代碼指針,因此它們的指針相等。
			// 這裏使用的函數必須與makeMethodValue中使用的函數匹配。
			f := methodValueCall
			return **(**uintptr)(unsafe.Pointer(&f)) // 間接指針取值
		}
		p := v.pointer()
		// Non-nil func value points at data block.
		// First word of data block is actual code.
		// 非nil func值指向數據塊。 數據塊的第一個字是實際代碼。
		if p != nil {
			p = *(*unsafe.Pointer)(p)
		}
		return uintptr(p)

	case Slice:
		return (*SliceHeader)(v.ptr).Data
	}
	panic(&ValueError{"reflect.Value.Pointer", v.kind()})
}

// Recv receives and returns a value from the channel v.
// It panics if v's Kind is not Chan.
// The receive blocks until a value is ready.
// The boolean value ok is true if the value x corresponds to a send
// on the channel, false if it is a zero value received because the channel is closed.
/**
 * Recv從通道v接收並返回一個值。
 * 如果v的類型(Kind)不是通道(Chan),就會引起恐慌。
 * 接收阻止,直到準備好值爲止。
 * 如果值x對應於通道上的發送的值,則布爾值ok爲true,如果由於通道關閉而接收到零值,則爲false。
 * @param
 * @return 
 **/
func (v Value) Recv() (x Value, ok bool) {
	v.mustBe(Chan)
	v.mustBeExported()
	return v.recv(false)
}

// internal recv, possibly non-blocking (nb).
// v is known to be a channel.
/**
 * 內部recv方法,可能是非阻塞(nb)。 v被稱爲通道。
 * @param true: 表示非阻塞
 * @return
 **/
func (v Value) recv(nb bool) (val Value, ok bool) {
	tt := (*chanType)(unsafe.Pointer(v.typ))
	if ChanDir(tt.dir)&RecvDir == 0 { // 非接收通道
		panic("reflect: recv on send-only channel")
	}
	t := tt.elem
	val = Value{t, nil, flag(t.Kind())}
	var p unsafe.Pointer // p是一個間接指針
	if ifaceIndir(t) { // 非間接指針
		p = unsafe_New(t)
		val.ptr = p
		val.flag |= flagIndir
	} else {
		p = unsafe.Pointer(&val.ptr)
	}
	selected, ok := chanrecv(v.pointer(), nb, p)
	if !selected { // 沒有收到返回值,就返回空
		val = Value{}
	}
	return
}

// Send sends x on the channel v.
// It panics if v's kind is not Chan or if x's type is not the same type as v's element type.
// As in Go, x's value must be assignable to the channel's element type.
/**
 * Send方法在通道v上發送x。
 * 如果v的種類不是Chan或x的類型與v的元素類型不同,則會引起恐慌。
 * 和Go一樣,x的值必須可分配給通道的元素類型。
 * @param
 * @return
 **/
func (v Value) Send(x Value) {
	v.mustBe(Chan)
	v.mustBeExported()
	v.send(x, false)
}

// internal send, possibly non-blocking.
// v is known to be a channel.
/**
 * 內部發送方法,可能是非阻塞的。v是一個通道。
 * @param
 * @param nb true: 表示不阻塞
 * @return
 **/
func (v Value) send(x Value, nb bool) (selected bool) {
	tt := (*chanType)(unsafe.Pointer(v.typ))
	if ChanDir(tt.dir)&SendDir == 0 { // 非發送通道
		panic("reflect: send on recv-only channel")
	}
	x.mustBeExported()
	x = x.assignTo("reflect.Value.Send", tt.elem, nil)
	var p unsafe.Pointer // p是一個間接指針
	if x.flag&flagIndir != 0 { // 非間接指針
		p = x.ptr
	} else {
		p = unsafe.Pointer(&x.ptr)
	}
	return chansend(v.pointer(), p, nb)
}

// Set assigns x to the value v.
// It panics if CanSet returns false.
// As in Go, x's value must be assignable to v's type.
/**
 * Set將x賦給值v。
 * 如果CanSet返回false,則會引起恐慌。
 * 和Go一樣,x的值必須可分配給v的類型。
 * @param
 * @return
 **/
func (v Value) Set(x Value) {
	v.mustBeAssignable() // 發須是可賦值的
	x.mustBeExported() // do not let unexported x leak // 不要讓未導出的x泄漏
	var target unsafe.Pointer
	if v.kind() == Interface { // 接口類型
		target = v.ptr
	}
	x = x.assignTo("reflect.Set", v.typ, target)
	if x.flag&flagIndir != 0 { // 非間接指針
		typedmemmove(v.typ, v.ptr, x.ptr)
	} else {
		*(*unsafe.Pointer)(v.ptr) = x.ptr
	}
}

// SetBool sets v's underlying value.
// It panics if v's Kind is not Bool or if CanSet() is false.
/**
 * SetBool設置v的底層值。
 * 如果v的Kind不是Bool或CanSet()爲false,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) SetBool(x bool) {
	v.mustBeAssignable()
	v.mustBe(Bool)
	*(*bool)(v.ptr) = x
}

// SetBytes sets v's underlying value.
// It panics if v's underlying value is not a slice of bytes.
/**
 * SetBytes設置v的底層值。
 * 如果v的底層值不是一個字節片,則會引起恐慌。
 * @param
 * @return
 **/
func (v Value) SetBytes(x []byte) {
	v.mustBeAssignable()
	v.mustBe(Slice)
	if v.typ.Elem().Kind() != Uint8 {
		panic("reflect.Value.SetBytes of non-byte slice")
	}
	*(*[]byte)(v.ptr) = x
}

// setRunes sets v's underlying value.
// It panics if v's underlying value is not a slice of runes (int32s).
/**
 * SetBytes設置v的底層值。
 * 如果v的底層值不是符文(int32s)切片,則會引起恐慌
 * @param
 * @return
 **/
func (v Value) setRunes(x []rune) {
	v.mustBeAssignable()
	v.mustBe(Slice)
	if v.typ.Elem().Kind() != Int32 {
		panic("reflect.Value.setRunes of non-rune slice")
	}
	*(*[]rune)(v.ptr) = x
}

// SetComplex sets v's underlying value to x.
// It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false.
/**
 * SetBytes設置v的底層值。
 * 如果v的Kind不是Complex64或Complex128,或者CanSet()爲false,則會引起恐慌
 * @param
 * @return
 **/
func (v Value) SetComplex(x complex128) {
	v.mustBeAssignable()
	switch k := v.kind(); k {
	default:
		panic(&ValueError{"reflect.Value.SetComplex", v.kind()})
	case Complex64:
		*(*complex64)(v.ptr) = complex64(x)
	case Complex128:
		*(*complex128)(v.ptr) = x
	}
}

// SetFloat sets v's underlying value to x.
// It panics if v's Kind is not Float32 or Float64, or if CanSet() is false.
/**
 * SetBytes設置v的底層值。
 * 如果v的Kind不是Float32或Float64,或者CanSet()爲false,則會引起恐慌
 * @param
 * @return
 **/
func (v Value) SetFloat(x float64) {
	v.mustBeAssignable()
	switch k := v.kind(); k {
	default:
		panic(&ValueError{"reflect.Value.SetFloat", v.kind()})
	case Float32:
		*(*float32)(v.ptr) = float32(x)
	case Float64:
		*(*float64)(v.ptr) = x
	}
}

// SetInt sets v's underlying value to x.
// It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false.
/**
 * SetBytes設置v的底層值。
 * 如果v的Kind不是Int, Int8, Int16, Int32, 或者 Int64,或者CanSet()爲false,則會引起恐慌
 * @param
 * @return
 **/
func (v Value) SetInt(x int64) {
	v.mustBeAssignable()
	switch k := v.kind(); k {
	default:
		panic(&ValueError{"reflect.Value.SetInt", v.kind()})
	case Int:
		*(*int)(v.ptr) = int(x)
	case Int8:
		*(*int8)(v.ptr) = int8(x)
	case Int16:
		*(*int16)(v.ptr) = int16(x)
	case Int32:
		*(*int32)(v.ptr) = int32(x)
	case Int64:
		*(*int64)(v.ptr) = x
	}
}

// SetLen sets v's length to n.
// It panics if v's Kind is not Slice or if n is negative or
// greater than the capacity of the slice.
/**
 * SetLen將v的長度設置爲n。
 * 如果v的Kind不是Slice,或者n爲負或大於slice的容量,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) SetLen(n int) {
	v.mustBeAssignable()
	v.mustBe(Slice)
	s := (*sliceHeader)(v.ptr)
	if uint(n) > uint(s.Cap) {
		panic("reflect: slice length out of range in SetLen")
	}
	s.Len = n
}

// SetCap sets v's capacity to n.
// It panics if v's Kind is not Slice or if n is smaller than the length or
// greater than the capacity of the slice.
/**
 * SetCap將v的容量設置爲n。
 * 如果v的Kind不是Slice,或者n小於length或大於slice的容量,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) SetCap(n int) {
	v.mustBeAssignable()
	v.mustBe(Slice)
	s := (*sliceHeader)(v.ptr)
	if n < s.Len || n > s.Cap {
		panic("reflect: slice capacity out of range in SetCap")
	}
	s.Cap = n
}

// SetMapIndex sets the element associated with key in the map v to elem.
// It panics if v's Kind is not Map.
// If elem is the zero Value, SetMapIndex deletes the key from the map.
// Otherwise if v holds a nil map, SetMapIndex will panic.
// As in Go, key's elem must be assignable to the map's key type,
// and elem's value must be assignable to the map's elem type.
/**
 * SetMapIndex將與map v中的key關聯的元素設置爲elem。
 * 如果v的Kind不是Map,它會感到恐慌。
 * 如果elem爲零值,則SetMapIndex會從map中刪除鍵。
 * 否則,如果v持有nil map,則SetMapIndex會恐慌。
 * 和Go一樣,鍵的elem必須可分配給map的鍵類型,並且elem的值必須可分配給map的值類型。
 * @param
 * @return
 **/
func (v Value) SetMapIndex(key, elem Value) {
	v.mustBe(Map) // 必須是map類型
	v.mustBeExported() // v必須是可導出類型
	key.mustBeExported() // key必須是可導出類型
	tt := (*mapType)(unsafe.Pointer(v.typ))
	key = key.assignTo("reflect.Value.SetMapIndex", tt.key, nil) // key必須可賦值給map的key
	var k unsafe.Pointer // 間接指針
	if key.flag&flagIndir != 0 { // 是間接指針
		k = key.ptr
	} else {
		k = unsafe.Pointer(&key.ptr)
	}
	if elem.typ == nil { // elem是nil類型,就從原map中刪除key並且返回
		mapdelete(v.typ, v.pointer(), k)
		return
	}
	elem.mustBeExported() // elem必須是可導出類型
	elem = elem.assignTo("reflect.Value.SetMapIndex", tt.elem, nil) // elem必須可賦值給map的value
	var e unsafe.Pointer // 間接指針
	if elem.flag&flagIndir != 0 { // 是間接指針
		e = elem.ptr
	} else {
		e = unsafe.Pointer(&elem.ptr)
	}
	mapassign(v.typ, v.pointer(), k, e) // 設值
}

// SetUint sets v's underlying value to x.
// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64, or if CanSet() is false.
/**
 * SetUint將v的底層設置爲x。
 * 如果v的Kind不是Uint,Uintptr,Uint8,Uint16,Uint32或Uint64,或者CanSet()爲false,則它會引起恐慌。
 * @param
 * @return
 **/
func (v Value) SetUint(x uint64) {
	v.mustBeAssignable()
	switch k := v.kind(); k {
	default:
		panic(&ValueError{"reflect.Value.SetUint", v.kind()})
	case Uint:
		*(*uint)(v.ptr) = uint(x)
	case Uint8:
		*(*uint8)(v.ptr) = uint8(x)
	case Uint16:
		*(*uint16)(v.ptr) = uint16(x)
	case Uint32:
		*(*uint32)(v.ptr) = uint32(x)
	case Uint64:
		*(*uint64)(v.ptr) = x
	case Uintptr:
		*(*uintptr)(v.ptr) = uintptr(x)
	}
}

// SetPointer sets the unsafe.Pointer value v to x.
// It panics if v's Kind is not UnsafePointer.
/**
 * SetPointer將unsafe.Pointer值v設置爲x。
 * 如果v的Kind不是UnsafePointer,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) SetPointer(x unsafe.Pointer) {
	v.mustBeAssignable()
	v.mustBe(UnsafePointer)
	*(*unsafe.Pointer)(v.ptr) = x
}

// SetString sets v's underlying value to x.
// It panics if v's Kind is not String or if CanSet() is false.
/**
 * SetString將v的底層值設置爲x。
 * 如果v的Kind不是String或CanSet()爲false,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) SetString(x string) {
	v.mustBeAssignable()
	v.mustBe(String)
	*(*string)(v.ptr) = x
}

// Slice returns v[i:j].
// It panics if v's Kind is not Array, Slice or String, or if v is an unaddressable array,
// or if the indexes are out of bounds.
/**
 * Slice返回v[i:j]。
 * 如果v的Kind不是Array,Slice或String,或者v是不可尋址的數組,或者索引超出範圍,則會發生恐慌。
 * @param
 * @return
 **/
func (v Value) Slice(i, j int) Value {
	var (
		cap  int
		typ  *sliceType
		base unsafe.Pointer
	)
	switch kind := v.kind(); kind {
	default:
		panic(&ValueError{"reflect.Value.Slice", v.kind()})

	case Array:
		if v.flag&flagAddr == 0 {
			panic("reflect.Value.Slice: slice of unaddressable array")
		}
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		cap = int(tt.len)
		typ = (*sliceType)(unsafe.Pointer(tt.slice))
		base = v.ptr

	case Slice:
		typ = (*sliceType)(unsafe.Pointer(v.typ))
		s := (*sliceHeader)(v.ptr)
		base = s.Data
		cap = s.Cap

	case String:
		s := (*stringHeader)(v.ptr)
		if i < 0 || j < i || j > s.Len {
			panic("reflect.Value.Slice: string slice index out of bounds")
		}
		var t stringHeader
		if i < s.Len {
			t = stringHeader{arrayAt(s.Data, i, 1, "i < s.Len"), j - i}
		}
		return Value{v.typ, unsafe.Pointer(&t), v.flag}
	}

	if i < 0 || j < i || j > cap {
		panic("reflect.Value.Slice: slice index out of bounds")
	}

	// Declare slice so that gc can see the base pointer in it.
	// 聲明slice,以便gc可以在其中看到基本指針。
	var x []unsafe.Pointer

	// Reinterpret as *sliceHeader to edit.
	// 重新解釋爲* sliceHeader進行編輯。
	s := (*sliceHeader)(unsafe.Pointer(&x))
	s.Len = j - i
	s.Cap = cap - i
	if cap-i > 0 {
		s.Data = arrayAt(base, i, typ.elem.Size(), "i < cap")
	} else {
		// do not advance pointer, to avoid pointing beyond end of slice
		// 不要前進指針,以避免指向超出切片末端
		s.Data = base
	}

	fl := v.flag.ro() | flagIndir | flag(Slice)
	return Value{typ.common(), unsafe.Pointer(&x), fl}
}

// Slice3 is the 3-index form of the slice operation: it returns v[i:j:k].
// It panics if v's Kind is not Array or Slice, or if v is an unaddressable array,
// or if the indexes are out of bounds.
/**
 * Slice3是切片操作的3索引形式:它返回v [i:j:k]。
 * 如果v的Kind不是Array或Slice,或者v是不可尋址的數組,或者索引超出範圍,則它會發生錯誤。
 * @param
 * @param
 * @param k 表示容量
 * @return
 **/
func (v Value) Slice3(i, j, k int) Value {
	var (
		cap  int
		typ  *sliceType
		base unsafe.Pointer
	)
	switch kind := v.kind(); kind {
	default:
		panic(&ValueError{"reflect.Value.Slice3", v.kind()})

	case Array:
		if v.flag&flagAddr == 0 {
			panic("reflect.Value.Slice3: slice of unaddressable array")
		}
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		cap = int(tt.len)
		typ = (*sliceType)(unsafe.Pointer(tt.slice))
		base = v.ptr

	case Slice:
		typ = (*sliceType)(unsafe.Pointer(v.typ))
		s := (*sliceHeader)(v.ptr)
		base = s.Data
		cap = s.Cap
	}

	if i < 0 || j < i || k < j || k > cap {
		panic("reflect.Value.Slice3: slice index out of bounds")
	}

	// Declare slice so that the garbage collector
	// can see the base pointer in it.
	// 聲明切片,以便垃圾收集器可以在其中看到基本指針。
	var x []unsafe.Pointer

	// Reinterpret as *sliceHeader to edit.
	// 重新解釋爲* sliceHeader進行編輯。
	s := (*sliceHeader)(unsafe.Pointer(&x))
	s.Len = j - i
	s.Cap = k - i
	if k-i > 0 {
		s.Data = arrayAt(base, i, typ.elem.Size(), "i < k <= cap")
	} else {
		// do not advance pointer, to avoid pointing beyond end of slice
		// 不要前進指針,以避免指向超出切片末端
		s.Data = base
	}

	fl := v.flag.ro() | flagIndir | flag(Slice) // 設置標記
	return Value{typ.common(), unsafe.Pointer(&x), fl}
}

// String returns the string v's underlying value, as a string.
// String is a special case because of Go's String method convention.
// Unlike the other getters, it does not panic if v's Kind is not String.
// Instead, it returns a string of the form "<T value>" where T is v's type.
// The fmt package treats Values specially. It does not call their String
// method implicitly but instead prints the concrete values they hold.
/**
 * String以字符串形式返回字符串v的底層值。
 * 由於Go的String方法約定,String是一種特殊情況。
 * 與其他獲取方法不同的是,如果v的Kind不是String,它不會驚慌。
 * 相反,它返回形式爲“ <T value>”的字符串,其中T是v的類型。
 * fmt包特別對待Values。 它不會隱式調用其String方法,而是打印它們持有的具體值。
 * @param
 * @return
 **/
func (v Value) String() string {
	switch k := v.kind(); k {
	case Invalid:
		return "<invalid Value>"
	case String:
		return *(*string)(v.ptr)
	}
	// If you call String on a reflect.Value of other type, it's better to
	// print something than to panic. Useful in debugging.
	// 如果在其他類型的reflect.Value上調用String,則打印某些內容要比恐慌好。 在調試中很有用。
	return "<" + v.Type().String() + " Value>"
}

// TryRecv attempts to receive a value from the channel v but will not block.
// It panics if v's Kind is not Chan.
// If the receive delivers a value, x is the transferred value and ok is true.
// If the receive cannot finish without blocking, x is the zero Value and ok is false.
// If the channel is closed, x is the zero value for the channel's element type and ok is false.
/**
 * TryRecv嘗試從通道v接收值,但不會阻塞。
 * 如果v's Kind不是Chan,就會引起恐慌。
 * 如果接收方提供了一個值,則x是已傳輸的值,而ok是true。
 * 如果接收無法完成而沒有阻塞,則x爲零值,ok爲false。
 * 如果關閉了通道,則x爲通道元素類型的零值,ok爲false。
 * @param
 * @return
 **/
func (v Value) TryRecv() (x Value, ok bool) {
	v.mustBe(Chan)
	v.mustBeExported()
	return v.recv(true)
}

// TrySend attempts to send x on the channel v but will not block.
// It panics if v's Kind is not Chan.
// It reports whether the value was sent.
// As in Go, x's value must be assignable to the channel's element type.
/**
 * TrySend嘗試在通道v上發送x,但不會阻塞。
 * 如果v's Kind不是Chan,就會感到恐慌。
 * 返回值報告是否發送了值。
 * 和Go一樣,x的值必須可分配給通道的元素類型。
 * @param
 * @return
 **/
func (v Value) TrySend(x Value) bool {
	v.mustBe(Chan)
	v.mustBeExported()
	return v.send(x, true)
}

// Type returns v's type.
/**
 * Type返回v的類型。
 * @param
 * @return
 **/
func (v Value) Type() Type {
	f := v.flag
	if f == 0 { // 非法類型
		panic(&ValueError{"reflect.Value.Type", Invalid})
	}
	if f&flagMethod == 0 { // 非方法類型
		// Easy case
		return v.typ
	}

	// Method value.
	// v.typ describes the receiver, not the method type.
	// 方法值。v.typ描述接收者,而不是方法類型。
	i := int(v.flag) >> flagMethodShift
	if v.typ.Kind() == Interface { // 接收者是接口
		// Method on interface.
		tt := (*interfaceType)(unsafe.Pointer(v.typ))
		if uint(i) >= uint(len(tt.methods)) { // 索引超出方法數
			panic("reflect: internal error: invalid method index")
		}
		m := &tt.methods[i]
		return v.typ.typeOff(m.typ)
	}
	// Method on concrete type.
	// 具體類型的方法。
	ms := v.typ.exportedMethods()
	if uint(i) >= uint(len(ms)) {
		panic("reflect: internal error: invalid method index")
	}
	m := ms[i]
	return v.typ.typeOff(m.mtyp)
}

// Uint returns v's underlying value, as a uint64.
// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
/**
 * Uint以uint64返回v的底層值。
 * 如果v的Kind不是Uint,Uintptr,Uint8,Uint16,Uint32或Uint64,則會出現恐慌。
 * @param
 * @return
 **/
func (v Value) Uint() uint64 {
	k := v.kind()
	p := v.ptr
	switch k {
	case Uint:
		return uint64(*(*uint)(p))
	case Uint8:
		return uint64(*(*uint8)(p))
	case Uint16:
		return uint64(*(*uint16)(p))
	case Uint32:
		return uint64(*(*uint32)(p))
	case Uint64:
		return *(*uint64)(p)
	case Uintptr:
		return uint64(*(*uintptr)(p))
	}
	panic(&ValueError{"reflect.Value.Uint", v.kind()})
}

//go:nocheckptr
// This prevents inlining Value.UnsafeAddr when -d=checkptr is enabled,
// which ensures cmd/compile can recognize unsafe.Pointer(v.UnsafeAddr())
// and make an exception.

// UnsafeAddr returns a pointer to v's data.
// It is for advanced clients that also import the "unsafe" package.
// It panics if v is not addressable.
/**
 * go:nocheckptr
 * 這樣可以防止在啓用-d=checkptr時內聯Value.UnsafeAddr,
 * 以確保cmd/compile可以識別unsafe.Pointer(v.UnsafeAddr())並生成異常。

 * UnsafeAddr返回指向v的數據的指針。
 * 適用於高級客戶,這些客戶也導入了“不安全”包。
 * 如果v不可尋址,則會出現恐慌情況。
 * @param
 * @return
 **/
func (v Value) UnsafeAddr() uintptr {
	// TODO: deprecate
	if v.typ == nil {
		panic(&ValueError{"reflect.Value.UnsafeAddr", Invalid})
	}
	if v.flag&flagAddr == 0 {
		panic("reflect.Value.UnsafeAddr of unaddressable value")
	}
	return uintptr(v.ptr)
}

// StringHeader is the runtime representation of a string.
// It cannot be used safely or portably and its representation may
// change in a later release.
// Moreover, the Data field is not sufficient to guarantee the data
// it references will not be garbage collected, so programs must keep
// a separate, correctly typed pointer to the underlying data.
/**
 * StringHeader是字符串的運行時表示形式。
 * 無法安全或便攜地使用它,並且其表示形式可能在以後的版本中更改。
 * 此外,“Data”字段還不足以保證不會對其進行垃圾回收,因此程序必須保留一個單獨的,
 * 正確類型的指向基礎數據的指針。
 * 注意:這是一個非穩定性結構,後續的版本可能會改變
 * @param
 * @return
 **/
type StringHeader struct {
	Data uintptr
	Len  int
}

// stringHeader is a safe version of StringHeader used within this package.
/**
 * stringHeader是此程序包中使用的StringHeader的安全版本。
 * @param
 * @return
 **/
type stringHeader struct {
	Data unsafe.Pointer
	Len  int
}

// SliceHeader is the runtime representation of a slice.
// It cannot be used safely or portably and its representation may
// change in a later release.
// Moreover, the Data field is not sufficient to guarantee the data
// it references will not be garbage collected, so programs must keep
// a separate, correctly typed pointer to the underlying data.
/**
 * SliceHeader是切片的運行時表示形式。
 * 無法安全或便攜地使用它,並且其表示形式可能在以後的版本中更改。
 * 此外,“Data”字段還不足以保證不會對其進行垃圾回收,因此程序必須保留一個單獨的,
 * 正確類型的指向基礎數據的指針。
 * 注意:這是一個非穩定性結構,後續的版本可能會改變
 * @param
 * @return
 **/
type SliceHeader struct {
	Data uintptr
	Len  int
	Cap  int
}

// sliceHeader is a safe version of SliceHeader used within this package.
/**
 * sliceHeader是此包中使用的SliceHeader的安全版本。
 * @param
 * @return
 **/
type sliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

/**
 * 兩種類型必須切爾西
 * @param
 * @return
 **/
func typesMustMatch(what string, t1, t2 Type) {
	if t1 != t2 {
		panic(what + ": " + t1.String() + " != " + t2.String())
	}
}

// arrayAt returns the i-th element of p,
// an array whose elements are eltSize bytes wide.
// The array pointed at by p must have at least i+1 elements:
// it is invalid (but impossible to check here) to pass i >= len,
// because then the result will point outside the array.
// whySafe must explain why i < len. (Passing "i < len" is fine;
// the benefit is to surface this assumption at the call site.)
/**
 * arrayAt返回p的第i個元素,其中p是eltSize字節寬的數組。
 * p指向的數組必須至少包含i+1個元素:傳遞i>=len無效(但此處無法檢查),因爲這樣結果將指向數組之外。
 * whySafe必須解釋爲什麼i<len。 (傳遞“i<len”是可以的;這樣做的好處是可以在調用點顯示此假設。)
 * @param
 * @return
 **/
func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Pointer {
	return add(p, uintptr(i)*eltSize, "i < len")
}

// grow grows the slice s so that it can hold extra more values, allocating
// more capacity if needed. It also returns the old and new slice lengths.
/**
 * 增長切片s,使其可以容納更多的值,並在需要時分配更多的容量。它還返回舊的和新的切片長度。
 * @param
 * @return
 **/
func grow(s Value, extra int) (Value, int, int) {
	i0 := s.Len()
	i1 := i0 + extra
	if i1 < i0 { // 溢出
		panic("reflect.Append: slice overflow")
	}
	m := s.Cap()
	if i1 <= m {
		return s.Slice(0, i1), i0, i1
	}
	if m == 0 {
		m = extra
	} else {
		for m < i1 {
			if i0 < 1024 { // 小於1024每次加倍,大於1024每次增長1/4
				m += m
			} else {
				m += m / 4
			}
		}
	}
	t := MakeSlice(s.Type(), i1, m)
	Copy(t, s)
	return t, i0, i1
}

// Append appends the values x to a slice s and returns the resulting slice.
// As in Go, each x's value must be assignable to the slice's element type.
/**
 * Append將值x附加到切片s上,並返回結果切片。與Go中一樣,每個x的值必須可分配給slice的元素類型。
 * @param
 * @return
 **/
func Append(s Value, x ...Value) Value {
	s.mustBe(Slice)
	s, i0, i1 := grow(s, len(x))
	for i, j := i0, 0; i < i1; i, j = i+1, j+1 {
		s.Index(i).Set(x[j])
	}
	return s
}

// AppendSlice appends a slice t to a slice s and returns the resulting slice.
// The slices s and t must have the same element type.
/**
 * AppendSlice將切片t附加到切片s上,並返回結果切片。 切片s和t必須具有相同的元素類型。
 * @param
 * @return
 **/
func AppendSlice(s, t Value) Value {
	s.mustBe(Slice)
	t.mustBe(Slice)
	typesMustMatch("reflect.AppendSlice", s.Type().Elem(), t.Type().Elem())
	s, i0, i1 := grow(s, t.Len())
	Copy(s.Slice(i0, i1), t)
	return s
}

// Copy copies the contents of src into dst until either
// dst has been filled or src has been exhausted.
// It returns the number of elements copied.
// Dst and src each must have kind Slice or Array, and
// dst and src must have the same element type.
//
// As a special case, src can have kind String if the element type of dst is kind Uint8.
/**
 * 複製將src的內容複製到dst中,直到填滿dst或用盡src。
 * 返回複製的元素數。
 * dst和src都必須具有切片或數組類型,並且dst和src必須具有相同的元素類型。
 *
 * 作爲一種特殊情況,如果dst的元素類型爲Uint8,則src可以具有String類型。
 * @param
 * @return
 **/
func Copy(dst, src Value) int {
	dk := dst.kind()
	if dk != Array && dk != Slice {
		panic(&ValueError{"reflect.Copy", dk})
	}
	if dk == Array {
		dst.mustBeAssignable()
	}
	dst.mustBeExported()

	sk := src.kind()
	var stringCopy bool
	if sk != Array && sk != Slice {
		stringCopy = sk == String && dst.typ.Elem().Kind() == Uint8
		if !stringCopy {
			panic(&ValueError{"reflect.Copy", sk})
		}
	}
	src.mustBeExported()

	de := dst.typ.Elem()
	if !stringCopy {
		se := src.typ.Elem()
		typesMustMatch("reflect.Copy", de, se)
	}

	var ds, ss sliceHeader
	if dk == Array {
		ds.Data = dst.ptr
		ds.Len = dst.Len()
		ds.Cap = ds.Len
	} else {
		ds = *(*sliceHeader)(dst.ptr)
	}
	if sk == Array {
		ss.Data = src.ptr
		ss.Len = src.Len()
		ss.Cap = ss.Len
	} else if sk == Slice {
		ss = *(*sliceHeader)(src.ptr)
	} else {
		sh := *(*stringHeader)(src.ptr)
		ss.Data = sh.Data
		ss.Len = sh.Len
		ss.Cap = sh.Len
	}

	return typedslicecopy(de.common(), ds, ss)
}

// A runtimeSelect is a single case passed to rselect.
// This must match ../runtime/select.go:/runtimeSelect
/**
 * runtimeSelect是傳遞給rselect的單個案例。
 * 這必須匹配../runtime/select.go:/runtimeSelect
 * @param
 * @return
 **/
type runtimeSelect struct {
	dir SelectDir    //  SelectSend, SelectRecv or SelectDefault  // 通道方向
	typ *rtype       //  channel type   // 通道數據類型
	ch  unsafe.Pointer // channel // 通道指針
	val unsafe.Pointer // ptr to data (SendDir) or ptr to receive buffer (RecvDir) // 數據指針
}

// rselect runs a select. It returns the index of the chosen case.
// If the case was a receive, val is filled in with the received value.
// The conventional OK bool indicates whether the receive corresponds
// to a sent value.
//go:noescape
/**
 * rselect運行select。 它返回所選case的索引。
 * 如果case是接收的,則用接收的值填充val。
 * 常規的OK bool指示接收是否與發送的值相對應。
 *go:noescape
 */
func rselect([]runtimeSelect) (chosen int, recvOK bool)

// A SelectDir describes the communication direction of a select case.
/**
 * SelectDir描述select case的通信方向。
 */
type SelectDir int

// NOTE: These values must match ../runtime/select.go:/selectDir.
// 注意:這些值必須匹配../runtime/select.go:/selectDir。

const (
	_             SelectDir = iota
	SelectSend            //  case Chan <- Send // 發送case
	SelectRecv            //  case <-Chan:      // 接收case
	SelectDefault         //  default           // 默認case
)

// A SelectCase describes a single case in a select operation.
// The kind of case depends on Dir, the communication direction.
//
// If Dir is SelectDefault, the case represents a default case.
// Chan and Send must be zero Values.
//
// If Dir is SelectSend, the case represents a send operation.
// Normally Chan's underlying value must be a channel, and Send's underlying value must be
// assignable to the channel's element type. As a special case, if Chan is a zero Value,
// then the case is ignored, and the field Send will also be ignored and may be either zero
// or non-zero.
//
// If Dir is SelectRecv, the case represents a receive operation.
// Normally Chan's underlying value must be a channel and Send must be a zero Value.
// If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
// When a receive operation is selected, the received Value is returned by Select.
//
/**
 * SelectCase描述了select操作中的單個case情況。case的種類取決於Dir,通訊方向。
 *
 * 如果Dir爲SelectDefault,則case表示default case。Chan和Send必須爲零值。
 *
 * 如果Dir是SelectSend,則case表示發送操作。
 * 通常,Chan的底層值必須是一個通道,Send的底層值必須可分配給該渠道的元素類型。
 * 作爲一種特殊情況,如果Chan爲零值,則忽略大小寫,並且字段Send也將被忽略,並且可以爲零或非零。
 *
 * 如果Dir是SelectRecv,則case表示接收操作。
 * 通常,Chan的底層值必須是一個通道,Send必須是零值。
 * 如果Chan是零值,則忽略大小寫,但是Send必須仍然是零值。
 * 選擇接收操作時,Select將返回接收到的值。
 *
 */
type SelectCase struct {
	Dir  SelectDir // direction of case // case方向
	Chan Value   //  channel to use (for send or receive) // 使用的通道(用於發送或接收)
	Send Value     // value to send (for send) // 要發送的值(用於發送)
}

// Select executes a select operation described by the list of cases.
// Like the Go select statement, it blocks until at least one of the cases
// can proceed, makes a uniform pseudo-random choice,
// and then executes that case. It returns the index of the chosen case
// and, if that case was a receive operation, the value received and a
// boolean indicating whether the value corresponds to a send on the channel
// (as opposed to a zero value received because the channel is closed).
/**
 * Select執行case列表所描述的選擇操作。
 * 像Go select語句一樣,它阻塞直到至少一種case可以繼續進行,做出統一的僞隨機選擇,然後執行該情況。
 * 它返回所選case的索引,如果該case是接收操作,則返回接收到的值和一個布爾值,指示該值是否對應於通道上的發送
 * (而不是因爲通道關閉而接收到的零值)。
 */
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool) {
	// NOTE: Do not trust that caller is not modifying cases data underfoot.
	// The range is safe because the caller cannot modify our copy of the len
	// and each iteration makes its own copy of the value c.
	// 注意:不要相信調用者沒有修改下面的case數據。
    // 範圍是安全的,因爲調用者無法修改我們的len副本,並且每次迭代都將自己複製值c。
	runcases := make([]runtimeSelect, len(cases))
	haveDefault := false // 是否有默認case
	for i, c := range cases { // 遍歷所有的case
		rc := &runcases[i]
		rc.dir = c.Dir
		switch c.Dir { // 通道方向
		default:
			panic("reflect.Select: invalid Dir")

		case SelectDefault: // default // 默認情況
			if haveDefault {
				panic("reflect.Select: multiple default cases")
			}
			haveDefault = true // 標記有select default
			if c.Chan.IsValid() {
				panic("reflect.Select: default case has Chan value")
			}
			if c.Send.IsValid() {
				panic("reflect.Select: default case has Send value")
			}

		case SelectSend: // 發送通道
			ch := c.Chan
			if !ch.IsValid() { // 通道無效
				break
			}
			ch.mustBe(Chan)
			ch.mustBeExported()
			tt := (*chanType)(unsafe.Pointer(ch.typ))
			if ChanDir(tt.dir)&SendDir == 0 { // 不是發送通道
				panic("reflect.Select: SendDir case using recv-only channel")
			}
			rc.ch = ch.pointer()
			rc.typ = &tt.rtype
			v := c.Send
			if !v.IsValid() { // 值無效
				panic("reflect.Select: SendDir case missing Send value")
			}
			v.mustBeExported()
			v = v.assignTo("reflect.Select", tt.elem, nil)
			if v.flag&flagIndir != 0 { // 間接指針
				rc.val = v.ptr
			} else {
				rc.val = unsafe.Pointer(&v.ptr) // 非間接指針,就構造間接指針
			}

		case SelectRecv: // 接收通道
			if c.Send.IsValid() { // 發送值有效
				panic("reflect.Select: RecvDir case has Send value")
			}
			ch := c.Chan
			if !ch.IsValid() { // 通道無效
				break
			}
			ch.mustBe(Chan)
			ch.mustBeExported()
			tt := (*chanType)(unsafe.Pointer(ch.typ))
			if ChanDir(tt.dir)&RecvDir == 0 { // 非接收通道
				panic("reflect.Select: RecvDir case using send-only channel")
			}
			rc.ch = ch.pointer()
			rc.typ = &tt.rtype
			rc.val = unsafe_New(tt.elem)
		}
	}

	chosen, recvOK = rselect(runcases)
	if runcases[chosen].dir == SelectRecv { // 如果是接收通道,需要處理接收值
		tt := (*chanType)(unsafe.Pointer(runcases[chosen].typ))
		t := tt.elem
		p := runcases[chosen].val
		fl := flag(t.Kind())
		if ifaceIndir(t) {
			recv = Value{t, p, fl | flagIndir}
		} else {
			recv = Value{t, *(*unsafe.Pointer)(p), fl}
		}
	}
	return chosen, recv, recvOK
}

/*
 * constructors
 */

// implemented in package runtime
/**
 * 在runtime包時中實現
 */
func unsafe_New(*rtype) unsafe.Pointer
func unsafe_NewArray(*rtype, int) unsafe.Pointer

// MakeSlice creates a new zero-initialized slice value
// for the specified slice type, length, and capacity.
/**
 * MakeSlice爲指定的切片類型,長度和容量創建一個新的零初始化切片值。
 * @param
 * @return
 **/
func MakeSlice(typ Type, len, cap int) Value {
	if typ.Kind() != Slice {
		panic("reflect.MakeSlice of non-slice type")
	}
	if len < 0 {
		panic("reflect.MakeSlice: negative len")
	}
	if cap < 0 {
		panic("reflect.MakeSlice: negative cap")
	}
	if len > cap {
		panic("reflect.MakeSlice: len > cap")
	}

	s := sliceHeader{unsafe_NewArray(typ.Elem().(*rtype), cap), len, cap}
	return Value{typ.(*rtype), unsafe.Pointer(&s), flagIndir | flag(Slice)}
}

// MakeChan creates a new channel with the specified type and buffer size.
/**
 * MakeChan用指定的類型和緩衝區大小創建一個新通道。
 * @param
 * @return
 **/
func MakeChan(typ Type, buffer int) Value {
	if typ.Kind() != Chan {
		panic("reflect.MakeChan of non-chan type")
	}
	if buffer < 0 {
		panic("reflect.MakeChan: negative buffer size")
	}
	if typ.ChanDir() != BothDir {
		panic("reflect.MakeChan: unidirectional channel type")
	}
	t := typ.(*rtype)
	ch := makechan(t, buffer)
	return Value{t, ch, flag(Chan)}
}

// MakeMap creates a new map with the specified type.
/**
 * MakeMap創建具有指定類型的新map。
 * @param
 * @return
 **/
func MakeMap(typ Type) Value {
	return MakeMapWithSize(typ, 0)
}

// MakeMapWithSize creates a new map with the specified type
// and initial space for approximately n elements.
/**
 * MakeMapWithSize會爲大約n個元素創建一個具有指定類型和初始空間的新Map。
 * @param
 * @return
 **/
func MakeMapWithSize(typ Type, n int) Value {
	if typ.Kind() != Map {
		panic("reflect.MakeMapWithSize of non-map type")
	}
	t := typ.(*rtype)
	m := makemap(t, n)
	return Value{t, m, flag(Map)}
}

// Indirect returns the value that v points to.
// If v is a nil pointer, Indirect returns a zero Value.
// If v is not a pointer, Indirect returns v.
/**
 * Indirect返回v指向的值。
 * 如果v是nil指針,則Indirect返回零值。
 * 如果v不是指針,則Indirect返回v。
 * @param
 * @return
 **/
func Indirect(v Value) Value {
	if v.Kind() != Ptr {
		return v
	}
	return v.Elem()
}

// ValueOf returns a new Value initialized to the concrete value
// stored in the interface i. ValueOf(nil) returns the zero Value.
/**
 * ValueOf返回一個新的Value,初始化爲存儲在接口i中的具體值。 ValueOf(nil)返回零值。
 * @param
 * @return
 **/
func ValueOf(i interface{}) Value {
	if i == nil {
		return Value{}
	}

	// TODO: Maybe allow contents of a Value to live on the stack.
	// For now we make the contents always escape to the heap. It
	// makes life easier in a few places (see chanrecv/mapassign
	// comment below).
	// 待辦事項:也許允許Value的內容保留在堆棧中。
    // 現在,我們使內容始終轉儲到堆中。 它使某些地方的使用更方便(生活更加輕鬆)(請參閱下面的chanrecv/mapassign評論)。
	escapes(i)

	return unpackEface(i)
}

// Zero returns a Value representing the zero value for the specified type.
// The result is different from the zero value of the Value struct,
// which represents no value at all.
// For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
// The returned value is neither addressable nor settable.
/**
 * Zero返回一個值,該值表示指定類型的零值。
 * 結果不同於Value結構的零值,該值根本不代表任何值。
 * 例如,Zero(TypeOf(42))返回具有Kind Int和值0的值。
 * 返回的值既不可尋址也不可設置。
 * @param
 * @return
 **/
func Zero(typ Type) Value {
	if typ == nil {
		panic("reflect: Zero(nil)")
	}
	t := typ.(*rtype)
	fl := flag(t.Kind())
	if ifaceIndir(t) { // 間接指針
		return Value{t, unsafe_New(t), fl | flagIndir}
	}
	return Value{t, nil, fl}
}

// New returns a Value representing a pointer to a new zero value
// for the specified type. That is, the returned Value's Type is PtrTo(typ).
/**
 * 新建返回一個值,該值表示指向指定類型的新零值的指針。 也就是說,返回的值的類型爲PtrTo(typ)。
 * @param
 * @return
 **/
func New(typ Type) Value {
	if typ == nil {
		panic("reflect: New(nil)")
	}
	t := typ.(*rtype)
	ptr := unsafe_New(t)
	fl := flag(Ptr) // 指針類型
	return Value{t.ptrTo(), ptr, fl}
}

// NewAt returns a Value representing a pointer to a value of the
// specified type, using p as that pointer.
/**
 * NewAt返回一個值,該值表示指向指定類型值的指針,並使用p作爲該指針。
 * @param
 * @return
 **/
func NewAt(typ Type, p unsafe.Pointer) Value {
	fl := flag(Ptr)
	t := typ.(*rtype)
	return Value{t.ptrTo(), p, fl}
}

// assignTo returns a value v that can be assigned directly to typ.
// It panics if v is not assignable to typ.
// For a conversion to an interface type, target is a suggested scratch space to use.
/**
 * AssignTo返回可以直接分配給typ的值v。
 * 如果無法將v分配給typ,則會出現恐慌情況。
 * 要轉換爲接口類型,target是建議使用的暫存空間。
 * @param
 * @return
 **/
func (v Value) assignTo(context string, dst *rtype, target unsafe.Pointer) Value {
	if v.flag&flagMethod != 0 { // v是一個方法類型
		v = makeMethodValue(context, v)
	}

	switch {
	case directlyAssignable(dst, v.typ): // 可以直接賦值
		// Overwrite type so that they match.
		// Same memory layout, so no harm done.
		// 覆蓋類型,使它們匹配。 相同的內存佈局,因此無害。
		fl := v.flag&(flagAddr|flagIndir) | v.flag.ro() // 設置標記
		fl |= flag(dst.Kind())
		return Value{dst, v.ptr, fl}

	case implements(dst, v.typ): // 類型實現
		if target == nil {
			target = unsafe_New(dst)
		}
		if v.Kind() == Interface && v.IsNil() { // v是接口類型,並且v值是nil
			// A nil ReadWriter passed to nil Reader is OK,
			// but using ifaceE2I below will panic.
			// Avoid the panic by returning a nil dst (e.g., Reader) explicitly.
			// 傳遞給nil Reader的nil ReadWriter是可以的,但是在下面使用ifaceE2I會引起恐慌。
            // 通過顯式返回nil dst(例如Reader)來避免恐慌。
			return Value{dst, nil, flag(Interface)}
		}
		x := valueInterface(v, false)
		if dst.NumMethod() == 0 { // dst沒有方法
			*(*interface{})(target) = x
		} else {
			ifaceE2I(dst, x, target)
		}
		return Value{dst, target, flagIndir | flag(Interface)} // 打上間接打針和接口標記
	}

	// Failed.
	panic(context + ": value of type " + v.typ.String() + " is not assignable to type " + dst.String())
}

// Convert returns the value v converted to type t.
// If the usual Go conversion rules do not allow conversion
// of the value v to type t, Convert panics.
/**
 * Convert返回將值v轉換爲類型t。
 * 如果通常的Go轉換規則不允許將值v轉換爲類型t,請轉換恐慌。
 * @param
 * @return
 **/
func (v Value) Convert(t Type) Value {
	if v.flag&flagMethod != 0 { // v是方法類型
		v = makeMethodValue("Convert", v)
	}
	op := convertOp(t.common(), v.typ) // 類型轉換
	if op == nil { // 結果爲nil,說明轉換非法
		panic("reflect.Value.Convert: value of type " + v.typ.String() + " cannot be converted to type " + t.String())
	}
	return op(v, t)
}

// convertOp returns the function to convert a value of type src
// to a value of type dst. If the conversion is illegal, convertOp returns nil.
/**
 * convertOp返回將src類型的值轉換爲dst類型的值的函數。 如果轉換是非法的,則convertOp返回nil。
 * @param dst 目標類型
 * @param src 源類型
 * @return Value nil表示轉換非法,非op返回的值是一個轉換方法
 **/
func convertOp(dst, src *rtype) func(Value, Type) Value {
	switch src.Kind() {
	case Int, Int8, Int16, Int32, Int64:
		switch dst.Kind() {
		case Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
			return cvtInt
		case Float32, Float64:
			return cvtIntFloat
		case String:
			return cvtIntString
		}

	case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
		switch dst.Kind() {
		case Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
			return cvtUint
		case Float32, Float64:
			return cvtUintFloat
		case String:
			return cvtUintString
		}

	case Float32, Float64:
		switch dst.Kind() {
		case Int, Int8, Int16, Int32, Int64:
			return cvtFloatInt
		case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
			return cvtFloatUint
		case Float32, Float64:
			return cvtFloat
		}

	case Complex64, Complex128:
		switch dst.Kind() {
		case Complex64, Complex128:
			return cvtComplex
		}

	case String:
		if dst.Kind() == Slice && dst.Elem().PkgPath() == "" {
			switch dst.Elem().Kind() {
			case Uint8:
				return cvtStringBytes
			case Int32:
				return cvtStringRunes
			}
		}

	case Slice:
		if dst.Kind() == String && src.Elem().PkgPath() == "" {
			switch src.Elem().Kind() {
			case Uint8:
				return cvtBytesString
			case Int32:
				return cvtRunesString
			}
		}

	case Chan:
		if dst.Kind() == Chan && specialChannelAssignability(dst, src) {
			return cvtDirect
		}
	}

	// dst and src have same underlying type.
	// dst和src具有相同的底層類型。
	if haveIdenticalUnderlyingType(dst, src, false) {
		return cvtDirect
	}

	// dst and src are non-defined pointer types with same underlying base type.
	// dst和src是具有相同基本類型的未定義指針類型。
	if dst.Kind() == Ptr && dst.Name() == "" &&
		src.Kind() == Ptr && src.Name() == "" &&
		haveIdenticalUnderlyingType(dst.Elem().common(), src.Elem().common(), false) {
		return cvtDirect
	}

	if implements(dst, src) { // dst實現了src
		if src.Kind() == Interface { // src是接口
			return cvtI2I
		}
		return cvtT2I
	}

	return nil
}

// makeInt returns a Value of type t equal to bits (possibly truncated),
// where t is a signed or unsigned int type.
/**
 * makeInt返回類型t的值,該值等於bits(可能被截斷),其中t是有符號或無符號int類型。
 * @param
 * @return
 **/
func makeInt(f flag, bits uint64, t Type) Value {
	typ := t.common()
	ptr := unsafe_New(typ)
	switch typ.size {
	case 1:
		*(*uint8)(ptr) = uint8(bits)
	case 2:
		*(*uint16)(ptr) = uint16(bits)
	case 4:
		*(*uint32)(ptr) = uint32(bits)
	case 8:
		*(*uint64)(ptr) = bits
	}
	return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
}

// makeFloat returns a Value of type t equal to v (possibly truncated to float32),
// where t is a float32 or float64 type.
/**
 * makeFloat返回的t類型的值等於v(可能被截斷爲float32),其中t是float32或float64類型。
 * @param
 * @return
 **/
func makeFloat(f flag, v float64, t Type) Value {
	typ := t.common()
	ptr := unsafe_New(typ)
	switch typ.size {
	case 4:
		*(*float32)(ptr) = float32(v)
	case 8:
		*(*float64)(ptr) = v
	}
	return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
}

// makeComplex returns a Value of type t equal to v (possibly truncated to complex64),
// where t is a complex64 or complex128 type.
/**
 * makeComplex返回類型爲t的值等於v(可能被截斷爲complex64),其中t是complex64或complex128類型。
 * @param
 * @return
 **/
func makeComplex(f flag, v complex128, t Type) Value {
	typ := t.common()
	ptr := unsafe_New(typ)
	switch typ.size {
	case 8:
		*(*complex64)(ptr) = complex64(v)
	case 16:
		*(*complex128)(ptr) = v
	}
	return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
}

func makeString(f flag, v string, t Type) Value {
	ret := New(t).Elem()
	ret.SetString(v)
	ret.flag = ret.flag&^flagAddr | f
	return ret
}

func makeBytes(f flag, v []byte, t Type) Value {
	ret := New(t).Elem()
	ret.SetBytes(v)
	ret.flag = ret.flag&^flagAddr | f
	return ret
}

func makeRunes(f flag, v []rune, t Type) Value {
	ret := New(t).Elem()
	ret.setRunes(v)
	ret.flag = ret.flag&^flagAddr | f
	return ret
}

// These conversion functions are returned by convertOp
// for classes of conversions. For example, the first function, cvtInt,
// takes any value v of signed int type and returns the value converted
// to type t, where t is any signed or unsigned int type.
/**
 * 這些轉換函數由convertOp返回,用於轉換類型。
 * 例如,第一個函數cvtInt接受帶符號int類型的任何值v並返回轉換爲類型t的值,
 * 其中t是任何帶符號或無符號int類型。
 * @param
 * @return
 **/

// convertOp: intXX -> [u]intXX
func cvtInt(v Value, t Type) Value {
	return makeInt(v.flag.ro(), uint64(v.Int()), t)
}

// convertOp: uintXX -> [u]intXX
func cvtUint(v Value, t Type) Value {
	return makeInt(v.flag.ro(), v.Uint(), t)
}

// convertOp: floatXX -> intXX
func cvtFloatInt(v Value, t Type) Value {
	return makeInt(v.flag.ro(), uint64(int64(v.Float())), t)
}

// convertOp: floatXX -> uintXX
func cvtFloatUint(v Value, t Type) Value {
	return makeInt(v.flag.ro(), uint64(v.Float()), t)
}

// convertOp: intXX -> floatXX
func cvtIntFloat(v Value, t Type) Value {
	return makeFloat(v.flag.ro(), float64(v.Int()), t)
}

// convertOp: uintXX -> floatXX
func cvtUintFloat(v Value, t Type) Value {
	return makeFloat(v.flag.ro(), float64(v.Uint()), t)
}

// convertOp: floatXX -> floatXX
func cvtFloat(v Value, t Type) Value {
	return makeFloat(v.flag.ro(), v.Float(), t)
}

// convertOp: complexXX -> complexXX
func cvtComplex(v Value, t Type) Value {
	return makeComplex(v.flag.ro(), v.Complex(), t)
}

// convertOp: intXX -> string
func cvtIntString(v Value, t Type) Value {
	return makeString(v.flag.ro(), string(v.Int()), t)
}

// convertOp: uintXX -> string
func cvtUintString(v Value, t Type) Value {
	return makeString(v.flag.ro(), string(v.Uint()), t)
}

// convertOp: []byte -> string
func cvtBytesString(v Value, t Type) Value {
	return makeString(v.flag.ro(), string(v.Bytes()), t)
}

// convertOp: string -> []byte
func cvtStringBytes(v Value, t Type) Value {
	return makeBytes(v.flag.ro(), []byte(v.String()), t)
}

// convertOp: []rune -> string
func cvtRunesString(v Value, t Type) Value {
	return makeString(v.flag.ro(), string(v.runes()), t)
}

// convertOp: string -> []rune
func cvtStringRunes(v Value, t Type) Value {
	return makeRunes(v.flag.ro(), []rune(v.String()), t)
}

// convertOp: direct copy
/**
 * 直接拷貝
 * @param
 * @return
 **/
func cvtDirect(v Value, typ Type) Value {
	f := v.flag
	t := typ.common()
	ptr := v.ptr
	if f&flagAddr != 0 { // 間接類型
		// indirect, mutable word - make a copy
		// 間接,可變成——進行復制
		c := unsafe_New(t)
		typedmemmove(t, c, ptr)
		ptr = c
		f &^= flagAddr
	}
	return Value{t, ptr, v.flag.ro() | f} // v.flag.ro()|f == f?
}

// convertOp: concrete -> interface
/**
 * 具體類型轉換成接口類型
 * Question: 使用場景是什麼
 * @param
 * @return
 **/
func cvtT2I(v Value, typ Type) Value {
	target := unsafe_New(typ.common())
	x := valueInterface(v, false)
	if typ.NumMethod() == 0 {
		*(*interface{})(target) = x
	} else {
		ifaceE2I(typ.(*rtype), x, target)
	}
	return Value{typ.common(), target, v.flag.ro() | flagIndir | flag(Interface)}
}

// convertOp: interface -> interface
func cvtI2I(v Value, typ Type) Value {
	if v.IsNil() {
		ret := Zero(typ)
		ret.flag |= v.flag.ro()
		return ret
	}
	return cvtT2I(v.Elem(), typ)
}

// implemented in ../runtime
// 在runtime包中實現
// 三個方法分別表示通道的容量,關閉通道,通道的長度
func chancap(ch unsafe.Pointer) int
func chanclose(ch unsafe.Pointer)
func chanlen(ch unsafe.Pointer) int

// Note: some of the noescape annotations below are technically a lie,
// but safe in the context of this package. Functions like chansend
// and mapassign don't escape the referent, but may escape anything
// the referent points to (they do shallow copies of the referent).
// It is safe in this package because the referent may only point
// to something a Value may point to, and that is always in the heap
// (due to the escapes() call in ValueOf).
/**
 * 注意:下面的一些noescape註釋從技術上來說是一個謊言,但在此軟件包的上下文中是安全的。
 * 諸如chansend和mapassign之類的功能不會轉義引用對象,但可能會轉義引用對象指向的任何內容(它們會做引用對象的淺拷貝)。
 * 在此包中是安全的,因爲引用對象只能指向Value可能指向的內容,並且始終位於堆中(由於ValueOf中的escapes()調用)。
 * @param
 * @return
 **/
//go:noescape
/**
 * 通道接收
 * @param
 * @return
 **/
func chanrecv(ch unsafe.Pointer, nb bool, val unsafe.Pointer) (selected, received bool)

//go:noescape
/**
 * 通道發送
 * @param
 * @return
 **/
func chansend(ch unsafe.Pointer, val unsafe.Pointer, nb bool) bool

/**
 * 創建通道
 * @param
 * @return
 **/
func makechan(typ *rtype, size int) (ch unsafe.Pointer)
/**
 * 創建map
 * @param
 * @return
 **/
func makemap(t *rtype, cap int) (m unsafe.Pointer)

//go:noescape
/**
 * 訪問map中的值
 * @param
 * @return
 **/
func mapaccess(t *rtype, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer)

//go:noescape
/**
 * map賦值
 * @param
 * @return
 **/
func mapassign(t *rtype, m unsafe.Pointer, key, val unsafe.Pointer)

//go:noescape
/**
 * map刪除key
 * @param
 * @return
 **/
func mapdelete(t *rtype, m unsafe.Pointer, key unsafe.Pointer)

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//go:noescape
/**
 * map迭代器初始化
 * m會轉義爲返回值,但mapiterinit的調用者不會讓返回值轉義。
 * @param
 * @return
 **/
func mapiterinit(t *rtype, m unsafe.Pointer) unsafe.Pointer

//go:noescape
/**
 * 獲取當前map迭代器的key
 * @param
 * @return
 **/
func mapiterkey(it unsafe.Pointer) (key unsafe.Pointer)

//go:noescape
/**
 * 獲取當前map迭代器的value
 * @param
 * @return
 **/
func mapiterelem(it unsafe.Pointer) (elem unsafe.Pointer)

//go:noescape
/**
 * 獲取當前map迭代器的下一個值
 * @param
 * @return
 **/
func mapiternext(it unsafe.Pointer)

//go:noescape
/**
 * 獲取map的大小
 * @param
 * @return
 **/
func maplen(m unsafe.Pointer) int

// call calls fn with a copy of the n argument bytes pointed at by arg.
// After fn returns, reflectcall copies n-retoffset result bytes
// back into arg+retoffset before returning. If copying result bytes back,
// the caller must pass the argument frame type as argtype, so that
// call can execute appropriate write barriers during the copy.
//
//go:linkname call runtime.reflectcall
/**
 * 使用arg指向的n個參數字節的副本調用fn。
 * 在fn返回之後,reflectcall將n-retoffset結果字節複製回arg + retoffset,然後再返回。
 * 如果將結果字節複製回去,則調用者必須將參數幀類型作爲argtype傳遞,以便調用可以在複製期間執行適當的寫障礙。
 *
 * go:linkname調用runtime.reflectcall
 * @param
 * @return
 **/
func call(argtype *rtype, fn, arg unsafe.Pointer, n uint32, retoffset uint32)

func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer)

// memmove copies size bytes to dst from src. No write barriers are used.
//go:noescape
/**
 * memmove將size大小字節從src複製到dst。 不使用寫屏障。
 * @param
 * @return
 **/
func memmove(dst, src unsafe.Pointer, size uintptr)

// typedmemmove copies a value of type t to dst from src.
//go:noescape
/**
 * typedmemmove將類型t的值從src複製到dst。
 * @param
 * @return
 **/
func typedmemmove(t *rtype, dst, src unsafe.Pointer)

// typedmemmovepartial is like typedmemmove but assumes that
// dst and src point off bytes into the value and only copies size bytes.
//go:noescape
/**
 * typedmemmovepartial類似於typedmemmove,但假定dst和src將字節指向該值,並且僅複製size大小字節。
 * @param
 * @return
 **/
func typedmemmovepartial(t *rtype, dst, src unsafe.Pointer, off, size uintptr)

// typedmemclr zeros the value at ptr of type t.
//go:noescape
/**
 * typedmemclr將類型t的ptr處的值清零。
 * @param
 * @return
 **/
func typedmemclr(t *rtype, ptr unsafe.Pointer)

// typedmemclrpartial is like typedmemclr but assumes that
// dst points off bytes into the value and only clears size bytes.
//go:noescape
/**
 * typedmemclrpartial與typedmemclr類似,但假定dst將字節指向值,並且僅清除大小字節。
 * @param
 * @return
 **/
func typedmemclrpartial(t *rtype, ptr unsafe.Pointer, off, size uintptr)

// typedslicecopy copies a slice of elemType values from src to dst,
// returning the number of elements copied.
//go:noescape
/**
 * typedslicecopy將elemType值的一部分從src複製到dst,返回複製的元素數。
 * @param
 * @return
 **/
func typedslicecopy(elemType *rtype, dst, src sliceHeader) int

//go:noescape
/**
 * 對類型求hash值
 * @param
 * @return
 **/
func typehash(t *rtype, p unsafe.Pointer, h uintptr) uintptr

// Dummy annotation marking that the value x escapes,
// for use in cases where the reflect code is so clever that
// the compiler cannot follow.
/**
 * Dummy類型,用於標記值x逃逸,
 * 在反射代碼非常聰明以至於編譯器無法遵循的情況下使用。
 */
func escapes(x interface{}) {
	if dummy.b {
		dummy.x = x
	}
}

var dummy struct {
	b bool
	x interface{}
}
```go
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章