Package eval
import "exp/eval"
This package is the beginning of an interpreter for Go. It can run simple Go programs but does not implement interface values or packages.
Package files
abort.go bridge.go compiler.go expr.go expr1.go func.go scope.go stmt.go type.go typec.go util.go value.go world.goVariables
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"})
)
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"})
)
var (
Float32Type = universe.DefineType("float32", universePos, &floatType{commonType{}, 32, "float32"})
Float64Type = universe.DefineType("float64", universePos, &floatType{commonType{}, 64, "float64"})
FloatType = universe.DefineType("float", universePos, &floatType{commonType{}, 0, "float"})
)
var BoolType = universe.DefineType("bool", universePos, &boolType{})
var StringType = universe.DefineType("string", universePos, &stringType{})
type ArrayType
type ArrayType struct {
Len int64
Elem Type
// contains 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 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, os.Error)
}
type Constant
type Constant struct {
token.Position
Type Type
Value Value
}
type Def
A definition can be a *Variable, *Constant, or Type.
type Def interface {
Pos() token.Position
}
type DivByZeroError
type DivByZeroError struct{}
func (DivByZeroError) String
func (DivByZeroError) String() 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 unexported fields
}
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.
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() *bignum.Rational
}
type IdealIntValue
TODO(austin) IdealIntValue and IdealFloatValue should not exist because ideals are not l-values.
type IdealIntValue interface {
Value
Get() *bignum.Integer
}
type IndexError
type IndexError struct {
Idx, Len int64
}
func (IndexError) String
func (e IndexError) String() 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 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) String
func (e KeyError) String() 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 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 unexported fields
}
type MultiType
MultiType is a special type used for multi-valued expressions, akin to a tuple type. It's not generally accessible within the language.
type MultiType struct {
Elems []Type
// contains unexported fields
}
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 {
token.Position
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 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) String
func (t *NamedType) String() string
func (*NamedType) Zero
func (t *NamedType) Zero() Value
type NegativeCapacityError
type NegativeCapacityError struct {
Len int64
}
func (NegativeCapacityError) String
func (e NegativeCapacityError) String() string
type NegativeLengthError
type NegativeLengthError struct {
Len int64
}
func (NegativeLengthError) String
func (e NegativeLengthError) String() string
type NilPointerError
type NilPointerError struct{}
func (NilPointerError) String
func (NilPointerError) String() string
type PtrType
type PtrType struct {
Elem Type
// contains 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) String
func (e *RedefinitionError) String() string
type Scope
A Scope is the compile-time analogue of a Frame, which captures some subtree of blocks.
type Scope struct {
// contains unexported fields
}
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) String
func (e SliceError) String() string
type SliceType
type SliceType struct {
Elem Type
// contains 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 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 unexported fields
}
func (*Thread) Abort
func (t *Thread) Abort(err os.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)) os.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
// The position where this type was defined, if any.
Pos() token.Position
// contains 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 {
token.Position
// 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
}
type World
type World struct {
// contains unexported fields
}
func NewWorld
func NewWorld() *World
func (*World) Compile
func (w *World) Compile(text string) (Code, os.Error)
func (*World) CompileDeclList
func (w *World) CompileDeclList(decls []ast.Decl) (Code, os.Error)
func (*World) CompileExpr
func (w *World) CompileExpr(e ast.Expr) (Code, os.Error)
func (*World) CompileStmtList
func (w *World) CompileStmtList(stmts []ast.Stmt) (Code, os.Error)
func (*World) DefineConst
func (w *World) DefineConst(name string, t Type, val Value) os.Error
func (*World) DefineVar
func (w *World) DefineVar(name string, t Type, val Value) os.Error
