entity

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package entity provides data representations of language concepts. They are used to construct syntax trees, and semantic trees. It additionally provides some utility functions to compare certain entities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatType

func FormatType(ty Type) string

FormatType returns a string representing a type. If the type is nil, it returns "Void".

func Quote

func Quote(in string) string

Quote puts quotes around a string to turn it into a string literal.

func TypesEqual

func TypesEqual(left, right Type) bool

TypesEqual checks if two types are equal to eachother, even if one or both are nil.

Types

type Access

type Access int

Access determines the external access control mode for a top-level entity.

const (
	// AccessPublic allows other modules to access an entity normally.
	AccessPublic Access = iota

	// AccessOpaque causes a top-level entity to appear opaque to other
	// units. Values of opaque types can be passed around, assigned to each-
	// other, and their methods can be called, but the implementation of the
	// type is entirely hidden. This access mode cannot be applied to
	// functions or methods.
	AccessOpaque

	// AccessPrivate disallows other modules from accessing a top-level
	// entity.
	AccessPrivate
)

func (Access) String

func (this Access) String() string

type Address

type Address string

Address is the address of a unit.

func (Address) Module

func (addr Address) Module() (string, bool)

Module returns the module associated with the address. If the address does does not point to a module, it returns "", false.

func (Address) Nickname

func (addr Address) Nickname() (string, bool)

Nickname automatically generates a nickname from the address, which is a valid Ident token. On failure "", false is returned. The nickname is generated according to the folowing rules:

  • If the name contains at least one dot, the last dot and everything after it is removed
  • All non-letter, non-numeric characters are removed, and any letters that were directly after them are converted to uppercase
  • All numeric digits at the start of the string are removed
  • The first character is converted to lowercase

func (Address) SourceFile

func (addr Address) SourceFile() (string, bool)

SourceFile returns the FSPL source file associated with the address. If the address does not point to an FSPL source file, it returns "", false.

func (Address) String

func (addr Address) String() string

func (Address) UUID

func (addr Address) UUID() uuid.UUID

UUID automatically generates a UUID from the address. It is the MD5 hash of the basename, with a space of the zero UUID.

type Assignment

type Assignment struct {
	Pos      errors.Position
	Location Expression
	Value    Expression
}

Assignment allows assigning the result of one expression to one or more location expressions. The assignment statement itself has no value and may not be assigned to anything. An assignment statement is never a valid location expression.

func (*Assignment) HasExplicitType

func (this *Assignment) HasExplicitType() bool

func (*Assignment) Position

func (this *Assignment) Position() errors.Position

func (*Assignment) String

func (this *Assignment) String() string

func (*Assignment) Type

func (this *Assignment) Type() Type

type BitCast

type BitCast struct {
	Pos   errors.Position
	Ty    Type
	Value Expression
}

Bit casting takes the raw data in memory of a certain value and re-interprets it as a value of another type. Since it contains inherent type information, it may be directly assigned to an interface. A bit cast is never a valid location expression.

func (*BitCast) HasExplicitType

func (this *BitCast) HasExplicitType() bool

func (*BitCast) Position

func (this *BitCast) Position() errors.Position

func (*BitCast) String

func (this *BitCast) String() string

func (*BitCast) Type

func (this *BitCast) Type() Type

type Block

type Block struct {
	// Syntax
	Pos   errors.Position
	Steps []Expression

	// Semantics
	Ty Type
	Scope
}

Block is an ordered collection of expressions that are evaluated sequentially. It has its own scope. The last expression in the block specifies the block's value, and any assignment rules of the block are equivalent to those of its last expression. A block is never a valid location expression.

func (*Block) HasExplicitType

func (this *Block) HasExplicitType() bool

func (*Block) Position

func (this *Block) Position() errors.Position

func (*Block) String

func (this *Block) String() string

func (*Block) Type

func (this *Block) Type() Type

type Break

type Break struct {
	// Syntax
	Pos   errors.Position
	Value Expression

	// Semantics
	Loop Breakable
}

Break allows breaking out of loops. It has no value and may not be assigned to anything. It is never a valid location expression.

func (*Break) HasExplicitType

func (this *Break) HasExplicitType() bool

func (*Break) Position

func (this *Break) Position() errors.Position

func (*Break) String

func (this *Break) String() string

func (*Break) Type

func (this *Break) Type() Type

type Breakable added in v0.3.0

type Breakable interface {
	Expression
	// contains filtered or unexported methods
}

Breakable is any expression that can be halted using a break.

type Call

type Call struct {
	// Syntax
	Pos          errors.Position
	UnitNickname string
	Name         string
	Arguments    []Expression

	// Semantics
	Function *Function
	Unit     uuid.UUID
}

Call calls upon the function specified by the first argument, passing the rest of the arguments to that function. The first argument must be a function name. The result of a call may be assigned to any type matching the function's return type. Since it contains inherent type information, it may be directly assigned to an interface. A call is never a valid location expression.

