eval

package module
v0.0.0-...-34e0159 Latest Latest
Warning

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

Go to latest
Published: May 21, 2016 License: BSD-3-Clause Imports: 19 Imported by: 7

README

go-eval

Build Status GoDoc

This is the new home for the exp/eval package: the beginning of an interpreter for Go.

Installation

$ go get github.com/sbinet/go-eval/...

Usage

$ go-eval
:: welcome to go-eval...
(hit ^D to exit)
> hello := "world"
> println(hello)
world
>

Documentation

http://godoc.org/github.com/sbinet/go-eval

Limitations (aka TODO)

  • channels are not implemented
  • imports are not implemented
  • goroutines are not implemented
  • consts are not implemented
  • select is not implemented

Interpreter

The go-eval command is rather barebone. But there is igo which is built on top of the eval package and provides some additional refinements.

See:

$ go get github.com/sbinet/igo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Uint8Type  = universe.DefineType("uint8", universePos, &uintType{commonType{}, 8, false, "uint8"})
	Uint16Type = universe.DefineType("uint16", universePos, &uintType{commonType{}, 16, false, "uint16"})
	Uint32Type = universe.DefineType("uint32", universePos, &uintType{commonType{}, 32, false, "uint32"})
	Uint64Type = universe.DefineType("uint64", universePos, &uintType{commonType{}, 64, false, "uint64"})

	UintType    = universe.DefineType("uint", universePos, &uintType{commonType{}, 0, false, "uint"})
	UintptrType = universe.DefineType("uintptr", universePos, &uintType{commonType{}, 0, true, "uintptr"})
)
View Source
var (
	Int8Type  = universe.DefineType("int8", universePos, &intType{commonType{}, 8, "int8"})
	Int16Type = universe.DefineType("int16", universePos, &intType{commonType{}, 16, "int16"})
	Int32Type = universe.DefineType("int32", universePos, &intType{commonType{}, 32, "int32"})
	Int64Type = universe.DefineType("int64", universePos, &intType{commonType{}, 64, "int64"})

	IntType = universe.DefineType("int", universePos, &intType{commonType{}, 0, "int"})
)
View Source
var (
	Float32Type = universe.DefineType("float32", universePos, &floatType{commonType{}, 32, "float32"})
	Float64Type = universe.DefineType("float64", universePos, &floatType{commonType{}, 64, "float64"})
)
View Source
var BoolType = universe.DefineType("bool", universePos, &boolType{})
View Source
var StringType = universe.DefineType("string", universePos, &stringType{})

Functions

func FuncFromNativeTyped

func FuncFromNativeTyped(fn func(*Thread, []Value, []Value), t interface{}) (*FuncType, FuncValue)

FuncFromNativeTyped is like FuncFromNative, but constructs the function type from a function pointer using reflection. Typically, the type will be given as a nil pointer to a function with the desired signature.

Types

type ArrayType

type ArrayType struct {
	Len  int64
	Elem Type
	// contains filtered or unexported fields
}

func NewArrayType

func NewArrayType(len int64, elem Type) *ArrayType

func (*ArrayType) String

func (t *ArrayType) String() string

func (*ArrayType) Zero

func (t *ArrayType) Zero() Value

type ArrayValue

type ArrayValue interface {
	Value
	// TODO(austin) Get() is here for uniformity, but is
	// completely useless.  If a lot of other types have similarly
	// useless Get methods, just special-case these uses.
	Get(*Thread) ArrayValue
	Elem(*Thread, int64) Value
	// Sub returns an ArrayValue backed by the same array that
	// starts from element i and has length len.
	Sub(i int64, len int64) ArrayValue
}

type BoolValue

type BoolValue interface {
	Value
	Get(*Thread) bool
	Set(*Thread, bool)
}

type BoundedType

type BoundedType interface {
	Type
	// contains filtered or unexported methods
}

type Code

