Documentation
¶
Overview ¶
Package sandbox runs the Starlark of the format — the predicate of a check, the expressions of a template and its solver — in go.starlark.net at the version the format names, in its one dialect, with the format's limits of steps and module-kit's clocks, on the caller's goroutine and with its context (format/README.md, sections 15, 23 and 24; R88 spec; R11; architecture 3.4).
It holds so far what a predicate takes: CheckExpr checks an expression of the dialect and the names it may take, and Eval evaluates one on a thread of its own under Limits, of which Predicate are a predicate's, stopping it with ErrSteps, ErrClock or ErrPanic, or with the error of a context that is done (R28). Compile compiles an expression once into a Func of the names it is written on, which Call evaluates on each binding of them under the same Limits and stops: the expressions of a template, on each combination of its parameters (R32). The solver takes the same thread with its own task of the epic of code (R16).
The sandbox shares nothing between evaluations and leaves starlark.Universe as it is: the dialect's built-in names are its 33 names at the version the format names, and an expression names no other even in a process that adds to it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrSteps = errors.New("the count of steps reached the limit") ErrClock = errors.New("the clock stopped the evaluation") ErrPanic = errors.New("the interpreter panicked") )
Why an evaluation stopped without its result. A context that is done stops it too, and then the error is the context's, wrapped: that is the caller's stop, not the sandbox's (R11).
var Predicate = Limits{Steps: 1_000_000, Clock: time.Second}
Predicate are the limits of a predicate: the format's 1 000 000 steps, and module-kit's clock of a second, which a simple predicate does not come near, since it takes 6 ms for the steps (format/README.md, section 15; R11).
Functions ¶
func CheckExpr ¶
CheckExpr says whether src is an expression of the dialect that names nothing but names, the names that it binds itself, such as n in [n * n for n in range(10)], and the built-in names of the dialect, as task.predicate-expression asks of a predicate on value (format/README.md, section 15). The error says why not, at the line and the column where go.starlark.net finds it.
func Eval ¶
func Eval(ctx context.Context, limits Limits, src string, env starlark.StringDict) (starlark.Value, error)
Eval evaluates the expression src, with env binding the names it is written on, on a thread of its own with the limits and ctx (format/README.md, sections 15 and 24; R11): a predicate, with value bound to the integer read. src is checked first as CheckExpr checks it, on the names of env, so that it names nothing else even in a process that changed starlark.Universe.
The error is the context's, wrapped, when ctx is done before the evaluation or stops it; ErrSteps, ErrClock or ErrPanic, wrapped, when the evaluation stops so; and otherwise that of the expression, which is none of the dialect, names what it may not, or fails as it runs.
Types ¶
type Func ¶ added in v0.1.19
type Func struct {
// contains filtered or unexported fields
}
A Func is an expression of the dialect compiled once on the names it is written on, so that it is evaluated on many bindings of them: an expression of a template, on each combination of the parameters (format/README.md, section 23). It holds nothing that changes, so one Func is called from many goroutines at once.
func Compile ¶ added in v0.1.19
Compile compiles src, an expression of the dialect that names nothing but names, the names that it binds itself and the built-in names of the dialect, as CheckExpr checks it, into a Func of names, in their order. The error is CheckExpr's.
The Func is a program of one statement, which assigns the parsed src to a global that names do not hold: built from its tree rather than its text, so that it compiles whatever CheckExpr takes — a comment, a line break — and is as deep to the parser as src, which a lambda around it would not be; and with the steps of src, as Eval counts them.
func (*Func) Call ¶ added in v0.1.19
func (f *Func) Call(ctx context.Context, limits Limits, args ...starlark.Value) (starlark.Value, error)
Call evaluates the expression with args bound to its names, in order, on a thread of its own with the limits and ctx, as Eval does, and its error is as Eval's. Args that are not one for each name are an error.
type Limits ¶
Limits are what one evaluation may take. Steps is the format's: the evaluation stops when the count of steps on its thread, as go.starlark.net at the version of the format counts them, reaches it. Clock is module-kit's: the wall time after which it stops the evaluation (R11). Zero is no limit.