values

package
v0.0.0-...-90deddd Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 13 Imported by: 6

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 Less

func Less(v, w T) bool

Less tells whether value v is (structurally) less than w.

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 struct {
	// contains filtered or unexported fields
}

Dir is an immutable type of directory values. Directory values are opaque and may only be accessed through its methods. This is to ensure proper usage, and that the directory is always accessed in the same order to provide determinism. The zero dir is a valid, empty directory. Dir is immutable.

func ReduceUsingSumDir

func ReduceUsingSumDir(dirs []Dir) (sumD Dir)

ReduceUsingSumDir reduces the given list of dirs into a Dir by successively calling SumDir.

func SumDir

func SumDir(d Dir, e Dir) Dir

SumDir returns a dir which behaves as the sum of the given dirs. ie, SumDir behaves like a map containing all the key-value mappings that exist in Dirs d and e. If there is a duplicate key in d and e, the value of e will be effective - just as what would happen if we created a new map and added all the mappings from d first and then from e.

func SumDirs

func SumDirs(dirs []Dir) (dir Dir)

SumDirs returns a dir which behaves as the sum of the given dirs. SumDirs is a generalized version of SumDir.

func (*Dir) DebugString

func (d *Dir) DebugString() string

func (*Dir) Equal

func (d *Dir) Equal(e *Dir) bool

Equal compares the file names and digests in the directory.

func (*Dir) Len

func (d *Dir) Len() int

Len returns the number of entries in the directory.

func (*Dir) Lookup

func (d *Dir) Lookup(path string) (file reflow.File, ok bool)

Lookup returns the entry associated with the provided path and a boolean indicating whether the entry was found.

func (*Dir) Scan

func (d *Dir) Scan() DirScanner

Scan returns a new scanner that traverses the directory in path-sorted order.

for scan := dir.Scan(); scan.Scan(); {
	fmt.Println(scan.Path(), scan.File())
}

func (*Dir) SortedKeys

func (d *Dir) SortedKeys() []string

SortedKeys returns a list of keys from this dir in sorted order.

type DirScanner

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

A DirScanner is a stateful scan of a directory. DirScanners should be instantiated by Dir.Scan.

func (*DirScanner) File

func (s *DirScanner) File() reflow.File

File returns the file of the currently scanned entry.

func (*DirScanner) Path

func (s *DirScanner) Path() string

Path returns the path of the currently scanned entry.

func (*DirScanner) Scan

func (s *DirScanner) Scan() bool

Scan advances the scanner to the next entry (the first entry for a fresh scanner). It returns false when the scan stops with no more entries.

type Env

type Env struct {
	// 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) Concat

func (e *Env) Concat(f *Env) *Env

Concat returns a new concatenated environment.

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) (d digest.Digest)

Digest returns the digest for the value with identifier 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.

Digest also caches the computed digests for an id, and will return the cached value upon subsequent calls.

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

func (e *Env) String() string

String returns a string describing all the bindings in this environment.

func (*Env) Value

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

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

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 struct {
	// contains filtered or unexported fields
}

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 in deterministic order.

TODO(marius): we really ought to use a representation that's more amenable to such (common) operations.

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 MutableDir

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

func (*MutableDir) Dir

func (d *MutableDir) Dir() Dir

Dir returns an immutable version of this dir.

func (*MutableDir) Set

func (d *MutableDir) Set(path string, file reflow.File)

Set sets the mutable directory's entry for the provided path. Set overwrites any previous file set at path.

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.

func (Symtab) PrettyString

func (s Symtab) PrettyString() string

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.

type Variant

type Variant struct {
	// Tag is the tag of this variant value.
	Tag string
	// Elem is the element of this variant. If this is a variant with no
	// element, this will be nil.
	Elem T
}

Variant holds a tagged value. It is the value type that occupies sum types.

Jump to

Keyboard shortcuts

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