func (*Call) HasExplicitType

func (this *Call) HasExplicitType() bool

func (*Call) Position

func (this *Call) Position() errors.Position

func (*Call) String

func (this *Call) String() string

func (*Call) Type

func (this *Call) Type() Type

type Declaration

type Declaration struct {
	Pos  errors.Position
	Name string
	Ty   Type
}

Declaration binds a local identifier to a typed variable, but also acts as a variable expression allowing the variable to be used the moment it is defined. Since it contains inherent type information, it may be directly assigned to an interface. A declaration is always a valid location expression.

func (*Declaration) HasExplicitType

func (this *Declaration) HasExplicitType() bool

func (*Declaration) Position

func (this *Declaration) Position() errors.Position

func (*Declaration) String

func (this *Declaration) String() string

func (*Declaration) Type

func (this *Declaration) Type() Type

type DefaultCase added in v0.4.0

type DefaultCase struct {
	Pos errors.Position
	Expression
	Scope
}

DefaultCase represents the default case in a switch or match expression.

func (*DefaultCase) Position added in v0.4.0

func (this *DefaultCase) Position() errors.Position

func (*DefaultCase) String added in v0.4.0

func (this *DefaultCase) String() string

type Dependency

type Dependency struct {
	Pos      errors.Position
	Address  Address
	Nickname string
}

Dependency is a metadata dependency listing.

func (*Dependency) Position

func (this *Dependency) Position() errors.Position

func (*Dependency) String

func (this *Dependency) String() string

type Dereference

type Dereference struct {
	// Syntax
	Pos     errors.Position
	Pointer Expression

	// Semantics
	Ty Type
}

Pointer dereferencing allows retrieving the value of a pointer. It accepts any pointer. It may be assigned to any type matching the pointer's pointed type. Since it contains inherent type information, it may be directly assigned to an interface. A dereference is a valid location expression only if the pointer being dereferenced is.

func (*Dereference) HasExplicitType

func (this *Dereference) HasExplicitType() bool

func (*Dereference) Position

func (this *Dereference) Position() errors.Position

func (*Dereference) String

func (this *Dereference) String() string

func (*Dereference) Type

func (this *Dereference) Type() Type

type Directive

type Directive interface {
	fmt.Stringer

	// Position returns the position of the directive within its metadata
	// file.
	Position() errors.Position
	// contains filtered or unexported methods
}

Directive is a declaration within a module metadata file.

type Expression

type Expression interface {
	fmt.Stringer

	// Position returns the position of the expression within its source
	// file.
	Position() errors.Position

	// Type returns the type of the expression. The return value of this is
	// only considered valid if the expression has its semantic information
	// fields filled.
	Type() Type

	// HasExplicitType returns true if the expression carries inherent type
	// information. If it returns false, the expression must be given a type
	// to conform to. The value of this does not depend on semantic
	// information fields.
	HasExplicitType() bool
	// contains filtered or unexported methods
}

Expression is any construct that can be evaluated.

type For added in v0.3.0

type For struct {
	// Syntax
	Pos     errors.Position
	Index   *Declaration
	Element *Declaration
	Over    Expression
	Body    Expression

	// Semantics
	Ty Type
	Scope
}

For is a special kind of loop that evaluates an expression for each element of an array or slice. It accepts an index declaration and an element declaration, which are scoped to the loop's body and are set to the index of the current element and the element itself respectively at the beginning of each iteration. The assignment rules of a for statement are identical to that of a normal loop.

func (*For) HasExplicitType added in v0.3.0

func (this *For) HasExplicitType() bool

func (*For) Position added in v0.3.0

func (this *For) Position() errors.Position

func (*For) String added in v0.3.0

func (this *For) String() string

func (*For) Type added in v0.3.0

func (this *For) Type() Type

type Function

type Function struct {
	// Syntax
	Pos       errors.Position
	Acc       Access
	LinkName  string
	Signature *Signature
	Body      Expression

	// Semantics
	Unt uuid.UUID
	Scope
}

Function binds a global identifier and argument list to an expression which is evaluated each time the function is called. If no expression is specified, the function is marked as external. Functions have an argument list, where each argument is passed as a separate variable. They return one value. All of these are typed.

func (*Function) Access added in v0.3.0

func (this *Function) Access() Access

func (*Function) Position

func (this *Function) Position() errors.Position

func (*Function) String

func (this *Function) String() string

func (*Function) Unit

func (this *Function) Unit() uuid.UUID

type Hash added in v0.2.0

type Hash [8]byte

A hash represents a hash sum that fits within a uint64.

func HashType added in v0.2.0

func HashType(ty Type) Hash

HashType returns a hash representing a type. If the type is nil, it returns NewHash([]byte("TypeVoid"))

func NewHash added in v0.2.0

func NewHash(data []byte) Hash

NewHash creates a new truncated md5 hash using the specified data.

func (Hash) Number added in v0.2.0

func (hash Hash) Number() uint64

