As a first hardware layer abstraction level, and to make addressing arithmetic between types as easy as possible, I propose this simple bitring-based type system, to which runtime values of the above kind are specialized:
bit
is the only atomic type and represents a value of either0
or1
.- A ring of
n
bit size is described with a simple integer constantn
and has degree1
.32
for example describes a bitring of size32
that can hold one of2**32
bit patterns and distinguishes between32
different keys of degree1
(0..31
). The elements of a bitring can be indexed with bitrings, whose value will be modulated by the ring size. - A
bit
is also a ring of size1
, which only accepts the value0
as key, and has degree1
. 0
describes a zero-element bitring of depth1
that accepts no keys and has degree0
.K * T
describes an multidimensional bitring of element typeT
, sizeK
and degreedegree(T)+1
, or the product of two rings.2 * 3 * 5
defines a 2-element ring of a 3-element ring of a 5-element ring of bits, or a ring of degree3
and size30
. The ring types30
and2 * 3 * 5
have the same size.*
is a non-commutative operator.T * K != K * T
, as keys need to be specified in order.*
is an irreducible operator.(64 * 64) * 32
describes a bitarray of degree2
with its top key being of degree2
as well.N ** T
describes a map of sizepow(sizeof(N),sizeof(T))
. The final type depends on the degree of provided arguments.2 ** 32
is equivalent to4294967296
.- All rings of same size are isomorphic to each other and can therefore be cast to each other without cost.
T @ K
describes indexing a bitarrayT
by key of typeK
. A key must have the same degree as the top ring type of the product.(2 * 3 * 5) @ 32
evaluates to3 * 5
.(2 * 3 * 5) @ 32 @ 32 @ 32
evaluates to1
.(64 * 64) * 32 @ (6 * 6)
evaluates to32
.inf
is a bitarray of degree1
and infinite length.a..b
describes a bitarray with a variable length between the two constant integers provided, both included....
describes a bitarray of unknown degree.... * ...
abstractly describes a polymorphic associative map permitting arbitrary keys.A | B | ...
describes a union of two or more bitarrays. The min/max size ismin(sizeof(A),sizeof(B))
andmax(sizeof(A),sizeof(B))
.A + B + ...
describes a tuple of two or more bitarrays.
Let's look at some LLVM or SPIR-V types and how they're equivalently described in this system. The alignment rules are vastly different, of course.
{}
orvoid
are equivalent to0
iN
is simplyN
; so booleans use1
, integers commonly use8
,16
,32
,64
.- Floats and doubles use
32
and64
. [T x N]
and<T x N>
are the same asN * T
. We do not distinguish between array or vector type.{A B C}
is the same asA + B + C
.- 64-bit pointers are perfectly described by
64
. Untyped main memory is of type2 ** 64 * 8
. - String constants are typically of type
N * 8
. - A RGBA8 layered image would use the type
L * H * W * 4 * 8
.