Documentation ¶
Index ¶
- Variables
- func DotPath(p cor.Path) (cor.Path, bool)
- func LookupKey(env Env, k string) (lit.Val, error)
- func LookupMod(p *Prog, qual string, rest cor.Path) (lit.Val, error)
- func LookupType(env Env) typ.Lookup
- func SelectLookup(v lit.Val, p cor.Path, eval bool) (lit.Val, error)
- func SigArgs(sig typ.Type) []typ.Param
- func SigRes(sig typ.Type) *typ.Param
- func SplitQualifier(k string) (q, _ string)
- type Builtins
- type Call
- type Dyn
- type Env
- type Exp
- func LayoutForm(sig typ.Type, els []Exp) ([]Exp, error)
- func LayoutFunc(sig typ.Type, els []Exp) ([]Exp, error)
- func LayoutSpec(sig typ.Type, els []Exp) ([]Exp, error)
- func Parse(str string) (Exp, error)
- func ParseAll(as []ast.Ast) (Exp, error)
- func ParseAst(a ast.Ast) (Exp, error)
- func Read(r io.Reader, name string) (Exp, error)
- type File
- type Lit
- type Mod
- type ModRef
- type ModRefs
- type Prog
- func (p *Prog) Eval(env Env, e Exp) (_ lit.Val, err error)
- func (p *Prog) EvalArgs(c *Call) (lit.Vals, error)
- func (p *Prog) Lookup(s *Sym, pp cor.Path, eval bool) (res lit.Val, err error)
- func (p *Prog) NextFnID() uint
- func (p *Prog) Parent() Env
- func (p *Prog) Resl(env Env, e Exp, h typ.Type) (Exp, error)
- func (p *Prog) Run(x Exp, arg lit.Val) (_ lit.Val, err error)
- func (p *Prog) RunStr(str string, arg lit.Val) (lit.Val, error)
- type Spec
- type SpecBase
- type SpecRef
- func (s *SpecRef) As(t typ.Type) (lit.Val, error)
- func (s *SpecRef) Assign(val lit.Val) error
- func (s *SpecRef) Eval(p *Prog, c *Call) (lit.Val, error)
- func (s *SpecRef) MarshalJSON() ([]byte, error)
- func (s *SpecRef) Mut() lit.Mut
- func (s *SpecRef) New() lit.Mut
- func (s *SpecRef) Nil() bool
- func (s *SpecRef) Parse(a ast.Ast) (err error)
- func (s *SpecRef) Print(p *bfr.P) error
- func (s *SpecRef) Ptr() interface{}
- func (s *SpecRef) Resl(p *Prog, env Env, c *Call, hint typ.Type) (Exp, error)
- func (s *SpecRef) String() string
- func (s *SpecRef) Type() typ.Type
- func (s *SpecRef) Value() lit.Val
- func (s *SpecRef) Zero() bool
- type Sym
- type Tag
- type Tupl
Constants ¶
This section is empty.
Variables ¶
var ErrDefer = fmt.Errorf("deferred resolution")
ErrDefer is a marker error used to indicate a deferred resolution and not a failure per-se. The user can errors.Is(err, ErrDefer) and resume program resolution with more context provided.
var ErrSymNotFound = fmt.Errorf("sym not found")
ErrSymNotFound is an error that indicates that a symbol was not found in the environment
Functions ¶
func DotPath ¶
DotPath returns whether p is a dot path or returns p with a leading dot segment removed.
func LookupType ¶
func SelectLookup ¶
SelectLookup reads path and returns the selected literal from l or an error. If eval is false we attempt to at least resolve the intended type if no value was found.
func SplitQualifier ¶
Types ¶
type Builtins ¶
Builtins is a root environment to resolve symbols to builtin specs and at last as types.
type Call ¶
Call is an executable expression that uses a spec to evaluate to a literal. It caches the resolved spec and environment.
type Dyn ¶
func DefaultDyn ¶
type Env ¶
type Env interface { // Parent returns the parent environment or nil. Parent() Env // Lookup resolves a symbol path and returns the result, an error or nothing. // We always update the symbol and return resolved values. // If eval is false the symbol resolves, but the value does not, we return nothing. // If the value is not resolved and eval is true we return an error. Lookup(s *Sym, path cor.Path, eval bool) (lit.Val, error) }
Env is a scoped context to resolve symbols. Envs configure most of the program resolution.
type Exp ¶
type Exp interface { Type() typ.Type Source() ast.Src String() string Print(*bfr.P) error Clone() Exp }
Exp is the common interface of all expressions with kind, type and source info.
type File ¶
type File struct { // URL is the resource locator for this input, it should be empty or conform to net/url. // It usually is a simple file path, but could point into a zip file served on the web. URL string // Refs contains all declared and used modules for this file. Refs ModRefs }
File is a simple representation of any xelf input that store information about modules.
type Mod ¶
type Mod struct { // File points to the original source file of this module. File *File // Name is the declare module name. Name string // Decl holds the exported module declarations, that are copied for each program. Decl *lit.Obj }
Mod is a simple representation of a module.
type Prog ¶
type Prog struct { Ctx context.Context Root Env Sys *typ.Sys Reg lit.Regs Arg lit.Val File File // Files collects all external files loaded by the program Files map[string]*File // Birth holds the uri for actively loading files to break recursive loads Birth map[string]struct{} Dyn Dyn // contains filtered or unexported fields }
Prog is the entry context to resolve an expression in an environment. Programs are bound to their expression and cannot be reused.
func NewProg ¶
NewProg returns a new program using the given registry, environment and expression. The registry argument can be nil, a new registry will be used by default.
func (*Prog) EvalArgs ¶
EvalArgs evaluates resolved call arguments and returns the result or an error. This is a convenience method for the most basic needs of many spec implementations.
func (*Prog) Resl ¶
Resl resolves an expression using a type hint and returns the result or an error.
type Spec ¶
type Spec interface { Type() typ.Type // Resl resolves a call using a type hint and returns the result or an error. // The first call to Resl should setup the environment for call c. Resl(p *Prog, env Env, c *Call, hint typ.Type) (Exp, error) // Eval evaluates a resolved call and returns a value or an error. Eval(p *Prog, c *Call) (lit.Val, error) }
Spec is a func or form specification used to resolve calls.
type SpecBase ¶
SpecBase is partial base definition for spec implementations. Implementations only need embed this type and declare the eval method.
func MustSpecBase ¶
type SpecRef ¶
SpecRef can wrap any spec with a new type and can represent null and unresolved specs.
func NewSpecRef ¶
func UnwrapSpec ¶
func UnwrapSpec(v interface{}) (s *SpecRef)