Types ===== Type compatibility ------------------ When LRL checks type compatibility, it will first check if both types have a name (and neither type is an alias). If so, the types are considered equal only if the names match. Otherwise, the structure of the types will be compared (e.g. it will be possible to assign an "int" to a "long", or two equals structs to each other). **TODO** Test aliases more thorougly **NOTE** should not be allowed to "cast" pointers from one named type to another through an unnamed structurally compatible type. perhaps change the rules to allow only casts of pointers in one direction? or not at all? Type qualifiers --------------- **TODO** Identifier types ---------------- **TODO** Builtin types ------------- There are several numeric types and a bool type. **NOTE** explain kinds of types, wrap around, etc. special types byte/uint8, eint, wuint/uint compatibility... **NOTE** short<=int<=long<=longlong **NOTE** float<=double etc. **NOTE** should byte be compatible with eint8? **NOTE** floating point formats have an implied bit in the coefficient
NameKindSigned?Wraps?Min BitsMax Bits
count Integer - word-sized   16
wcount Integer - word-sized  Yes 16
uint Integer - system size  16
wuint Integer - system size  16
int Integer - system sizeYes  15+1
eint Integer - system size  15+1
ushort Integer - system size  16
wushort Integer - system size  16
short Integer - system sizeYes  15+1
eshort Integer - system size  15+1
ulong Integer - system size  32
wulong Integer - system size  32
long Integer - system sizeYes  31+1
elong Integer - system size  31+1
ulonglong Integer - system size  64
wulonglongInteger - system size  64
longlong Integer - system sizeYes  63+1
elonglong Integer - system size  63+1
byte Integer - fixed size    88
char Integer - fixed size    88
uint8 Integer - fixed size    88
wuint8 Integer - fixed size  Yes 88
int8 Integer - fixed size Yes   7+17+1
eint8 Integer - fixed size    7+17+1
uint16 Integer - fixed size   1616
wuint16 Integer - fixed size  Yes 1616
int16 Integer - fixed size Yes  15+115+1
eint16 Integer - fixed size   15+115+1
uint32 Integer - fixed size   3232
wuint32 Integer - fixed size  Yes 3232
int32 Integer - fixed size Yes  31+131+1
eint32 Integer - fixed size   31+131+1
uint64 Integer - fixed size   6464
wuint64 Integer - fixed size  Yes 6464
int64 Integer - fixed size Yes  63+163+1
eint64 Integer - fixed size   63+163+1
uint128 Integer - fixed size   128128
wuint128 Integer - fixed size  Yes 128128
int128 Integer - fixed size Yes  127+1127+1
eint128 Integer - fixed size   127+1127+1
float Floating point - system sizeYes  32(1+23+8)
float16 Floating point - fixed size Yes  16(1+10+5)16
float32 Floating point - fixed size Yes  32(1+23+8)32
float64 Floating point - fixed size Yes  64(1+52+11)64
float80 Floating point - fixed size Yes  80(1+63+16)80
float128 Floating point - fixed size Yes  128(1+112+15)128
cfloat Floating point - system sizeYes  32(1+23+8)
cdouble Floating point - system sizeYes  64(1+52+11)
clongdoubleFloating point - system sizeYes  64(1+52+11)
bool Boolean   1+15
**TODO** Array types ----------- Syntax: elemtype#[size] elemtype#[size,size...] **TODO** **NOTE** the qualifier is placed before the element type, not before the #[ Bitfield types -------------- Syntax: basetype bits (bitfields...) Bitfield syntax: ident N bits ident N bits typeoverride ident **TODO** **NOTE** the base type is optional **NOTE** trailing comma allowed **NOTE** should be used carfully with shared/volatile Enumeration types ----------------- Syntax: basetype enum(name1=value1, name2=value2...) **TODO** **NOTE** the base type is optional **NOTE** the values are optional **NOTE** trailing comma allowed Function types -------------- Syntax: flags returntype() flags returntype(arguments....) **TODO** **NOTE** flags = noreturn, optional **NOTE** arguments may contain names also Optional types -------------- Syntax: type? **TODO** **NOTE** optional pointer types are stored without any extra overhead. other types, including "optional optional pointer types" require wrapping in a struct with a boolean flag before the actual value. Pointer types ------------- Syntax: type^ type+> type*> type+*> **TODO** Struct types ------------ Syntax: () (type1 name1) (type1 name1, type2 name2...) **TODO** **NOTE** names are optional **NOTE** trailing comma is allowed Union types ----------- Syntax: () (type1 name1) (type1 name1, type2 name2...) **TODO** **NOTE** names are optional **NOTE** trailing comma is allowed **TODO** it should be possible to have "locked down" unions where only one member can ever be accessed through its life-time (disallowing so called "type punning"). perhaps it should be the default (the alternative could be called e.g. "multiunion" or "punningunion") Parametric types ---------------- Syntax: identifiertype[T] identifiertype[T,U...] **TODO** **NOTE** type param don't have to be T and U. can be any identifier (and more than 1 character) any types --------- Syntax: any **TODO** **NOTE** can be any type EXCEPT function types! (perhaps we should have a "anyfunction" type?) **NOTE** can only be used in pointers private types ------------- Syntax: private **TODO**