type Code interface {
	// The type of the value Run returns, or nil if Run returns nil.
	Type() Type

	// Run runs the code; if the code is a single expression
	// with a value, it returns the value; otherwise it returns nil.
	Run() (Value, error)
}

type Constant

type Constant struct {
	ConstPos token.Pos
	Type     Type
	Value    Value
}

func (*Constant) Pos

func (c *Constant) Pos() token.Pos

type Def

type Def interface {
	Pos() token.Pos
}

A definition can be a *Variable, *Constant, or Type.

type DivByZeroError

type DivByZeroError struct{}

func (DivByZeroError) Error

func (DivByZeroError) Error() string

type FloatValue

type FloatValue interface {
	Value
	Get(*Thread) float64
	Set(*Thread, float64)
}

type Frame

type Frame struct {
	Outer *Frame
	Vars  []Value
}

func (*Frame) Get

func (f *Frame) Get(level int, index int) Value

type Func

type Func interface {
	NewFrame() *Frame
	Call(*Thread)
}

type FuncDecl

type FuncDecl struct {
	Type *FuncType
	Name *ast.Ident // nil for function literals
	// InNames will be one longer than Type.In if this function is
	// variadic.
	InNames  []*ast.Ident
	OutNames []*ast.Ident
}

func (*FuncDecl) String

func (t *FuncDecl) String() string

type FuncType

type FuncType struct {

	// TODO(austin) Separate receiver Type for methods?
	In       []Type
	Variadic bool
	Out      []Type
	// contains filtered or unexported fields
}

func NewFuncType

func NewFuncType(in []Type, variadic bool, out []Type) *FuncType

func (*FuncType) String

func (t *FuncType) String() string

func (*FuncType) Zero

func (t *FuncType) Zero() Value

type FuncValue

type FuncValue interface {
	Value
	Get(*Thread) Func
	Set(*Thread, Func)
}

func FuncFromNative

func FuncFromNative(fn func(*Thread, []Value, []Value), t *FuncType) FuncValue

FuncFromNative creates an interpreter function from a native function that takes its in and out arguments as slices of interpreter Value's. While somewhat inconvenient, this avoids value marshalling.

type IMethod

type IMethod struct {
	Name string
	Type *FuncType
}

type IdealFloatValue

type IdealFloatValue interface {
	Value
	Get() *big.Rat
}

type IdealIntValue

type IdealIntValue interface {
	Value
	Get() *big.Int
}

TODO(austin) IdealIntValue and IdealFloatValue should not exist because ideals are not l-values.

type IndexError

type IndexError struct {
	Idx, Len int64
}

func (IndexError) Error

func (e IndexError) Error() string

type IntValue

type IntValue interface {
	Value
	Get(*Thread) int64
	Set(*Thread, int64)
}

type Interface

type Interface struct {
	Type  Type
	Value Value
}

type InterfaceType

type InterfaceType struct {
	// contains filtered or unexported fields
}

func NewInterfaceType

func NewInterfaceType(methods []IMethod, embeds []*InterfaceType) *InterfaceType

func (*InterfaceType) String

func (t *InterfaceType) String() string

func (*InterfaceType) Zero

func (t *InterfaceType) Zero() Value

type InterfaceValue

type InterfaceValue interface {
	Value
	Get(*Thread) Interface
	Set(*Thread, Interface)
}

type KeyError

type KeyError struct {
	Key interface{}
}

func (KeyError) Error

func (e KeyError) Error() string

type Map

type Map interface {
	Len(*Thread) int64
	// Retrieve an element from the map, returning nil if it does
	// not exist.
	Elem(t *Thread, key interface{}) Value
	// Set an entry in the map.  If val is nil, delete the entry.
	SetElem(t *Thread, key interface{}, val Value)
	// TODO(austin)  Perhaps there should be an iterator interface instead.
	Iter(func(key interface{}, val Value) bool)
}

type MapType

