data

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataPrefix = defs.InvisiblePrefix

	BasetypeMDName    = "basetype"
	BasetypeMDKey     = MetadataPrefix + BasetypeMDName
	ElementTypesName  = "elements"
	ElementTypesMDKey = MetadataPrefix + ElementTypesName
	MembersMDName     = "members"
	MembersMDKey      = MetadataPrefix + MembersMDName
	ReplicaMDName     = "replica"
	ReplicaMDKey      = MetadataPrefix + ReplicaMDName
	ReadonlyMDName    = "readonly"
	ReadonlyMDKey     = MetadataPrefix + ReadonlyMDName
	SizeMDName        = "size"
	SizeMDKey         = MetadataPrefix + SizeMDName
	StaticMDName      = "static"
	StaticMDKey       = MetadataPrefix + StaticMDName
	SymbolsMDName     = "symbols"
	SymbolsMDKey      = MetadataPrefix + SymbolsMDName
	TypeMDName        = "type"
	TypeMDKey         = MetadataPrefix + TypeMDName
)

Common metadata keys.

View Source
const (
	UndefinedKind = iota
	BoolKind
	ByteKind
	Int32Kind
	IntKind
	Int64Kind
	Float32Kind
	Float64Kind
	StringKind
	StructKind
	ErrorKind
	ChanKind
	MapKind
	InterfaceKind // alias for defs.Any
	PointerKind   // Pointer to some type
	ArrayKind     // Array of some type
	PackageKind   // A package

	WaitGroupKind
	MutexKind

	VarArgsKind // pseudo type used for variable argument list items
	TypeKind    // something defined by a type statement
)

Define data types as abstract identifiers. These are the base types for all other types. For example, a pointer to an integer in constructed from a PointerKind type that references an IntKind type.

IMPORTANT: the order of these must be from less-precise to most-precise for numeric values, as this ordering is used to normalize two values of different types before performing math on them.

View Source
const (
	StringTypeName    = "string"
	BoolTypeName      = "bool"
	ByteTypeName      = "byte"
	IntTypeName       = "int"
	Int32TypeName     = "int32"
	Int64TypeName     = "int64"
	Float32TypeName   = "float32"
	Float64TypeName   = "float64"
	StructTypeName    = "struct"
	MapTypeName       = "map"
	PackageTypeName   = "package"
	InterfaceTypeName = "interface{}"
	ErrorTypeName     = "error"
	VoidTypeName      = "void"
	UndefinedTypeName = "undefined"
)
View Source
const (
	True   = "true"
	False  = "false"
	NoName = ""
)

Variables

