Documentation ¶
Overview ¶
experimental simplified type system
Defintions:
- A `byte` is the smallest addressable unit in the CPU, this does not need to be 8 bits, though it usually is. In rj32 it's 16 bits.
- A `word` is the largest value that can fit in a register. This can be the the same as the word size, as it is in rj32 (16 bits)
- A `pointer` can be larger than 1 word, if it is, generally an `int` will also be larger than 1 word. This is common on 8-bit systems.
- In general, though, you will want `int` and `uint` to be the same size as a word, but at least 16 bits.
TinyGo uses a system to compactly represent types in a way that can be embedded for runtime reflection. We use a very similar system here to optimize code reuse.
There are less than 32 basic types (19? plus some compiler specific ones) which can fit in 5 bits. These are the BasicTypes in the types package.
Extended types come in 8 other flavours. 4 of those flavours just decorate another type (chan interface pointer slice). 4 of them are more complex (func, array, map, struct).
As much as possible is packed into the Type code itself including all the basic types as well as decorated basic types, as long as none of them are named types. After that, the Type simply contains an ID for further information to be looked up in side tables, and it's fundamental Kind.
T = type kind K = map key type kind, chan direction, array size D = type decoration I = type index in side tables
An unnamed basic type, inc: empty struct, empty interface, `func()` 0000 0000 00TT TTT0
A named basic type IIII IIII IITT TTT0
An unnamed decorated basic type
- maps with basic types as both key and value have both specified
- channels have their direction specified as K
- if an array, and the array length fits in K bits
KKKK KKTT TTT0 DDD1
A named/extended decorated type IIII IIII III1 DDD1
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KindStrings ¶
func KindStrings() []string
KindStrings returns a slice of all String values of the enum
Types ¶
type Kind ¶
type Kind uint8
const ( Invalid Kind = iota // basic types B // bool I // int I8 I16 I32 I64 U // uint U8 U16 U32 U64 Uptr // uintptr F32 // float F64 Complex64 Complex128 Str // string UnsafePtr // unsafe.Pointer // types for untyped (constant) values CB // constant bool CI // constant int CR // constant rune CF // constant float CComplex // constant complex CStr // constant string CNil // constant nil CSR // flags Mem // memory Blank // blank variable _ // composite types Interface Struct Func Chan Ptr // pointer Slice Array Map NumTypes // aliases Byte = U8 Rune = I32 )
func KindString ¶
KindString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.