stdlib

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package stdlib provides wrappers of standard library packages to be imported natively in mvm.

Index

Constants

This section is empty.

Variables

View Source
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

func PassthroughIface(_ *vm.Machine, ifc vm.Iface) reflect.Value

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.

func (*BridgeClose) Close

func (b *BridgeClose) Close() error

Close implements io.Closer.

type BridgeError

type BridgeError struct {
	Fn       func() string
	FnFormat func(fmt.State, rune)
	Val      any
	Ifc      vm.Iface
}

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

type BridgeFlagValue struct {
	FnString func() string
	FnSet    func(string) error
}

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

type BridgeFormat struct {
	Fn func(fmt.State, rune)
}

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).

func (*BridgeFormat) Format added in v0.2.0

func (b *BridgeFormat) Format(f fmt.State, verb rune)

Format implements fmt.Formatter.

type BridgeGoString

type BridgeGoString struct {
	Fn  func() string
	Val any
}

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

type BridgeMarshalJSON struct{ Fn func() ([]byte, error) }

BridgeMarshalJSON bridges the json.Marshaler interface method.

func (*BridgeMarshalJSON) MarshalJSON

func (b *BridgeMarshalJSON) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type BridgeRead

type BridgeRead struct{ Fn func([]byte) (int, error) }

BridgeRead bridges the io.Reader interface method.

func (*BridgeRead) Read

func (b *BridgeRead) Read(p []byte) (int, error)

Read implements io.Reader.

type BridgeReadFrom

type BridgeReadFrom struct {
	Fn func(io.Reader) (int64, error)
}

BridgeReadFrom bridges the io.ReaderFrom interface method.

func (*BridgeReadFrom) ReadFrom

func (b *BridgeReadFrom) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

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).

func (*BridgeReaderWriterTo) Read

func (b *BridgeReaderWriterTo) Read(p []byte) (int, error)

func (*BridgeReaderWriterTo) WriteTo

func (b *BridgeReaderWriterTo) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

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

type BridgeString struct {
	Fn  func() string
	Val any
}

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

type BridgeUnmarshalJSON struct{ Fn func([]byte) error }

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

type BridgeWrite struct{ Fn func([]byte) (int, error) }

BridgeWrite bridges the io.Writer interface method.

func (*BridgeWrite) Write

func (b *BridgeWrite) Write(p []byte) (int, error)

Write implements io.Writer.

type BridgeWriteTo

type BridgeWriteTo struct {
	Fn func(io.Writer) (int64, error)
}

BridgeWriteTo bridges the io.WriterTo interface method.

func (*BridgeWriteTo) WriteTo

func (b *BridgeWriteTo) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

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).

func (*BridgeWriterReaderFrom) ReadFrom

func (b *BridgeWriterReaderFrom) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

func (*BridgeWriterReaderFrom) Write

func (b *BridgeWriterReaderFrom) Write(p []byte) (int, error)

type PackagePatcher

type PackagePatcher func(m *vm.Machine, values map[string]vm.Value)

PackagePatcher mutates a package's exported values at interpreter startup. m is the live VM; values is the package's vm.Value symbol map (the same map the interpreter resolves imports against).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL