Documentation
¶
Overview ¶
Package stdlib provides wrappers of standard library packages to be imported natively in mvm.
Index ¶
- Variables
- func EmbeddedStd() []byte
- func GorootSrcDir(importPath string) string
- func GorootTestFS() fs.FS
- func IsStdlibImport(name string) bool
- func PackagePatchers() map[string][]PackagePatcher
- func PassthroughIface(_ *vm.Machine, ifc vm.Iface) reflect.Value
- func RegisterPackagePatcher(importPath string, fn PackagePatcher)
- func TestOverlay() map[string]map[string]reflect.Value
- type BridgeAs
- type BridgeClose
- type BridgeError
- type BridgeErrorIsAsUnwrap
- type BridgeErrorUnwrap
- type BridgeFlagValue
- type BridgeFormat
- type BridgeGoString
- type BridgeHeapInterface
- type BridgeIs
- type BridgeMarshalJSON
- type BridgeMessageSigner
- type BridgeRead
- type BridgeReadFrom
- type BridgeReaderWriterTo
- type BridgeSigner
- type BridgeSortInterface
- type BridgeStream
- type BridgeString
- type BridgeUnmarshalJSON
- type BridgeUnwrap
- type BridgeWrite
- type BridgeWriteTo
- type BridgeWriterReaderFrom
- type PackagePatcher
Constants ¶
This section is empty.
Variables ¶
var TestValues = map[string]map[string]reflect.Value{ "strings": { "StringFind": reflect.ValueOf(func(pattern, text string) int { return strings.Index(text, pattern) }), "DumpTables": reflect.ValueOf(func(pattern string) ([]int, []int) { f := makeStringFinder(pattern) return f.badCharSkip[:], f.goodSuffixSkip }), }, }
TestValues holds faithful stand-ins for symbols that a stdlib package's own export_test.go injects into the package under test. Bridged stdlib packages are native, so those internal-only symbols don't exist on the bridge; here we reproduce the ones that can be built from exported API (or self-contained ported source) so external *_test.go files using them can run.
Merged over Values ONLY by `mvm test` (see TestOverlay); `mvm run` never sees these, so the real package surface stays clean.
Only faithfully-reproducible symbols belong here. Ones that read a package's unexported state -- e.g. (*strings.Replacer).Replacer()/PrintTrie(), which return the internal algorithm value/trie -- cannot be reproduced (and would need a method attached to a native type, which mvm can't dispatch), so they are left to `mvm test`'s drop-on-compile-error retry.
var Values = map[string]map[string]reflect.Value{}
Values variable stores the map of stdlib values per package.
Functions ¶
func EmbeddedStd ¶ added in v0.2.0
func EmbeddedStd() []byte
EmbeddedStd returns the Go-module-proxy-format zip bytes for the std module snapshot baked into this binary.
func GorootSrcDir ¶ added in v0.3.0
GorootSrcDir returns the absolute path of $GOROOT/src/<importPath> on the host, or "" when GOROOT is unknown or the path is not a directory. Callers chdir there before driving bridged-stdlib tests so testdata- relative paths resolve against the host's stdlib source tree.
func GorootTestFS ¶ added in v0.3.0
GorootTestFS returns an fs.FS rooted at $GOROOT/src, intended to serve stdlib *_test.go files for `mvm test <stdlib-path>` against the existing reflect bindings (e.g. `mvm test strings` loads strings_test.go from the host Go installation).
Returns nil if GOROOT cannot be determined or its src/ subtree is absent. Callers (the parser's test-source FS hook) must accept nil and treat it as "no test sources available" rather than failing.
Important: this FS is intentionally NOT chained into ordinary import resolution. Wiring it next to stdlibfs/remotefs would make `import "strings"` start loading interpreted source side-by-side with the reflect bridge, double-defining every exported symbol. It must only be consulted from the test-loading branch in LoadPackageSources.
func IsStdlibImport ¶ added in v0.3.0
IsStdlibImport reports whether path looks like a Go stdlib import path: non-empty and with no dot in its first segment (which would mark a module-qualified third-party path like example.com/x).
func PackagePatchers ¶
func PackagePatchers() map[string][]PackagePatcher
PackagePatchers returns the registered patchers keyed by import path. Callers must not mutate the returned map.
func PassthroughIface ¶ added in v0.2.0
PassthroughIface returns the underlying typed value of a mvm Iface, or a zero of its declared type when the Val is unset. Used as a vm.ProxyFactory for native functions that need the concrete value rather than a bridge wrapper (reflect.DeepEqual; errorsx targetProxy).
func RegisterPackagePatcher ¶
func RegisterPackagePatcher(importPath string, fn PackagePatcher)
RegisterPackagePatcher adds fn to the patcher list for importPath. Intended for init() in side-effect intercept packages such as stdlib/jsonx, so the interpreter itself needs no knowledge of them.
Types ¶
type BridgeClose ¶
type BridgeClose struct{ Fn func() error }
BridgeClose bridges the io.Closer interface method.
type BridgeError ¶
BridgeError bridges the error interface method. Val holds the concrete value for non-string format verbs (%d, %x, etc.). FnFormat, when non-nil, dispatches to the interpreted type's own fmt.Formatter so user-defined Format(s, verb) bodies are invoked instead of the display fallback. Ifc preserves the original mvm Iface so the bridge can be unwrapped back at native->mvm boundaries (vm.UnbridgeIface).
func (*BridgeError) Error ¶
func (b *BridgeError) Error() string
Error implements the error interface.
func (*BridgeError) Format ¶
func (b *BridgeError) Format(f fmt.State, verb rune)
Format implements fmt.Formatter. Routes to the user-defined Format method when set, otherwise uses the display fallback.
func (*BridgeError) Is ¶ added in v0.2.0
func (b *BridgeError) Is(target error) bool
Is enables stderrors.Is to compare two BridgeError instances that wrap the same underlying interpreted value. Two bridges of the same mvm Iface share Val (the interpreted struct pointer), so this gives stderrors.Is a value-level fallback when interface == fails.
type BridgeErrorIsAsUnwrap ¶ added in v0.3.0
type BridgeErrorIsAsUnwrap struct {
FnError func() string
FnIs func(error) bool
FnAs func(any) bool
FnUnwrap func() error
FnFormat func(fmt.State, rune)
Val any
Ifc vm.Iface
}
BridgeErrorIsAsUnwrap is the composite bridge for types that implement Error + Is + As + Unwrap (e.g. hashicorp/go-multierror's chain), required so stderrors.Is/As reach the interpreted Is/As when walking the chain instead of falling back to Unwrap-only.
func (*BridgeErrorIsAsUnwrap) As ¶ added in v0.3.0
func (b *BridgeErrorIsAsUnwrap) As(target any) bool
As delegates to the interpreted As body.
func (*BridgeErrorIsAsUnwrap) Error ¶ added in v0.3.0
func (b *BridgeErrorIsAsUnwrap) Error() string
Error implements the error interface.
func (*BridgeErrorIsAsUnwrap) Format ¶ added in v0.3.0
func (b *BridgeErrorIsAsUnwrap) Format(f fmt.State, verb rune)
Format implements fmt.Formatter, routing to user code when present.
func (*BridgeErrorIsAsUnwrap) Is ¶ added in v0.3.0
func (b *BridgeErrorIsAsUnwrap) Is(target error) bool
Is enables stderrors.Is to short-circuit on cross-bridge identity and otherwise delegates to the interpreted Is body.
func (*BridgeErrorIsAsUnwrap) Unwrap ¶ added in v0.3.0
func (b *BridgeErrorIsAsUnwrap) Unwrap() error
Unwrap implements interface{ Unwrap() error }.
type BridgeErrorUnwrap ¶ added in v0.2.0
type BridgeErrorUnwrap struct {
FnError func() string
FnUnwrap func() error
FnFormat func(fmt.State, rune)
Val any
Ifc vm.Iface
}
BridgeErrorUnwrap is the composite bridge for types that implement both Error() string and Unwrap() error. Required so a value bridged as `error` also satisfies the anonymous `interface{ Unwrap() error }` assertion that errors.Is / errors.As / errors.Unwrap perform when walking a chain. FnFormat is set (by wrapIfaceMulti) when the type also defines fmt.Formatter, so user Format() is invoked. Val holds the underlying interpreted value for identity-based comparisons in Is and for unbridgeValue.
func (*BridgeErrorUnwrap) Error ¶ added in v0.2.0
func (b *BridgeErrorUnwrap) Error() string
Error implements the error interface.
func (*BridgeErrorUnwrap) Format ¶ added in v0.2.0
func (b *BridgeErrorUnwrap) Format(f fmt.State, verb rune)
Format implements fmt.Formatter. Routes to the user-defined Format method when set, otherwise uses the display fallback.
func (*BridgeErrorUnwrap) Is ¶ added in v0.2.0
func (b *BridgeErrorUnwrap) Is(target error) bool
Is enables stderrors.Is to match two BridgeErrorUnwrap instances that wrap the same underlying interpreted value.
func (*BridgeErrorUnwrap) Unwrap ¶ added in v0.2.0
func (b *BridgeErrorUnwrap) Unwrap() error
Unwrap implements the standard-library single-error unwrap protocol.
type BridgeFlagValue ¶
BridgeFlagValue bridges flag.Value (String, Set).
func (*BridgeFlagValue) Set ¶
func (b *BridgeFlagValue) Set(s string) error
Set implements flag.Value.
func (*BridgeFlagValue) String ¶
func (b *BridgeFlagValue) String() string
String implements flag.Value.
type BridgeFormat ¶ added in v0.2.0
BridgeFormat bridges the fmt.Formatter interface method. Used when an interpreted type defines its own Format(fmt.State, rune) so fmt routes every verb through user code rather than through the display-bridge fallback (which only handles %s/%v via Error/String/GoString).
type BridgeGoString ¶
BridgeGoString bridges the fmt.GoStringer interface method.
func (*BridgeGoString) Format ¶
func (b *BridgeGoString) Format(f fmt.State, verb rune)
Format implements fmt.Formatter.
func (*BridgeGoString) GoString ¶
func (b *BridgeGoString) GoString() string
GoString implements fmt.GoStringer.
type BridgeHeapInterface ¶
type BridgeHeapInterface struct {
BridgeSortInterface
FnPush func(any)
FnPop func() any
}
BridgeHeapInterface bridges heap.Interface (Len, Less, Swap, Push, Pop). Embeds BridgeSortInterface for the sort.Interface methods.
func (*BridgeHeapInterface) Pop ¶
func (b *BridgeHeapInterface) Pop() any
Pop implements heap.Interface.
func (*BridgeHeapInterface) Push ¶
func (b *BridgeHeapInterface) Push(x any)
Push implements heap.Interface.
type BridgeIs ¶ added in v0.3.0
BridgeIs and BridgeAs exist so that an Is or As method gets counted as bridgeable when wrapIface selects a multi-method composite. The Val/Ifc-carrying fields live on the composite bridge instead.
type BridgeMarshalJSON ¶
BridgeMarshalJSON bridges the json.Marshaler interface method.
func (*BridgeMarshalJSON) MarshalJSON ¶
func (b *BridgeMarshalJSON) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type BridgeMessageSigner ¶ added in v0.3.0
type BridgeMessageSigner struct {
FnPublic func() crypto.PublicKey
FnSign func(io.Reader, []byte, crypto.SignerOpts) ([]byte, error)
FnSignMessage func(io.Reader, []byte, crypto.SignerOpts) ([]byte, error)
Val any
Ifc vm.Iface
}
BridgeMessageSigner bridges crypto.MessageSigner (Public, Sign, SignMessage). Registered as a richer bridge than BridgeSigner so a value that implements SignMessage keeps that capability when passed to a crypto.Signer parameter; crypto.SignMessage upgrades via signer.(MessageSigner).
func (*BridgeMessageSigner) Public ¶ added in v0.3.0
func (b *BridgeMessageSigner) Public() crypto.PublicKey
Public implements crypto.Signer.
func (*BridgeMessageSigner) Sign ¶ added in v0.3.0
func (b *BridgeMessageSigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
Sign implements crypto.Signer.
func (*BridgeMessageSigner) SignMessage ¶ added in v0.3.0
func (b *BridgeMessageSigner) SignMessage(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
SignMessage implements crypto.MessageSigner.
type BridgeRead ¶
BridgeRead bridges the io.Reader interface method.
type BridgeReadFrom ¶
BridgeReadFrom bridges the io.ReaderFrom interface method.
type BridgeReaderWriterTo ¶
type BridgeReaderWriterTo struct {
FnRead func([]byte) (int, error)
FnWriteTo func(io.Writer) (int64, error)
}
BridgeReaderWriterTo is a composite bridge implementing io.Reader + io.WriterTo. Used to preserve WriterTo capability when wrapping for an io.Reader target (e.g. io.Copy).
type BridgeSigner ¶ added in v0.3.0
type BridgeSigner struct {
FnPublic func() crypto.PublicKey
FnSign func(io.Reader, []byte, crypto.SignerOpts) ([]byte, error)
Val any
Ifc vm.Iface
}
BridgeSigner bridges crypto.Signer (Public, Sign) so an interpreted private key type can be passed to native APIs that accept a Signer.
func (*BridgeSigner) Public ¶ added in v0.3.0
func (b *BridgeSigner) Public() crypto.PublicKey
Public implements crypto.Signer.
func (*BridgeSigner) Sign ¶ added in v0.3.0
func (b *BridgeSigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
Sign implements crypto.Signer.
type BridgeSortInterface ¶
type BridgeSortInterface struct {
FnLen func() int
FnLess func(int, int) bool
FnSwap func(int, int)
}
BridgeSortInterface bridges sort.Interface (Len, Less, Swap).
func (*BridgeSortInterface) Len ¶
func (b *BridgeSortInterface) Len() int
func (*BridgeSortInterface) Less ¶
func (b *BridgeSortInterface) Less(i, j int) bool
func (*BridgeSortInterface) Swap ¶
func (b *BridgeSortInterface) Swap(i, j int)
type BridgeStream ¶ added in v0.3.0
BridgeStream bridges cipher.Stream so an interpreted type implementing XORKeyStream can be stored in native cipher.Stream slots (e.g. cipher.StreamReader.S) and called back from native code.
func (*BridgeStream) XORKeyStream ¶ added in v0.3.0
func (b *BridgeStream) XORKeyStream(dst, src []byte)
XORKeyStream implements cipher.Stream.
type BridgeString ¶
BridgeString bridges the fmt.Stringer interface method.
func (*BridgeString) Format ¶
func (b *BridgeString) Format(f fmt.State, verb rune)
Format implements fmt.Formatter.
func (*BridgeString) String ¶
func (b *BridgeString) String() string
String implements fmt.Stringer.
type BridgeUnmarshalJSON ¶
BridgeUnmarshalJSON bridges the json.Unmarshaler interface method.
func (*BridgeUnmarshalJSON) UnmarshalJSON ¶
func (b *BridgeUnmarshalJSON) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type BridgeUnwrap ¶ added in v0.2.0
type BridgeUnwrap struct{ Fn func() error }
BridgeUnwrap bridges the `interface{ Unwrap() error }` capability used by errors.Is / errors.As / errors.Unwrap chains.
func (*BridgeUnwrap) Unwrap ¶ added in v0.2.0
func (b *BridgeUnwrap) Unwrap() error
Unwrap implements the standard-library single-error unwrap protocol.
type BridgeWrite ¶
BridgeWrite bridges the io.Writer interface method.
type BridgeWriteTo ¶
BridgeWriteTo bridges the io.WriterTo interface method.
type BridgeWriterReaderFrom ¶
type BridgeWriterReaderFrom struct {
FnWrite func([]byte) (int, error)
FnReadFrom func(io.Reader) (int64, error)
}
BridgeWriterReaderFrom is a composite bridge implementing io.Writer + io.ReaderFrom. Used to preserve ReaderFrom capability when wrapping for an io.Writer target (e.g. io.Copy).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all is the convenience aggregator for stdlib bindings: blank-import it to get the full set (core + ext + jsonx).
|
Package all is the convenience aggregator for stdlib bindings: blank-import it to get the full set (core + ext + jsonx). |
|
Package core provides wrappers for core standard library packages.
|
Package core provides wrappers for core standard library packages. |
|
Package errorsx is a mvm-aware replacement for the parts of stdlib `errors` that need to walk error chains containing interpreted error types.
|
Package errorsx is a mvm-aware replacement for the parts of stdlib `errors` that need to walk error chains containing interpreted error types. |
|
Package gobx bridges interpreted types that implement encoding.BinaryMarshaler/BinaryUnmarshaler through native encoding/gob.
|
Package gobx bridges interpreted types that implement encoding.BinaryMarshaler/BinaryUnmarshaler through native encoding/gob. |
|
Package jsonx is a mvm-aware replacement for the encoding/json functions that need to honour mvm-defined methods on struct types (MarshalJSON, UnmarshalJSON).
|
Package jsonx is a mvm-aware replacement for the encoding/json functions that need to honour mvm-defined methods on struct types (MarshalJSON, UnmarshalJSON). |
|
Package stdmod redirects stdlib-shaped import paths to a std module hosted on the Go module proxy.
|
Package stdmod redirects stdlib-shaped import paths to a std module hosted on the Go module proxy. |
|
Package xmlx is a mvm-aware shim for the encoding/xml functions that must honour xml.Unmarshaler methods (UnmarshalXML) defined on interpreted types.
|
Package xmlx is a mvm-aware shim for the encoding/xml functions that must honour xml.Unmarshaler methods (UnmarshalXML) defined on interpreted types. |