transform

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2017 License: Apache-2.0 Imports: 8 Imported by: 44

Documentation

Overview

Package transform provides transforms on commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeadCodeElimination

type DeadCodeElimination struct {
	// contains filtered or unexported fields
}

DeadCodeElimination is an implementation of Transformer that outputs live commands. That is, all commands which do not affect the requested output are omitted. It is named after the standard compiler optimization. (state is like memory and commands are instructions which read/write it). Construct with NewDeadCodeElimination, do not build directly.

func NewDeadCodeElimination

func NewDeadCodeElimination(ctx context.Context, depGraph *dependencygraph.DependencyGraph) *DeadCodeElimination

NewDeadCodeElimination constructs and returns a new DeadCodeElimination transform.

The transform generates commands from the given depGraph, it does not take inputs.

func (*DeadCodeElimination) Flush

func (t *DeadCodeElimination) Flush(ctx context.Context, out Writer)

func (*DeadCodeElimination) Request

func (t *DeadCodeElimination) Request(id api.CmdID)

Request ensures that we keep alive all commands needed to render framebuffer at the given point.

func (*DeadCodeElimination) Transform

func (t *DeadCodeElimination) Transform(ctx context.Context, id api.CmdID, c api.Cmd, out Writer)

type Injector

type Injector struct {
	// contains filtered or unexported fields
}

Injector is an implementation of Transformer that can inject commands into the stream.

func (*Injector) Flush

func (t *Injector) Flush(ctx context.Context, out Writer)

Flush implements the Transformer interface.

func (*Injector) Inject

func (t *Injector) Inject(after api.CmdID, cmd api.Cmd)

Inject emits cmd after the command with identifier after.

func (*Injector) Transform

func (t *Injector) Transform(ctx context.Context, id api.CmdID, cmd api.Cmd, out Writer)

Transform implements the Transformer interface.

type Terminator

type Terminator interface {
	Transformer

	// Add relaxes the termination limit to pass-through all commands before and
	// including the command or subcommand.
	Add(context.Context, api.CmdID, []uint64) error
}

Terminator is an Transformer that prevents commands passing-through it after a certain point in the stream.

func NewEarlyTerminator

func NewEarlyTerminator(api api.ID) Terminator

NewEarlyTerminator returns a Terminator that will consume all commands of the given API type that come after the last command passed to Add.

type TransformWriter

type TransformWriter struct {
	S *api.State
	T Transformer
	O Writer
}

TransformWriter implements the Writer interface, transforming each atom that is written with T, before writing the result to O.

func (TransformWriter) MutateAndWrite

func (p TransformWriter) MutateAndWrite(ctx context.Context, id api.CmdID, cmd api.Cmd)

func (TransformWriter) State

func (p TransformWriter) State() *api.State

type Transformer

type Transformer interface {
	// Transform takes a given command and identifier and Writes out a possibly
	// transformed set of commands to the output.
	// Transform must not modify cmd in any way.
	Transform(ctx context.Context, id api.CmdID, cmd api.Cmd, output Writer)
	// Flush is called at the end of an command stream to cause Transformers
	// that cache commands to send any they have stored into the output.
	Flush(ctx context.Context, output Writer)
}

Transformer is the interface that wraps the basic Transform method.

func NewFileLog

func NewFileLog(ctx context.Context, path string) Transformer

NewFileLog returns a Transformer that will log all commands passed through it to the text file at path.

func Transform

func Transform(name string, f func(ctx context.Context, id api.CmdID, cmd api.Cmd, output Writer)) Transformer

Transform is a helper for building simple Transformers that are implemented by function f. name is used to identify the transform when logging.

type Transforms

type Transforms []Transformer

Transforms is a list of Transformer objects.

func (*Transforms) Add

func (l *Transforms) Add(t ...Transformer)

Add is a convenience function for appending the list of Transformers t to the end of the Transforms list, after filtering out nil Transformers.

func (*Transforms) Prepend

func (l *Transforms) Prepend(t Transformer)

Prepend adds the given transformer to the beginning of the transform chain.

func (Transforms) Transform

func (l Transforms) Transform(ctx context.Context, cmds []api.Cmd, out Writer)

Transform sequentially transforms the atoms by each of the transformers in the list, before writing the final output to the output atom Writer.

type Writer

type Writer interface {
	// State returns the state object associated with this writer.
	State() *api.State
	// MutateAndWrite mutates the state object associated with this writer,
	// and it passes the atom to further consumers.
	MutateAndWrite(ctx context.Context, id api.CmdID, cmd api.Cmd)
}

Writer is the interface which consumes the output of an Transformer. It also keeps track of state changes caused by all commands written to it. Conceptually, each Writer object contains its own separate State object, which is modified when MutateAndWrite is called. This allows the transform to access the state both before and after the mutation of state happens. It is also possible to omit/insert commands. In practice, single state object can be shared by all transforms for performance (i.e. the mutation is done only once at the very end). This potentially allows state changes to leak upstream so care is needed. There is a configuration flag to switch between the shared/separate modes.

Jump to

Keyboard shortcuts

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