-
Notifications
You must be signed in to change notification settings - Fork 996
extend stdlib to allow import of more packages #1099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f068eb6
c3f7c28
8b46fa3
ab9dc3d
c5d1578
d865e6e
5696b98
76d38a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package os | ||
|
|
||
| func Getenv(key string) string { | ||
| return "" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package os | ||
|
|
||
| import ( | ||
| "errors" | ||
| ) | ||
|
|
||
| var ( | ||
| ErrInvalid = errors.New("invalid argument") | ||
| ErrPermission = errors.New("permission denied") | ||
| ErrClosed = errors.New("file already closed") | ||
| ) | ||
|
|
||
| func IsPermission(err error) bool { | ||
| return err == ErrPermission | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not complete (it doesn't unwrap the error) but I guess it's fine for now. |
||
| } | ||
|
|
||
| func NewSyscallError(syscall string, err error) error { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
| return &SyscallError{syscall, err} | ||
| } | ||
|
|
||
| // SyscallError records an error from a specific system call. | ||
| type SyscallError struct { | ||
| Syscall string | ||
| Err error | ||
| } | ||
|
|
||
| func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Err.Error() } | ||
|
|
||
| func (e *SyscallError) Unwrap() error { return e.Err } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package os | ||
|
|
||
| type Signal interface { | ||
| String() string | ||
| Signal() // to distinguish from other Stringers | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package os | ||
|
|
||
| func Hostname() (name string, err error) { | ||
| return "", ErrNotImplemented | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package reflect | ||
|
|
||
| func DeepEqual(x, y interface{}) bool { | ||
| if x == nil || y == nil { | ||
| return x == y | ||
| } | ||
|
|
||
| panic("unimplemented: reflect.DeepEqual()") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,7 +227,7 @@ func (t Type) Field(i int) StructField { | |
| // There is a tag. | ||
| var tagNum uintptr | ||
| tagNum, p = readVarint(p) | ||
| field.Tag = readStringSidetable(unsafe.Pointer(&structNamesSidetable), tagNum) | ||
| field.Tag = StructTag(readStringSidetable(unsafe.Pointer(&structNamesSidetable), tagNum)) | ||
| } else { | ||
| // There is no tag. | ||
| field.Tag = "" | ||
|
|
@@ -445,6 +445,22 @@ func (t Type) Comparable() bool { | |
| } | ||
| } | ||
|
|
||
| func (t Type) ConvertibleTo(u Type) bool { | ||
| panic("unimplemented: (reflect.Type).ConvertibleTo()") | ||
| } | ||
|
|
||
| func (t Type) NumMethod() int { | ||
| panic("unimplemented: (reflect.Type).NumMethod()") | ||
| } | ||
|
|
||
| func (t Type) Name() string { | ||
| panic("unimplemented: (reflect.Type).Name()") | ||
| } | ||
|
|
||
| func (t Type) Key() Type { | ||
| panic("unimplemented: (reflect.Type).Key()") | ||
| } | ||
|
|
||
| // A StructField describes a single field in a struct. | ||
| type StructField struct { | ||
| // Name indicates the field name. | ||
|
|
@@ -455,11 +471,74 @@ type StructField struct { | |
| PkgPath string | ||
|
|
||
| Type Type | ||
| Tag string | ||
| Tag StructTag // field tag string | ||
| Anonymous bool | ||
| Offset uintptr | ||
| } | ||
|
|
||
| // A StructTag is the tag string in a struct field. | ||
| type StructTag string | ||
|
|
||
| // Get returns the value associated with key in the tag string. | ||
| func (tag StructTag) Get(key string) string { | ||
| v, _ := tag.Lookup(key) | ||
| return v | ||
| } | ||
|
|
||
| // Lookup returns the value associated with key in the tag string. | ||
| func (tag StructTag) Lookup(key string) (value string, ok bool) { | ||
|
Comment on lines
+495
to
+496
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get and Lookup will need tests. Please add them to testdata/reflect.go. You can probably just try to lookup a few tags and if they are present, print them (just like many other properties of types/values are printed).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be better to use something other than a string for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you actually need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added your proposal to do it at compile time as a TODO comment. For this MR i focused on getting more libraries to compile.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked both libraries.
Not sure what to do here, maybe using raw strings is better after all (even though it will likely increase code size). Maybe there are optimizations possible here, but I'm not sure whether that's possible in a sane way.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you write this code yourself or did you copy it? If you copied it, it should have a copyright note (just like the strconv.go file). |
||
| for tag != "" { | ||
| // Skip leading space. | ||
| i := 0 | ||
| for i < len(tag) && tag[i] == ' ' { | ||
| i++ | ||
| } | ||
| tag = tag[i:] | ||
| if tag == "" { | ||
| break | ||
| } | ||
|
|
||
| // Scan to colon. A space, a quote or a control character is a syntax error. | ||
| // Strictly speaking, control chars include the range [0x7f, 0x9f], not just | ||
| // [0x00, 0x1f], but in practice, we ignore the multi-byte control characters | ||
| // as it is simpler to inspect the tag's bytes than the tag's runes. | ||
| i = 0 | ||
| for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f { | ||
| i++ | ||
| } | ||
| if i == 0 || i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' { | ||
| break | ||
| } | ||
| name := string(tag[:i]) | ||
| tag = tag[i+1:] | ||
|
|
||
| // Scan quoted string to find value. | ||
| i = 1 | ||
| for i < len(tag) && tag[i] != '"' { | ||
| if tag[i] == '\\' { | ||
| i++ | ||
| } | ||
| i++ | ||
| } | ||
| if i >= len(tag) { | ||
| break | ||
| } | ||
| qvalue := string(tag[:i+1]) | ||
| tag = tag[i+1:] | ||
|
|
||
| if key == name { | ||
| // TODO strconv causes import cycle | ||
| //value, err := strconv.Unquote(qvalue) | ||
| //if err != nil { | ||
| // break | ||
| //} | ||
| //return value, true | ||
| return qvalue, true | ||
cornelk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| return "", false | ||
| } | ||
|
|
||
| // 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 { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package runtime | ||
|
|
||
| // The Error interface identifies a run time error. | ||
| type Error interface { | ||
| error | ||
|
|
||
| RuntimeError() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package runtime | ||
|
|
||
| // Stack is a stub, not implemented | ||
| func Stack(buf []byte, all bool) int { | ||
|
||
| return 0 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright 2017 The Go Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package syscall | ||
|
|
||
| // A RawConn is a raw network connection. | ||
| type RawConn interface { | ||
| // Control invokes f on the underlying connection's file | ||
| // descriptor or handle. | ||
| // The file descriptor fd is guaranteed to remain valid while | ||
| // f executes but not after f returns. | ||
| Control(f func(fd uintptr)) error | ||
|
|
||
| // Read invokes f on the underlying connection's file | ||
| // descriptor or handle; f is expected to try to read from the | ||
| // file descriptor. | ||
| // If f returns true, Read returns. Otherwise Read blocks | ||
| // waiting for the connection to be ready for reading and | ||
| // tries again repeatedly. | ||
| // The file descriptor is guaranteed to remain valid while f | ||
| // executes but not after f returns. | ||
| Read(f func(fd uintptr) (done bool)) error | ||
|
|
||
| // Write is like Read but for writing. | ||
| Write(f func(fd uintptr) (done bool)) error | ||
| } | ||
|
|
||
| // Conn is implemented by some types in the net and os packages to provide | ||
| // access to the underlying file descriptor or handle. | ||
| type Conn interface { | ||
| // SyscallConn returns a raw network connection. | ||
| SyscallConn() (RawConn, error) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.