View Source
var BoolType = &Type{
	name:      BoolTypeName,
	kind:      BoolKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var ByteType = &Type{
	name:      ByteTypeName,
	kind:      ByteKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var ChanType = &Type{
	name:      "chan",
	kind:      ChanKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var ErrorType = &Type{
	name: ErrorTypeName,
	kind: ErrorKind,
}
View Source
var Float32Type = &Type{
	name:      Float32TypeName,
	kind:      Float32Kind,
	keyType:   nil,
	valueType: nil,
}
View Source
var Float64Type = &Type{
	name:      Float64TypeName,
	kind:      Float64Kind,
	keyType:   nil,
	valueType: nil,
}
View Source
var Int32Type = &Type{
	name:      Int32TypeName,
	kind:      Int32Kind,
	keyType:   nil,
	valueType: nil,
}
View Source
var Int64Type = &Type{
	name:      Int64TypeName,
	kind:      Int64Kind,
	keyType:   nil,
	valueType: nil,
}
View Source
var IntType = &Type{
	name:      IntTypeName,
	kind:      IntKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var InterfaceType = &Type{
	name:      InterfaceTypeName,
	kind:      InterfaceKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var MutexType = &Type{
	name:      "Mutex",
	kind:      MutexKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var StringType = &Type{
	name:      StringTypeName,
	kind:      StringKind,
	keyType:   nil,
	valueType: nil,
}
View Source
var StructType = &Type{
	name: StructTypeName,
	kind: StructKind,
}
View Source
var TypeDeclarations = []TypeDeclaration{
	{
		[]string{"sync", ".", "WaitGroup"},
		nil,
		WaitGroupType,
	},
	{
		[]string{"*", "sync", ".", "WaitGroup"},
		nil,
		PointerType(WaitGroupType),
	},
	{
		[]string{"sync", ".", "Mutex"},
		nil,
		MutexType,
	},
	{
		[]string{"*", "sync", ".", "Mutex"},
		nil,
		PointerType(MutexType),
	},
	{
		[]string{"chan"},
		chanModel,
		ChanType,
	},
	{
		[]string{"[", "]", ByteTypeName},
		NewArray(ByteType, 0),
		ArrayType(ByteType),
	},
	{
		[]string{"[", "]", Int32TypeName},
		NewArray(Int32Type, 0),
		ArrayType(Int32Type),
	},
	{
		[]string{"[", "]", IntTypeName},
		NewArray(IntType, 0),
		ArrayType(IntType),
	},
	{
		[]string{"[", "]", Int64TypeName},
		NewArray(Int64Type, 0),
		ArrayType(Int64Type),
	},
	{
		[]string{"[", "]", BoolTypeName},
		NewArray(BoolType, 0),
		ArrayType(BoolType),
	},
	{
		[]string{"[", "]", Float64TypeName},
		NewArray(Float64Type, 0),
		ArrayType(Float64Type),
	},
	{
		[]string{"[", "]", Float32TypeName},
		NewArray(Float32Type, 0),
		ArrayType(Float32Type),
	},
	{
		[]string{"[", "]", StringTypeName},
		NewArray(StringType, 0),
		ArrayType(StringType),
	},
	{
		[]string{"[", "]", InterfaceTypeName},
		NewArray(InterfaceType, 0),
		ArrayType(InterfaceType),
	},
	{
		[]string{BoolTypeName},
		boolModel,
		BoolType,
	},
	{
		[]string{ByteTypeName},
		byteModel,
		ByteType,
	},
	{
		[]string{Int32TypeName},
		int32Model,
		Int32Type,
	},
	{
		[]string{IntTypeName},
		intModel,
		IntType,
	},
	{
		[]string{Int64TypeName},
		int64Model,
		Int64Type,
	},
	{
		[]string{Float64TypeName},
		float64Model,
		Float64Type,
	},
	{
		[]string{Float32TypeName},
		float32Model,
		Float32Type,
	},
	{
		[]string{StringTypeName},
		stringModel,
		StringType,
	},
	{
		[]string{InterfaceTypeName},
		interfaceModel,
		InterfaceType,
	},
	{
		[]string{"interface", "{}"},
		interfaceModel,
		InterfaceType,
	},
	{
		[]string{"*", BoolTypeName},
		&boolInterface,
		PointerType(BoolType),
	},
	{
		[]string{"*", Int32TypeName},
		&int32Interface,
		PointerType(Int32Type),
	},
	{
		[]string{"*", ByteTypeName},
		&byteInterface,
		PointerType(ByteType),
	},
	{
		[]string{"*", IntTypeName},
		&intInterface,
		PointerType(IntType),
	},
	{
		[]string{"*", Int64TypeName},
		&int64Interface,
		PointerType(Int64Type),
	},
	{
		[]string{"*", Float64TypeName},
		&float64Interface,
		PointerType(Float64Type),
	},
	{
		[]string{"*", Float32TypeName},
		&float32Interface,
		PointerType(Float32Type),
	},
	{
		[]string{"*", StringTypeName},
		&stringInterface,
		PointerType(StringType),
	},
	{
		[]string{"*", InterfaceTypeName},
		&interfaceModel,
		PointerType(InterfaceType),
	},
	{
		[]string{"*", "interface", "{}"},
		&interfaceModel,
		PointerType(InterfaceType),
	},
}

TypeDeclarations is a dictionary of all the type declaration token sequences. This includes _Ego_ types and also native types, such as sync.WaitGroup. Note that for native types, you may also have to update InstanceOf() to generate a unique instance of the required type, usually via pointer so the native function can reference/update the native value.

View Source
var UndefinedType = &Type{
	name: UndefinedTypeName,
	kind: UndefinedKind,
}
View Source
var VarArgsType = &Type{
	name: "...",
	kind: VarArgsKind,
}
View Source
var VoidType = &Type{
	name: VoidTypeName,
}
View Source
var WaitGroupType = &Type{
	name:      "WaitGroup",
	kind:      WaitGroupKind,
	keyType:   nil,
	valueType: nil,
}

Functions

func AddressOf

func AddressOf(v interface{}) (interface{}, error)

func Bool

func Bool(v interface{}) bool

GetString retrieves the boolean value of the argument, converting if needed.

func Byte

func Byte(v interface{}) byte

Byte retrieves the byte value of the argument, converting if needed.

func Coerce

func Coerce(v interface{}, model interface{}) interface{}

Coerce returns the value after it has been converted to the type of the model value.

func CoerceType

func CoerceType(v interface{}, typeName string) interface{}

CoerceType will coerce an interface to a given type by name.

func DeepCopy

func DeepCopy(v interface{}) interface{}

DeepCopy creates a new copy of the interface. This includes recursively copying any member elements of arrays, maps, or structures. This cannot be used on a pointer value.

func Dereference

func Dereference(v interface{}) (interface{}, error)

func Float32

func Float32(v interface{}) float32

Float32 retrieves the float32 value of the argument, converting if needed.

func Float64

func Float64(v interface{}) float64

Float64 retrieves the float64 value of the argument, converting if needed.

func Format

func Format(element interface{}) string

func FormatUnquoted

func FormatUnquoted(arg interface{}) string

FormatUnquoted formats a value but does not put quotes on strings.

func FormatWithType

func FormatWithType(element interface{}) string

func GenerateName

func GenerateName() string

Threadsafe name generator.

func GetBuiltinDeclaration

func GetBuiltinDeclaration(name string) string

func GetMetadata

func GetMetadata(value *Package, key string) (interface{}, bool)

For a given struct, fetch a metadata value by key. The boolean flag indicates if the value was found or has to be created.

func GetNativeArray

func GetNativeArray(v interface{}) []interface{}

GetNativeArray extracts a struct from an abstract interface. Returns nil if the interface did not contain a struct/map.

func GetNativeMap

func GetNativeMap(v interface{}) map[string]interface{}

GetNativeMap extracts a map from an abstract interface. Returns nil if the interface did not contain a map. Note this is NOT an Ego map, but rather is used by runtime.Table() for actual maps.

func InstanceOfType

func InstanceOfType(t *Type) interface{}

InstanceOfType accepts a kind type indicator, and returns the zero-value model of that type. This only applies to base types.

func Int

func Int(v interface{}) int

Int retrieves the int value of the argument, converting if needed.

func Int32

func Int32(v interface{}) int32

Int32 retrieves the int32 value of the argument, converting if needed.

func Int64

func Int64(v interface{}) int64

Int64 retrieves the int64 value of the argument, converting if needed.

func IsBaseType

func IsBaseType(v interface{}, t *Type) bool

Compare the value to the base type of the type given. This recursively peels away any type definition layers and compares the value type to the ultimate base type. If the type passed in is already a base type, this is no different than calling IsType() directly.

func IsNativeType

func IsNativeType(kind int) bool

Is this type associated with a native Ego type that has extended native function support?

func IsNil

func IsNil(v interface{}) bool

Determine if the given value is "nil". This an be either an actual nil value, or a value that represents the "nil values" for the given type (which are recorded as the address of the zero value).

func IsNumeric

func IsNumeric(i interface{}) bool

IsNumeric determines if the value passed is an numeric type. The parameter value can be an actual value (int, byte, float32, etc) or a Type which represents a numeric value.

func IsType

func IsType(v interface{}, t *Type) bool

IsType accepts an arbitrary value that is either an Ego or native data value, and a type specification, and indicates if it is of the provided Ego datatype indicator.

func KindOf

func KindOf(i interface{}) int

func Normalize

func Normalize(v1 interface{}, v2 interface{}) (interface{}, interface{})

Normalize accepts two different values and promotes them to the most compatable format.

func PackageForKind

func PackageForKind(kind int) string

For a given type, return the native package that contains it. For example, sync.WaitGroup would return "sync".

func RealSizeOf

func RealSizeOf(v interface{}) int

func Sanitize

func Sanitize(v interface{}) interface{}

For any given _Ego_ object type, remove any metadata from it and return a sanitized copy. This is used to send HTTP response values, for example.

func SetMetadata

func SetMetadata(m *Package, key string, v interface{})

For a given structure, set a key/value in the metadata. The metadata member and it's map are created if necessary.

func SetType

func SetType(m *Package, t *Type)

For a given package, set it's type value in the metadata. If the item is not a struct map then do no work.

func String

func String(v interface{}) string

String retrieves the string value of the argument, converting if needed.

Types

type Array

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

Array is the representation in native code of an Ego array. This includes an array of interfaces that contain the actual data items, a base type (which may be InterfaceType if the array is untypted) and a counting semaphore used to track if the array should be considered writable or not.

func NewArray

func NewArray(valueType *Type, size int) *Array

Create a new empty array of the given type and size. The values of the array members are all initialized to nil. Note special case for []byte which is stored natively so it can be used with native Go methods that expect a byte array.

func NewArrayFromArray

func NewArrayFromArray(valueType *Type, source []interface{}) *Array

NewArrayFromArray accepts a type and an array of interfaces, and constructs an EgoArray that uses the source array as it's base array. Note special processing for []byte which results in a native Go []byte array.

func (*Array) Append

func (a *Array) Append(i interface{}) *Array

Append an item to the array. If the item being appended is an array itself, we append the elements of the array.

func (*Array) BaseArray

func (a *Array) BaseArray() []interface{}

BaseArray returns the underlying native array that contains the individual array members. This is needed for things like sort.Slice(). Note that if its a []byte type, we must convert the native Go array into an []interface{} first...

func (*Array) DeepEqual

func (a *Array) DeepEqual(b *Array) bool

DeepEqual is a recursive compare with another Ego array. The recursive compare is performed on each member of the array.

func (*Array) Delete

func (a *Array) Delete(i int) error

Delete removes an item from the array by index number. The index must be a valid array index. The return value is nil if no error occurs, else an error if the index is out-of-bounds or the array is marked as immutable.

func (*Array) Get

func (a *Array) Get(i interface{}) (interface{}, error)

Get retrieves a member of the array. If the array index is out-of-bounds for the array size, an error is returned.

func (*Array) GetBytes

func (a *Array) GetBytes() []byte

GetBytes returns the native byte array for this array, or nil if this is not a byte array.

func (*Array) GetSlice

func (a *Array) GetSlice(first, last int) ([]interface{}, error)

Fetach a slice of the underlying array and return it as an array of interfaces. This can't be used directly as a new array, but can be used to create a new array.

func (*Array) GetSliceAsArray

func (a *Array) GetSliceAsArray(first, last int) (*Array, error)

Fetach a slice of the underlying array and return it as an array of interfaces. This can't be used directly as a new array, but can be used to create a new array.

func (*Array) Len

func (a *Array) Len() int

Len returns the length of the array.

func (*Array) Make

func (a *Array) Make(size int) *Array

Make creates a new array patterned off of the type of the receiver array, of the given size. Note special handling for []byte types which creates a native Go array.

func (Array) MarshalJSON

func (a Array) MarshalJSON() ([]byte, error)

MarshalJSON converts the array representation to valid JSON and returns the data as a byte array.

func (*Array) Set

func (a *Array) Set(i interface{}, value interface{}) error

Set stores a value in the array. The array must not be set to immutable. The array index must be within the size of the array. If the array is a typed array, the type must match the array type. The value can handle conversion of integer and float types to fit the target array base type.

func (*Array) SetAlways

func (a *Array) SetAlways(i interface{}, value interface{}) *Array

Simplified Set() that does no type checking. Used internally to load values into an array that is known to be of the correct kind.

func (*Array) SetReadonly

func (a *Array) SetReadonly(b bool) *Array

SetReadonly sets or clears the flag that marks the array as immutable. When an array is marked as immutable, it cannot be modified (but can be deleted in it's entirety). Note that this function actually uses a semaphore to track the state, so there must bre an exact match of calls to SetReadonly(false) as there were to SetReadonly(true) to allow modifiations to the array.

func (*Array) SetSize

func (a *Array) SetSize(size int) *Array

Force the size of the array. Existing values are retained if the array grows; existing values are truncated if the size is reduced.

func (*Array) SetType

func (a *Array) SetType(i *Type) error

SetType can be called once on an anonymous array (whose members are all abstract interfaces). This sets the base type of the array to the given type. If the array already has a base type, you cannot set a new one. This (along with the Validate() function) can be used to convert an anonymous array to a typed array.

func (*Array) Sort

func (a *Array) Sort() error

Sort will sort the array into ascending order. It uses either native sort functions or the native sort.Slice function to do the sort. This can only be performed on an array of scalar types (no structs, arrays, or maps).

func (*Array) String

func (a *Array) String() string

Make a string representation of the array suitable for display.

func (*Array) TypeString

func (a *Array) TypeString() string

Generate a type description string for this array.

func (*Array) Validate

func (a *Array) Validate(kind *Type) error

Validate checks that all the members of the array are of a given type. This is used to validate anonymous arrays for use as a typed array.

func (*Array) ValueType

func (a *Array) ValueType() *Type

ValueType returns the base type of the array.

type Channel

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

Structure of an Ego channel wrapper around Go channels.

func NewChannel

func NewChannel(size int) *Channel

Create a mew instance of an Ego channel. The size passed indicates the buffer size, which is 1 unless size is greater than 1, in which case it is set to the given size.

func (*Channel) Close

func (c *Channel) Close() bool

Close the channel so no more sends are permitted to the channel, and the receiver can test for channel completion. Must do the logging before taking the exclusive lock so c.String() can work.

func (*Channel) IsEmpty

func (c *Channel) IsEmpty() bool

IsEmpty checks to see if a channel has been drained (i.e. it is closed and there are no more items). This is used by the len() function, for example.

func (*Channel) IsOpen

func (c *Channel) IsOpen() bool

Return a boolean value indicating if this channel is still open for business.

func (*Channel) Receive

func (c *Channel) Receive() (interface{}, error)

Receive accepts an arbitrary data object through the channel, waiting if there is no information available yet. If it's not open, we also check to see if the messages have all been drained by looking at the counter.

func (*Channel) Send

func (c *Channel) Send(datum interface{}) error

Send transmits an arbitrary data object through the channel, if it is open. We must verify that the chanel is open before using it. It is important to put the logging message out brefore re-locking the channel since c.String needs a read-lock.

func (*Channel) String

func (c *Channel) String() string

type Field

type Field struct {
	Name string
	Type *Type
}

type Function

type Function struct {
	Declaration *FunctionDeclaration
	Value       interface{} // Generally bytecode
}

type FunctionDeclaration

type FunctionDeclaration struct {
	Name         string
	ReceiverType *Type
	Parameters   []FunctionParameter
	ReturnTypes  []*Type
	Variadic     bool
}

func (FunctionDeclaration) String

func (f FunctionDeclaration) String() string

type FunctionParameter

type FunctionParameter struct {
	Name     string
	ParmType *Type
}

type Map

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

Map is a wrapper around a native Go map. The actual map supports interface items for both key and value. The wrapper contains additional information about the expected types for key and value, as well as a counting semaphore to determine if the map should be considered immutable (such as during a for...range loop).

func NewMap

func NewMap(keyType, valueType *Type) *Map

Generate a new map value. The caller must supply the data type codes for the expected key and value types (such as data.StringType or data.FloatType). You can also use data.InterfaceType for a type value, which means any type is accepted. The result is an initialized map that you can begin to store or read values from.

func NewMapFromMap

func NewMapFromMap(sourceMap interface{}) *Map

Given a map whose keys and values are simple types (string, int, float64, bool), create a new EgoMap with the appropriate types, populated with the values from the source map.

func (*Map) Delete

func (m *Map) Delete(key interface{}) (bool, error)

Delete will delete a given value from the map based on key. The return value indicates if the value was found (and therefore deleted) versus was not found.

func (*Map) Get

func (m *Map) Get(key interface{}) (interface{}, bool, error)

Get reads a value from the map. The key value must be compatible with the type declaration of the map (no coercion occurs). This returns the actual value, or nil if not found. It also returns a flag indicating if the interface was found or not (i.e. should the result be considered value). Finally, it returns an error code if there is a type mismatch.

func (*Map) KeyType

func (m *Map) KeyType() *Type

ValueType returns the integer description of the declared key type for this map.

func (*Map) Keys

func (m *Map) Keys() []interface{}

Keys returns the set of keys for the map as an array. If the values are strings, ints, or floats they are returned in ascending sorted order.

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

func (*Map) Set

func (m *Map) Set(key interface{}, value interface{}) (bool, error)

Set sets a value in the map. The key value and type value must be compatible with the type declaration for the map. Bad type values result in an error. The function also returns a boolean indicating if the value replaced an existing item or not.

func (*Map) SetReadonly

func (m *Map) SetReadonly(b bool)

SetReadonly marks the map as immutable. This is passed in as a boolean value (true means immutable). Internally, this is actually a counting semaphore, so the calls to SetReadonly to set/clear the state must be balanced to prevent having a map that is permanently locked or unlocked.

func (*Map) String

func (m *Map) String() string

String displays a simplified formatted string value of a map, using the Ego anonymous struct syntax. Key values are not quoted, but data values are if they are strings.

func (*Map) Type

func (m *Map) Type() *Type

Type returns a type descriptor for the current map.

func (*Map) TypeString

func (m *Map) TypeString() string

TypeString produces a human-readable string describing the map type in Ego native terms.

func (*Map) ValueType

func (m *Map) ValueType() *Type

ValueType returns the integer description of the declared value type for this map.

type Package

type Package struct {
	ID string
	// contains filtered or unexported fields
}

This describes the items in a package. Each item could be an arbitrary object (function, data type, etc).

func NewPackage

func NewPackage(name string) *Package

NewPackage creates a new, empty package definition.

func NewPackageFromMap

func NewPackageFromMap(name string, items map[string]interface{}) *Package

NewPackageFromMap creates a new package, and then populates it using the provided map. If the map is a nil value, then an empty package definition is created.

func (*Package) Builtins

func (p *Package) Builtins() bool

func (*Package) Constants

func (p *Package) Constants() bool

func (*Package) Delete

func (p *Package) Delete(name string)

Delete removes a package from the list. It is not an error if the package does not have a hash map, or the value is not in the hash map.

func (*Package) Get

func (p *Package) Get(key string) (interface{}, bool)

Get retrieves a value from the package structure by name. It returns the value and a boolean value indicating if it was found. The flag is true if the package has been initialized, the hash map is initialized, and the named value is found in the hashmap.

func (*Package) HasImportedSource

func (p *Package) HasImportedSource() bool

func (*Package) HasTypes

func (p *Package) HasTypes() bool

func (*Package) IsEmpty

func (p *Package) IsEmpty() bool

IsEmpty reports if a package is empty. This could be due to a null pointer, uninitialized internal hash map, or an empty hash map.

func (*Package) Keys

func (p *Package) Keys() []string

Keys provides a list of keys for the package as an array of strings. The array will be empty if the package pointer is null, the hash map is uninitialized, or the hash map is empty.

func (*Package) Merge

func (p *Package) Merge(source Package)

Merge adds any entries from a package to the current package that do not already exist.

func (*Package) Name

func (p *Package) Name() string

func (*Package) Set

func (p *Package) Set(key string, value interface{})

Set sets a given value in the package. If the hash map was not yet initialized, it is created now before setting the value.

func (*Package) SetBuiltins

func (p *Package) SetBuiltins(f bool) *Package

func (*Package) SetImported

func (p *Package) SetImported(f bool) *Package

func (*Package) String

func (p *Package) String() string

String formats the package as a string value, to support "%v" operations.

type Struct

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

func NewStruct

func NewStruct(t *Type) *Struct

func NewStructFromMap

func NewStructFromMap(m map[string]interface{}) *Struct

func NewStructOfTypeFromMap

func NewStructOfTypeFromMap(t *Type, m map[string]interface{}) *Struct

func (*Struct) AsType

func (s *Struct) AsType(t *Type) *Struct

This is used only by the unit testing to explicitly set the type of a structure. It changes no data, only updates the type value.

func (*Struct) Copy

func (s *Struct) Copy() *Struct

Make a copy of the current structure object.

func (*Struct) FieldNames

func (s *Struct) FieldNames() []string

func (*Struct) FieldNamesArray

func (s *Struct) FieldNamesArray() *Array

func (*Struct) FromBuiltinPackage

func (s *Struct) FromBuiltinPackage() *Struct

func (*Struct) Get

func (s *Struct) Get(name string) (interface{}, bool)

Get retrieves a field from the structure. Note that if the structure is a synthetic package type, we only allow access to exported names.

func (*Struct) GetAlways

func (s *Struct) GetAlways(name string) interface{}

GetAlways retrieves a value from the named field. No error checking is done to verify that the field exists; if it does not then a nil value is returned. This is a short-cut used in runtime code to access well-known fields from pre-defined object types, such as a db.Client().

func (*Struct) GetType

func (s *Struct) GetType() *Type

func (*Struct) MarshalJSON

func (s *Struct) MarshalJSON() ([]byte, error)

func (*Struct) PackageType

func (s *Struct) PackageType() string

func (*Struct) Reflect

func (s *Struct) Reflect() *Struct

func (*Struct) Set

func (s *Struct) Set(name string, value interface{}) error

func (*Struct) SetAlways

func (s *Struct) SetAlways(name string, value interface{}) *Struct

Store a value in the structure under the given name. This ignores type safety, static, or readonly attributes, so be VERY sure the value is the right type!

func (*Struct) SetReadonly

func (s *Struct) SetReadonly(b bool) *Struct

func (*Struct) SetStatic

func (s *Struct) SetStatic(b bool) *Struct

func (*Struct) SetTyping

func (s *Struct) SetTyping(b bool) *Struct

func (*Struct) String

func (s *Struct) String() string

func (*Struct) ToMap

func (s *Struct) ToMap() map[string]interface{}

func (*Struct) TypeString

func (s *Struct) TypeString() string

type Type

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

func ArrayType

func ArrayType(t *Type) *Type

Construct a type that is an array of the given type.

func MapType

func MapType(key, value *Type) *Type

Construct a type that is a map, specifying the key and value types.

func NewInterfaceType

func NewInterfaceType(name string) *Type

func PackageType

func PackageType(name string) *Type

Construct a type for a package of the given name.

func PointerType

func PointerType(t *Type) *Type

Construct a type that is a pointer to the given type.

func StructureType

func StructureType(fields ...Field) *Type

Construct a structure type, with optional field definitions. You can later add additional fields using the AddField method.

func TypeDefinition

func TypeDefinition(name string, base *Type) *Type

Create a type that is a named type definition, with the given type name and base type.

func TypeOf

func TypeOf(i interface{}) *Type

TypeOf accepts an interface of arbitrary Ego or native data type, and returns the associated type specification, such as data.intKind or data.stringKind.

func TypeOfPointer

func TypeOfPointer(v interface{}) *Type

For a given interface pointer, unwrap the pointer and return the type it actually points to.

func UserType

func UserType(packageName, typeName string) Type

func (*Type) BaseType

func (t *Type) BaseType() *Type

For a given type, return the type of its base type. So for an array, this is the type of each array element. For a pointer, it is the type it points to.

func (Type) Coerce

func (t Type) Coerce(v interface{}) interface{}

func (*Type) DefineField

func (t *Type) DefineField(name string, ofType *Type) *Type

For a given type, add a new field of the given name and type. Returns an error if the current type is not a structure, or if the field already is defined.

func (*Type) DefineFunction

func (t *Type) DefineFunction(name string, declaration *FunctionDeclaration, value interface{})

Define a function for a type, that can be used as a receiver function.

func (*Type) DefineFunctions

func (t *Type) DefineFunctions(functions map[string]Function)

Helper function that defines a set of functions in a single call. Note this can only define functipoin values, not declarations.

func (Type) Field

func (t Type) Field(name string) (*Type, error)

Retrieve the type of a field by name. The current type must be a structure type, and the field name must exist.

func (Type) FieldNames

func (t Type) FieldNames() []string

Return a list of all the fieldnames for the type. The array is empty if this is not a struct or a struct type.

func (Type) Function

func (t Type) Function(name string) interface{}

Retrieve a receiver function from the given type. Returns nil if there is no such function.

func (Type) FunctionNameList

func (t Type) FunctionNameList() string

Return a string containing the list of receiver functions for this type. If there are no functions defined, it returns an empty string. The results are a comma-separated list of function names plus "()".

func (Type) FunctionNames

func (t Type) FunctionNames() []string

Return a string array containing the list of receiver functions for this type. If there are no functions defined, it returns an empty array.

func (Type) HasFunctions

func (t Type) HasFunctions() bool

Return a flag indicating if the given type includes function definitions.

func (Type) InstanceOf

func (t Type) InstanceOf(superType *Type) interface{}

func (Type) IsArray

func (t Type) IsArray() bool

Returns true if the current type is an array.

func (Type) IsFloatType

func (t Type) IsFloatType() bool

IsFloatType returns true if the type represents any of the floating point types. This is used to relax type checking for array initializers, for example.

func (Type) IsIntegerType

func (t Type) IsIntegerType() bool

IsIntegerType returns true if the type represents any of the integer types. This is used to relax type checking for array initializers, for example.

func (Type) IsInterface

func (t Type) IsInterface() bool

Determine if the type is an interface. This could be a simple interface object ("interface{}") or a type that specifies an interface.

func (Type) IsKind

func (t Type) IsKind(k int) bool

For a given type, return true if the type is of the given scalar base kind. Note this cannot be used for user-defined Types.

func (Type) IsPointer

func (t Type) IsPointer() bool

Return true if this type is a pointer to something.

func (Type) IsType

func (t Type) IsType(i *Type) bool

Return true if this type is the same as the provided type.

func (Type) IsTypeDefinition

func (t Type) IsTypeDefinition() bool

Returns true if the current type is a type definition created by code (as opposed to a base type).

func (Type) IsUndefined

func (t Type) IsUndefined() bool

Return true if the current type is the undefined type.

func (Type) KeyType

func (t Type) KeyType() *Type

For a given type, return the key type. This only applies to arrays and will return a nil pointer for any other type.

func (Type) Kind

func (t Type) Kind() int

For a given type, return it's kind (i.e. int, string, etc.). This is mostly used for parsing, and for switch statements based on Ego data types.

func (Type) Name

func (t Type) Name() string

Return the name of the type (not the same as the formatted string, but usually refers to a user-defined type name).

func (Type) Reflect

func (t Type) Reflect() *Struct

Generate a reflection object that describes the type.

func (*Type) SetPackage

func (t *Type) SetPackage(name string) *Type

func (Type) ShortTypeString

func (t Type) ShortTypeString() string

FullTypeString returns the type by name but also includes the full underlying type definition.

func (Type) String

func (t Type) String() string

Produce a human-readable version of the type definition.

func (Type) TypeString

func (t Type) TypeString() string

func (Type) ValidateFunctions

func (t Type) ValidateFunctions(i *Type) error

ValidateFunctions compares the functions for a given type against the functions for an associated interface definition.

type TypeDeclaration

type TypeDeclaration struct {
	Tokens []string
	Model  interface{}
	Kind   *Type
}

This defines the token structure for various type declarations, including a model of that type and the type designation.

Jump to

Keyboard shortcuts

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