Documentation
¶
Overview ¶
Package eval is the evaluator of the Go R interpreter: R values, environments, promises, closures and the primitives, written from the R Language Definition and checked against R 4.6.2 (see docs/m2-design.md). Nothing is translated from R's sources.
Index ¶
- Constants
- func Builtins() []string
- func Length(v Value) int
- func ToRDS(v Value) rds.Value
- type Arg
- type Attr
- type Builtin
- type Closure
- type Dots
- type Double
- type Env
- type Error
- type Formal
- type Formals
- type Integer
- type Lang
- type List
- type Logical
- type Options
- type Promise
- type Result
- type Session
- func (s *Session) Eval(src string) (*Result, error)
- func (s *Session) EvalContext(ctx context.Context, src string) (*Result, error)
- func (s *Session) EvalIn(ctx context.Context, src string, env *Env) (res *Result, err error)
- func (s *Session) Get(name string) (Value, bool)
- func (s *Session) Set(name string, v Value)
- type Str
- type String
- type Symbol
- type Type
- type Value
- type Warning
Constants ¶
const ( DefaultMaxDepth = 5000 DefaultMaxSteps = 30_000_000 DefaultMaxAlloc = 16 << 30 DefaultTimeout = 10 * time.Second )
The defaults of Options, chosen by measurement (TestMeasureLimits): the golden snippets and the heaviest cells a notebook runs on purpose (a loop of 10^6 iterations: 3 million steps; a list grown by 20 000 assignments: 1.6 GB of copies, 0.63 s) each get about ten times the largest legitimate use.
const Unbounded = -1
Unbounded, given as MaxSteps, MaxAlloc or Timeout, removes that limit. It is the only way to do so: a zero selects the default, and any other negative value panics in NewSession. Use it only for trusted code.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dots ¶
type Dots struct {
Args []Arg // Value is a *Promise, a constant, or Missing
}
Dots is the value of `...`: the promises of the extra arguments.
type Double ¶
The vectors. Their slices are never modified in place once a value is visible to R code (copy on modify; see docs/m2-design.md).
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is an environment: a frame of bindings and an enclosure.
type Error ¶
type Error struct {
Message string
Call string
// Condition is the condition object that was signalled (nil for errors
// that no handler could see: limits and interrupts).
Condition Value
// Output and Stderr are what the cell had written before it failed.
Output, Stderr string
// Warnings are the warnings raised before the error.
Warnings []Warning
// contains filtered or unexported fields
}
Error is an R error that reached the top level. Message is R's conditionMessage and Call the deparsed conditionCall ("" for none).
type Formals ¶
type Formals struct{ F []Formal }
Formals is the formal-argument list of a `function` expression, which sits in the second place of the call to `function`.
type Integer ¶
The vectors. Their slices are never modified in place once a value is visible to R code (copy on modify; see docs/m2-design.md).
type List ¶
The vectors. Their slices are never modified in place once a value is visible to R code (copy on modify; see docs/m2-design.md).
type Logical ¶
The vectors. Their slices are never modified in place once a value is visible to R code (copy on modify; see docs/m2-design.md).
type Options ¶
type Options struct {
// MaxDepth bounds the nesting of evaluations: R's option "expressions"
// (default 5000). Exceeding it is R's error "evaluation nested too deeply".
MaxDepth int
// MaxVector bounds the length of any vector the runtime allocates.
MaxVector int
// MaxAlloc bounds the bytes of vector storage one Eval allocates, in
// total over the evaluation, copies included (default DefaultMaxAlloc).
// Exceeding it ends the evaluation with an error.
MaxAlloc int
// MaxSteps bounds the number of calls and loop iterations evaluated by
// one Eval (default DefaultMaxSteps).
MaxSteps int
// Timeout bounds the time one Eval may take (default DefaultTimeout); a
// context passed to EvalContext bounds it too.
Timeout time.Duration
// Parse bounds the source text of an Eval.
Parse syntax.Limits
}
Options bound a session. A zero field selects its default; Unbounded (MaxSteps, MaxAlloc, Timeout only) removes the limit explicitly.
type Result ¶
type Result struct {
// Value is the value of the last expression.
Value Value
// Visible says whether R would print it.
Visible bool
// Output is what the cell printed on standard output: what print() and
// cat() wrote, and the auto-printed value of every visible top-level
// expression, as an R console shows them.
Output string
// Stderr is what the cell wrote on standard error: message() output.
Stderr string
// Warnings are the warnings raised and not muffled.
Warnings []Warning
}
Result is what one Eval returns.
type Session ¶
type Session struct {
Base, Global, Empty *Env
// contains filtered or unexported fields
}
Session is one interpreter: a global environment that persists from one Eval to the next. It is not safe for concurrent use.
func NewSession ¶
NewSession makes a session whose global environment is empty, enclosed by the base environment holding the primitives.
func (*Session) Eval ¶
Eval parses src and evaluates its expressions in order in the global environment, as one notebook cell. The result is that of the last one. Errors are *Error (a runtime error: R's message and call, with the output and warnings so far), *syntax.Error or *syntax.LimitError.
func (*Session) EvalContext ¶
EvalContext is Eval that ends, with an *Error wrapping the context's error, when ctx is done; Options.Timeout bounds it as well.
func (*Session) EvalIn ¶
EvalIn is EvalContext in the given environment (a child of the global one, for a cell that must not leave names behind).
type String ¶
The vectors. Their slices are never modified in place once a value is visible to R code (copy on modify; see docs/m2-design.md).