funcs

package
v0.0.0-...-f342e06 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package funcs provides a framework for functions that change over time.

Index

Constants

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

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

func LookupOperator(operator string, size int) ([]*types.Type, error)

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 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.

func RegisterOperator

func RegisterOperator(operator string, fn *types.FuncValue)

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

func (*Edge) String

func (obj *Edge) String() string

String displays the list of arguments this edge satisfies. It is a required property to be a valid pgraph.Edge.

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) Close

func (obj *Engine) Close() error

Close shuts down the function engine. It waits till everything has finished.

func (*Engine) Init

func (obj *Engine) Init() error

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

func (obj *Engine) Run() error

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

func (obj *Engine) SafeLogf(format string, v ...interface{})

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

func (obj *Engine) Stream() chan error

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

func (obj *Engine) Validate() error

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) 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) 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) 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) 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) 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. It typically re-labels the input arg names to match what is actually used.

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

func (*State) Init

func (obj *State) Init() error

Init creates the function state if it can be found in the registered list.

func (*State) String

func (obj *State) String() string

String satisfies fmt.Stringer so that these print nicely.

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) 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) Validate

func (obj *StructLookupPolyFunc) Validate() error

Validate tells us if the input struct takes a valid form.

Directories

Path Synopsis
Package facts provides a framework for language values that change over time.
Package facts provides a framework for language values that change over time.

Jump to

Keyboard shortcuts

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