values

package
v0.0.0-...-0f4c570 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package values defines data structures for representing (runtime) values in Reflow. Any valid reflow type has representable values (see grail.com/reflow/types) and the structures in this package mirror those in the type system.

Values are represented by values.T, defined as

type T = interface{}

which is done to clarify code that uses reflow values.

Index

Constants

This section is empty.

Variables

Digester is the digester used to compute value digests.

View Source
var Unit = struct{}{}

Unit is the unit value.

Functions

func Digest

func Digest(v T, t *types.T) digest.Digest

Digest computes the digest for value v, given type t.

func Equal

func Equal(v, w T) bool

Equal tells whether values v and w are structurally equal.

func Sprint

func Sprint(v T, t *types.T) string

Sprint returns a pretty-printed version of value v with type t.

func WriteDigest

func WriteDigest(w io.Writer, v T, t *types.T)

WriteDigest writes digest material for value v (given type t) into the writer w.

Types

type Dir

type Dir map[string]File

Dir is the type of directory values.

type Env

type Env struct {
	// Symtab is the symbol table for this level.
	Symtab Symtab
	// contains filtered or unexported fields
}

Env binds identifiers to evaluation.

func NewEnv

func NewEnv() *Env

NewEnv constructs and initializes a new Env.

func (*Env) Bind

func (e *Env) Bind(id string, v T)

Bind binds the identifier id to value v.

func (*Env) Contains

func (e *Env) Contains(id string) bool

Contains tells whether environment e binds identifier id.

func (*Env) Debug

func (e *Env) Debug()

Debug sets the debug flag on this environment. This causes IsDebug to return true.

func (*Env) Digest

func (e *Env) Digest(id string, t *types.T) digest.Digest

Digest returns the digest for the value with idenfier id. The supplied type is used to compute the digest. If the value is a digest.Digest, it is returned directly; if implements the interface

interface{
	Digest() digest.Digest
}

it returns the result of calling the Digest Method.

func (*Env) IsDebug

func (e *Env) IsDebug() bool

IsDebug returns true if the debug flag is set in this environment.

func (*Env) Level

func (e *Env) Level(id string) int

Level returns the level of identifier id. Level can thus be used as a de-Bruijn index (in conjunction with the identifier).

func (*Env) Push

func (e *Env) Push() *Env

Push returns returns a new environment level, linked to the previous.

func (*Env) Value

func (e *Env) Value(id string) T

Value returns the value bound to identifier id, or else nil.

type File

type File struct {
	ID   digest.Digest
	Size int64
}

File is the type of file values.

type Func

type Func interface {
	// Apply invokes this function with an argument list.
	// The supplied location may be used by system functions
	// for debugging and decorating flows.
	Apply(loc Location, args []T) (T, error)

	// Digest returns the digest of this function.
	Digest() digest.Digest
}

Func is the type of function value.

type List

type List []T

List is the type of list values.

type Location

type Location struct {
	Ident    string
	Position string
}

Location stores source code position and identifiers.

type Map

type Map map[digest.Digest][]mapEntry

Map is the type of map values. It uses a Go map as a hash table based on the key's digest, which in turn stores a list of entries that share the same hash bucket.

func MakeMap

func MakeMap(kt *types.T, kvs ...T) Map

MakeMap is a convenient way to construct a from a set of key-value pairs.

func (Map) Each

func (m Map) Each(fn func(k, v T))

Each enumerates all key-value pairs in map m.

func (Map) Insert

func (m Map) Insert(d digest.Digest, key, value T)

Insert inserts the provided key-value pair into the map, overriding any previous definiton of the key. The caller must provide the digest which is used as a hash.

func (Map) Len

func (m Map) Len() int

Len returns the total number of entries in the map.

func (Map) Lookup

func (m Map) Lookup(d digest.Digest, key T) T

Lookup looks up the provided key in map m. The caller must provide the key's digest which is used as a hash.

type Module

type Module map[string]T

Module is the type of module values.

type Struct

type Struct map[string]T

Struct is the type of struct values.

type Symtab

type Symtab map[string]T

Symtab is a symbol table of values.

type T

type T interface{}

T is the type of value. It is just an alias to interface{}, but is used throughout code for clarity.

func NewFloat

func NewFloat(f float64) T

NewFloat returns a new floating point value.

func NewInt

func NewInt(i int64) T

NewInt returns a new integer value.

type Tuple

type Tuple []T

Tuple is the type of tuple values.

Jump to

Keyboard shortcuts

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