Skip to content

Commit

Permalink
chore: Fix changes for tinygo
Browse files Browse the repository at this point in the history
  • Loading branch information
victro committed Feb 16, 2022
1 parent a7a69d3 commit 20d5436
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 12 deletions.
102 changes: 101 additions & 1 deletion src/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}

16 changes: 16 additions & 0 deletions src/net/tcpsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
}
5 changes: 5 additions & 0 deletions src/os/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ func Clearenv() {
func Environ() []string {
return syscall.Environ()
}


func Symlink(oldname, newname string) error {
panic("")
}
7 changes: 7 additions & 0 deletions src/os/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()") }
4 changes: 4 additions & 0 deletions src/os/file_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ func isWindowsNulName(name string) bool {
}
return true
}

func Symlink(oldname, newname string) error {
panic("unimplemented: os.Symlink()")
}
33 changes: 33 additions & 0 deletions src/os/user/user.go
Original file line number Diff line number Diff line change
@@ -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()")
}
97 changes: 87 additions & 10 deletions src/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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()")
}
Loading

0 comments on commit 20d5436

Please sign in to comment.