sandbox

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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). The expressions of a template and the solver take the same thread with their own tasks 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

View Source
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).

View Source
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

func CheckExpr(src string, names ...string) error

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 Limits

type Limits struct {
	Steps uint64
	Clock time.Duration
}

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.

Jump to

Keyboard shortcuts

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