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 PackageList() (list []string)
- func ParseBuiltin(fset *token.FileSet, pkg string) (*ast.File, error)
- 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 ExitError
- type FindMethod
- type Importer
- type Interp
- func (i *Interp) Exit(code int)
- 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) GetSymbol(key string) (m ssa.Member, v interface{}, ok bool)
- func (i *Interp) GetType(key string) (reflect.Type, bool)
- func (i *Interp) GetVarAddr(key string) (interface{}, bool)
- func (i *Interp) MainPkg() *ssa.Package
- 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") ErrNoCustomBuiltin = errors.New("no custom builtin") )
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
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 ¶
golang.org/x/tools/go/types/typeutil.IntuitiveMethodSet
func IsConstNil ¶
func PackageList ¶ added in v0.7.4
func PackageList() (list []string)
PackageList return all register packages
func ParseBuiltin ¶ added in v0.7.4
func RegisterCustomBuiltin ¶
func RegisterExternal ¶
func RegisterExternal(key string, i interface{})
register external function for no function body
func RegisterFileProcess ¶
func RegisterFileProcess(ext string, fn SourceProcessFunc)
Types ¶
type Context ¶
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 (*Context) BuildPackage ¶
func (*Context) ClearOverrideFunction ¶
ClearOverrideFunction reset override function
func (*Context) IsEvalMode ¶
func (*Context) LoadAstFile ¶
func (*Context) LoadAstPackage ¶
func (*Context) SetLeastCallForEnablePool ¶
SetLeastCallForEnablePool set least call count for enable function pool, default 64
func (*Context) SetOverrideFunction ¶
SetOverrideFunction register external function to override function. match func fullname and signature
func (*Context) SetPrintOutput ¶
set builtin print/println captured output
type FindMethod ¶
type Interp ¶
type Interp struct {
// contains filtered or unexported fields
}
State shared between all interpreted goroutines.
func (*Interp) FindMethod ¶
func (*Interp) GetVarAddr ¶
type Loader ¶
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 ¶
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 ¶
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 ¶
LookupPackage lookup register pkgs
type Repl ¶
type Repl struct {
// contains filtered or unexported fields
}
func (*Repl) SetFileName ¶
type SourceProcessFunc ¶
type TypesLoader ¶
type TypesLoader struct {
// contains filtered or unexported fields
}
func (*TypesLoader) GetPackage ¶
func (r *TypesLoader) GetPackage(pkg string) *types.Package
func (*TypesLoader) Insert ¶
func (r *TypesLoader) Insert(v reflect.Value)
func (*TypesLoader) InsertAlias ¶
func (*TypesLoader) InsertConst ¶
func (*TypesLoader) InsertFunc ¶
func (*TypesLoader) InsertInterface ¶
func (*TypesLoader) InsertNamedType ¶
func (r *TypesLoader) InsertNamedType(p *types.Package, name string, t NamedType)
func (*TypesLoader) InsertTypedConst ¶
func (r *TypesLoader) InsertTypedConst(p *types.Package, name string, v TypedConst)
func (*TypesLoader) InsertUntypedConst ¶
func (r *TypesLoader) InsertUntypedConst(p *types.Package, name string, v UntypedConst)
func (*TypesLoader) Installed ¶
func (r *TypesLoader) Installed(path string) (pkg *Package, ok bool)
func (*TypesLoader) LookupPackage ¶
func (r *TypesLoader) LookupPackage(pkgpath string) (*types.Package, bool)
func (*TypesLoader) LookupReflect ¶
func (*TypesLoader) LookupType ¶
func (r *TypesLoader) LookupType(typ string) types.Type
func (*TypesLoader) LookupTypes ¶
func (*TypesLoader) Packages ¶
func (r *TypesLoader) Packages() (pkgs []*types.Package)
type TypesRecord ¶
type TypesRecord struct {
// contains filtered or unexported fields
}
func NewTypesRecord ¶
func NewTypesRecord(loader Loader, finder FindMethod) *TypesRecord
func (*TypesRecord) Load ¶
func (r *TypesRecord) Load(pkg *ssa.Package)
func (*TypesRecord) LookupLocalTypes ¶
func (*TypesRecord) LookupReflect ¶
func (*TypesRecord) LookupTypes ¶
func (*TypesRecord) ToTypeList ¶
func (r *TypesRecord) ToTypeList(tuple *types.Tuple) []reflect.Type
type UntypedConst ¶
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 “igop help” command.
|
Package help implements the “igop help” command. |
internal/run
Package run implements the “gop run” command.
|
Package run implements the “gop run” command. |
internal/test
Package test implements the “igop test” command.
|
Package test implements the “igop test” command. |