From 20d5436d8e92f801f4502fa8576485cfc5116cea Mon Sep 17 00:00:00 2001 From: Victor Rada Date: Tue, 15 Feb 2022 20:17:18 -0800 Subject: [PATCH] chore: Fix changes for tinygo --- src/net/net.go | 102 ++++++++++++++++++++++++++++++++++++++++- src/net/tcpsock.go | 16 +++++++ src/os/env.go | 5 ++ src/os/errors.go | 7 +++ src/os/file_windows.go | 4 ++ src/os/user/user.go | 33 +++++++++++++ src/reflect/type.go | 97 +++++++++++++++++++++++++++++++++++---- src/reflect/value.go | 28 ++++++++++- src/runtime/extern.go | 4 ++ src/runtime/symtab.go | 1 + 10 files changed, 285 insertions(+), 12 deletions(-) create mode 100644 src/os/user/user.go diff --git a/src/net/net.go b/src/net/net.go index 65789e30b2..1c884546af 100644 --- a/src/net/net.go +++ b/src/net/net.go @@ -9,8 +9,35 @@ package net import ( "io" "time" + "context" + "internal/singleflight" ) +// Addr represents a network end point address. +// +// The two methods Network and String conventionally return strings +// that can be passed as the arguments to Dial, but the exact form +// and meaning of the strings is up to the implementation. + + +type UnixAddr struct { + Name string + Net string +} +func (a *UnixAddr) String() string { + panic("unimplemented: UnixAddr.String()") +} +func (a *UnixAddr) Network() string { + panic("unimplemented: UnixAddr.Network()") +} + +type UnknownNetworkError string +func (e UnknownNetworkError) Error() string { + panic("unimplemented net.Error()") +} +func (e UnknownNetworkError) Timeout() bool { panic("unimplemented Timeout()") } +func (e UnknownNetworkError) Temporary() bool { panic("unimplemented Temporary()") } + // Addr represents a network end point address. // // The two methods Network and String conventionally return strings @@ -20,7 +47,6 @@ type Addr interface { Network() string // name of the network (for example, "tcp", "udp") String() string // string form of address (for example, "192.0.2.1:25", "[2001:db8::1]:80") } - // Conn is a generic stream-oriented network connection. // // Multiple goroutines may invoke methods on a Conn simultaneously. @@ -261,3 +287,77 @@ func (v *Buffers) consume(n int64) { *v = (*v)[1:] } } +type SRV struct { + Target string + Port uint16 + Priority uint16 + Weight uint16 +} + +var DefaultResolver = &Resolver{} +type Resolver struct { + // PreferGo controls whether Go's built-in DNS resolver is preferred + // on platforms where it's available. It is equivalent to setting + // GODEBUG=netdns=go, but scoped to just this resolver. + PreferGo bool + + // StrictErrors controls the behavior of temporary errors + // (including timeout, socket errors, and SERVFAIL) when using + // Go's built-in resolver. For a query composed of multiple + // sub-queries (such as an A+AAAA address lookup, or walking the + // DNS search list), this option causes such errors to abort the + // whole query instead of returning a partial result. This is + // not enabled by default because it may affect compatibility + // with resolvers that process AAAA queries incorrectly. + StrictErrors bool + + // Dial optionally specifies an alternate dialer for use by + // Go's built-in DNS resolver to make TCP and UDP connections + // to DNS services. The host in the address parameter will + // always be a literal IP address and not a host name, and the + // port in the address parameter will be a literal port number + // and not a service name. + // If the Conn returned is also a PacketConn, sent and received DNS + // messages must adhere to RFC 1035 section 4.2.1, "UDP usage". + // Otherwise, DNS messages transmitted over Conn must adhere + // to RFC 7766 section 5, "Transport Protocol Selection". + // If nil, the default dialer is used. + Dial func(ctx context.Context, network, address string) (Conn, error) + + // lookupGroup merges LookupIPAddr calls together for lookups for the same + // host. The lookupGroup key is the LookupIPAddr.host argument. + // The return values are ([]IPAddr, error). + lookupGroup singleflight.Group + + // TODO(bradfitz): optional interface impl override hook + // TODO(bradfitz): Timeout time.Duration? +} + + +type DNSError struct { + Err string // description of the error + Name string // name looked for + Server string // server used + IsTimeout bool // if true, timed out; not all timeouts set this + IsTemporary bool // if true, error is temporary; not all errors set this + IsNotFound bool // if true, host could not be found +} + +func (e *DNSError) Error() string { + panic("unimplemented: DNSError.Error()") +} + + +func (r *Resolver) LookupHost(ctx context.Context, host string) (addrs []string, err error) { + panic("unimplemented: Resolver.LookupHost()") +} + + +func (r *Resolver) LookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) { + panic("unimplemented: Resolver.LookupSRV()") +} + +func (r *Resolver) LookupTXT(ctx context.Context, name string) ([]string, error) { + panic("unimplemented: Resolver.lookupTXT") +} + diff --git a/src/net/tcpsock.go b/src/net/tcpsock.go index 4af06a857e..bab570a246 100644 --- a/src/net/tcpsock.go +++ b/src/net/tcpsock.go @@ -9,3 +9,19 @@ type TCPConn struct { func (c *TCPConn) CloseWrite() error { return &OpError{"close", "", nil, nil, ErrNotImplemented} } + +// TCPAddr represents the address of a TCP end point. +type TCPAddr struct { + IP IP + Port int + Zone string // IPv6 scoped addressing zone +} + +func ResolveTCPAddr(network, address string) (*TCPAddr, error) { + panic("unimplemented tcpsock.ResoveTCPAddr()") +} + +func (a *TCPAddr) Network() string { return "tcp" } +func (a *TCPAddr) String() string { + panic("unimplemented: TCPAddr.String()") +} \ No newline at end of file diff --git a/src/os/env.go b/src/os/env.go index 330297b36a..1e13938c0e 100644 --- a/src/os/env.go +++ b/src/os/env.go @@ -139,3 +139,8 @@ func Clearenv() { func Environ() []string { return syscall.Environ() } + + +func Symlink(oldname, newname string) error { + panic("") +} \ No newline at end of file diff --git a/src/os/errors.go b/src/os/errors.go index fc8693ebdf..29f35920ec 100644 --- a/src/os/errors.go +++ b/src/os/errors.go @@ -73,3 +73,10 @@ func underlyingError(err error) error { } return err } + +var ErrDeadlineExceeded error = &DeadlineExceededError{} + +// DeadlineExceededError is returned for an expired deadline. +type DeadlineExceededError struct{} + +func (e *DeadlineExceededError) Error() string { panic("unimplemented Error.Error()") } diff --git a/src/os/file_windows.go b/src/os/file_windows.go index 3e1c63b919..ea6c5badab 100644 --- a/src/os/file_windows.go +++ b/src/os/file_windows.go @@ -99,3 +99,7 @@ func isWindowsNulName(name string) bool { } return true } + +func Symlink(oldname, newname string) error { + panic("unimplemented: os.Symlink()") +} diff --git a/src/os/user/user.go b/src/os/user/user.go new file mode 100644 index 0000000000..de11efd7f0 --- /dev/null +++ b/src/os/user/user.go @@ -0,0 +1,33 @@ +package user + +func lookupUser(username string) (*User, error) { + panic("unimplemented: User.lookupUser()") +} + +type User struct { + // Uid is the user ID. + // On POSIX systems, this is a decimal number representing the uid. + // On Windows, this is a security identifier (SID) in a string format. + // On Plan 9, this is the contents of /dev/user. + Uid string + // Gid is the primary group ID. + // On POSIX systems, this is a decimal number representing the gid. + // On Windows, this is a SID in a string format. + // On Plan 9, this is the contents of /dev/user. + Gid string + // Username is the login name. + Username string + // Name is the user's real or display name. + // It might be blank. + // On POSIX systems, this is the first (or only) entry in the GECOS field + // list. + // On Windows, this is the user's display name. + // On Plan 9, this is the contents of /dev/user. + Name string + // HomeDir is the path to the user's home directory (if they have one). + HomeDir string +} + +func Current() (*User, error) { + panic("unimplemented: user.Current()") +} \ No newline at end of file diff --git a/src/reflect/type.go b/src/reflect/type.go index 4ead369b29..b52bfca369 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -121,6 +121,23 @@ func (k Kind) String() string { } } +// Method represents a single method. +type Method struct { + // Name is the method name. + Name string + + // PkgPath is the package path that qualifies a lower case (unexported) + // method name. It is empty for upper case (exported) method names. + // The combination of PkgPath and Name uniquely identifies a method + // in a method set. + // See https://golang.org/ref/spec#Uniqueness_of_identifiers + PkgPath string + + Type Type // method type + Func Value // func with receiver as first argument + Index int // index for Type.Method +} + // basicType returns a new Type for this kind if Kind is a basic type. func (k Kind) basicType() rawType { return rawType(k << 1) @@ -173,7 +190,7 @@ type Type interface { // // For an interface type, the returned Method's Type field gives the // method signature, without a receiver, and the Func field is nil. - //MethodByName(string) (Method, bool) + MethodByName(string) (Method, bool) // NumMethod returns the number of exported methods in the type's method set. NumMethod() int @@ -187,7 +204,7 @@ type Type interface { // If the type was predeclared (string, error) or not defined (*T, struct{}, // []int, or A where A is an alias for a non-defined type), the package path // will be the empty string. - //PkgPath() string + PkgPath() string // Size returns the number of bytes needed to store // a value of the given type; it is analogous to unsafe.Sizeof. @@ -234,7 +251,7 @@ type Type interface { // ChanDir returns a channel type's direction. // It panics if the type's Kind is not Chan. - //ChanDir() ChanDir + ChanDir() ChanDir // IsVariadic reports whether a function type's final input parameter // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's @@ -248,7 +265,7 @@ type Type interface { // t.IsVariadic() == true // // IsVariadic panics if the type's Kind is not Func. - //IsVariadic() bool + IsVariadic() bool // Elem returns a type's element type. // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice. @@ -263,11 +280,11 @@ type Type interface { // to the index sequence. It is equivalent to calling Field // successively for each index i. // It panics if the type's Kind is not Struct. - //FieldByIndex(index []int) StructField + FieldByIndex(index []int) StructField // FieldByName returns the struct field with the given name // and a boolean indicating if the field was found. - //FieldByName(name string) (StructField, bool) + FieldByName(name string) (StructField, bool) // FieldByNameFunc returns the struct field with a name // that satisfies the match function and a boolean indicating if @@ -286,7 +303,7 @@ type Type interface { // In returns the type of a function type's i'th input parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumIn()). - //In(i int) Type + In(i int) Type // Key returns a map type's key type. // It panics if the type's Kind is not Map. @@ -302,20 +319,28 @@ type Type interface { // NumIn returns a function type's input parameter count. // It panics if the type's Kind is not Func. - //NumIn() int + NumIn() int // NumOut returns a function type's output parameter count. // It panics if the type's Kind is not Func. - //NumOut() int + NumOut() int // Out returns the type of a function type's i'th output parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumOut()). - //Out(i int) Type + Out(i int) Type } // The typecode as used in an interface{}. type rawType uintptr +// ChanDir represents a channel type's direction. +type ChanDir uint64 + +const ( + RecvDir ChanDir = 1 << iota // <-chan + SendDir // chan<- + BothDir = RecvDir | SendDir // chan +) func TypeOf(i interface{}) Type { return ValueOf(i).typecode @@ -704,6 +729,7 @@ type StructField struct { Tag StructTag // field tag string Anonymous bool Offset uintptr + Index []int // index sequence for Type.FieldByIndex } // IsExported reports whether the field is exported. @@ -787,6 +813,37 @@ func (tag StructTag) Lookup(key string) (value string, ok bool) { return "", false } +func (t rawType) In(i int) Type { + panic("unimplemented: (reflect.Type).In()") +} + +func (t rawType) NumIn() int { + panic("unimplemented: (reflect.Type).NumIn()") +} + +func (t rawType) Out(i int) Type { + panic("unimplemented: (reflect.Type).Out()") +} + +func (t rawType) NumOut() int { + panic("unimplemented: (reflect.Type).NumOut()") +} + +func (t rawType) IsVariadic() bool { + panic("unimplemented: (reflect.Type).IsVariadic()") +} +func (t rawType) ChanDir() ChanDir { + panic("unimplemented: (reflect.Type).ChanDir()") +} +func (t rawType) MethodByName(name string) (Method, bool) { + panic("unimplemented: (reflect.Type).MethodByName()") +} + +func (t rawType) PkgPath() string { + panic("unimplemented: (reflect.Type).PkgPath()") +} + + // TypeError is the error that is used in a panic when invoking a method on a // type that is not applicable to that type. type TypeError struct { @@ -800,3 +857,23 @@ func (e *TypeError) Error() string { func align(offset uintptr, alignment uintptr) uintptr { return (offset + alignment - 1) &^ (alignment - 1) } + +func SliceOf(t Type) Type { + panic("unimplemented: reflect.SliceOf()") +} + +func MapOf(key, elem Type) Type { + panic("unimplemented: reflect.SliceOf()") +} + +func (t rawType) FieldByName(name string) (StructField, bool) { + panic("unimplemented: reflect.FieldByName()") +} + +func (t rawType) FieldByIndex(index []int) StructField { + panic("unimplemented: reflect.FieldByIndex()") +} + +func ArrayOf(length int, elem Type) Type { + panic("unimplemented: reflect.ArrayOf()") +} \ No newline at end of file diff --git a/src/reflect/value.go b/src/reflect/value.go index be086e5fea..0d07ea17ec 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -35,6 +35,10 @@ func (v Value) isExported() bool { return v.flags&valueFlagExported != 0 } +func MakeMapWithSize(typ Type, n int) Value { + panic("unimplemented: reflect.MakeMapWithSize()") +} + func Indirect(v Value) Value { if v.Kind() != Ptr { return v @@ -788,10 +792,11 @@ type stringHeader struct { type ValueError struct { Method string + Kind Kind } func (e *ValueError) Error() string { - return "reflect: call of reflect.Value." + e.Method + " on invalid type" + panic("unimplemented method: (reflect.Value).Error()") } // Calls to this function are converted to LLVM intrinsic calls such as @@ -865,3 +870,24 @@ func MakeMap(typ Type) Value { func (v Value) Call(in []Value) []Value { panic("unimplemented: (reflect.Value).Call()") } + +func (v Value) MethodByName(name string) Value { + panic("unimplemented: (reflect.Value).MethodByName()") +} + +func NewAt(typ Type, p unsafe.Pointer) Value { + panic("unimplemented: reflect.New()") +} + +// 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. +func (v Value) Recv() (x Value, ok bool) { + panic("unimplemented: reflect.Recv()") +} + +func (v Value) Slice3(i, j, k int) Value { + panic("unimplemented: reflect.Slice3()") +} diff --git a/src/runtime/extern.go b/src/runtime/extern.go index 12de028401..fa140fa7fd 100644 --- a/src/runtime/extern.go +++ b/src/runtime/extern.go @@ -3,3 +3,7 @@ package runtime func Callers(skip int, pc []uintptr) int { return 0 } + +func Version() string { + panic("unimplemented: runtime.Version()") +} diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index cfc9885d7f..6683cbabf2 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -10,6 +10,7 @@ type Frame struct { File string Line int PC uintptr + Func *Func } func CallersFrames(callers []uintptr) *Frames {