Number converts the hash into a uint64.

type IfElse

type IfElse struct {
	// Syntax
	Pos       errors.Position
	Condition Expression
	True      Expression
	False     Expression

	// Semantics
	Ty Type
}

If/else is a control flow branching expression that executes one of two expressions depending on a boolean value. If the value of the if/else is unused, the else expression need not be specified. It may be assigned to any type that satisfies the assignment rules of both the true and false expressions. An If/else is never a valid location expression.

func (*IfElse) HasExplicitType

func (this *IfElse) HasExplicitType() bool

func (*IfElse) Position

func (this *IfElse) Position() errors.Position

func (*IfElse) String

func (this *IfElse) String() string

func (*IfElse) Type

func (this *IfElse) Type() Type

type Key

type Key struct {
	Unit   uuid.UUID
	Name   string
	Method string
}

Key globally indexes top level entities in contexts where modules matter.

func (Key) Hash added in v0.2.0

func (key Key) Hash() Hash

Hash returns a representation of the hash of this key that fits within a uint64.

func (Key) LinkName

func (key Key) LinkName() string

LinkName returns the name that the entity it refers to will be given when compiled.

func (Key) String

func (key Key) String() string

func (Key) StripMethod

func (key Key) StripMethod() Key

StripMethod returns a copy of the key that refers to a type instead of a method.

type Length

type Length struct {
	// Syntax
	Pos   errors.Position
	Slice Expression

	// Semantics
	Ty Type
}

Length returns the length of an array or a slice. It always returns a value of type Index. A length is never a valid location expression.

func (*Length) HasExplicitType

func (this *Length) HasExplicitType() bool

func (*Length) Position

func (this *Length) Position() errors.Position

func (*Length) String

func (this *Length) String() string

func (*Length) Type

func (this *Length) Type() Type

type LiteralArray

type LiteralArray struct {
	// Syntax
	Pos      errors.Position
	Elements []Expression

	// Semantics
	Ty Type
}

LiteralArray is a composite array literal. It can contain any number of values. It can be assigned to any array type that:

  1. has an identical length, and
  2. who's element type can be assigned to by all the element values in the literal.

It cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralArray) HasExplicitType

func (this *LiteralArray) HasExplicitType() bool

func (*LiteralArray) Position

func (this *LiteralArray) Position() errors.Position

func (*LiteralArray) String

func (this *LiteralArray) String() string

func (*LiteralArray) Type

func (this *LiteralArray) Type() Type

type LiteralBoolean

type LiteralBoolean struct {
	// Syntax
	Pos   errors.Position
	Value bool

	// Semantics
	Ty Type
}

LiteralBoolean is a boolean literal. It may be either true or false. It can be assigned to any type derived from a boolean. It cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralBoolean) HasExplicitType

func (this *LiteralBoolean) HasExplicitType() bool

func (*LiteralBoolean) Position

func (this *LiteralBoolean) Position() errors.Position

func (*LiteralBoolean) String

func (this *LiteralBoolean) String() string

func (*LiteralBoolean) Type

func (this *LiteralBoolean) Type() Type

type LiteralFloat

type LiteralFloat struct {
	// Syntax
	Pos   errors.Position
	Value float64

	// Semantics
	Ty Type
}

LiteralFloat specifies a floating point value. It can be assigned to any type that is derived from a float. It cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralFloat) HasExplicitType

func (this *LiteralFloat) HasExplicitType() bool

func (*LiteralFloat) Position

func (this *LiteralFloat) Position() errors.Position

func (*LiteralFloat) String

func (this *LiteralFloat) String() string

func (*LiteralFloat) Type

func (this *LiteralFloat) Type() Type

type LiteralInt

type LiteralInt struct {
	// Syntax
	Pos   errors.Position
	Value int

	// Semantics
	Ty Type
}

LiteralInt specifies an integer value. It can be assigned to any type that is derived from an integer or a float, as long as the value fo the literal can fit within the range of the type. It cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralInt) HasExplicitType

func (this *LiteralInt) HasExplicitType() bool

func (*LiteralInt) Position

func (this *LiteralInt) Position() errors.Position

func (*LiteralInt) String

func (this *LiteralInt) String() string

func (*LiteralInt) Type

func (this *LiteralInt) Type() Type

type LiteralNil

type LiteralNil struct {
	// Syntax
	Pos errors.Position

	// Semantics
	Ty Type
}

TODO: document, put in spec, fully implement nil for slices interfaces etc

func (*LiteralNil) HasExplicitType

func (this *LiteralNil) HasExplicitType() bool

func (*LiteralNil) Position

func (this *LiteralNil) Position() errors.Position

func (*LiteralNil) String

func (this *LiteralNil) String() string

func (*LiteralNil) Type

func (this *LiteralNil) Type() Type

type LiteralString

type LiteralString struct {
	// Syntax
	Pos        errors.Position
	ValueUTF8  string
	ValueUTF16 []uint16
	ValueUTF32 []rune

	// Semantics
	Ty Type
}

