Documentation
¶
Overview ¶
Package stdlib provides wrappers of standard library packages to be imported natively in mvm.
Index ¶
- Variables
- func EmbeddedStd() []byte
- func PackagePatchers() map[string][]PackagePatcher
- func PassthroughIface(_ *vm.Machine, ifc vm.Iface) reflect.Value
- func RegisterPackagePatcher(importPath string, fn PackagePatcher)
- type BridgeClose
- type BridgeError
- type BridgeErrorUnwrap
- type BridgeFlagValue
- type BridgeFormat
- type BridgeGoString
- type BridgeHeapInterface
- type BridgeMarshalJSON
- type BridgeRead
- type BridgeReadFrom
- type BridgeReaderWriterTo
- type BridgeSortInterface
- type BridgeString
- type BridgeUnmarshalJSON
- type BridgeUnwrap
- type BridgeWrite
- type BridgeWriteTo
- type BridgeWriterReaderFrom
- type PackagePatcher
Constants ¶
This section is empty.
Variables ¶
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 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 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 BridgeMarshalJSON ¶
BridgeMarshalJSON bridges the json.Marshaler interface method.
func (*BridgeMarshalJSON) MarshalJSON ¶
func (b *BridgeMarshalJSON) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
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 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 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 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. |