eval

package
v0.0.0-...-8666326 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2014 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package eval handles evaluation of nodes and consists the runtime of the shell.

Index

Constants

View Source
const (
	// FdNil is a special impossible fd value. Used for "close fd" in
	// syscall.ProcAttr.Files.
	FdNil uintptr = ^uintptr(0)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyType

type AnyType struct {
}

func (AnyType) Caret

func (at AnyType) Caret(t Type) Type

func (AnyType) Default

func (at AnyType) Default() Value

type Closure

type Closure struct {
	ArgNames []string
	Op       Op
	Enclosed map[string]*Value
	Bounds   [2]StreamType
}

Closure is a closure.

func NewClosure

func NewClosure(a []string, op Op, e map[string]*Value, b [2]StreamType) *Closure

func (*Closure) Caret

func (c *Closure) Caret(ev *Evaluator, v Value) Value

func (*Closure) Repr

func (c *Closure) Repr() string

func (*Closure) String

func (c *Closure) String() string

func (*Closure) Type

func (c *Closure) Type() Type

type ClosureType

type ClosureType struct {
	Bounds [2]StreamType
}

func (ClosureType) Caret

func (ct ClosureType) Caret(t Type) Type

func (ClosureType) Default

func (st ClosureType) Default() Value

type Command

type Command struct {
	Func    builtinFuncImpl // A builtin function
	Special strOp           // A builtin special form
	Path    string          // External command full path
	Closure *Closure        // The closure value
}

A Command is either a builtin function, a builtin special form, an external command or a closure.

type Compiler

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

Compiler compiles an Elvish AST into an Op.

func NewCompiler

func NewCompiler() *Compiler

func (*Compiler) Compile

func (cp *Compiler) Compile(name, text string, n *parse.ChunkNode, scope map[string]Type) (op Op, err error)

type Env

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

Env provides access to environment variables.

func NewEnv

func NewEnv() *Env

func (*Env) Caret

func (e *Env) Caret(ev *Evaluator, v Value) Value

func (*Env) Export

func (e *Env) Export() []string

func (*Env) Repr

func (e *Env) Repr() string

func (*Env) String

func (e *Env) String() string

func (*Env) Type

func (e *Env) Type() Type

type EnvType

type EnvType struct {
}

func (EnvType) Caret

func (et EnvType) Caret(t Type) Type

func (EnvType) Default

func (et EnvType) Default() Value

type Evaluator

type Evaluator struct {
	Compiler *Compiler
	// contains filtered or unexported fields
}

Evaluator maintains runtime context of elvish code within a single goroutine. When elvish code spawns goroutines, the Evaluator is copied and has certain components replaced.

func NewEvaluator

func NewEvaluator() *Evaluator

NewEvaluator creates a new Evaluator from a slice of environment strings in the form "key=value".

func (*Evaluator) Eval

func (ev *Evaluator) Eval(name, text string, n *parse.ChunkNode) error

Eval evaluates a chunk node n. The name and text of it is used for diagnostic messages.

func (*Evaluator) MakeCompilerScope

func (ev *Evaluator) MakeCompilerScope() map[string]Type

type Op

type Op func(*Evaluator)

Op operates on an Evaluator.

type StateUpdate

type StateUpdate struct {
	Terminated bool
	Msg        string
}

StateUpdate represents a change of state of a command.

type StreamType

type StreamType byte

StreamType represents what form of data stream a command expects on each port.

type String

type String string

String is a string.

func NewString

func NewString(s string) *String

func (*String) Caret

func (s *String) Caret(ev *Evaluator, v Value) Value

func (*String) Repr

func (s *String) Repr() string

func (*String) String

func (s *String) String() string

func (*String) Type

func (s *String) Type() Type

type StringType

type StringType struct {
}

func (StringType) Caret

func (st StringType) Caret(t Type) Type

func (StringType) Default

func (st StringType) Default() Value

type Table

type Table struct {
	List []Value
	Dict map[Value]Value
}

Table is a list-dict hybrid.

func NewTable

func NewTable() *Table

func (*Table) Caret

func (t *Table) Caret(ev *Evaluator, v Value) Value

func (*Table) Repr

func (t *Table) Repr() string

func (*Table) String

func (t *Table) String() string

func (*Table) Type

func (t *Table) Type() Type

type TableType

type TableType struct {
}

func (TableType) Caret

func (tt TableType) Caret(t Type) Type

func (TableType) Default

func (tt TableType) Default() Value

type Type

type Type interface {
	Default() Value
	Caret(t Type) Type
}

type Value

type Value interface {
	Type() Type
	Repr() string
	String() string
	Caret(ev *Evaluator, v Value) Value
}

Value is the runtime representation of an elvish value.

Notes

Bugs

  • the fn builtin now modifies the closure in place, making it possible to write:

    var f; set f = { }

    fn g a b $f // Changes arity of $f!

  • When evaluating closures, async access to globals, in and out can be problematic.

  • Closure arguments is (again) not supported

Jump to

Keyboard shortcuts

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