LiteralString specifies a string value. It takes on different data representations depending on what the base type of what it is assigned to is structurally equivalent to:

  • Integer: Single unicode code point. When assigning to an integer, the string literal may not be longer than one code point, and that code point must fit in the integer.
  • Slice of 8 bit integers: UTF-8 string.
  • Slice of 16 bit integers: UTF-16 string.
  • Slice of 32 bit (or larger) integers: UTF-32 string.
  • Array of integers: The same as slices of integers, but the string literal must fit inside of the array.
  • Pointer to 8 bit integer: Null-terminated UTF-8 string (AKA C-string).

A string literal cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralString) HasExplicitType

func (this *LiteralString) HasExplicitType() bool

func (*LiteralString) Position

func (this *LiteralString) Position() errors.Position

func (*LiteralString) String

func (this *LiteralString) String() string

func (*LiteralString) Type

func (this *LiteralString) Type() Type

type LiteralStruct

type LiteralStruct struct {
	// Syntax
	Pos     errors.Position
	Members []*Member

	// Semantics
	Ty          Type
	MemberOrder []string
	MemberMap   map[string]*Member
}

LiteralStruct is a composite structure literal. It can contain any number of name:value pairs. It can be assigned to any struct type that:

  1. has at least the members specified in the literal
  2. who's member types can be assigned to by the corresponding member values in the literal.

It cannot be directly assigned to an interface because it contains no inherent type information. A value cast may be used for this purpose.

func (*LiteralStruct) HasExplicitType

func (this *LiteralStruct) HasExplicitType() bool

func (*LiteralStruct) Position

func (this *LiteralStruct) Position() errors.Position

func (*LiteralStruct) String

func (this *LiteralStruct) String() string

func (*LiteralStruct) Type

func (this *LiteralStruct) Type() Type

type Loop

type Loop struct {
	// Syntax
	Pos  errors.Position
	Body Expression

	// Semantics
	Ty Type
}

Loop is a control flow expression that repeats an expression until a break statement is called from within it. The break statement must be given a value if the value of the loop is used. Otherwise, it need not even have a break statement. The result of the loop may be assigned to any type that satisfies the assignment rules of all of its break statements. Loops may be nested, and break statements only apply to the closest containing loop. The value of the loop's expression is never used. A loop is never a valid location expression.

func (*Loop) HasExplicitType

func (this *Loop) HasExplicitType() bool

func (*Loop) Position

func (this *Loop) Position() errors.Position

func (*Loop) String

func (this *Loop) String() string

func (*Loop) Type

func (this *Loop) Type() Type

type Match added in v0.2.0

type Match struct {
	// Syntax
	Pos     errors.Position
	Value   Expression
	Cases   []*MatchCase
	Default *DefaultCase

	// Semantics
	Ty        Type
	CaseOrder []Hash
	CaseMap   map[Hash]*MatchCase
}

Match is a control flow branching expression that executes one of several case expressions depending on the input. It can be used to check the type of a union value. Each case takes the form of a declaration, and an associated expression. If the type of the union matches the type of the declaration in the case, the expression is executed and the value of the union is made available to it through the declaration. If the value of the match expression is used, all possible types in the union must be accounted for. It may be assigned to any type that satisfies the assignment rules of its first case.

func (*Match) HasExplicitType added in v0.2.0

func (this *Match) HasExplicitType() bool

func (*Match) Position added in v0.2.0

func (this *Match) Position() errors.Position

func (*Match) String added in v0.2.0

func (this *Match) String() string

func (*Match) Type added in v0.2.0

func (this *Match) Type() Type

type MatchCase added in v0.4.0

type MatchCase struct {
	Pos         errors.Position
	Declaration *Declaration
	Expression
	Scope
}

MatchCase represents a case in a match expression.

func (*MatchCase) Position added in v0.4.0

func (this *MatchCase) Position() errors.Position

func (*MatchCase) String added in v0.4.0

func (this *MatchCase) String() string

type Member

type Member struct {
	Pos   errors.Position
	Name  string
	Value Expression
}

Member is a syntactical construct that is used to list members in struct literals.

func (*Member) Position

func (this *Member) Position() errors.Position

func (*Member) String

func (this *Member) String() string

type MemberAccess

type MemberAccess struct {
	// Syntax
	Pos    errors.Position
	Source Expression
	Member string

	// Semantics
	Ty Type
}

Member access allows referring to a specific member of a value with a struct type. It accepts any struct type that contains the specified member name, and may be assigned to any type that matches the type of the selected member. Since it contains inherent type information, it may be directly assigned to an interface. A member access is a valid location expression only when the struct being accessed is.

func (*MemberAccess) HasExplicitType

func (this *MemberAccess) HasExplicitType() bool

func (*MemberAccess) Position

func (this *MemberAccess) Position() errors.Position

func (*MemberAccess) String

func (this *MemberAccess) String() string

func (*MemberAccess) Type