type MapType struct {
	Key  Type
	Elem Type
	// contains filtered or unexported fields
}

func NewMapType

func NewMapType(key Type, elem Type) *MapType

func (*MapType) String

func (t *MapType) String() string

func (*MapType) Zero

func (t *MapType) Zero() Value

type MapValue

type MapValue interface {
	Value
	Get(*Thread) Map
	Set(*Thread, Map)
}

type Method

type Method struct {
	// contains filtered or unexported fields
}

type MultiType

type MultiType struct {
	Elems []Type
	// contains filtered or unexported fields
}

MultiType is a special type used for multi-valued expressions, akin to a tuple type. It's not generally accessible within the language.

func NewMultiType

func NewMultiType(elems []Type) *MultiType

func (*MultiType) String

func (t *MultiType) String() string

func (*MultiType) Zero

func (t *MultiType) Zero() Value

type NamedType

type NamedType struct {
	NamePos token.Pos
	Name    string
	// Underlying type.  If incomplete is true, this will be nil.
	// If incomplete is false and this is still nil, then this is
	// a placeholder type representing an error.
	Def Type
	// contains filtered or unexported fields
}

func NewNamedType

func NewNamedType(name string) *NamedType

TODO(austin) This is temporarily needed by the debugger's remote type parser. This should only be possible with block.DefineType.

func (*NamedType) Complete

func (t *NamedType) Complete(def Type)

func (*NamedType) Pos

func (t *NamedType) Pos() token.Pos

func (*NamedType) String

func (t *NamedType) String() string

func (*NamedType) Zero

func (t *NamedType) Zero() Value

type NegativeCapacityError

type NegativeCapacityError struct {
	Len int64
}

func (NegativeCapacityError) Error

func (e NegativeCapacityError) Error() string

type NegativeLengthError

type NegativeLengthError struct {
	Len int64
}

func (NegativeLengthError) Error

func (e NegativeLengthError) Error() string

type NilPointerError

type NilPointerError struct{}

func (NilPointerError) Error

func (NilPointerError) Error() string

type PackageValue

type PackageValue interface {
	Value
	Get(*Thread) PackageValue
	Ident(*Thread, int) Value
}

type PkgIdent

type PkgIdent struct {
	PkgPos token.Pos
	// contains filtered or unexported fields
}

func (*PkgIdent) Pos

func (p *PkgIdent) Pos() token.Pos

type PtrType

type PtrType struct {
	Elem Type
	// contains filtered or unexported fields
}

func NewPtrType

func NewPtrType(elem Type) *PtrType

func (*PtrType) String

func (t *PtrType) String() string

func (*PtrType) Zero

func (t *PtrType) Zero() Value

type PtrValue

type PtrValue interface {
	Value
	Get(*Thread) Value
	Set(*Thread, Value)
}

type RedefinitionError

type RedefinitionError struct {
	Name string
	Prev Def
}

func (*RedefinitionError) Error

func (e *RedefinitionError) Error() string

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

A Scope is the compile-time analogue of a Frame, which captures some subtree of blocks.

func (Scope) ChildScope

func (b Scope) ChildScope() *Scope

func (Scope) DefineConst

func (b Scope) DefineConst(name string, pos token.Pos, t Type, v Value) (*Constant, Def)

func (Scope) DefinePackage

func (b Scope) DefinePackage(id, path string, pos token.Pos) (*PkgIdent, Def)

func (Scope) DefineTemp

func (b Scope) DefineTemp(t Type) *Variable

func (Scope) DefineType

func (b Scope) DefineType(name string, pos token.Pos, t Type) Type

func (Scope) DefineVar

func (b Scope) DefineVar(name string, pos token.Pos, t Type) (*Variable, Def)

func (Scope) Lookup

func (b Scope) Lookup(name string) (bl *block, level int, def Def)

func (*Scope) NewFrame

func (s *Scope) NewFrame(outer *Frame) *Frame

type Slice

