env

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 6 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Packages is a where packages can be stored so VM import command can be used to import them.
	// reflect.Value must be valid or VM may crash.
	// For nil must use NilValue.
	Packages = make(map[string]map[string]reflect.Value)
	// PackageTypes is a where package types can be stored so VM import command can be used to import them
	// reflect.Type must be valid or VM may crash.
	// For nil type must use NilType.
	PackageTypes = make(map[string]map[string]reflect.Type)

	// NilType is the reflect.type of nil
	NilType = reflect.TypeOf(nil)
	// NilValue is the reflect.value of nil
	NilValue = reflect.New(reflect.TypeOf((*interface{})(nil)).Elem()).Elem()

	// ErrSymbolContainsDot symbol contains .
	ErrSymbolContainsDot = errors.New("symbol contains '.'")
)

Functions

This section is empty.

Types

type Env

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

Env is the environment needed for a VM to run in.

func NewEnv

func NewEnv() *Env

NewEnv creates new global scope.

func (*Env) Addr

func (e *Env) Addr(symbol string) (reflect.Value, error)

Addr returns reflect.Addr of value for first matching symbol found in current or parent scope.

func (*Env) Copy

func (e *Env) Copy() *Env

Copy the Env for current scope

func (*Env) DeepCopy

func (e *Env) DeepCopy() *Env

DeepCopy the Env for current scope and parent scopes. Note that each scope is a consistent snapshot but not the whole.

func (*Env) Define

func (e *Env) Define(symbol string, value interface{}) error

Define defines/sets interface value to symbol in current scope.

func (*Env) DefineGlobal

func (e *Env) DefineGlobal(symbol string, value interface{}) error

DefineGlobal defines/sets interface value to symbol in global scope.

func (*Env) DefineGlobalReflectType

func (e *Env) DefineGlobalReflectType(symbol string, reflectType reflect.Type) error

DefineGlobalReflectType defines type in global scope.

func (*Env) DefineGlobalType

func (e *Env) DefineGlobalType(symbol string, aType interface{}) error

DefineGlobalType defines type in global scope.

func (*Env) DefineGlobalValue

func (e *Env) DefineGlobalValue(symbol string, value reflect.Value) error

DefineGlobalValue defines/sets reflect value to symbol in global scope.

func (*Env) DefineReflectType

func (e *Env) DefineReflectType(symbol string, reflectType reflect.Type) error

DefineReflectType defines type in current scope.

func (*Env) DefineType

func (e *Env) DefineType(symbol string, aType interface{}) error

DefineType defines type in current scope.

func (*Env) DefineValue

func (e *Env) DefineValue(symbol string, value reflect.Value) error

DefineValue defines/sets reflect value to symbol in current scope.

func (*Env) Delete

func (e *Env) Delete(symbol string)

Delete deletes symbol in current scope.

func (*Env) DeleteGlobal

func (e *Env) DeleteGlobal(symbol string)

DeleteGlobal deletes the first matching symbol found in current or parent scope.

func (*Env) Get

func (e *Env) Get(symbol string) (interface{}, error)

Get returns interface value from the scope where symbol is frist found.

func (*Env) GetEnvFromPath

func (e *Env) GetEnvFromPath(path []string) (*Env, error)

GetEnvFromPath returns Env from path

func (*Env) GetValue

func (e *Env) GetValue(symbol string) (reflect.Value, error)

GetValue returns reflect value from the scope where symbol is frist found.

func (*Env) NewEnv

func (e *Env) NewEnv() *Env

NewEnv creates new child scope.

func (*Env) NewModule

func (e *Env) NewModule(symbol string) (*Env, error)

NewModule creates new child scope and define it as a symbol. This is a shortcut for calling e.NewEnv then Define that new Env.

func (*Env) Set

func (e *Env) Set(symbol string, value interface{}) error

Set interface value to the scope where symbol is frist found.

func (*Env) SetExternalLookup

func (e *Env) SetExternalLookup(externalLookup ExternalLookup)

SetExternalLookup sets an external lookup

func (*Env) SetValue

func (e *Env) SetValue(symbol string, value reflect.Value) error

SetValue reflect value to the scope where symbol is frist found.

func (*Env) String

func (e *Env) String() string

String returns string of values and types in current scope.

func (*Env) Type

func (e *Env) Type(symbol string) (reflect.Type, error)

Type returns reflect type from the scope where symbol is frist found.

type ExternalLookup

type ExternalLookup interface {
	Get(string) (reflect.Value, error)
	Type(string) (reflect.Type, error)
}

ExternalLookup for Env external lookup of values and types.

Jump to

Keyboard shortcuts

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