func (this *MemberAccess) Type() Type

type Metadata

type Metadata struct {
	Pos          errors.Position
	UUID         uuid.UUID
	Dependencies []*Dependency
}

Metadata represents a module metadata file.

func (*Metadata) Position

func (this *Metadata) Position() errors.Position

func (*Metadata) String

func (this *Metadata) String() string

type Method

type Method struct {
	// Syntax
	Pos       errors.Position
	Acc       Access
	TypeName  string
	LinkName  string
	Signature *Signature
	Body      Expression

	// Semantics
	Unt  uuid.UUID
	Type Type
	This *Declaration
	Scope
}

Method is like a function, except localized to a defined type. Methods are called on an instance of that type, and receive a pointer to that instance via the "this" variable when they are run. Method names are not globally unique, but are unique within the type they are defined on.

func (*Method) Access added in v0.3.0

func (this *Method) Access() Access

func (*Method) Position

func (this *Method) Position() errors.Position

func (*Method) String

func (this *Method) String() string

func (*Method) Unit

func (this *Method) Unit() uuid.UUID

type MethodCall

type MethodCall struct {
	// Syntax
	Pos       errors.Position
	Source    Expression
	Name      string
	Arguments []Expression

	// Semantics
	Method   *Method
	Behavior *Signature
	Ty       Type
}

MethodCall calls upon the method of the variable before the dot that is specified by the first argument, passing the rest of the arguments to the method. The first argument must be a method name. The result of a call may be assigned to any type matching the method's return type. Since it contains inherent type information, it may be directly assigned to an interface. A method call is never a valid location expression.

func (*MethodCall) HasExplicitType

func (this *MethodCall) HasExplicitType() bool

func (*MethodCall) Position

func (this *MethodCall) Position() errors.Position

func (*MethodCall) String

func (this *MethodCall) String() string

func (*MethodCall) Type

func (this *MethodCall) Type() Type

type Operation

type Operation struct {
	// Syntax
	Pos       errors.Position
	Operator  Operator
	Arguments []Expression

	// Semantics
	Ty Type
}

Operations perform math, logic, or bit manipulation on values. They accept values of the same type as the type they are being assigned to, except in special cases. Since they contain no inherent type information, they may not be assigned to interfaces. An operation is never a valid location expression.

func (*Operation) HasExplicitType

func (this *Operation) HasExplicitType() bool

func (*Operation) Position

func (this *Operation) Position() errors.Position

func (*Operation) String

func (this *Operation) String() string

func (*Operation) Type

func (this *Operation) Type() Type

type Operator

type Operator int

Operator determines which operation to apply to a value in an operation expression.

const (
	// Math
	OperatorAdd Operator = iota
	OperatorIncrement
	OperatorSubtract
	OperatorDecrement
	OperatorMultiply
	OperatorDivide
	OperatorModulo

	// Logic
	OperatorLogicalNot
	OperatorLogicalOr
	OperatorLogicalAnd
	OperatorLogicalXor

	// Bit manipulation
	OperatorNot
	OperatorOr
	OperatorAnd
	OperatorXor
	OperatorLeftShift
	OperatorRightShift

	// Comparison
	OperatorLess
	OperatorGreater
	OperatorLessEqual
	OperatorGreaterEqual
	OperatorEqual
)

func OperatorFromString

func OperatorFromString(str string) Operator

func (Operator) ResultsInBoolean

func (operator Operator) ResultsInBoolean() bool

ResultsInBoolean determines whether or not this operation will always result in a boolean value.

func (Operator) String

func (this Operator) String() string

type Reference

type Reference struct {
	// Syntax
	Pos   errors.Position
	Value Expression

	// Semantics
	Ty Type
}

Value referencing allows retrieving the location of a value in memory. It accepts any location expression, and can be assigned to any type that is a pointer to the location expression's type. Since it contains inherent type information, it can be directly assigned to an interface, although it doesn't make a whole lot of sense to do so because assigning a value to an interface automatically references it anyway. A reference is never a valid location expression.

func (*Reference) HasExplicitType

func (this *Reference) HasExplicitType() bool

func (*Reference) Position

func (this *Reference) Position() errors.Position

func (*Reference) String

func (this *Reference) String() string

func (*Reference) Type

func (this *Reference) Type() Type

type Return

type Return struct {
	// Syntax
	Pos   errors.Position
	Value Expression

	// Semantics
	Declaration TopLevel
}

Return allows terminating functions before they have reached their end. It accepts values that may be assigned to the function's return type. If a function does not return anything, the return statement does not accept a value. In all cases, return statements have no value and may not be assigned to anything. A return statement is never a valid location expression.

func (*Return) HasExplicitType

func (this *Return) HasExplicitType() bool

func (*Return) Position

func (this *Return) Position() errors.Position

func (*Return) String

func (this *Return) String() string

func (*Return) Type

func (this *Return) Type() Type

type Scope

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

Scope implements a scope.

