value

package
v0.0.0-...-e696326 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IvyEval func(context Context, s string) Value

Implemented in main, handled as a func to avoid a dependency loop.

View Source
var (
	MaxBigInt63 = big.NewInt(int64(^uint64(0) >> 1))
)

Functions

func Errorf

func Errorf(format string, args ...interface{})

Errorf panics with the formatted string, with type Error.

func ParseString

func ParseString(s string) string

ParseString parses a string. Single quotes and double quotes are both allowed (but must be consistent.) The result must contain only valid Unicode code points.

Types

type BigFloat

type BigFloat struct {
	*big.Float
}

func Consts

func Consts(c Context) (e, pi BigFloat)

func (BigFloat) Eval

func (f BigFloat) Eval(Context) Value

func (BigFloat) Format

func (i BigFloat) Format()

The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Float implements Formatter, and we embed it in our BigFloat type. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.

func (BigFloat) ProgString

func (f BigFloat) ProgString() string

func (BigFloat) Sprint

func (f BigFloat) Sprint(conf *config.Config) string

func (BigFloat) String

func (f BigFloat) String() string

type BigInt

type BigInt struct {
	*big.Int
}

func (BigInt) BitLen

func (i BigInt) BitLen() int64

func (BigInt) Eval

func (i BigInt) Eval(Context) Value

func (BigInt) Format

func (i BigInt) Format()

The fmt package looks for Formatter before Stringer, but we want to use Stringer only. big.Int and big.Rat implement Formatter, and we embed them in our BigInt and BigRat types. To make sure that our String gets called rather than the inner Format, we put a non-matching stub Format method into this interface. This is ugly but very simple and cheap.

func (BigInt) ProgString

func (i BigInt) ProgString() string

func (BigInt) Sprint

func (i BigInt) Sprint(conf *config.Config) string

func (BigInt) String

func (i BigInt) String() string

type BigRat

type BigRat struct {
	*big.Rat
}

func (BigRat) Eval

func (r BigRat) Eval(Context) Value

func (BigRat) ProgString

func (r BigRat) ProgString() string

func (BigRat) Sprint

func (r BigRat) Sprint(conf *config.Config) string

func (BigRat) String

func (r BigRat) String() string

type Char

type Char rune

func (Char) Eval

func (c Char) Eval(Context) Value

func (Char) ProgString

func (c Char) ProgString() string

func (Char) Sprint

func (c Char) Sprint(conf *config.Config) string

func (Char) String

func (c Char) String() string

type Context

type Context interface {
	// Lookup returns the configuration state for evaluation.
	Config() *config.Config

	// Lookup returns the value of a symbol.
	Lookup(name string) Value

	// Assign assigns the variable the value. The variable must
	// be defined either in the current function or globally.
	// Inside a function, new variables become locals.
	Assign(name string, value Value)

	// Eval evaluates a list of expressions.
	Eval(exprs []Expr) []Value

	// EvalUnaryFn evaluates a unary operator.
	EvalUnary(op string, right Value) Value

	// EvalBinary evaluates a binary operator.
	EvalBinary(left Value, op string, right Value) Value

	// UserDefined reports whether the specified op is user-defined.
	UserDefined(op string, isBinary bool) bool
}

Context is the execution context for evaluation. The only implementation is ../exec/Context, but the interface is defined separately, here, because of the dependence on Expr and the import cycle that would otherwise result.

type Error

type Error string

Error is the type we recognize as a recoverable run-time error.

func (Error) Error

func (err Error) Error() string

type Expr

type Expr interface {
	// ProgString returns the unambiguous representation of the
	// expression to be used in program source.
	ProgString() string

	Eval(Context) Value
}

Expr is the interface for a parsed expression.

type Int

type Int int64

func (Int) Eval

func (i Int) Eval(Context) Value

func (Int) ProgString

func (i Int) ProgString() string

func (Int) Sprint

func (i Int) Sprint(conf *config.Config) string

func (Int) String

func (i Int) String() string

func (Int) ToBool

func (i Int) ToBool() bool

type Matrix

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

func NewMatrix

func NewMatrix(shape, data []Value) Matrix

NewMatrix makes a new matrix. The number of elements must fit in an Int.

func (*Matrix) Data

func (m *Matrix) Data() Vector

Data returns the data of the matrix as a vector.

func (Matrix) Eval

func (m Matrix) Eval(Context) Value

func (Matrix) ProgString

func (m Matrix) ProgString() string

func (*Matrix) Shape

func (m *Matrix) Shape() Vector

Shape returns the shape of the matrix.

func (Matrix) Sprint

func (m Matrix) Sprint(conf *config.Config) string

func (Matrix) String

func (m Matrix) String() string

type Value

type Value interface {
	// String is for internal debugging only. It uses default configuration
	// and puts parentheses around every value so it's clear when it is used.
	// All user output should call Sprint instead.
	String() string
	Sprint(*config.Config) string
	Eval(Context) Value

	// ProgString is like String, but suitable for program listing.
	// For instance, it ignores the user format for numbers and
	// puts quotes on chars, guaranteeing a correct representation.
	ProgString() string
	// contains filtered or unexported methods
}

func Binary

func Binary(c Context, u Value, opName string, v Value) Value

func Parse

func Parse(conf *config.Config, s string) (Value, error)

func Unary

func Unary(c Context, opName string, v Value) Value

type Vector

type Vector []Value

func NewVector

func NewVector(elem []Value) Vector

func (Vector) AllChars

func (v Vector) AllChars() bool

AllChars reports whether the vector contains only Chars.

func (Vector) Copy

func (v Vector) Copy() Vector

func (Vector) Eval

func (v Vector) Eval(Context) Value

func (Vector) ProgString

func (v Vector) ProgString() string

func (Vector) Sprint

func (v Vector) Sprint(conf *config.Config) string

func (Vector) String

func (v Vector) String() string

Jump to

Keyboard shortcuts

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