Documentation ¶
Index ¶
- Constants
- Variables
- func AddressOf(v interface{}) (interface{}, error)
- func Bool(v interface{}) bool
- func Byte(v interface{}) byte
- func Coerce(v interface{}, model interface{}) interface{}
- func CoerceType(v interface{}, typeName string) interface{}
- func DeepCopy(v interface{}) interface{}
- func Dereference(v interface{}) (interface{}, error)
- func Float32(v interface{}) float32
- func Float64(v interface{}) float64
- func Format(element interface{}) string
- func FormatUnquoted(arg interface{}) string
- func FormatWithType(element interface{}) string
- func GenerateName() string
- func GetBuiltinDeclaration(name string) string
- func GetMetadata(value *Package, key string) (interface{}, bool)
- func GetNativeArray(v interface{}) []interface{}
- func GetNativeMap(v interface{}) map[string]interface{}
- func InstanceOfType(t *Type) interface{}
- func Int(v interface{}) int
- func Int32(v interface{}) int32
- func Int64(v interface{}) int64
- func IsBaseType(v interface{}, t *Type) bool
- func IsNativeType(kind int) bool
- func IsNil(v interface{}) bool
- func IsNumeric(i interface{}) bool
- func IsType(v interface{}, t *Type) bool
- func KindOf(i interface{}) int
- func Normalize(v1 interface{}, v2 interface{}) (interface{}, interface{})
- func PackageForKind(kind int) string
- func RealSizeOf(v interface{}) int
- func Sanitize(v interface{}) interface{}
- func SetMetadata(m *Package, key string, v interface{})
- func SetType(m *Package, t *Type)
- func String(v interface{}) string
- type Array
- func (a *Array) Append(i interface{}) *Array
- func (a *Array) BaseArray() []interface{}
- func (a *Array) DeepEqual(b *Array) bool
- func (a *Array) Delete(i int) error
- func (a *Array) Get(i interface{}) (interface{}, error)
- func (a *Array) GetBytes() []byte
- func (a *Array) GetSlice(first, last int) ([]interface{}, error)
- func (a *Array) GetSliceAsArray(first, last int) (*Array, error)
- func (a *Array) Len() int
- func (a *Array) Make(size int) *Array
- func (a Array) MarshalJSON() ([]byte, error)
- func (a *Array) Set(i interface{}, value interface{}) error
- func (a *Array) SetAlways(i interface{}, value interface{}) *Array
- func (a *Array) SetReadonly(b bool) *Array
- func (a *Array) SetSize(size int) *Array
- func (a *Array) SetType(i *Type) error
- func (a *Array) Sort() error
- func (a *Array) String() string
- func (a *Array) TypeString() string
- func (a *Array) Validate(kind *Type) error
- func (a *Array) ValueType() *Type
- type Channel
- type Field
- type Function
- type FunctionDeclaration
- type FunctionParameter
- type Map
- func (m *Map) Delete(key interface{}) (bool, error)
- func (m *Map) Get(key interface{}) (interface{}, bool, error)
- func (m *Map) KeyType() *Type
- func (m *Map) Keys() []interface{}
- func (m *Map) MarshalJSON() ([]byte, error)
- func (m *Map) Set(key interface{}, value interface{}) (bool, error)
- func (m *Map) SetReadonly(b bool)
- func (m *Map) String() string
- func (m *Map) Type() *Type
- func (m *Map) TypeString() string
- func (m *Map) ValueType() *Type
- type Package
- func (p *Package) Builtins() bool
- func (p *Package) Constants() bool
- func (p *Package) Delete(name string)
- func (p *Package) Get(key string) (interface{}, bool)
- func (p *Package) HasImportedSource() bool
- func (p *Package) HasTypes() bool
- func (p *Package) IsEmpty() bool
- func (p *Package) Keys() []string
- func (p *Package) Merge(source Package)
- func (p *Package) Name() string
- func (p *Package) Set(key string, value interface{})
- func (p *Package) SetBuiltins(f bool) *Package
- func (p *Package) SetImported(f bool) *Package
- func (p *Package) String() string
- type Struct
- func (s *Struct) AsType(t *Type) *Struct
- func (s *Struct) Copy() *Struct
- func (s *Struct) FieldNames() []string
- func (s *Struct) FieldNamesArray() *Array
- func (s *Struct) FromBuiltinPackage() *Struct
- func (s *Struct) Get(name string) (interface{}, bool)
- func (s *Struct) GetAlways(name string) interface{}
- func (s *Struct) GetType() *Type
- func (s *Struct) MarshalJSON() ([]byte, error)
- func (s *Struct) PackageType() string
- func (s *Struct) Reflect() *Struct
- func (s *Struct) Set(name string, value interface{}) error
- func (s *Struct) SetAlways(name string, value interface{}) *Struct
- func (s *Struct) SetReadonly(b bool) *Struct
- func (s *Struct) SetStatic(b bool) *Struct
- func (s *Struct) SetTyping(b bool) *Struct
- func (s *Struct) String() string
- func (s *Struct) ToMap() map[string]interface{}
- func (s *Struct) TypeString() string
- type Type
- func ArrayType(t *Type) *Type
- func MapType(key, value *Type) *Type
- func NewInterfaceType(name string) *Type
- func PackageType(name string) *Type
- func PointerType(t *Type) *Type
- func StructureType(fields ...Field) *Type
- func TypeDefinition(name string, base *Type) *Type
- func TypeOf(i interface{}) *Type
- func TypeOfPointer(v interface{}) *Type
- func UserType(packageName, typeName string) Type
- func (t *Type) BaseType() *Type
- func (t Type) Coerce(v interface{}) interface{}
- func (t *Type) DefineField(name string, ofType *Type) *Type
- func (t *Type) DefineFunction(name string, declaration *FunctionDeclaration, value interface{})
- func (t *Type) DefineFunctions(functions map[string]Function)
- func (t Type) Field(name string) (*Type, error)
- func (t Type) FieldNames() []string
- func (t Type) Function(name string) interface{}
- func (t Type) FunctionNameList() string
- func (t Type) FunctionNames() []string
- func (t Type) HasFunctions() bool
- func (t Type) InstanceOf(superType *Type) interface{}
- func (t Type) IsArray() bool
- func (t Type) IsFloatType() bool
- func (t Type) IsIntegerType() bool
- func (t Type) IsInterface() bool
- func (t Type) IsKind(k int) bool
- func (t Type) IsPointer() bool
- func (t Type) IsType(i *Type) bool
- func (t Type) IsTypeDefinition() bool
- func (t Type) IsUndefined() bool
- func (t Type) KeyType() *Type
- func (t Type) Kind() int
- func (t Type) Name() string
- func (t Type) Reflect() *Struct
- func (t *Type) SetPackage(name string) *Type
- func (t Type) ShortTypeString() string
- func (t Type) String() string
- func (t Type) TypeString() string
- func (t Type) ValidateFunctions(i *Type) error
- type TypeDeclaration
Constants ¶
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.
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.
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" )
const ( True = "true" False = "false" NoName = "" )
Variables ¶
var BoolType = &Type{ name: BoolTypeName, kind: BoolKind, keyType: nil, valueType: nil, }
var ByteType = &Type{ name: ByteTypeName, kind: ByteKind, keyType: nil, valueType: nil, }
var ChanType = &Type{ name: "chan", kind: ChanKind, keyType: nil, valueType: nil, }
var ErrorType = &Type{ name: ErrorTypeName, kind: ErrorKind, }
var Float32Type = &Type{ name: Float32TypeName, kind: Float32Kind, keyType: nil, valueType: nil, }
var Float64Type = &Type{ name: Float64TypeName, kind: Float64Kind, keyType: nil, valueType: nil, }
var Int32Type = &Type{ name: Int32TypeName, kind: Int32Kind, keyType: nil, valueType: nil, }
var Int64Type = &Type{ name: Int64TypeName, kind: Int64Kind, keyType: nil, valueType: nil, }
var IntType = &Type{ name: IntTypeName, kind: IntKind, keyType: nil, valueType: nil, }
var InterfaceType = &Type{ name: InterfaceTypeName, kind: InterfaceKind, keyType: nil, valueType: nil, }
var MutexType = &Type{ name: "Mutex", kind: MutexKind, keyType: nil, valueType: nil, }
var StringType = &Type{ name: StringTypeName, kind: StringKind, keyType: nil, valueType: nil, }
var StructType = &Type{ name: StructTypeName, kind: StructKind, }
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.
var UndefinedType = &Type{ name: UndefinedTypeName, kind: UndefinedKind, }
var VarArgsType = &Type{ name: "...", kind: VarArgsKind, }
var VoidType = &Type{ name: VoidTypeName, }
var WaitGroupType = &Type{ name: "WaitGroup", kind: WaitGroupKind, keyType: nil, valueType: nil, }
Functions ¶
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 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 GetBuiltinDeclaration ¶
func GetMetadata ¶
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 ¶
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 ¶
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 ¶
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 Normalize ¶
func Normalize(v1 interface{}, v2 interface{}) (interface{}, interface{})
Normalize accepts two different values and promotes them to the most compatable format.
func PackageForKind ¶
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 ¶
For a given structure, set a key/value in the metadata. The metadata member and it's map are created if necessary.
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 ¶
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 ¶
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 ¶
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 ¶
DeepEqual is a recursive compare with another Ego array. The recursive compare is performed on each member of the array.
func (*Array) Delete ¶
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 ¶
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 ¶
GetBytes returns the native byte array for this array, or nil if this is not a byte array.
func (*Array) GetSlice ¶
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 ¶
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) Make ¶
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 ¶
MarshalJSON converts the array representation to valid JSON and returns the data as a byte array.
func (*Array) Set ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) TypeString ¶
Generate a type description string for this array.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Structure of an Ego channel wrapper around Go channels.
func NewChannel ¶
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 ¶
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 ¶
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 ¶
Return a boolean value indicating if this channel is still open for business.
func (*Channel) Receive ¶
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.
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 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 ¶
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 ¶
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 ¶
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 ¶
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 (*Map) Set ¶
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 ¶
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 ¶
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) TypeString ¶
TypeString produces a human-readable string describing the map type in Ego native terms.
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 ¶
NewPackage creates a new, empty package definition.
func NewPackageFromMap ¶
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) Delete ¶
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 ¶
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 (*Package) IsEmpty ¶
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 ¶
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 ¶
Merge adds any entries from a package to the current package that do not already exist.
func (*Package) Set ¶
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 (*Package) SetImported ¶
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
func NewStructFromMap ¶
func NewStructOfTypeFromMap ¶
func (*Struct) AsType ¶
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) FieldNames ¶
func (*Struct) FieldNamesArray ¶
func (*Struct) FromBuiltinPackage ¶
func (*Struct) Get ¶
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 ¶
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) MarshalJSON ¶
func (*Struct) PackageType ¶
func (*Struct) SetAlways ¶
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 (*Struct) TypeString ¶
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
func NewInterfaceType ¶
func PackageType ¶
Construct a type for a package of the given name.
func PointerType ¶
Construct a type that is a pointer to the given type.
func StructureType ¶
Construct a structure type, with optional field definitions. You can later add additional fields using the AddField method.
func TypeDefinition ¶
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 (*Type) BaseType ¶
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) DefineField ¶
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 ¶
Helper function that defines a set of functions in a single call. Note this can only define functipoin values, not declarations.
func (Type) Field ¶
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 ¶
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 ¶
Retrieve a receiver function from the given type. Returns nil if there is no such function.
func (Type) FunctionNameList ¶
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 ¶
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 ¶
Return a flag indicating if the given type includes function definitions.
func (Type) InstanceOf ¶
func (Type) IsFloatType ¶
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 ¶
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 ¶
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 ¶
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) IsTypeDefinition ¶
Returns true if the current type is a type definition created by code (as opposed to a base type).
func (Type) IsUndefined ¶
Return true if the current type is the undefined type.
func (Type) KeyType ¶
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 ¶
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 ¶
Return the name of the type (not the same as the formatted string, but usually refers to a user-defined type name).
func (*Type) SetPackage ¶
func (Type) ShortTypeString ¶
FullTypeString returns the type by name but also includes the full underlying type definition.
func (Type) TypeString ¶
func (Type) ValidateFunctions ¶
ValidateFunctions compares the functions for a given type against the functions for an associated interface definition.
type TypeDeclaration ¶
This defines the token structure for various type declarations, including a model of that type and the type designation.