From 0b8beb77c11209e5a232d0521551990a252bd854 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 23 Oct 2018 15:39:53 +0200 Subject: [PATCH] reflect: add stub reflect package This is necessary to compile fmt. However, it cannot link yet. --- src/reflect/swapper.go | 5 ++ src/reflect/type.go | 70 ++++++++++++++++++++ src/reflect/value.go | 144 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 src/reflect/swapper.go create mode 100644 src/reflect/type.go create mode 100644 src/reflect/value.go diff --git a/src/reflect/swapper.go b/src/reflect/swapper.go new file mode 100644 index 00000000..2f880167 --- /dev/null +++ b/src/reflect/swapper.go @@ -0,0 +1,5 @@ +package reflect + +func Swapper(slice interface{}) func(i, j int) { + panic("unimplemented: reflect.Swapper") +} diff --git a/src/reflect/type.go b/src/reflect/type.go new file mode 100644 index 00000000..c5722532 --- /dev/null +++ b/src/reflect/type.go @@ -0,0 +1,70 @@ +package reflect + +// A Kind is the number that the compiler uses for this type. +// +// Not used directly. These types are all replaced with the number the compiler +// uses internally for the type. +type Kind uint16 + +// Copied from reflect/type.go +// https://golang.org/src/reflect/type.go?s=8302:8316#L217 +const ( + Invalid Kind = iota + Bool + Int + Int8 + Int16 + Int32 + Int64 + Uint + Uint8 + Uint16 + Uint32 + Uint64 + Uintptr + Float32 + Float64 + Complex64 + Complex128 + Array + Chan + Func + Interface + Map + Ptr + Slice + String + Struct + UnsafePointer +) + +// The typecode as used in an interface{}. +type Type uint16 + +func TypeOf(i interface{}) Type { + return ValueOf(i).typecode +} + +func (t Type) String() string { + return "T" +} + +func (t Type) Kind() Kind { + return Invalid // TODO +} + +func (t Type) Elem() Type { + panic("unimplemented: (reflect.Type).Elem()") +} + +func (t Type) Field(i int) StructField { + panic("unimplemented: (reflect.Type).Field()") +} + +func (t Type) Bits() int { + panic("unimplemented: (reflect.Type).Bits()") +} + +type StructField struct { + Name string +} diff --git a/src/reflect/value.go b/src/reflect/value.go new file mode 100644 index 00000000..42556979 --- /dev/null +++ b/src/reflect/value.go @@ -0,0 +1,144 @@ +package reflect + +import ( + _ "unsafe" // for go:linkname +) + +// This is the same thing as an interface{}. +type Value struct { + typecode Type + value *uint8 +} + +func ValueOf(i interface{}) Value + +//go:linkname _ValueOf reflect.ValueOf +func _ValueOf(i Value) Value { + return i +} + +func (v Value) Interface() interface{} + +func (v Value) Type() Type { + return v.typecode +} + +func (v Value) Kind() Kind { + return Invalid // TODO +} + +func (v Value) IsNil() bool { + panic("unimplemented: (reflect.Value).IsNil()") +} + +func (v Value) Pointer() uintptr { + panic("unimplemented: (reflect.Value).Pointer()") +} + +func (v Value) IsValid() bool { + panic("unimplemented: (reflect.Value).IsValid()") +} + +func (v Value) CanInterface() bool { + panic("unimplemented: (reflect.Value).CanInterface()") +} + +func (v Value) CanAddr() bool { + panic("unimplemented: (reflect.Value).CanAddr()") +} + +func (v Value) Addr() Value { + panic("unimplemented: (reflect.Value).Addr()") +} + +func (v Value) Bool() bool { + panic("unimplemented: (reflect.Value).Bool()") +} + +func (v Value) Int() int64 { + panic("unimplemented: (reflect.Value).Int()") +} + +func (v Value) Uint() uint64 { + panic("unimplemented: (reflect.Value).Uint()") +} + +func (v Value) Float() float64 { + panic("unimplemented: (reflect.Value).Float()") +} + +func (v Value) Complex() complex128 { + panic("unimplemented: (reflect.Value).Complex()") +} + +func (v Value) String() string { + panic("unimplemented: (reflect.Value).String()") +} + +func (v Value) Bytes() []byte { + panic("unimplemented: (reflect.Value).Bytes()") +} + +func (v Value) Slice(i, j int) Value { + panic("unimplemented: (reflect.Value).Slice()") +} + +func (v Value) Len() int { + panic("unimplemented: (reflect.Value).Len()") +} + +func (v Value) NumField() int { + panic("unimplemented: (reflect.Value).NumField()") +} + +func (v Value) Elem() Value { + panic("unimplemented: (reflect.Value).Elem()") +} + +func (v Value) Field(i int) Value { + panic("unimplemented: (reflect.Value).Field()") +} + +func (v Value) Index(i int) Value { + panic("unimplemented: (reflect.Value).Index()") +} + +func (v Value) MapKeys() []Value { + panic("unimplemented: (reflect.Value).MapKeys()") +} + +func (v Value) MapIndex(key Value) Value { + panic("unimplemented: (reflect.Value).MapIndex()") +} + +func (v Value) Set(x Value) { + panic("unimplemented: (reflect.Value).Set()") +} + +func (v Value) SetBool(x bool) { + panic("unimplemented: (reflect.Value).SetBool()") +} + +func (v Value) SetInt(x int64) { + panic("unimplemented: (reflect.Value).SetInt()") +} + +func (v Value) SetUint(x uint64) { + panic("unimplemented: (reflect.Value).SetUint()") +} + +func (v Value) SetFloat(x float64) { + panic("unimplemented: (reflect.Value).SetFloat()") +} + +func (v Value) SetComplex(x complex128) { + panic("unimplemented: (reflect.Value).SetComplex()") +} + +func (v Value) SetString(x string) { + panic("unimplemented: (reflect.Value).SetString()") +} + +func MakeSlice(typ Type, len, cap int) Value { + panic("unimplemented: reflect.MakeSlice()") +}