func (*Scope) AddVariable

func (this *Scope) AddVariable(declaration *Declaration)

func (*Scope) OverVariables

func (this *Scope) OverVariables(callback func(*Declaration) bool)

func (*Scope) Variable

func (this *Scope) Variable(name string) *Declaration

type Scoped

type Scoped interface {
	// Variable returns the declaration of the variable with the given name.
	// If no variable is found in this scope, it returns nil. Only the scope
	// in this entity is searched.
	Variable(name string) *Declaration

	// AddVariable adds a variable to this entity's scope.
	AddVariable(declaration *Declaration)

	// OverVariables calls callback for each defined variable, stopping if
	// returns false.
	OverVariables(callback func(*Declaration) bool)
}

Scoped represents any entity that has its own scope.

type Signature

type Signature struct {
	// Syntax
	Pos       errors.Position
	Name      string
	Arguments []*Declaration
	Return    Type

	// Semantics
	Acc           Access
	Unt           uuid.UUID
	ArgumentOrder []string
	ArgumentMap   map[string]*Declaration
}

Signature is a function or method signature that is used in functions, methods, and specifying interface behaviors. It defines the type of a function.

func (*Signature) Access

func (this *Signature) Access() Access

func (*Signature) Equals

func (this *Signature) Equals(ty Type) bool

func (*Signature) Hash added in v0.2.0

func (this *Signature) Hash() Hash

func (*Signature) Position

func (this *Signature) Position() errors.Position

func (*Signature) String

func (this *Signature) String() string

func (*Signature) Unit

func (this *Signature) Unit() uuid.UUID

type Slice

type Slice struct {
	// Syntax
	Pos   errors.Position
	Slice Expression
	Start Expression
	End   Expression
}

Slice adjusts the start and end points of a slice relative to its current starting index, and returns an adjusted copy pointing to the same data. Any assignment rules of this expression are equivalent to those of the slice it is operating on. A slice is never a valid location expression.

func (*Slice) HasExplicitType

func (this *Slice) HasExplicitType() bool

func (*Slice) Position

func (this *Slice) Position() errors.Position

func (*Slice) String

func (this *Slice) String() string

func (*Slice) Type

func (this *Slice) Type() Type

type Subscript

type Subscript struct {
	// Syntax
	Pos    errors.Position
	Slice  Expression
	Offset Expression

	// Semantics
	Ty Type
}

Slice subscripting allows referring to a specific element of a slice. It accepts any slice, and any offset of type Size. It may be assigned to any type matching the slice's element type. Since it contains inherent type information, it may be directly assigned to an interface. A subscript is a valid location expression only if the array being subscripted is.

func (*Subscript) HasExplicitType

func (this *Subscript) HasExplicitType() bool

func (*Subscript) Position

func (this *Subscript) Position() errors.Position

func (*Subscript) String

func (this *Subscript) String() string

func (*Subscript) Type

func (this *Subscript) Type() Type

type Switch added in v0.4.0

type Switch struct {
	// Syntax
	Pos     errors.Position
	Value   Expression
	Cases   []*SwitchCase
	Default *DefaultCase

	// Semantics
	Ty        Type
	CaseOrder []int64
	CaseMap   map[int64]*SwitchCase
}

Switch is a control flow branching expression that executes one of several case expressions depending on the value of the input. It accepts any pointer or integer type. If the value of the switch expression is used, a default case must be present. It may be assigned to any type that satisfies the assignment rules of its first case.

func (*Switch) HasExplicitType added in v0.4.0

func (this *Switch) HasExplicitType() bool

func (*Switch) Position added in v0.4.0

func (this *Switch) Position() errors.Position

func (*Switch) String added in v0.4.0

func (this *Switch) String() string

func (*Switch) Type added in v0.4.0

func (this *Switch) Type() Type

type SwitchCase added in v0.4.0

type SwitchCase struct {
	Pos errors.Position
	Key Expression
	Expression
	Scope
}

SwitchCase represents a case in a switch expression.

func (*SwitchCase) Position added in v0.4.0

func (this *SwitchCase) Position() errors.Position

func (*SwitchCase) String added in v0.4.0

func (this *SwitchCase) String() string

type TopLevel

type TopLevel interface {
	fmt.Stringer

	// Position returns the position of the entity within its source file.
	Position() errors.Position

	// Access returns the access control mode of the entity.
	Access() Access

	// Unit returns the unit that the entity was defined in.
	Unit() uuid.UUID
	// contains filtered or unexported methods
}

TopLevel is any construct that is placed at the root of a file.

type Type

type Type interface {
	fmt.Stringer

	// Position returns the position of the type within its source file.
	Position() errors.Position

	// Equals returns whether this type is equivalent to another type.
	Equals(ty Type) bool

	// Access returns the access control mode of the type.
	Access() Access

	// Unit returns the unit that the type was defined in.
	Unit() uuid.UUID

	// Hash returns a hash of this type that fits within a uint64.
	Hash() Hash
	// contains filtered or unexported methods
}