type Slice struct {
	Base     ArrayValue
	Len, Cap int64
}

type SliceError

type SliceError struct {
	Lo, Hi, Cap int64
}

func (SliceError) Error

func (e SliceError) Error() string

type SliceType

type SliceType struct {
	Elem Type
	// contains filtered or unexported fields
}

func NewSliceType

func NewSliceType(elem Type) *SliceType

func (*SliceType) String

func (t *SliceType) String() string

func (*SliceType) Zero

func (t *SliceType) Zero() Value

type SliceValue

type SliceValue interface {
	Value
	Get(*Thread) Slice
	Set(*Thread, Slice)
}

type StringValue

type StringValue interface {
	Value
	Get(*Thread) string
	Set(*Thread, string)
}

type StructField

type StructField struct {
	Name      string
	Type      Type
	Anonymous bool
}

type StructType

type StructType struct {
	Elems []StructField
	// contains filtered or unexported fields
}

func NewStructType

func NewStructType(fields []StructField) *StructType

func (*StructType) String

func (t *StructType) String() string

func (*StructType) Zero

func (t *StructType) Zero() Value

type StructValue

type StructValue interface {
	Value
	// TODO(austin) This is another useless Get()
	Get(*Thread) StructValue
	Field(*Thread, int) Value
}

type Thread

type Thread struct {
	// contains filtered or unexported fields
}

func (*Thread) Abort

func (t *Thread) Abort(err error)

Abort aborts the thread's current computation, causing the innermost Try to return err.

func (*Thread) Try

func (t *Thread) Try(f func(t *Thread)) error

Try executes a computation; if the computation Aborts, Try returns the error passed to abort.

type Type

type Type interface {

	// Zero returns a new zero value of this type.
	Zero() Value
	// String returns the string representation of this type.
	String() string
	// contains filtered or unexported methods
}
var EmptyType Type = NewMultiType([]Type{})
var IdealFloatType Type = &idealFloatType{}
var IdealIntType Type = &idealIntType{}

func TypeFromNative

func TypeFromNative(t reflect.Type) Type

TypeFromNative converts a regular Go type into a the corresponding interpreter Type.

func TypeOfNative

func TypeOfNative(v interface{}) Type

TypeOfNative returns the interpreter Type of a regular Go value.

type UintValue

type UintValue interface {
	Value
	Get(*Thread) uint64
	Set(*Thread, uint64)
}

type Value

type Value interface {
	String() string
	// Assign copies another value into this one.  It should
	// assume that the other value satisfies the same specific
	// value interface (BoolValue, etc.), but must not assume
	// anything about its specific type.
	Assign(t *Thread, o Value)
}

type Variable

type Variable struct {
	VarPos token.Pos
	// Index of this variable in the Frame structure
	Index int
	// Static type of this variable
	Type Type
	// Value of this variable.  This is only used by Scope.NewFrame;
	// therefore, it is useful for global scopes but cannot be used
	// in function scopes.
	Init Value
}

func (*Variable) Pos

func (v *Variable) Pos() token.Pos

type World

type World struct {
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld() *World

func (*World) Compile

func (w *World) Compile(fset *token.FileSet, text string) (Code, error)

func (*World) CompileDeclList

func (w *World) CompileDeclList(fset *token.FileSet, decls []ast.Decl) (Code, error)

func (*World) CompileExpr

func (w *World) CompileExpr(fset *token.FileSet, e ast.Expr) (Code, error)

func (*World) CompilePackage

func (w *World) CompilePackage(fset *token.FileSet, files []*ast.File, pkgpath string) (Code, error)

func (*World) CompileStmtList

func (w *World) CompileStmtList(fset *token.FileSet, stmts []ast.Stmt) (Code, error)

func (*World) DefineConst

func (w *World) DefineConst(name string, t Type, val Value) error

func (*World) DefineVar

func (w *World) DefineVar(name string, t Type, val Value) error

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

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