package entity import "fmt" import "git.tebibyte.media/fspl/fspl/errors" // 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. type LiteralInt struct { // Syntax Position errors.Position Value int // Semantics Ty Type } func (*LiteralInt) expression(){} func (this *LiteralInt) Type () Type { return this.Ty } func (this *LiteralInt) String () string { return fmt.Sprint(this.Value) } // 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. type LiteralFloat struct { // Syntax Position errors.Position Value float64 // Semantics Ty Type } func (*LiteralFloat) expression(){} func (this *LiteralFloat) Type () Type { return this.Ty } func (this *LiteralFloat) String () string { return fmt.Sprint(this.Value) } // 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. type LiteralString struct { // Syntax Position errors.Position ValueUTF8 string ValueUTF16 []uint16 ValueUTF32 []rune // Semantics Ty Type } func (*LiteralString) expression(){} func (this *LiteralString) Type () Type { return this.Ty } func (this *LiteralString) String () string { return Quote(this.ValueUTF8) } // 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. type LiteralArray struct { // Syntax Position errors.Position Elements []Expression // Semantics Ty Type } func (*LiteralArray) expression(){} func (this *LiteralArray) Type () Type { return this.Ty } func (this *LiteralArray) String () string { out := "(*" for _, element := range this.Elements { out += fmt.Sprint(" ", element) } return out + ")" } // 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. type LiteralStruct struct { // Syntax Position errors.Position Members []*Member // Semantics Ty Type MemberOrder []string MemberMap map[string] *Member } func (*LiteralStruct) expression(){} func (this *LiteralStruct) Type () Type { return this.Ty } func (this *LiteralStruct) String () string { out := "(." for _, member := range this.Members { out += fmt.Sprint(" ", member) } return out + ")" } // 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. type LiteralBoolean struct { // Syntax Position errors.Position Value bool // Semantics Ty Type } func (*LiteralBoolean) expression(){} func (this *LiteralBoolean) Type () Type { return this.Ty } func (this *LiteralBoolean) String () string { if this.Value { return "true" } else { return "false" } } type LiteralNil struct { // Syntax Position errors.Position // Semantics Ty Type } func (*LiteralNil) expression(){} func (this *LiteralNil) Type () Type { return this.Ty } func (this *LiteralNil) String () string { return "nil" }