Type is any type notation.

type TypeArray

type TypeArray struct {
	Pos     errors.Position
	Length  int
	Element Type

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeArray is a group of values of a given type stored next to eachother. The length of an array is fixed and is part of its type. Arrays are passed by value unless a pointer is used.

func (*TypeArray) Access

func (this *TypeArray) Access() Access

func (*TypeArray) Equals

func (this *TypeArray) Equals(ty Type) bool

func (*TypeArray) Hash added in v0.2.0

func (this *TypeArray) Hash() Hash

func (*TypeArray) Position

func (this *TypeArray) Position() errors.Position

func (*TypeArray) String

func (this *TypeArray) String() string

func (*TypeArray) Unit

func (this *TypeArray) Unit() uuid.UUID

type TypeFloat

type TypeFloat struct {
	Pos   errors.Position
	Width int

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeFloat represents any floating point type.

func (*TypeFloat) Access

func (this *TypeFloat) Access() Access

func (*TypeFloat) Equals

func (this *TypeFloat) Equals(ty Type) bool

func (*TypeFloat) Hash added in v0.2.0

func (this *TypeFloat) Hash() Hash

func (*TypeFloat) Position

func (this *TypeFloat) Position() errors.Position

func (*TypeFloat) String

func (this *TypeFloat) String() string

func (*TypeFloat) Unit

func (this *TypeFloat) Unit() uuid.UUID

type TypeInt

type TypeInt struct {
	Pos    errors.Position
	Width  int
	Signed bool

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeInt represents any signed or unsigned integer type.

func (*TypeInt) Access

func (this *TypeInt) Access() Access

func (*TypeInt) Equals

func (this *TypeInt) Equals(ty Type) bool

func (*TypeInt) Hash added in v0.2.0

func (this *TypeInt) Hash() Hash

func (*TypeInt) Position

func (this *TypeInt) Position() errors.Position

func (*TypeInt) String

func (this *TypeInt) String() string

func (*TypeInt) Unit

func (this *TypeInt) Unit() uuid.UUID

type TypeInterface

type TypeInterface struct {
	// Syntax
	Pos       errors.Position
	Behaviors []*Signature

	// Semantics
	Acc           Access
	Unt           uuid.UUID
	BehaviorOrder []string
	BehaviorMap   map[string]*Signature
}

TypeInterface is a polymorphic pointer that allows any value of any type through, except it must have at least the methods defined within the interface. Interfaces are always passed by reference. When assigning a value to an interface, it will be referenced automatically. When assigning a pointer to an interface, the pointer's reference will be used instead.

func (*TypeInterface) Access

func (this *TypeInterface) Access() Access

func (*TypeInterface) Equals

func (this *TypeInterface) Equals(ty Type) bool

func (*TypeInterface) Hash added in v0.2.0

func (this *TypeInterface) Hash() Hash

func (*TypeInterface) Position

func (this *TypeInterface) Position() errors.Position

func (*TypeInterface) String

func (this *TypeInterface) String() string

func (*TypeInterface) Unit

func (this *TypeInterface) Unit() uuid.UUID

type TypeNamed

type TypeNamed struct {
	// Syntax
	Pos          errors.Position
	UnitNickname string
	Name         string
	Type         Type

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeNamed refers to a user-defined or built in named type.

func (*TypeNamed) Access

func (this *TypeNamed) Access() Access

func (*TypeNamed) Equals

func (this *TypeNamed) Equals(ty Type) bool

func (*TypeNamed) Hash added in v0.2.0

func (this *TypeNamed) Hash() Hash

func (*TypeNamed) Position

func (this *TypeNamed) Position() errors.Position

func (*TypeNamed) String

func (this *TypeNamed) String() string

func (*TypeNamed) Unit

func (this *TypeNamed) Unit() uuid.UUID

type TypePointer

type TypePointer struct {
	Pos        errors.Position
	Referenced Type

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypePointer is a pointer to another type.

func (*TypePointer) Access

func (this *TypePointer) Access() Access

func (*TypePointer) Equals

func (this *TypePointer) Equals(ty Type) bool

func (*TypePointer) Hash added in v0.2.0

func (this *TypePointer) Hash() Hash

func (*TypePointer) Position

func (this *TypePointer) Position() errors.Position

func (*TypePointer) String

func (this *TypePointer) String() string

func (*TypePointer) Unit

func (this *TypePointer) Unit() uuid.UUID

type TypeSlice

type TypeSlice struct {
	Pos     errors.Position
	Element Type

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeSlice is a pointer to several values of a given type stored next to eachother. Its length is not built into its type and can be changed at runtime.

func (*TypeSlice) Access

func (this *TypeSlice) Access() Access

func (*TypeSlice) Equals

func (this *TypeSlice) Equals(ty Type) bool

func (*TypeSlice) Hash added in v0.2.0

func (this *TypeSlice) Hash() Hash

func (*TypeSlice) Position

func (this *TypeSlice) Position() errors.Position

func (*TypeSlice) String

func (this *TypeSlice) String() string

func (*TypeSlice) Unit

func (this *TypeSlice) Unit() uuid.UUID

type TypeStruct

type TypeStruct struct {
	// Syntax
	Pos     errors.Position
	Members []*Declaration

	// Semantics
	Acc         Access
	Unt         uuid.UUID
	MemberOrder []string
	MemberMap   map[string]*Declaration
}

TypeStruct is a composite type that stores keyed values. The positions of the values within the struct are decided at compile time, based on the order they are specified in. Structs are passed by value unless a pointer is used.

func (*TypeStruct) Access

func (this *TypeStruct) Access() Access

func (*TypeStruct) Equals

func (this *TypeStruct) Equals(ty Type) bool

func (*TypeStruct) Hash added in v0.2.0

func (this *TypeStruct) Hash() Hash

func (*TypeStruct) Position

func (this *TypeStruct) Position() errors.Position

func (*TypeStruct) String

func (this *TypeStruct) String() string

func (*TypeStruct) Unit

func (this *TypeStruct) Unit() uuid.UUID

type TypeUnion added in v0.2.0

type TypeUnion struct {
	// Syntax
	Pos     errors.Position
	Allowed []Type

	// Semantics
	Acc          Access
	Unt          uuid.UUID
	AllowedOrder []Hash
	AllowedMap   map[Hash]Type
}

TypeUnion is a polymorphic type that can hold any value as long as it is one of a list of allowed types. It is not a pointer. It holds the hash of the actual type of the value stored within it, followed by the value. The hash field is computed using the type's name, and the UUID that it was defined in. If it is not named, then the hash is computed using the structure of the type. The value field is always big enough to hold the largest type in the allowed list.

func (*TypeUnion) Access added in v0.2.0

func (this *TypeUnion) Access() Access

func (*TypeUnion) Equals added in v0.2.0

func (this *TypeUnion) Equals(ty Type) bool

func (*TypeUnion) Hash added in v0.2.0

func (this *TypeUnion) Hash() Hash

func (*TypeUnion) Position added in v0.2.0

func (this *TypeUnion) Position() errors.Position

func (*TypeUnion) String added in v0.2.0

func (this *TypeUnion) String() string

func (*TypeUnion) Unit added in v0.2.0

func (this *TypeUnion) Unit() uuid.UUID

type TypeWord

type TypeWord struct {
	Pos    errors.Position
	Signed bool

	// Semantics
	Acc Access
	Unt uuid.UUID
}

TypeWord represents an integer type of unspecified width. The optimal width is chosen based on the machine word size (32 on 32 bit systems, 64 on 64 bit systems, etc)

func (*TypeWord) Access

func (this *TypeWord) Access() Access

func (*TypeWord) Equals

func (this *TypeWord) Equals(ty Type) bool

func (*TypeWord) Hash added in v0.2.0

func (this *TypeWord) Hash() Hash

func (*TypeWord) Position

func (this *TypeWord) Position() errors.Position

func (*TypeWord) String

func (this *TypeWord) String() string

func (*TypeWord) Unit

func (this *TypeWord) Unit() uuid.UUID

type Typedef

type Typedef struct {
	// Syntax
	Pos  errors.Position
	Acc  Access
	Name string
	Type Type

	// Semantics
	Unt     uuid.UUID
	Methods map[string]*Method
}

Typedef binds a type to a global identifier.

func (*Typedef) Access added in v0.3.0

func (this *Typedef) Access() Access

func (*Typedef) Position

func (this *Typedef) Position() errors.Position

func (*Typedef) String

func (this *Typedef) String() string

func (*Typedef) Unit

func (this *Typedef) Unit() uuid.UUID

type ValueCast

type ValueCast struct {
	Pos   errors.Position
	Ty    Type
	Value Expression
}

Vaue casting converts a value of a certain type to another type. Since it contains inherent type information, it may be directly assigned to an interface. A value cast is never a valid location expression.

func (*ValueCast) HasExplicitType

func (this *ValueCast) HasExplicitType() bool

func (*ValueCast) Position

func (this *ValueCast) Position() errors.Position

func (*ValueCast) String

func (this *ValueCast) String() string

func (*ValueCast) Type

func (this *ValueCast) Type() Type

type Variable

type Variable struct {
	// Syntax
	Pos  errors.Position
	Name string

	// Semantics
	Declaration *Declaration
}

Variable specifies a named variable. It can be assigned to a type matching the variable declaration's type. Since it contains inherent type information, it may be directly assigned to an interface. A variable is always a valid location expression.

func (*Variable) HasExplicitType

func (this *Variable) HasExplicitType() bool

func (*Variable) Position

func (this *Variable) Position() errors.Position

func (*Variable) String

func (this *Variable) String() string

func (*Variable) Type

func (this *Variable) Type() Type

Jump to

Keyboard shortcuts

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