Documentation
¶
Overview ¶
Package funcs provides a framework for functions that change over time.
Index ¶
- Constants
- Variables
- func Lookup(name string) (interfaces.Func, error)
- func LookupOperator(operator string, size int) ([]*types.Type, error)
- func LookupOperatorShort(operator string, size int) ([]*types.Type, error)
- func LookupPrefix(prefix string) map[string]func() interfaces.Func
- func Map() map[string]func() interfaces.Func
- func ModuleRegister(module, name string, fn func() interfaces.Func)
- func PureFuncExec(handle interfaces.Func, args []types.Value) (types.Value, error)
- func Register(name string, fn func() interfaces.Func)
- func RegisterOperator(operator string, fn *types.FuncValue)
- type ContainsPolyFunc
- func (obj *ContainsPolyFunc) ArgGen(index int) (string, error)
- func (obj *ContainsPolyFunc) Build(typ *types.Type) error
- func (obj *ContainsPolyFunc) Close() error
- func (obj *ContainsPolyFunc) Info() *interfaces.Info
- func (obj *ContainsPolyFunc) Init(init *interfaces.Init) error
- func (obj *ContainsPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
- func (obj *ContainsPolyFunc) Stream() error
- func (obj *ContainsPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
- func (obj *ContainsPolyFunc) Validate() error
- type Edge
- type Engine
- type HistoryFunc
- func (obj *HistoryFunc) ArgGen(index int) (string, error)
- func (obj *HistoryFunc) Build(typ *types.Type) error
- func (obj *HistoryFunc) Close() error
- func (obj *HistoryFunc) Info() *interfaces.Info
- func (obj *HistoryFunc) Init(init *interfaces.Init) error
- func (obj *HistoryFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
- func (obj *HistoryFunc) Stream() error
- func (obj *HistoryFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
- func (obj *HistoryFunc) Validate() error
- type MapLookupPolyFunc
- func (obj *MapLookupPolyFunc) ArgGen(index int) (string, error)
- func (obj *MapLookupPolyFunc) Build(typ *types.Type) error
- func (obj *MapLookupPolyFunc) Close() error
- func (obj *MapLookupPolyFunc) Info() *interfaces.Info
- func (obj *MapLookupPolyFunc) Init(init *interfaces.Init) error
- func (obj *MapLookupPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
- func (obj *MapLookupPolyFunc) Stream() error
- func (obj *MapLookupPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
- func (obj *MapLookupPolyFunc) Validate() error
- type OperatorPolyFunc
- func (obj *OperatorPolyFunc) ArgGen(index int) (string, error)
- func (obj *OperatorPolyFunc) Build(typ *types.Type) error
- func (obj *OperatorPolyFunc) Close() error
- func (obj *OperatorPolyFunc) Info() *interfaces.Info
- func (obj *OperatorPolyFunc) Init(init *interfaces.Init) error
- func (obj *OperatorPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
- func (obj *OperatorPolyFunc) Stream() error
- func (obj *OperatorPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
- func (obj *OperatorPolyFunc) Validate() error
- type State
- type StructLookupPolyFunc
- func (obj *StructLookupPolyFunc) ArgGen(index int) (string, error)
- func (obj *StructLookupPolyFunc) Build(typ *types.Type) error
- func (obj *StructLookupPolyFunc) Close() error
- func (obj *StructLookupPolyFunc) Info() *interfaces.Info
- func (obj *StructLookupPolyFunc) Init(init *interfaces.Init) error
- func (obj *StructLookupPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
- func (obj *StructLookupPolyFunc) Stream() error
- func (obj *StructLookupPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
- func (obj *StructLookupPolyFunc) Validate() error
Constants ¶
const ( // ModuleSep is the character used for the module scope separation. For // example when using `fmt.printf` or `math.sin` this is the char used. // It is included here for convenience when importing this package. ModuleSep = interfaces.ModuleSep // ReplaceChar is a special char that is used to replace ModuleSep when // it can't be used for some reason. This currently only happens in the // golang template library. Even with this limitation in that library, // we don't want to allow this as the first or last character in a name. // NOTE: the template library will panic if it is one of: .-# ReplaceChar = "_" )
const ( // ContainsFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. // XXX: change to _contains and add syntax in the lexer/parser ContainsFuncName = "contains" )
const ( // HistoryFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. HistoryFuncName = "_history" )
const ( // MapLookupFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. // XXX: change to _maplookup and add syntax in the lexer/parser MapLookupFuncName = "maplookup" )
const ( // OperatorFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. OperatorFuncName = "_operator" )
const ( // StructLookupFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. // XXX: change to _structlookup and add syntax in the lexer/parser StructLookupFuncName = "structlookup" )
Variables ¶
var OperatorFuncs = make(map[string][]*types.FuncValue) // must initialize
OperatorFuncs maps an operator to a list of callable function values.
Functions ¶
func Lookup ¶
func Lookup(name string) (interfaces.Func, error)
Lookup returns a pointer to the function's struct. It may be convertible to a PolyFunc if the particular function implements those additional methods.
func LookupOperator ¶
LookupOperator returns a list of type strings for each operator. An empty operator string means return everything. If you specify a size that is less than zero, we don't filter by arg length, otherwise we only return signatures which have an arg length equal to size.
func LookupOperatorShort ¶
LookupOperatorShort is similar to LookupOperator except that it returns the "short" (standalone) types of the direct functions that are attached to each operator. IOW, if you specify "+" and 2, you'll get the sigs for "a" + "b" and 1 + 2, without the third "op" as the first argument.
func LookupPrefix ¶
func LookupPrefix(prefix string) map[string]func() interfaces.Func
LookupPrefix returns a map of names to functions that start with a module prefix. This search automatically adds the period separator. So if you want functions in the `fmt` package, search for `fmt`, not `fmt.` and it will find all the correctly registered functions. This removes that prefix from the result in the map keys that it returns. If you search for an empty prefix, then this will return all the top-level functions that aren't in a module.
func Map ¶
func Map() map[string]func() interfaces.Func
Map returns a map from all registered function names to a function to return that one. We return a copy of our internal registered function store so that this result can be manipulated safely. We return the functions that produce the Func interface because we might use this result to create multiple functions, and each one must have its own unique memory address to work properly.
func ModuleRegister ¶
func ModuleRegister(module, name string, fn func() interfaces.Func)
ModuleRegister is exactly like Register, except that it registers within a named module.
func PureFuncExec ¶
PureFuncExec is usually used to provisionally speculate about the result of a pure function, by running it once, and returning the result. Pure functions are expected to only produce one value that depends only on the input values. This won't run any slow functions either.
func Register ¶
func Register(name string, fn func() interfaces.Func)
Register takes a func and its name and makes it available for use. It is commonly called in the init() method of the func at program startup. There is no matching Unregister function. You may also register functions which satisfy the PolyFunc interface. To register a function which lives in a module, you must join the module name to the function name with the ModuleSep character. It is defined as a const and is probably the period character.
func RegisterOperator ¶
RegisterOperator registers the given string operator and function value implementation with the mini-database for this generalized, static, polymorphic operator implementation.
Types ¶
type ContainsPolyFunc ¶
type ContainsPolyFunc struct { Type *types.Type // this is the type of value stored in our list // contains filtered or unexported fields }
ContainsPolyFunc returns true if a value is found in a list. Otherwise false.
func (*ContainsPolyFunc) ArgGen ¶
func (obj *ContainsPolyFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*ContainsPolyFunc) Build ¶
func (obj *ContainsPolyFunc) Build(typ *types.Type) error
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*ContainsPolyFunc) Close ¶
func (obj *ContainsPolyFunc) Close() error
Close runs some shutdown code for this function and turns off the stream.
func (*ContainsPolyFunc) Info ¶
func (obj *ContainsPolyFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*ContainsPolyFunc) Init ¶
func (obj *ContainsPolyFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*ContainsPolyFunc) Polymorphisms ¶
func (obj *ContainsPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
Polymorphisms returns the list of possible function signatures available for this static polymorphic function. It relies on type and value hints to limit the number of returned possibilities.
func (*ContainsPolyFunc) Stream ¶
func (obj *ContainsPolyFunc) Stream() error
Stream returns the changing values that this func has over time.
func (*ContainsPolyFunc) Unify ¶
func (obj *ContainsPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
Unify returns the list of invariants that this func produces.
func (*ContainsPolyFunc) Validate ¶
func (obj *ContainsPolyFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type Edge ¶
type Edge struct {
Args []string // list of named args that this edge sends to
}
Edge links an output vertex (value) to an input vertex with a named argument.
type Engine ¶
type Engine struct { Graph *pgraph.Graph Hostname string World engine.World Debug bool Logf func(format string, v ...interface{}) // Glitch: https://en.wikipedia.org/wiki/Reactive_programming#Glitches Glitch bool // allow glitching? (more responsive, but less accurate) // contains filtered or unexported fields }
Engine represents the running time varying directed acyclic function graph.
func (*Engine) Init ¶
Init initializes the struct. This is the first call you must make. Do not proceed with calls to other methods unless this succeeds first. This also loads all the functions by calling Init on each one in the graph. TODO: should Init take the graph as an input arg to keep it as a private field?
func (*Engine) RLock ¶
func (obj *Engine) RLock()
RLock takes a read lock on the data that gets written to the AST, so that interpret can be run without anything changing part way through.
func (*Engine) RUnlock ¶
func (obj *Engine) RUnlock()
RUnlock frees a read lock on the data that gets written to the AST, so that interpret can be run without anything changing part way through.
func (*Engine) Run ¶
Run starts up this function engine and gets it all running. It errors if the startup failed for some reason. On success, use the Stream and Table methods for future interaction with the engine, and the Close method to shut it off.
func (*Engine) SafeLogf ¶
SafeLogf logs a message, although it adds a read lock around the logging in case a `node` argument is passed in which would set off the race detector.
func (*Engine) Stream ¶
Stream returns a channel of engine events. Wait for nil events to know when the Table map has changed. An error event means this will shutdown shortly. Do not run the Table function before we've received one non-error event.
func (*Engine) Validate ¶
Validate the graph type checks properly and other tests. Must run Init first. This should check that: (1) all vertices have the correct number of inputs, (2) that the *Info signatures all match correctly, (3) that the argument names match correctly, and that the whole graph is statically correct.
type HistoryFunc ¶
type HistoryFunc struct { Type *types.Type // type of input value (same as output type) // contains filtered or unexported fields }
HistoryFunc is special function which returns the Nth oldest value seen. It must store up incoming values until it gets enough to return the desired one. A restart of the program, will expunge the stored state. This obviously takes more memory, the further back you wish to index. A change in the index var is generally not useful, but it is permitted. Moving it to a smaller value will cause older index values to be expunged. If this is undesirable, a max count could be added. This was not implemented with efficiency in mind. Since some functions might not send out un-changed values, it might also make sense to implement a *time* based hysteresis, since this only looks at the last N changed values. A time based hysteresis would tick every precision-width, and store whatever the latest value at that time is.
func (*HistoryFunc) ArgGen ¶
func (obj *HistoryFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*HistoryFunc) Build ¶
func (obj *HistoryFunc) Build(typ *types.Type) error
Build takes the now known function signature and stores it so that this function can appear to be static. That type is used to build our function statically.
func (*HistoryFunc) Close ¶
func (obj *HistoryFunc) Close() error
Close runs some shutdown code for this function and turns off the stream.
func (*HistoryFunc) Info ¶
func (obj *HistoryFunc) Info() *interfaces.Info
Info returns some static info about itself.
func (*HistoryFunc) Init ¶
func (obj *HistoryFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*HistoryFunc) Polymorphisms ¶
func (obj *HistoryFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
Polymorphisms returns the possible type signature for this function. In this case, since the number of possible types for the first arg can be infinite, it returns the final precise type only if it can be gleamed statically. If not, it returns that unknown as a variant, which is hopefully solved during unification.
func (*HistoryFunc) Stream ¶
func (obj *HistoryFunc) Stream() error
Stream returns the changing values that this func has over time.
func (*HistoryFunc) Unify ¶
func (obj *HistoryFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
Unify returns the list of invariants that this func produces.
func (*HistoryFunc) Validate ¶
func (obj *HistoryFunc) Validate() error
Validate makes sure we've built our struct properly. It is usually unused for normal functions that users can use directly.
type MapLookupPolyFunc ¶
type MapLookupPolyFunc struct { Type *types.Type // Kind == Map, that is used as the map we lookup // contains filtered or unexported fields }
MapLookupPolyFunc is a key map lookup function.
func (*MapLookupPolyFunc) ArgGen ¶
func (obj *MapLookupPolyFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*MapLookupPolyFunc) Build ¶
func (obj *MapLookupPolyFunc) Build(typ *types.Type) error
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*MapLookupPolyFunc) Close ¶
func (obj *MapLookupPolyFunc) Close() error
Close runs some shutdown code for this function and turns off the stream.
func (*MapLookupPolyFunc) Info ¶
func (obj *MapLookupPolyFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*MapLookupPolyFunc) Init ¶
func (obj *MapLookupPolyFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*MapLookupPolyFunc) Polymorphisms ¶
func (obj *MapLookupPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
Polymorphisms returns the list of possible function signatures available for this static polymorphic function. It relies on type and value hints to limit the number of returned possibilities.
func (*MapLookupPolyFunc) Stream ¶
func (obj *MapLookupPolyFunc) Stream() error
Stream returns the changing values that this func has over time.
func (*MapLookupPolyFunc) Unify ¶
func (obj *MapLookupPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
Unify returns the list of invariants that this func produces.
func (*MapLookupPolyFunc) Validate ¶
func (obj *MapLookupPolyFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type OperatorPolyFunc ¶
type OperatorPolyFunc struct { Type *types.Type // Kind == Function, including operator arg // contains filtered or unexported fields }
OperatorPolyFunc is an operator function that performs an operation on N values.
func (*OperatorPolyFunc) ArgGen ¶
func (obj *OperatorPolyFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*OperatorPolyFunc) Build ¶
func (obj *OperatorPolyFunc) Build(typ *types.Type) error
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*OperatorPolyFunc) Close ¶
func (obj *OperatorPolyFunc) Close() error
Close runs some shutdown code for this function and turns off the stream.
func (*OperatorPolyFunc) Info ¶
func (obj *OperatorPolyFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*OperatorPolyFunc) Init ¶
func (obj *OperatorPolyFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*OperatorPolyFunc) Polymorphisms ¶
func (obj *OperatorPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
Polymorphisms returns the list of possible function signatures available for this static polymorphic function. It relies on type and value hints to limit the number of returned possibilities.
func (*OperatorPolyFunc) Stream ¶
func (obj *OperatorPolyFunc) Stream() error
Stream returns the changing values that this func has over time.
func (*OperatorPolyFunc) Unify ¶
func (obj *OperatorPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
Unify returns the list of invariants that this func produces.
func (*OperatorPolyFunc) Validate ¶
func (obj *OperatorPolyFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type State ¶
type State struct { Expr interfaces.Expr // pointer to the expr vertex // contains filtered or unexported fields }
State represents the state of a function vertex. This corresponds to an AST expr, which is the memory address (pointer) in the graph.
type StructLookupPolyFunc ¶
type StructLookupPolyFunc struct { Type *types.Type // Kind == Struct, that is used as the struct we lookup Out *types.Type // type of field we're extracting // contains filtered or unexported fields }
StructLookupPolyFunc is a key map lookup function.
func (*StructLookupPolyFunc) ArgGen ¶
func (obj *StructLookupPolyFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*StructLookupPolyFunc) Build ¶
func (obj *StructLookupPolyFunc) Build(typ *types.Type) error
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*StructLookupPolyFunc) Close ¶
func (obj *StructLookupPolyFunc) Close() error
Close runs some shutdown code for this function and turns off the stream.
func (*StructLookupPolyFunc) Info ¶
func (obj *StructLookupPolyFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*StructLookupPolyFunc) Init ¶
func (obj *StructLookupPolyFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*StructLookupPolyFunc) Polymorphisms ¶
func (obj *StructLookupPolyFunc) Polymorphisms(partialType *types.Type, partialValues []types.Value) ([]*types.Type, error)
Polymorphisms returns the list of possible function signatures available for this static polymorphic function. It relies on type and value hints to limit the number of returned possibilities.
func (*StructLookupPolyFunc) Stream ¶
func (obj *StructLookupPolyFunc) Stream() error
Stream returns the changing values that this func has over time.
func (*StructLookupPolyFunc) Unify ¶
func (obj *StructLookupPolyFunc) Unify(expr interfaces.Expr) ([]interfaces.Invariant, error)
Unify returns the list of invariants that this func produces.
func (*StructLookupPolyFunc) Validate ¶
func (obj *StructLookupPolyFunc) Validate() error
Validate tells us if the input struct takes a valid form.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package bindata stores core mcl code that is built-in at compile time.
|
Package bindata stores core mcl code that is built-in at compile time. |
Package facts provides a framework for language values that change over time.
|
Package facts provides a framework for language values that change over time. |
Package vars provides a framework for language vars.
|
Package vars provides a framework for language vars. |