Documentation ¶
Overview ¶
Package ssa/interp defines an interpreter for the SSA representation of Go programs.
This interpreter is provided as an adjunct for testing the SSA construction algorithm. Its purpose is to provide a minimal metacircular implementation of the dynamic semantics of each SSA instruction. It is not, and will never be, a production-quality Go interpreter.
The following is a partial list of Go features that are currently unsupported or incomplete in the interpreter.
* Unsafe operations, including all uses of unsafe.Pointer, are impossible to support given the "boxed" value representation we have chosen.
* The reflect package is only partially implemented.
* The "testing" package is no longer supported because it depends on low-level details that change too often.
* "sync/atomic" operations are not atomic due to the "boxed" value representation: it is not possible to read, modify and write an interface value atomically. As a consequence, Mutexes are currently broken.
* recover is only partially implemented. Also, the interpreter makes no attempt to distinguish target panics from interpreter crashes.
* the sizes of the int, uint and uintptr types in the target program are assumed to be the same as those of the interpreter itself.
* all values occupy space, even those of types defined by the spec to have zero size, e.g. struct{}. This can cause asymptotic performance degradation.
* os.Exit is implemented using panic, causing deferred functions to run.
Index ¶
- Variables
- func AllMethod(typ reflect.Type, enableUnexport bool) []reflect.Method
- func CreateTestMainPackage(pkg *ssa.Package) (*ssa.Package, error)deprecated
- func Field(v interface{}, index int) (interface{}, error)
- func FieldAddr(v interface{}, index int) (interface{}, error)
- func FindTests(pkg *ssa.Package) (tests, benchmarks, examples []*ssa.Function, main *ssa.Function)deprecated
- func IntuitiveMethodSet(T types.Type) []*types.Selection
- func IsConstNil(v ssa.Value) bool
- func IsNil(v reflect.Value) bool
- func RegisterCustomBuiltin(key string, fn interface{}) error
- func RegisterExternal(key string, i interface{})
- func RegisterFileProcess(ext string, fn SourceProcessFunc)
- func RegisterPackage(pkg *Package)
- func Run(path string, args []string, mode Mode) (exitCode int, err error)
- func RunFile(filename string, src interface{}, args []string, mode Mode) (exitCode int, err error)
- func RunTest(path string, args []string, mode Mode) error
- func SetValue(v reflect.Value, x reflect.Value)
- type Context
- func (ctx *Context) BuildPackage(fset *token.FileSet, pkg *types.Package, files []*ast.File) (*ssa.Package, *types.Info, error)
- func (c *Context) ClearOverrideFunction(key string)
- func (c *Context) IsEvalMode() bool
- func (c *Context) LoadAstFile(fset *token.FileSet, file *ast.File) (*ssa.Package, error)
- func (c *Context) LoadAstPackage(fset *token.FileSet, apkg *ast.Package) (*ssa.Package, error)
- func (c *Context) LoadDir(fset *token.FileSet, path string) (pkgs []*ssa.Package, first error)
- func (c *Context) LoadFile(fset *token.FileSet, filename string, src interface{}) (*ssa.Package, error)
- func (c *Context) NewInterp(mainPkg *ssa.Package) (*Interp, error)
- func (c *Context) ParseFile(fset *token.FileSet, filename string, src interface{}) (*ast.File, error)
- func (c *Context) Run(path string, args []string) (exitCode int, err error)
- func (c *Context) RunFile(filename string, src interface{}, args []string) (exitCode int, err error)
- func (c *Context) RunFunc(mainPkg *ssa.Package, fnname string, args ...Value) (ret Value, err error)
- func (c *Context) RunPkg(mainPkg *ssa.Package, input string, args []string) (exitCode int, err error)
- func (c *Context) RunTest(path string, args []string) error
- func (c *Context) SetDebug(fn func(*DebugInfo))
- func (c *Context) SetLeastCallForEnablePool(count int)
- func (c *Context) SetOverrideFunction(key string, fn interface{})
- func (c *Context) SetPrintOutput(output *bytes.Buffer)
- func (c *Context) TestPkg(pkgs []*ssa.Package, input string, args []string) error
- type DebugInfo
- type FindMethod
- type Importer
- type Interp
- func (i *Interp) ExitCode() int
- func (i *Interp) FindMethod(mtyp reflect.Type, fn *types.Func) func([]reflect.Value) []reflect.Value
- func (i *Interp) GetConst(key string) (constant.Value, bool)
- func (i *Interp) GetFunc(key string) (interface{}, bool)
- func (i *Interp) GetType(key string) (reflect.Type, bool)
- func (i *Interp) GetVarAddr(key string) (interface{}, bool)
- func (i *Interp) RunFunc(name string, args ...Value) (r Value, err error)
- func (i *Interp) RunInit() (err error)
- func (i *Interp) RunMain() (exitCode int, err error)
- type Loader
- type Mode
- type NamedType
- type Package
- type Repl
- type SourceProcessFunc
- type Tuple
- type TypedConst
- type TypesLoader
- func (r *TypesLoader) GetPackage(pkg string) *types.Package
- func (r *TypesLoader) Import(path string) (*types.Package, error)
- func (r *TypesLoader) Insert(v reflect.Value)
- func (r *TypesLoader) InsertAlias(p *types.Package, name string, rt reflect.Type)
- func (r *TypesLoader) InsertConst(p *types.Package, name string, typ types.Type, c constant.Value)
- func (r *TypesLoader) InsertFunc(p *types.Package, name string, v reflect.Value)
- func (r *TypesLoader) InsertInterface(p *types.Package, name string, rt reflect.Type)
- func (r *TypesLoader) InsertNamedType(p *types.Package, name string, t NamedType)
- func (r *TypesLoader) InsertTypedConst(p *types.Package, name string, v TypedConst)
- func (r *TypesLoader) InsertUntypedConst(p *types.Package, name string, v UntypedConst)
- func (r *TypesLoader) InsertVar(p *types.Package, name string, v reflect.Value)
- func (r *TypesLoader) Installed(path string) (pkg *Package, ok bool)
- func (r *TypesLoader) LookupPackage(pkgpath string) (*types.Package, bool)
- func (r *TypesLoader) LookupReflect(typ types.Type) (reflect.Type, bool)
- func (r *TypesLoader) LookupType(typ string) types.Type
- func (r *TypesLoader) LookupTypes(typ reflect.Type) (types.Type, bool)
- func (r *TypesLoader) Packages() (pkgs []*types.Package)
- func (r *TypesLoader) ToType(rt reflect.Type) types.Type
- type TypesRecord
- func (r *TypesRecord) Load(pkg *ssa.Package)
- func (r *TypesRecord) LoadType(typ types.Type) reflect.Type
- func (r *TypesRecord) LookupLocalTypes(rt reflect.Type) (typ types.Type, ok bool)
- func (r *TypesRecord) LookupReflect(typ types.Type) (rt reflect.Type, ok bool)
- func (r *TypesRecord) LookupTypes(rt reflect.Type) (typ types.Type, ok bool)
- func (r *TypesRecord) ToType(typ types.Type) reflect.Type
- func (r *TypesRecord) ToTypeList(tuple *types.Tuple) []reflect.Type
- type UntypedConst
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPackage = errors.New("no package") ErrPackage = errors.New("package contain errors") ErrNotFoundMain = errors.New("not found main package") ErrTestFailed = errors.New("test failed") ErrNotFoundPackage = errors.New("not found package") ErrNotFoundImporter = errors.New("not found provider for types.Importer") ErrGoexitDeadlock = errors.New("fatal error: no goroutines (main called runtime.Goexit) - deadlock!") ErrNoFunction = errors.New("no function") )
Functions ¶
func CreateTestMainPackage
deprecated
CreateTestMainPackage creates and returns a synthetic "testmain" package for the specified package if it defines tests, benchmarks or executable examples, or nil otherwise. The new package is named "main" and provides a function named "main" that runs the tests, similar to the one that would be created by the 'go test' tool.
Subsequent calls to prog.AllPackages include the new package. The package pkg must belong to the program prog.
Deprecated: Use golang.org/x/tools/go/packages to access synthetic testmain packages.
func FindTests
deprecated
added in
v0.2.6
FindTests returns the Test, Benchmark, and Example functions (as defined by "go test") defined in the specified package, and its TestMain function, if any.
Deprecated: Use golang.org/x/tools/go/packages to access synthetic testmain packages.
func IntuitiveMethodSet ¶ added in v0.2.0
golang.org/x/tools/go/types/typeutil.IntuitiveMethodSet
func IsConstNil ¶
func RegisterCustomBuiltin ¶ added in v0.3.25
func RegisterExternal ¶
func RegisterExternal(key string, i interface{})
register external function for no function body
func RegisterFileProcess ¶ added in v0.2.10
func RegisterFileProcess(ext string, fn SourceProcessFunc)
Types ¶
type Context ¶ added in v0.2.0
type Context struct { Loader Loader // types loader Mode Mode // mode ParserMode parser.Mode // parser mode BuilderMode ssa.BuilderMode // ssa builder mode External types.Importer // external import Sizes types.Sizes // types size for package unsafe // contains filtered or unexported fields }
Context ssa context
func NewContext ¶ added in v0.2.0
NewContext create a new Context
func (*Context) BuildPackage ¶ added in v0.2.0
func (*Context) ClearOverrideFunction ¶ added in v0.3.17
ClearOverrideFunction reset override function
func (*Context) IsEvalMode ¶ added in v0.3.25
func (*Context) LoadAstFile ¶ added in v0.2.0
func (*Context) LoadAstPackage ¶ added in v0.2.0
func (*Context) SetLeastCallForEnablePool ¶ added in v0.3.18
SetLeastCallForEnablePool set least call count for enable function pool, default 64
func (*Context) SetOverrideFunction ¶ added in v0.3.15
SetOverrideFunction register external function to override function. match func fullname and signature
func (*Context) SetPrintOutput ¶ added in v0.3.17
set builtin print/println captured output
type FindMethod ¶ added in v0.2.0
type Importer ¶ added in v0.2.0
type Importer struct {
// contains filtered or unexported fields
}
func NewImporter ¶ added in v0.2.0
type Interp ¶ added in v0.2.0
type Interp struct {
// contains filtered or unexported fields
}
State shared between all interpreted goroutines.
func (*Interp) FindMethod ¶ added in v0.2.0
func (*Interp) GetVarAddr ¶ added in v0.2.11
type Loader ¶ added in v0.2.0
type Loader interface { Import(path string) (*types.Package, error) Installed(path string) (*Package, bool) Packages() []*types.Package LookupReflect(typ types.Type) (reflect.Type, bool) LookupTypes(typ reflect.Type) (types.Type, bool) }
Loader types loader interface
func NewTypesLoader ¶ added in v0.2.0
NewTypesLoader install package and readonly
type Mode ¶
type Mode uint
Mode is a bitmask of options affecting the interpreter.
const ( DisableRecover Mode = 1 << iota // Disable recover() in target programs; show interpreter crash instead. DisableCustomBuiltin // Disable load custom builtin func DisableUnexportMethods // Disable unexport methods EnableTracing // Print a trace of all instructions as they are interpreted. EnableDumpInstr // Print packages & SSA instruction code EnablePrintAny // Enable builtin print for any type ( struct/array ) )
type Package ¶ added in v0.2.0
type Package struct { Name string Path string Interfaces map[string]reflect.Type NamedTypes map[string]NamedType AliasTypes map[string]reflect.Type Vars map[string]reflect.Value Funcs map[string]reflect.Value TypedConsts map[string]TypedConst UntypedConsts map[string]UntypedConst Deps map[string]string // contains filtered or unexported fields }
func LookupPackage ¶ added in v0.2.0
LookupPackage lookup register pkgs
type Repl ¶ added in v0.3.25
type Repl struct {
// contains filtered or unexported fields
}
func (*Repl) SetFileName ¶ added in v0.3.25
type SourceProcessFunc ¶ added in v0.2.10
type TypesLoader ¶ added in v0.2.0
type TypesLoader struct {
// contains filtered or unexported fields
}
func (*TypesLoader) GetPackage ¶ added in v0.2.0
func (r *TypesLoader) GetPackage(pkg string) *types.Package
func (*TypesLoader) Import ¶ added in v0.2.0
func (r *TypesLoader) Import(path string) (*types.Package, error)
func (*TypesLoader) Insert ¶ added in v0.2.0
func (r *TypesLoader) Insert(v reflect.Value)
func (*TypesLoader) InsertAlias ¶ added in v0.2.0
func (*TypesLoader) InsertConst ¶ added in v0.2.0
func (*TypesLoader) InsertFunc ¶ added in v0.2.0
func (*TypesLoader) InsertInterface ¶ added in v0.2.0
func (*TypesLoader) InsertNamedType ¶ added in v0.2.0
func (r *TypesLoader) InsertNamedType(p *types.Package, name string, t NamedType)
func (*TypesLoader) InsertTypedConst ¶ added in v0.2.0
func (r *TypesLoader) InsertTypedConst(p *types.Package, name string, v TypedConst)
func (*TypesLoader) InsertUntypedConst ¶ added in v0.2.0
func (r *TypesLoader) InsertUntypedConst(p *types.Package, name string, v UntypedConst)
func (*TypesLoader) Installed ¶ added in v0.2.0
func (r *TypesLoader) Installed(path string) (pkg *Package, ok bool)
func (*TypesLoader) LookupPackage ¶ added in v0.2.0
func (r *TypesLoader) LookupPackage(pkgpath string) (*types.Package, bool)
func (*TypesLoader) LookupReflect ¶ added in v0.2.0
func (*TypesLoader) LookupType ¶ added in v0.2.0
func (r *TypesLoader) LookupType(typ string) types.Type
func (*TypesLoader) LookupTypes ¶ added in v0.2.0
func (*TypesLoader) Packages ¶ added in v0.2.0
func (r *TypesLoader) Packages() (pkgs []*types.Package)
type TypesRecord ¶ added in v0.2.0
type TypesRecord struct {
// contains filtered or unexported fields
}
func NewTypesRecord ¶ added in v0.2.0
func NewTypesRecord(loader Loader, finder FindMethod) *TypesRecord
func (*TypesRecord) Load ¶ added in v0.2.0
func (r *TypesRecord) Load(pkg *ssa.Package)
func (*TypesRecord) LoadType ¶ added in v0.2.0
func (r *TypesRecord) LoadType(typ types.Type) reflect.Type
func (*TypesRecord) LookupLocalTypes ¶ added in v0.2.0
func (*TypesRecord) LookupReflect ¶ added in v0.2.0
func (*TypesRecord) LookupTypes ¶ added in v0.2.0
func (*TypesRecord) ToType ¶ added in v0.2.0
func (r *TypesRecord) ToType(typ types.Type) reflect.Type
func (*TypesRecord) ToTypeList ¶ added in v0.2.0
func (r *TypesRecord) ToTypeList(tuple *types.Tuple) []reflect.Type
type UntypedConst ¶ added in v0.2.0
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal/base
Package base defines shared xtype pieces of the gop command, in particular logging and the Command structure.
|
Package base defines shared xtype pieces of the gop command, in particular logging and the Command structure. |
internal/help
Package help implements the “gossa help” command.
|
Package help implements the “gossa help” command. |
internal/run
Package run implements the “gop run” command.
|
Package run implements the “gop run” command. |
internal/test
Package test implements the “gossa test” command.
|
Package test implements the “gossa test” command. |
internal
|
|